mail[Wesnoth-commits] r28317 - in /trunk/src: tests/utils/fake_event_source.cpp tests/utils/fake_event_source.hpp wesconfig.h


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by paniemin on August 04, 2008 - 09:27:
Author: suokko
Date: Mon Aug  4 09:27:20 2008
New Revision: 28317

URL: http://svn.gna.org/viewcvs/wesnoth?rev=28317&view=rev
Log:
* Added support for fake mouse events in unit tests
* fixed warning about redefined preprocessor macro in wesconfig.h

Modified:
    trunk/src/tests/utils/fake_event_source.cpp
    trunk/src/tests/utils/fake_event_source.hpp
    trunk/src/wesconfig.h

Modified: trunk/src/tests/utils/fake_event_source.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_event_source.cpp?rev=28317&r1=28316&r2=28317&view=diff
==============================================================================
--- trunk/src/tests/utils/fake_event_source.cpp (original)
+++ trunk/src/tests/utils/fake_event_source.cpp Mon Aug  4 09:27:20 2008
@@ -71,6 +71,20 @@
        {
                SDL_WarpMouse(event_.motion.x,event_.motion.y);
        }
+
+       event_node_mouse_click::event_node_mouse_click(size_t time, 
SDL_Event& event) : event_node(time,event)
+       {}
+       void event_node_mouse_click::fire_event()
+       {
+               // We have to use temporaries because of difference
+               // in types for mouse position.
+               int x, y;
+               SDL_GetMouseState(&x, &y);
+               event_.button.x = x;
+               event_.button.y = y;
+               event_node::fire_event();
+       }
+
 
        fake_event_source::fake_event_source() : frame_count_(0)
        {
@@ -131,6 +145,34 @@
                return new_move;
        }
 
+       SDL_Event fake_event_source::make_mouse_click_event(const Uint8 type, 
const Uint8 button)
+       {
+               SDL_Event event;
+               event.type = type;
+               if (type == SDL_MOUSEBUTTONDOWN)
+                       event.button.state = SDL_PRESSED;
+               else
+                       event.button.state = SDL_RELEASED;
+               event.button.button = button;
+               return event;
+       }
+
+       event_node_ptr fake_event_source::mouse_press(const size_t time, 
const Uint8 button)
+       {
+               SDL_Event event = make_mouse_click_event(SDL_MOUSEBUTTONDOWN, 
button);
+               event_node_ptr new_click(new event_node_mouse_click(time, 
event));
+               add_event(new_click);
+               return new_click;
+       }
+
+       event_node_ptr fake_event_source::mouse_release(const size_t time, 
const Uint8 button)
+       {
+               SDL_Event event = make_mouse_click_event(SDL_MOUSEBUTTONDOWN, 
button);
+               event_node_ptr new_click(new event_node_mouse_click(time, 
event));
+               add_event(new_click);
+               return new_click;
+       }
+
        event_node_ptr fake_event_source::press_key(const size_t time, const 
SDLKey key, const SDLMod mod)
        {
                SDL_Event event = make_key_event(SDL_KEYDOWN, key, mod);

Modified: trunk/src/tests/utils/fake_event_source.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/tests/utils/fake_event_source.hpp?rev=28317&r1=28316&r2=28317&view=diff
==============================================================================
--- trunk/src/tests/utils/fake_event_source.hpp (original)
+++ trunk/src/tests/utils/fake_event_source.hpp Mon Aug  4 09:27:20 2008
@@ -48,12 +48,19 @@
                event_node(const size_t time, const SDL_Event& event);
                virtual ~event_node();
 
+               /**
+                * Used to fire sdl event stored in this object.
+                * Child class may extend or override functionality
+                **/
                virtual void fire_event();
                /**
-                * @return true if this should stop firing events
+                * Test if this event should fire now
                 **/
                bool test_if_should_fire(const size_t frame_count ) const;
 
+               /**
+                * @return true if this event has fired
+                **/
                bool is_fired() const;
 
                /**
@@ -62,15 +69,33 @@
                bool operator<(const event_node& o) const;
        };
 
+       /**
+        * modifies SDL_GetKeyState table to have 
+        * correct state.
+        **/
        class event_node_keyboard : public event_node {
                public:
                        event_node_keyboard(size_t time, SDL_Event& event);
                        virtual void fire_event();
        };
 
+       /**
+        * Uses special SDL_WarpMouse function to
+        * generate mouse move events
+        **/
        class event_node_mouse_motion : public event_node {
                public:
                        event_node_mouse_motion(size_t time, SDL_Event& 
event);
+                       virtual void fire_event();
+       };
+
+       /**
+        * Used to create SDL_MOUSEBUTTONDOWN/UP events
+        * with correct x,y values
+        **/
+       class event_node_mouse_click : public event_node {
+               public:
+                       event_node_mouse_click(size_t time, SDL_Event& event);
                        virtual void fire_event();
        };
 
@@ -93,20 +118,50 @@
                        event_queue queue_;
 
                        SDL_Event make_key_event(Uint8 type, const SDLKey 
key, const SDLMod mod);
+                       SDL_Event make_mouse_click_event(const Uint8 type, 
const Uint8 button);
                public:
                        fake_event_source();
                        ~fake_event_source();
+
+                       /**
+                        * adds a generic event to queue
+                        **/
                        void add_event(const size_t time, const SDL_Event& 
event);
+                       /**
+                        * adds any type of event to queue
+                        **/
                        void add_event(event_node_ptr new_node);
+
+                       /**
+                        * Sets event time source back to zero
+                        **/
                        void start();
 
+                       /**
+                        * adds keyboard press event to queue
+                        **/
                        event_node_ptr press_key(const size_t time, const 
SDLKey key, const SDLMod mod = KMOD_NONE);
+                       /**
+                        * adds keyboard release event to queue
+                        **/
                        event_node_ptr release_key(const size_t time, const 
SDLKey key, const SDLMod mod =KMOD_NONE);
 
+                       /**
+                        * Adds mouse motion event to queue
+                        **/
                        event_node_ptr move_mouse(const size_t time, const 
int x, const int y);
+                       /**
+                        * adds mouse button click event to queue
+                        **/
                        event_node_ptr mouse_press(const size_t time, const 
Uint8 button);
+                       /**
+                        * adds mouse button realease event to queue
+                        **/
                        event_node_ptr mouse_release(const size_t time, const 
Uint8 button);
 
+                       /**
+                        * Called by events::pump() to fire events
+                        **/
                        void process(events::pump_info& /*info*/);
        };
 }

Modified: trunk/src/wesconfig.h
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/wesconfig.h?rev=28317&r1=28316&r2=28317&view=diff
==============================================================================
--- trunk/src/wesconfig.h (original)
+++ trunk/src/wesconfig.h Mon Aug  4 09:27:20 2008
@@ -22,8 +22,12 @@
 #  define LOCALEDIR "translations"
 # endif
 #endif
+#ifndef VERSION
 #define VERSION "1.5.2+svn"
+#endif
+#ifndef PACKAGE
 #define PACKAGE "wesnoth"
+#endif
 
 /**
  * Some older savegames of Wesnoth cannot be loaded anymore,




Related Messages


Powered by MHonArc, Updated Mon Aug 04 09:40:35 2008