예제 #1
0
void ttitle_screen::update_tip(twindow& window, const bool previous)
{
	next_tip_of_day(tips_, previous);
	const config *tip = get_tip_of_day(tips_);
	assert(tip);

	find_widget<tlabel>(&window, "tip", false).set_label((*tip)["text"]);
	find_widget<tlabel>(&window, "source", false).set_label((*tip)["source"]);

	/**
	 * @todo Convert the code to use a multi_page so the invalidate is not
	 * needed.
	 */
	window.invalidate_layout();
}
예제 #2
0
/**
 *  Show one tip-of-the-day in a frame on the titlescreen.
 *  This frame has 2 buttons: Next-Tip, and Show-Help.
 */
static void draw_tip_of_day(CVideo& screen,
							config& tips_of_day,
							const gui::dialog_frame::style& style,
							const SDL_Rect* const main_dialog_area
							)
{
	if(preferences::show_tip_of_day() == false) {
		return;
	}
	
    // Restore the previous tip of day area to its old state (section of the title image).
    //tip_of_day_restorer.restore();
		
    // Draw tip of the day
    const config* tip = get_tip_of_day(tips_of_day);
    if(tip != NULL) {
    	int tip_width = main_dialog_area->w; //game_config::title_tip_width * screen.w() / 1024;
		
		try {
	        const std::string& text =
			font::word_wrap_text((*tip)["text"], font::SIZE_NORMAL, tip_width);
			const std::string& source =
			font::word_wrap_text((*tip)["source"], font::SIZE_NORMAL, tip_width);
			
//			const int pad = game_config::title_tip_padding;
			
#ifdef __IPAD__
			const int pad = 10;
#else
			const int pad = 5;
#endif
			
			SDL_Rect area = font::text_area(text,font::SIZE_NORMAL);
			area.w = tip_width;
			SDL_Rect source_area = font::text_area(source, font::SIZE_NORMAL, TTF_STYLE_ITALIC);
			area.w = std::max<size_t>(area.w, source_area.w) + 2*pad;
			//area.x = main_dialog_area->x; // - (game_config::title_tip_x * screen.w() / 1024) - area.w;
			//area.y = main_dialog_area->y + (main_dialog_area->h - area.h)/2;
			
			SDL_Rect total_area;
			total_area.w = area.w;
			total_area.h = area.h + source_area.h + 3*pad;
			total_area.x = main_dialog_area->x;
			total_area.y = main_dialog_area->y + (main_dialog_area->h - total_area.h)/2;

			source_area.y = total_area.y + area.h + pad;
			
						
			// Note: The buttons' locations need to be set before the dialog frame is drawn.
			// Otherwise, when the buttons restore their area, they
			// draw parts of the old dialog frame at their old locations.
			// This way, the buttons draw a part of the title image,
			// because the call to restore above restored the area
			// of the old tip of the day to its initial state (the title image).
//			int button_x = area.x + area.w - next_tip_button->location().w - pad;
//			int button_y = area.y + area.h - pad - next_tip_button->location().h;
//			next_tip_button->set_location(button_x, button_y);
//			next_tip_button->set_dirty(); //force redraw even if location did not change.
			
//			button_x -= previous_tip_button->location().w + pad;
//			previous_tip_button->set_location(button_x, button_y);
//			previous_tip_button->set_dirty();
			
//			button_x = area.x + pad;
//			if (help_tip_button != NULL)
//			{
//				help_tip_button->set_location(button_x, button_y);
//				help_tip_button->set_dirty();
//			}
			
			gui::dialog_frame tip_frame(screen, "", gui::dialog_frame::titlescreen_style, false);
			SDL_Rect borderRect = total_area;
			tip_frame.layout(borderRect);	
			tip_frame.draw_background();
			tip_frame.draw_border();
			
			
//			gui::dialog_frame f(screen, "", style, false);
//			tip_of_day_restorer = surface_restorer(&screen.video(), f.layout(area).exterior);
//			f.draw_background();
//			f.draw_border();
			
			font::draw_text(&screen, total_area, font::SIZE_NORMAL, font::NORMAL_COLOUR,
							text, total_area.x + pad, total_area.y + pad);

			font::draw_text(&screen, total_area, font::SIZE_NORMAL, font::NORMAL_COLOUR,
							source, total_area.x + total_area.w - source_area.w - pad,
							source_area.y,
							false, TTF_STYLE_ITALIC);
		} catch (utils::invalid_utf8_exception&) {
			LOG_STREAM(err, engine) << "Invalid utf-8 found, tips of day aren't drawn.\n";
			return;
		}
		
//	    LOG_DP << "drew tip of day\n";
	}
}