Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TESTS_UTILS_FAKE_EVENT_SOURCE_HPP_INCLUDED
00017 #define TESTS_UTILS_FAKE_EVENT_SOURCE_HPP_INCLUDED
00018
00019 #include <boost/shared_ptr.hpp>
00020 #include <boost/noncopyable.hpp>
00021 #include <queue>
00022 #include "SDL.h"
00023
00024 #include "events.hpp"
00025
00026 namespace test_utils {
00027
00028
00029 template<class T>
00030 struct less_ptr {
00031 bool operator()(const T& a, const T& b) const
00032 {
00033 return (*a) < (*b);
00034 }
00035 };
00036
00037
00038
00039
00040 class event_node :
00041 public boost::noncopyable
00042 {
00043 size_t time_;
00044 bool fired_;
00045 protected:
00046 SDL_Event event_;
00047
00048 public:
00049 event_node(const size_t time, const SDL_Event& event);
00050 virtual ~event_node();
00051
00052
00053
00054
00055
00056 virtual void fire_event();
00057
00058
00059
00060 bool test_if_should_fire(const size_t frame_count ) const;
00061
00062
00063
00064
00065 bool is_fired() const;
00066
00067
00068
00069
00070 bool operator<(const event_node& o) const;
00071 };
00072
00073
00074
00075
00076
00077 class event_node_keyboard : public event_node {
00078 public:
00079 event_node_keyboard(size_t time, SDL_Event& event);
00080 virtual void fire_event();
00081 };
00082
00083
00084
00085
00086
00087 class event_node_mouse_motion : public event_node {
00088 public:
00089 event_node_mouse_motion(size_t time, SDL_Event& event);
00090 virtual void fire_event();
00091 };
00092
00093
00094
00095
00096
00097 class event_node_mouse_click : public event_node {
00098 public:
00099 event_node_mouse_click(size_t time, SDL_Event& event);
00100 virtual void fire_event();
00101 };
00102
00103 typedef boost::shared_ptr<event_node> event_node_ptr;
00104
00105
00106
00107
00108
00109
00110
00111
00112 class fake_event_source
00113 : public events::pump_monitor,
00114 public boost::noncopyable
00115 {
00116 size_t frame_count_;
00117 typedef std::priority_queue<event_node_ptr,std::vector<event_node_ptr>,less_ptr<event_node_ptr> > event_queue;
00118
00119 event_queue queue_;
00120
00121 SDL_Event make_key_event(Uint8 type, const SDLKey key, const SDLMod mod);
00122 SDL_Event make_mouse_click_event(const Uint8 type, const Uint8 button);
00123 public:
00124 fake_event_source();
00125 ~fake_event_source();
00126
00127
00128
00129
00130 void add_event(const size_t time, const SDL_Event& event);
00131
00132
00133
00134 void add_event(event_node_ptr new_node);
00135
00136
00137
00138
00139 void start();
00140
00141
00142
00143
00144 event_node_ptr press_key(const size_t time, const SDLKey key, const SDLMod mod = KMOD_NONE);
00145
00146
00147
00148 event_node_ptr release_key(const size_t time, const SDLKey key, const SDLMod mod =KMOD_NONE);
00149
00150
00151
00152
00153
00154 event_node_ptr type_key(const size_t time, const SDLKey key, const SDLMod mod =KMOD_NONE);
00155
00156
00157
00158
00159 event_node_ptr move_mouse(const size_t time, const int x, const int y);
00160
00161
00162
00163 event_node_ptr mouse_press(const size_t time, const Uint8 button);
00164
00165
00166
00167 event_node_ptr mouse_release(const size_t time, const Uint8 button);
00168
00169
00170
00171
00172
00173 event_node_ptr mouse_click(const size_t time, const Uint8 button);
00174
00175
00176
00177
00178 void process(events::pump_info& );
00179 };
00180 }
00181 #endif