Author: alink
Date: Thu May 22 02:43:18 2008
New Revision: 26762

URL: http://svn.gna.org/viewcvs/wesnoth?rev=26762&view=rev
Log:
Fix slow refresh of the titlescreen after closing simple dialogs.
(caused by the redraw + scaling of background when resolution is not 1024x768)
PS: still need to fix an useless redraw after the multiplayer dialogs

Modified:
    trunk/src/game.cpp
    trunk/src/titlescreen.cpp
    trunk/src/titlescreen.hpp

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=26762&r1=26761&r2=26762&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Thu May 22 02:43:18 2008
@@ -2410,6 +2410,8 @@
 
        LOG_CONFIG << "time elapsed: "<<  (SDL_GetTicks() - start_ticks) << " 
ms\n";
 
+       bool redraw_background = true;
+
        for(int first_time = true;;first_time = false){
         //init_config already processed the configs, so we don't need to do it 
for the
         //first loop pass.
@@ -2447,14 +2449,20 @@
                        continue; //Go to main menu
                }
 
-
-               gui::TITLE_RESULT res = game.is_loading() ? gui::LOAD_GAME : 
gui::TIP_NEXT;
-
-               while(res == gui::TIP_NEXT) {
-                       res = gui::show_title(game.disp(),tips_of_day);
+               gui::TITLE_RESULT res = game.is_loading() ? gui::LOAD_GAME : 
gui::NOTHING;
+
+               while(res == gui::NOTHING) {
+                       res = gui::show_title(game.disp(),tips_of_day, 
redraw_background);
+                       if (res == gui::REDRAW_BACKGROUND) {
+                               redraw_background = true;
+                               res = gui::NOTHING;
+                       } else {
+                               redraw_background = false;
+                       }
                }
 
                game_controller::RELOAD_GAME_DATA should_reload = 
game_controller::RELOAD_DATA;
+
                if(res == gui::QUIT_GAME) {
                        LOG_GENERAL << "quitting game...\n";
                        return 0;
@@ -2472,7 +2480,12 @@
                        }
                } else if(res == gui::MULTIPLAYER) {
                        if(game.play_multiplayer() == false) {
-                               continue;
+                               // Need a redraw because we can left the lobby 
without playing.
+                               // (the redraw is only useless when canceling 
the multiplayer dialog)
+                               // FIXME: game.play_multiplayer() always return 
false (why?),
+                               // perhaps change this to identify real 
"cancel" cases?
+                               redraw_background = true;
+                               continue;       
                        }
                } else if(res == gui::CHANGE_LANGUAGE) {
                        if(game.change_language() == true) {
@@ -2481,6 +2494,9 @@
                        continue;
                } else if(res == gui::EDIT_PREFERENCES) {
                        game.show_preferences();
+                       if (game.disp().video().modeChanged()) {
+                               redraw_background = true;
+                       }
                        continue;
                } else if(res == gui::SHOW_ABOUT) {
                        about::show_about(game.disp());
@@ -2498,6 +2514,7 @@
 #ifdef MAP_EDITOR
                } else if(res == gui::START_MAP_EDITOR) {
                        gui::show_error_message(game.disp(), "The map editor is 
not available. Yet.");
+                       //NOTE: will probably need a "redraw_background = true";
                        continue;
 #endif
                }
@@ -2508,6 +2525,9 @@
                else{
                        game.play_replay();
                }
+
+               // We played something, refresh background
+               redraw_background = true;
        }
 
        return 0;

Modified: trunk/src/titlescreen.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/titlescreen.cpp?rev=26762&r1=26761&r2=26762&view=diff
==============================================================================
--- trunk/src/titlescreen.cpp (original)
+++ trunk/src/titlescreen.cpp Thu May 22 02:43:18 2008
@@ -274,56 +274,34 @@
        }
 }
 
