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10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.
  3 
  4 #ifndef tools_sg_event
  5 #define tools_sg_event
  6 
  7 #include "../scast"
  8 #include "../S_STRING"
  9 #include "../typedefs"
 10 
 11 #ifdef TOOLS_MEM
 12 #include "../mem"
 13 #endif
 14 
 15 #define TOOLS_SG_EVENT_ID_CAST
 16 
 17 namespace tools {
 18 namespace sg {
 19 
 20 class event {
 21 public:
 22 #ifdef TOOLS_SG_EVENT_ID_CAST
 23   static cid id_class() {return 0;}
 24   virtual void* cast(cid) const = 0;
 25 #else
 26   virtual void* cast(const std::string&) const = 0;
 27 #endif
 28   virtual event* copy() const = 0;
 29 public:
 30 #ifdef TOOLS_MEM
 31   TOOLS_SCLASS(tools::sg::event)
 32 #endif
 33 public:
 34   event(){
 35 #ifdef TOOLS_MEM
 36     mem::increment(s_class().c_str());
 37 #endif
 38   }
 39   virtual ~event(){
 40 #ifdef TOOLS_MEM
 41     mem::decrement(s_class().c_str());
 42 #endif
 43   }
 44 public:
 45   event(const event&){
 46 #ifdef TOOLS_MEM
 47     mem::increment(s_class().c_str());
 48 #endif
 49   }
 50   event& operator=(const event&){return *this;}
 51 };
 52 
 53 class size_event : public event {
 54   typedef event parent;
 55 public:
 56 #ifdef TOOLS_SG_EVENT_ID_CAST
 57   static cid id_class() {return parent::id_class()+1;}
 58   virtual void* cast(cid a_class) const {
 59     if(void* p = cmp_cast<size_event>(this,a_class)) return p;
 60     return 0;
 61   }
 62 #else
 63   TOOLS_SCLASS(tools::sg::size_event)
 64   virtual void* cast(const std::string& a_class) const {
 65     if(void* p = cmp_cast<size_event>(this,a_class)) {return p;}
 66     return 0;
 67   }
 68 #endif
 69   virtual event* copy() const {return new size_event(*this);}
 70 public:
 71   size_event(unsigned int a_ow,unsigned int a_oh,
 72              unsigned int a_w,unsigned int a_h)
 73   :m_ow(a_ow)
 74   ,m_oh(a_oh)
 75   ,m_w(a_w)
 76   ,m_h(a_h)
 77   {}
 78   virtual ~size_event(){}
 79 public:
 80   size_event(const size_event& a_from)
 81   :event(a_from)
 82   ,m_ow(a_from.m_ow)
 83   ,m_oh(a_from.m_oh)
 84   ,m_w(a_from.m_w)
 85   ,m_h(a_from.m_h)
 86   {}
 87   size_event& operator=(const size_event& a_from){
 88     event::operator=(a_from);
 89     m_ow = a_from.m_ow;
 90     m_oh = a_from.m_oh;
 91     m_w = a_from.m_w;
 92     m_h = a_from.m_h;
 93     return *this;
 94   }
 95 public:
 96   unsigned int old_width() const {return m_ow;}
 97   unsigned int old_height() const {return m_oh;}
 98   unsigned int width() const {return m_w;}
 99   unsigned int height() const {return m_h;}
100 protected:
101   unsigned int m_ow;
102   unsigned int m_oh;
103   unsigned int m_w;
104   unsigned int m_h;
105 };
106 
107 class mouse_down_event : public event {
108   typedef event parent;
109 public:
110 #ifdef TOOLS_SG_EVENT_ID_CAST
111   static cid id_class() {return parent::id_class()+2;}
112   virtual void* cast(cid a_class) const {
113     if(void* p = cmp_cast<mouse_down_event>(this,a_class)) return p;
114     return 0;
115   }
116 #else
117   TOOLS_SCLASS(tools::sg::mouse_down_event)
118   virtual void* cast(const std::string& a_class) const {
119     if(void* p = cmp_cast<mouse_down_event>(this,a_class)) {return p;}
120     return 0;
121   }
122 #endif
123   virtual event* copy() const {return new mouse_down_event(*this);}
124 public:
125   mouse_down_event(int a_x,int a_y) //signed because of wall.
126   :m_x(a_x)
127   ,m_y(a_y)
128   {}
129   virtual ~mouse_down_event(){}
130 public:
131   mouse_down_event(const mouse_down_event& a_from)
132   :event(a_from)
133   ,m_x(a_from.m_x)
134   ,m_y(a_from.m_y)
135   {}
136   mouse_down_event& operator=(const mouse_down_event& a_from){
137     event::operator=(a_from);
138     m_x = a_from.m_x;
139     m_y = a_from.m_y;
140     return *this;
141   }
142 public:
143   int x() const {return m_x;}
144   int y() const {return m_y;}
145 protected:
146   int m_x;
147   int m_y;
148 };
149 
150 class mouse_up_event : public event {
151   typedef event parent;
152 public:
153 #ifdef TOOLS_SG_EVENT_ID_CAST
154   static cid id_class() {return parent::id_class()+3;}
155   virtual void* cast(cid a_class) const {
156     if(void* p = cmp_cast<mouse_up_event>(this,a_class)) return p;
157     return 0;
158   }
159 #else
160   TOOLS_SCLASS(tools::sg::mouse_up_event)
161   virtual void* cast(const std::string& a_class) const {
162     if(void* p = cmp_cast<mouse_up_event>(this,a_class)) {return p;}
163     return 0;
164   }
165 #endif
166   virtual event* copy() const {return new mouse_up_event(*this);}
167 public:
168   mouse_up_event(int a_x,int a_y) //signed because of wall.
169   :m_x(a_x)
170   ,m_y(a_y)
171   {}
172   virtual ~mouse_up_event(){}
173 public:
174   mouse_up_event(const mouse_up_event& a_from)
175   :event(a_from)
176   ,m_x(a_from.m_x)
177   ,m_y(a_from.m_y)
178   {}
179   mouse_up_event& operator=(const mouse_up_event& a_from){
180     event::operator=(a_from);
181     m_x = a_from.m_x;
182     m_y = a_from.m_y;
183     return *this;
184   }
185 public:
186   int x() const {return m_x;}
187   int y() const {return m_y;}
188 protected:
189   int m_x;
190   int m_y;
191 };
192 
193 class mouse_move_event : public event {
194   typedef event parent;
195 public:
196 #ifdef TOOLS_SG_EVENT_ID_CAST
197   static cid id_class() {return parent::id_class()+4;}
198   virtual void* cast(cid a_class) const {
199     if(void* p = cmp_cast<mouse_move_event>(this,a_class)) return p;
200     return 0;
201   }
202 #else
203   TOOLS_SCLASS(tools::sg::mouse_move_event)
204   virtual void* cast(const std::string& a_class) const {
205     if(void* p = cmp_cast<mouse_move_event>(this,a_class)) {return p;}
206     return 0;
207   }
208 #endif
209   virtual event* copy() const {return new mouse_move_event(*this);}
210 public:
211   mouse_move_event(int a_x,int a_y, //signed because of wall.
212                    int a_ox,int a_oy,
213                    bool a_touch) //for sliders.
214   :m_x(a_x)
215   ,m_y(a_y)
216   ,m_ox(a_ox)
217   ,m_oy(a_oy)
218   ,m_touch(a_touch)
219   {}
220   virtual ~mouse_move_event(){}
221 public:
222   mouse_move_event(const mouse_move_event& a_from)
223   :event(a_from)
224   ,m_x(a_from.m_x)
225   ,m_y(a_from.m_y)
226   ,m_ox(a_from.m_ox)
227   ,m_oy(a_from.m_oy)
228   ,m_touch(a_from.m_touch)
229   {}
230   mouse_move_event& operator=(const mouse_move_event& a_from){
231     event::operator=(a_from);
232     m_x = a_from.m_x;
233     m_y = a_from.m_y;
234 
235     m_ox = a_from.m_ox;
236     m_oy = a_from.m_oy;
237 
238     m_touch = a_from.m_touch;
239     return *this;
240   }
241 public:
242   int x() const {return m_x;}
243   int y() const {return m_y;}
244   int ox() const {return m_ox;}
245   int oy() const {return m_oy;}
246   bool is_touch() const {return m_touch;}
247 protected:
248   int m_x;
249   int m_y;
250   int m_ox;
251   int m_oy;  //+ = up.
252   // etc :
253   bool m_touch;
254 };
255 
256 class anim_event : public event {
257   typedef event parent;
258 public:
259 #ifdef TOOLS_SG_EVENT_ID_CAST
260   static cid id_class() {return parent::id_class()+5;}
261   virtual void* cast(cid a_class) const {
262     if(void* p = cmp_cast<anim_event>(this,a_class)) return p;
263     return 0;
264   }
265 #else
266   TOOLS_SCLASS(tools::sg::anim_event)
267   virtual void* cast(const std::string& a_class) const {
268     if(void* p = cmp_cast<anim_event>(this,a_class)) {return p;}
269     return 0;
270   }
271 #endif
272   virtual event* copy() const {return new anim_event(*this);}
273 public:
274   typedef uint64 num_t;
275   anim_event(num_t a_secs,num_t a_micro_secs)
276   :m_secs(a_secs),m_micro_secs(a_micro_secs)
277   ,m_some_found(false)
278   {}
279   virtual ~anim_event(){}
280 public:
281   anim_event(const anim_event& a_from)
282   :event(a_from)
283   ,m_secs(a_from.m_secs)
284   ,m_micro_secs(a_from.m_micro_secs)
285   ,m_some_found(a_from.m_some_found)
286   {}
287   anim_event& operator=(const anim_event& a_from){
288     event::operator=(a_from);
289     m_secs = a_from.m_secs;
290     m_micro_secs = a_from.m_micro_secs;
291     m_some_found = a_from.m_some_found;
292     return *this;
293   }
294 public:
295 /*
296   void set_time(num_t a_secs,num_t a_micro_secs) {
297     m_secs = a_secs;
298     m_micro_secs = a_micro_secs;
299   }
300 */
301   num_t seconds() const {return m_secs;}
302   num_t micro_seconds() const {return m_micro_secs;}
303 
304   void set_some_found(bool a_v) {m_some_found = a_v;}
305   bool some_found() const {return m_some_found;}
306 protected:
307   num_t m_secs;
308   num_t m_micro_secs;
309   bool m_some_found;
310 };
311 
312 class key_down_event : public event {
313   typedef event parent;
314 public:
315 #ifdef TOOLS_SG_EVENT_ID_CAST
316   static cid id_class() {return parent::id_class()+6;}
317   virtual void* cast(cid a_class) const {
318     if(void* p = cmp_cast<key_down_event>(this,a_class)) return p;
319     return 0;
320   }
321 #else
322   TOOLS_SCLASS(tools::sg::key_down_event)
323   virtual void* cast(const std::string& a_class) const {
324     if(void* p = cmp_cast<key_down_event>(this,a_class)) {return p;}
325     return 0;
326   }
327 #endif
328   virtual event* copy() const {return new key_down_event(*this);}
329 public:
330   key_down_event(key_code a_key)
331   :m_key(a_key)
332   {}
333   virtual ~key_down_event(){}
334 public:
335   key_down_event(const key_down_event& a_from)
336   :event(a_from)
337   ,m_key(a_from.m_key)
338   {}
339   key_down_event& operator=(const key_down_event& a_from){
340     event::operator=(a_from);
341     m_key = a_from.m_key;
342     return *this;
343   }
344 public:
345   key_code key() const {return m_key;}
346 protected:
347   key_code m_key;
348 };
349 
350 class key_up_event : public event {
351   typedef event parent;
352 public:
353 #ifdef TOOLS_SG_EVENT_ID_CAST
354   static cid id_class() {return parent::id_class()+7;}
355   virtual void* cast(cid a_class) const {
356     if(void* p = cmp_cast<key_up_event>(this,a_class)) return p;
357     return 0;
358   }
359 #else
360   TOOLS_SCLASS(tools::sg::key_up_event)
361   virtual void* cast(const std::string& a_class) const {
362     if(void* p = cmp_cast<key_up_event>(this,a_class)) {return p;}
363     return 0;
364   }
365 #endif
366   virtual event* copy() const {return new key_up_event(*this);}
367 public:
368   key_up_event(key_code a_key)
369   :m_key(a_key)
370   {}
371   virtual ~key_up_event(){}
372 public:
373   key_up_event(const key_up_event& a_from)
374   :event(a_from)
375   ,m_key(a_from.m_key)
376   {}
377   key_up_event& operator=(const key_up_event& a_from){
378     event::operator=(a_from);
379     m_key = a_from.m_key;
380     return *this;
381   }
382 public:
383   key_code key() const {return m_key;}
384 protected:
385   key_code m_key;
386 };
387 
388 class wheel_rotate_event : public event {
389   typedef event parent;
390 public:
391 #ifdef TOOLS_SG_EVENT_ID_CAST
392   static cid id_class() {return parent::id_class()+8;}
393   virtual void* cast(cid a_class) const {
394     if(void* p = cmp_cast<wheel_rotate_event>(this,a_class)) return p;
395     return 0;
396   }
397 #else
398   TOOLS_SCLASS(tools::sg::wheel_rotate_event)
399   virtual void* cast(const std::string& a_class) const {
400     if(void* p = cmp_cast<wheel_rotate_event>(this,a_class)) {return p;}
401     return 0;
402   }
403 #endif
404   virtual event* copy() const {return new wheel_rotate_event(*this);}
405 public:
406   wheel_rotate_event(int a_angle)
407   :m_angle(a_angle)
408   {}
409   virtual ~wheel_rotate_event(){}
410 public:
411   wheel_rotate_event(const wheel_rotate_event& a_from)
412   :event(a_from)
413   ,m_angle(a_from.m_angle)
414   {}
415   wheel_rotate_event& operator=(const wheel_rotate_event& a_from){
416     event::operator=(a_from);
417     m_angle = a_from.m_angle;
418     return *this;
419   }
420 public:
421   int angle() const {return m_angle;}
422 protected:
423   int m_angle;
424 };
425 
426 #ifdef TOOLS_SG_EVENT_ID_CAST
427 template <class FROM,class TO> inline TO* event_cast(FROM& a_o) {return id_cast<FROM,TO>(a_o);}
428 template <class FROM,class TO> inline const TO* event_cast(const FROM& a_o) {return id_cast<FROM,TO>(a_o);}
429 #else
430 template <class FROM,class TO> inline TO* event_cast(FROM& a_o) {return safe_cast<FROM,TO>(a_o);}
431 template <class FROM,class TO> inline const TO* event_cast(const FROM& a_o) {return safe_cast<FROM,TO>(a_o);}
432 #endif
433 
434 inline bool get_event_xy(const sg::event& a_event,int& a_x,int& a_y) {
435   typedef sg::event evt_t;
436   typedef sg::mouse_up_event up_evt_t;
437   typedef sg::mouse_down_event dn_evt_t;
438   if(const dn_evt_t* devt = event_cast<evt_t,dn_evt_t>(a_event)) {
439     a_x = devt->x();
440     a_y = devt->y();
441     return true;
442 
443   } else if(const up_evt_t* uevt = event_cast<evt_t,up_evt_t>(a_event)) {
444     a_x = uevt->x();
445     a_y = uevt->y();
446     return true;
447 
448   }
449   a_x = 0;
450   a_y = 0;
451   return false;
452 }
453 
454 }}
455 
456 #endif