Author: ilor
Date: Sat Oct  4 23:43:38 2008
New Revision: 29885

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29885&view=rev
Log:
add basic keyboard control in main menu, happens to be fr / bug #3835

Modified:
    trunk/src/titlescreen.cpp
    trunk/src/widgets/button.cpp
    trunk/src/widgets/button.hpp

Modified: trunk/src/titlescreen.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/titlescreen.cpp?rev=29885&r1=29884&r2=29885&view=diff
==============================================================================
--- trunk/src/titlescreen.cpp (original)
+++ trunk/src/titlescreen.cpp Sat Oct  4 23:43:38 2008
@@ -475,7 +475,9 @@
        LOG_DP << "drew buttons dialog\n";
 
        CKey key;
-
+       
+       size_t keyboard_button = nbuttons;      
+       bool key_processed = false;
 
        update_whole_screen();
        background_is_dirty_ = false;
@@ -507,17 +509,45 @@
                if(beg_button.pressed()) {
                        return BEG_FOR_UPLOAD;
                }
+               if (key[SDLK_UP]) {
+                       if (!key_processed) {
+                               buttons[keyboard_button].set_active(false);
+                               if (keyboard_button == 0) {
+                                       keyboard_button = nbuttons - 1;
+                               } else {
+                                       keyboard_button--;
+                               }
+                               key_processed = true;
+                               buttons[keyboard_button].set_active(true);
+                       }
+               } else if (key[SDLK_DOWN]) {
+                       if (!key_processed) {
+                               buttons[keyboard_button].set_active(false);
+                               if (keyboard_button > nbuttons - 1) {
+                                       keyboard_button = 0;
+                               } else {
+                                       keyboard_button++;
+                               }
+                               key_processed = true;
+                               buttons[keyboard_button].set_active(true);
+                       }
+               } else {
+                       key_processed = false;
+               }               
 
                events::raise_process_event();
                events::raise_draw_event();
 
                screen.flip();
 
-               if(key[SDLK_ESCAPE])
+               if (key[SDLK_ESCAPE])
                        return QUIT_GAME;
-               if(key[SDLK_F5])
+               if (key[SDLK_F5])
                        return RELOAD_GAME_DATA;
 
+               if (key[SDLK_RETURN] && keyboard_button < nbuttons) {
+                       return static_cast<TITLE_RESULT>(keyboard_button + 
TUTORIAL);
+               }
 
 
 

Modified: trunk/src/widgets/button.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/button.cpp?rev=29885&r1=29884&r2=29885&view=diff
==============================================================================
--- trunk/src/widgets/button.cpp (original)
+++ trunk/src/widgets/button.cpp Sat Oct  4 23:43:38 2008
@@ -152,6 +152,17 @@
        STATE new_state = check ? PRESSED : NORMAL;
        if (state_ != new_state) {
                state_ = new_state;
+               set_dirty();
+       }
+}
+
+void button::set_active(bool active)
+{
+       if ((state_ == NORMAL) && active) {
+               state_ = ACTIVE;
+               set_dirty();
+       } else if ((state_ == ACTIVE) && !active) {
+               state_ = NORMAL;
                set_dirty();
        }
 }

Modified: trunk/src/widgets/button.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/widgets/button.hpp?rev=29885&r1=29884&r2=29885&view=diff
==============================================================================
--- trunk/src/widgets/button.hpp (original)
+++ trunk/src/widgets/button.hpp Sat Oct  4 23:43:38 2008
@@ -41,6 +41,7 @@
 
        virtual ~button() {}
        void set_check(bool check);
+       void set_active(bool active);
        bool checked() const;
 
        void set_label(const std::string& val);


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

Reply via email to