Exemple #1
0
void menu::draw_contents()
{
	
	// KP: now draw a nice frame!
	SDL_Rect frame_rect = inner_location();
	gui::dialog_frame f(video(), "", gui::dialog_frame::preview_style, false);
	f.layout(frame_rect);
//	f.draw_background();
	f.draw_border();
	
	
	SDL_Rect heading_rect = inner_location();
	heading_rect.h = heading_height();
	style_->draw_row(*this,0,heading_rect,HEADING_ROW);
	
	// KP: make sure to clip
	SDL_Rect content_rect = inner_location();
	content_rect.y += heading_rect.h;
	content_rect.h -= heading_rect.h;
	clip_rect_setter clippy(content_rect);
	

	for(size_t i = 0; i != item_pos_.size(); ++i) {
		style_->draw_row(*this,item_pos_[i],get_item_rect(i),
			 (!out_ && item_pos_[i] == selected_) ? SELECTED_ROW : NORMAL_ROW);
	}
}
void progress_bar::draw_contents()
{
	surface surf = video().getSurface();
	SDL_Rect area = location();

	if(area.w >= 2 && area.h >= 2) {
		int fcr =  21, fcg =  53, fcb =  80;		// RGB-values for finished piece.
		int bcr =   0, bcg =   0, bcb =   0;		// Border color.
		int gcr = 255, gcg = 255, gcb = 255;		// Groove color.
		int	lightning_thickness = 2;
		static const SDL_Color selected_text_color = {0xCC,0xCC,0xCC,0};

		SDL_Rect inner_area = create_rect(area.x + 1
				, area.y + 1
				, area.w - 2
				, area.h - 2);

		sdl_fill_rect(surf,&area,SDL_MapRGB(surf->format,bcr,bcg,bcb));
		sdl_fill_rect(surf,&inner_area,SDL_MapRGB(surf->format,gcr,gcg,gcb));

		inner_area.w = (inner_area.w*progress_)/100;
		sdl_fill_rect(surf,&inner_area,SDL_MapRGB(surf->format,fcr,fcg,fcb));

		SDL_Rect lightning = inner_area;
		lightning.h = lightning_thickness;
		//we add 25% of white to the color of the bar to simulate a light effect
		sdl_fill_rect(surf,&lightning,SDL_MapRGB(surf->format,(fcr*3+255)/4,(fcg*3+255)/4,(fcb*3+255)/4));
		lightning.y = inner_area.y+inner_area.h-lightning.h;
		//remove 50% of color to simulate a shadow effect
		sdl_fill_rect(surf,&lightning,SDL_MapRGB(surf->format,fcr/2,fcg/2,fcb/2));

		const std::string text = text_.empty() ? str_cast(progress_) + "%" :
		                         text_ + " (" + str_cast(progress_) + "%)";
		SDL_Rect text_area = font::text_area(text,font::SIZE_NORMAL);

		text_area.x = area.x + area.w/2 - text_area.w/2;
		text_area.y = area.y + area.h/2 - text_area.h/2;

		font::draw_text(
			&video(),
			location(),
			font::SIZE_NORMAL,
			font::BLACK_COLOR,
			text,
			text_area.x,
			text_area.y
		);

		// Draw a white text section for the highlighted area
		// of the bar
		SDL_Rect selected_text_location = location();
		selected_text_location.w = inner_area.w;
		selected_text_location.h = inner_area.h;
		{
			clip_rect_setter clippy(surf, &selected_text_location);
			font::draw_text(
				&video(),
				selected_text_location,
				font::SIZE_NORMAL,
				selected_text_color,
				text,
				text_area.x,
				text_area.y
			);
		}
	}

	update_rect(location());
}