-namespace gui {
-
-//! Show titlepage with logo and background, menu-buttons and tip-of-the-day.
-//!
-//! After the page is shown, this routine waits
-//! for the user to click one of the menu-buttons,
-//! or a keypress.
-//!
-//! @param     screen                  surface to write on
-//! @param     tips_of_day             list of tips
-//! @param     ntip                    number of the tip to show
-//!
-//! @return    the value of the menu-item the user has choosen.
-//! @retval    see @ref TITLE_RESULT for possible values
-//!
-TITLE_RESULT show_title(game_display& screen, config& tips_of_day)
-{
-       cursor::set(cursor::NORMAL);
-
-       const preferences::display_manager disp_manager(&screen);
-       const hotkey::basic_handler key_handler(&screen);
-
-       const font::floating_label_context label_manager;
-
-       screen.video().modeChanged(); // resets modeChanged value
-
+//! Draw the map image background, revision number
+//! and fade the log the first time
+static void draw_background(game_display& screen)
+{
        bool fade_failed = false;
        do {
                int logo_x = game_config::title_logo_x * screen.w() / 1024,
-                   logo_y = game_config::title_logo_y * screen.h() / 768;
+                       logo_y = game_config::title_logo_y * screen.h() / 768;
 
                /*Select a random game_title*/
                std::vector<std::string> game_title_list =
-                   utils::split(game_config::game_title, ',', 
utils::STRIP_SPACES | utils::REMOVE_EMPTY);
+                       utils::split(game_config::game_title, ',', 
utils::STRIP_SPACES | utils::REMOVE_EMPTY);
 
                if(game_title_list.empty()) {
-                   ERR_CONFIG << "No title image defined\n";
+                       ERR_CONFIG << "No title image defined\n";
                } else {
-                   surface const title_surface(scale_surface(
-                           
image::get_image(game_title_list[rand()%game_title_list.size()]),
-                           screen.w(), screen.h()));
-               
-               
-                   if (title_surface.null()) {
+                       surface const title_surface(scale_surface(
+                               
image::get_image(game_title_list[rand()%game_title_list.size()]),
+                               screen.w(), screen.h()));
+
+
+                       if (title_surface.null()) {
                                ERR_DP << "Could not find title image\n";
-                   } else {
+                       } else {
                                screen.video().blit_surface(0, 0, 
title_surface);
                                update_rect(screen_area());
                                LOG_DP << "displayed title image\n";
-                   }
+                       }
                }
 
                fade_failed = !fade_logo(screen, logo_x, logo_y);
@@ -347,6 +325,37 @@
        }
 
        LOG_DP << "drew version number\n";
+}
+
+
+namespace gui {
+
+//! Show titlepage with logo and background, menu-buttons and tip-of-the-day.
+//!
+//! After the page is shown, this routine waits
+//! for the user to click one of the menu-buttons,
+//! or a keypress.
+//!
+//! @param     screen                  display object
+//! @param     tips_of_day             list of tips
+//! @param     redraw_background redraw background and buttons box, see 
draw_background()
+//!
+//! @return    the value of the menu-item the user has choosen.
+//! @retval    see @ref TITLE_RESULT for possible values
+//!
+TITLE_RESULT show_title(game_display& screen, config& tips_of_day, bool 
redraw_background)
+{
+       cursor::set(cursor::NORMAL);
+
+       const preferences::display_manager disp_manager(&screen);
+       const hotkey::basic_handler key_handler(&screen);
+
+       const font::floating_label_context label_manager;
+
+       screen.video().modeChanged(); // resets modeChanged value
+
+       if (redraw_background)
+               draw_background(screen);
 
        //- Texts for the menu-buttons.
        //- Members of this array must correspond to the enumeration 
TITLE_RESULT
@@ -418,8 +427,13 @@
 
        gui::dialog_frame main_frame(screen.video(), "", 
gui::dialog_frame::titlescreen_style, false);
        main_frame.layout(main_dialog_area);
-       main_frame.draw_background();
-       main_frame.draw_border();
+
+       // we only redraw transparent parts when asked,
+       // to prevent alpha growing
+       if (redraw_background) {
+               main_frame.draw_background();
+               main_frame.draw_border();
+       }
 
        for(b = 0; b != nbuttons; ++b) {
                buttons[b].set_width(max_width);
@@ -505,7 +519,7 @@
                // If the resolution has changed due to the user resizing the 
screen,
                // or from changing between windowed and fullscreen:
                if(screen.video().modeChanged()) {
-                       return TIP_NEXT;
+                       return REDRAW_BACKGROUND;
                }
 
                screen.delay(20);

Modified: trunk/src/titlescreen.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/titlescreen.hpp?rev=26762&r1=26761&r2=26762&view=diff
==============================================================================
--- trunk/src/titlescreen.hpp (original)
+++ trunk/src/titlescreen.hpp Thu May 22 02:43:18 2008
@@ -31,14 +31,16 @@
                     CHANGE_LANGUAGE, EDIT_PREFERENCES,
                                        SHOW_ABOUT,                     //!< 
Show credits
                                        QUIT_GAME,
-                                       TIP_PREVIOUS,   //!< Show previous 
tip-of-the-day
-                                       TIP_NEXT,               //!< Show next 
tip-of-the-day
+                                       TIP_PREVIOUS,           //!< Show 
previous tip-of-the-day
+                                       TIP_NEXT,                       //!< 
Show next tip-of-the-day
                                        SHOW_HELP,
-                                       BEG_FOR_UPLOAD          //!< Ask user 
for permission to upload game-stats as feedback
+                                       BEG_FOR_UPLOAD,         //!< Ask user 
for permission to upload game-stats as feedback
+                                       REDRAW_BACKGROUND,      //!< Used after 
an action needing a redraw (ex: fullscreen)
+                                       NOTHING                         //!< 
Default, nothing done, no redraw needed
                                  };
 
-//! Show titlepage with logo & background, menu-buttons and tip-of-day.
-TITLE_RESULT show_title(game_display& screen, config& tips_of_day);
+//! Show titlepage with logo & background, revision number, menu-buttons and 
tip-of-day.
+TITLE_RESULT show_title(game_display& screen, config& tips_of_day, bool 
redraw_background);
 }
 
 #endif


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to