Warning, /include/Geant4/tools/sg/event is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_event
0005 #define tools_sg_event
0006
0007 #include "../scast"
0008 #include "../S_STRING"
0009 #include "../typedefs"
0010
0011 #ifdef TOOLS_MEM
0012 #include "../mem"
0013 #endif
0014
0015 #define TOOLS_SG_EVENT_ID_CAST
0016
0017 namespace tools {
0018 namespace sg {
0019
0020 class event {
0021 public:
0022 #ifdef TOOLS_SG_EVENT_ID_CAST
0023 static cid id_class() {return 0;}
0024 virtual void* cast(cid) const = 0;
0025 #else
0026 virtual void* cast(const std::string&) const = 0;
0027 #endif
0028 virtual event* copy() const = 0;
0029 public:
0030 #ifdef TOOLS_MEM
0031 TOOLS_SCLASS(tools::sg::event)
0032 #endif
0033 public:
0034 event(){
0035 #ifdef TOOLS_MEM
0036 mem::increment(s_class().c_str());
0037 #endif
0038 }
0039 virtual ~event(){
0040 #ifdef TOOLS_MEM
0041 mem::decrement(s_class().c_str());
0042 #endif
0043 }
0044 public:
0045 event(const event&){
0046 #ifdef TOOLS_MEM
0047 mem::increment(s_class().c_str());
0048 #endif
0049 }
0050 event& operator=(const event&){return *this;}
0051 };
0052
0053 class size_event : public event {
0054 typedef event parent;
0055 public:
0056 #ifdef TOOLS_SG_EVENT_ID_CAST
0057 static cid id_class() {return parent::id_class()+1;}
0058 virtual void* cast(cid a_class) const {
0059 if(void* p = cmp_cast<size_event>(this,a_class)) return p;
0060 return 0;
0061 }
0062 #else
0063 TOOLS_SCLASS(tools::sg::size_event)
0064 virtual void* cast(const std::string& a_class) const {
0065 if(void* p = cmp_cast<size_event>(this,a_class)) {return p;}
0066 return 0;
0067 }
0068 #endif
0069 virtual event* copy() const {return new size_event(*this);}
0070 public:
0071 size_event(unsigned int a_ow,unsigned int a_oh,
0072 unsigned int a_w,unsigned int a_h)
0073 :m_ow(a_ow)
0074 ,m_oh(a_oh)
0075 ,m_w(a_w)
0076 ,m_h(a_h)
0077 {}
0078 virtual ~size_event(){}
0079 public:
0080 size_event(const size_event& a_from)
0081 :event(a_from)
0082 ,m_ow(a_from.m_ow)
0083 ,m_oh(a_from.m_oh)
0084 ,m_w(a_from.m_w)
0085 ,m_h(a_from.m_h)
0086 {}
0087 size_event& operator=(const size_event& a_from){
0088 event::operator=(a_from);
0089 m_ow = a_from.m_ow;
0090 m_oh = a_from.m_oh;
0091 m_w = a_from.m_w;
0092 m_h = a_from.m_h;
0093 return *this;
0094 }
0095 public:
0096 unsigned int old_width() const {return m_ow;}
0097 unsigned int old_height() const {return m_oh;}
0098 unsigned int width() const {return m_w;}
0099 unsigned int height() const {return m_h;}
0100 protected:
0101 unsigned int m_ow;
0102 unsigned int m_oh;
0103 unsigned int m_w;
0104 unsigned int m_h;
0105 };
0106
0107 class mouse_down_event : public event {
0108 typedef event parent;
0109 public:
0110 #ifdef TOOLS_SG_EVENT_ID_CAST
0111 static cid id_class() {return parent::id_class()+2;}
0112 virtual void* cast(cid a_class) const {
0113 if(void* p = cmp_cast<mouse_down_event>(this,a_class)) return p;
0114 return 0;
0115 }
0116 #else
0117 TOOLS_SCLASS(tools::sg::mouse_down_event)
0118 virtual void* cast(const std::string& a_class) const {
0119 if(void* p = cmp_cast<mouse_down_event>(this,a_class)) {return p;}
0120 return 0;
0121 }
0122 #endif
0123 virtual event* copy() const {return new mouse_down_event(*this);}
0124 public:
0125 mouse_down_event(int a_x,int a_y) //signed because of wall.
0126 :m_x(a_x)
0127 ,m_y(a_y)
0128 {}
0129 virtual ~mouse_down_event(){}
0130 public:
0131 mouse_down_event(const mouse_down_event& a_from)
0132 :event(a_from)
0133 ,m_x(a_from.m_x)
0134 ,m_y(a_from.m_y)
0135 {}
0136 mouse_down_event& operator=(const mouse_down_event& a_from){
0137 event::operator=(a_from);
0138 m_x = a_from.m_x;
0139 m_y = a_from.m_y;
0140 return *this;
0141 }
0142 public:
0143 int x() const {return m_x;}
0144 int y() const {return m_y;}
0145 protected:
0146 int m_x;
0147 int m_y;
0148 };
0149
0150 class mouse_up_event : public event {
0151 typedef event parent;
0152 public:
0153 #ifdef TOOLS_SG_EVENT_ID_CAST
0154 static cid id_class() {return parent::id_class()+3;}
0155 virtual void* cast(cid a_class) const {
0156 if(void* p = cmp_cast<mouse_up_event>(this,a_class)) return p;
0157 return 0;
0158 }
0159 #else
0160 TOOLS_SCLASS(tools::sg::mouse_up_event)
0161 virtual void* cast(const std::string& a_class) const {
0162 if(void* p = cmp_cast<mouse_up_event>(this,a_class)) {return p;}
0163 return 0;
0164 }
0165 #endif
0166 virtual event* copy() const {return new mouse_up_event(*this);}
0167 public:
0168 mouse_up_event(int a_x,int a_y) //signed because of wall.
0169 :m_x(a_x)
0170 ,m_y(a_y)
0171 {}
0172 virtual ~mouse_up_event(){}
0173 public:
0174 mouse_up_event(const mouse_up_event& a_from)
0175 :event(a_from)
0176 ,m_x(a_from.m_x)
0177 ,m_y(a_from.m_y)
0178 {}
0179 mouse_up_event& operator=(const mouse_up_event& a_from){
0180 event::operator=(a_from);
0181 m_x = a_from.m_x;
0182 m_y = a_from.m_y;
0183 return *this;
0184 }
0185 public:
0186 int x() const {return m_x;}
0187 int y() const {return m_y;}
0188 protected:
0189 int m_x;
0190 int m_y;
0191 };
0192
0193 class mouse_move_event : public event {
0194 typedef event parent;
0195 public:
0196 #ifdef TOOLS_SG_EVENT_ID_CAST
0197 static cid id_class() {return parent::id_class()+4;}
0198 virtual void* cast(cid a_class) const {
0199 if(void* p = cmp_cast<mouse_move_event>(this,a_class)) return p;
0200 return 0;
0201 }
0202 #else
0203 TOOLS_SCLASS(tools::sg::mouse_move_event)
0204 virtual void* cast(const std::string& a_class) const {
0205 if(void* p = cmp_cast<mouse_move_event>(this,a_class)) {return p;}
0206 return 0;
0207 }
0208 #endif
0209 virtual event* copy() const {return new mouse_move_event(*this);}
0210 public:
0211 mouse_move_event(int a_x,int a_y, //signed because of wall.
0212 int a_ox,int a_oy,
0213 bool a_touch) //for sliders.
0214 :m_x(a_x)
0215 ,m_y(a_y)
0216 ,m_ox(a_ox)
0217 ,m_oy(a_oy)
0218 ,m_touch(a_touch)
0219 {}
0220 virtual ~mouse_move_event(){}
0221 public:
0222 mouse_move_event(const mouse_move_event& a_from)
0223 :event(a_from)
0224 ,m_x(a_from.m_x)
0225 ,m_y(a_from.m_y)
0226 ,m_ox(a_from.m_ox)
0227 ,m_oy(a_from.m_oy)
0228 ,m_touch(a_from.m_touch)
0229 {}
0230 mouse_move_event& operator=(const mouse_move_event& a_from){
0231 event::operator=(a_from);
0232 m_x = a_from.m_x;
0233 m_y = a_from.m_y;
0234
0235 m_ox = a_from.m_ox;
0236 m_oy = a_from.m_oy;
0237
0238 m_touch = a_from.m_touch;
0239 return *this;
0240 }
0241 public:
0242 int x() const {return m_x;}
0243 int y() const {return m_y;}
0244 int ox() const {return m_ox;}
0245 int oy() const {return m_oy;}
0246 bool is_touch() const {return m_touch;}
0247 protected:
0248 int m_x;
0249 int m_y;
0250 int m_ox;
0251 int m_oy; //+ = up.
0252 // etc :
0253 bool m_touch;
0254 };
0255
0256 class anim_event : public event {
0257 typedef event parent;
0258 public:
0259 #ifdef TOOLS_SG_EVENT_ID_CAST
0260 static cid id_class() {return parent::id_class()+5;}
0261 virtual void* cast(cid a_class) const {
0262 if(void* p = cmp_cast<anim_event>(this,a_class)) return p;
0263 return 0;
0264 }
0265 #else
0266 TOOLS_SCLASS(tools::sg::anim_event)
0267 virtual void* cast(const std::string& a_class) const {
0268 if(void* p = cmp_cast<anim_event>(this,a_class)) {return p;}
0269 return 0;
0270 }
0271 #endif
0272 virtual event* copy() const {return new anim_event(*this);}
0273 public:
0274 typedef uint64 num_t;
0275 anim_event(num_t a_secs,num_t a_micro_secs)
0276 :m_secs(a_secs),m_micro_secs(a_micro_secs)
0277 ,m_some_found(false)
0278 {}
0279 virtual ~anim_event(){}
0280 public:
0281 anim_event(const anim_event& a_from)
0282 :event(a_from)
0283 ,m_secs(a_from.m_secs)
0284 ,m_micro_secs(a_from.m_micro_secs)
0285 ,m_some_found(a_from.m_some_found)
0286 {}
0287 anim_event& operator=(const anim_event& a_from){
0288 event::operator=(a_from);
0289 m_secs = a_from.m_secs;
0290 m_micro_secs = a_from.m_micro_secs;
0291 m_some_found = a_from.m_some_found;
0292 return *this;
0293 }
0294 public:
0295 /*
0296 void set_time(num_t a_secs,num_t a_micro_secs) {
0297 m_secs = a_secs;
0298 m_micro_secs = a_micro_secs;
0299 }
0300 */
0301 num_t seconds() const {return m_secs;}
0302 num_t micro_seconds() const {return m_micro_secs;}
0303
0304 void set_some_found(bool a_v) {m_some_found = a_v;}
0305 bool some_found() const {return m_some_found;}
0306 protected:
0307 num_t m_secs;
0308 num_t m_micro_secs;
0309 bool m_some_found;
0310 };
0311
0312 class key_down_event : public event {
0313 typedef event parent;
0314 public:
0315 #ifdef TOOLS_SG_EVENT_ID_CAST
0316 static cid id_class() {return parent::id_class()+6;}
0317 virtual void* cast(cid a_class) const {
0318 if(void* p = cmp_cast<key_down_event>(this,a_class)) return p;
0319 return 0;
0320 }
0321 #else
0322 TOOLS_SCLASS(tools::sg::key_down_event)
0323 virtual void* cast(const std::string& a_class) const {
0324 if(void* p = cmp_cast<key_down_event>(this,a_class)) {return p;}
0325 return 0;
0326 }
0327 #endif
0328 virtual event* copy() const {return new key_down_event(*this);}
0329 public:
0330 key_down_event(key_code a_key)
0331 :m_key(a_key)
0332 {}
0333 virtual ~key_down_event(){}
0334 public:
0335 key_down_event(const key_down_event& a_from)
0336 :event(a_from)
0337 ,m_key(a_from.m_key)
0338 {}
0339 key_down_event& operator=(const key_down_event& a_from){
0340 event::operator=(a_from);
0341 m_key = a_from.m_key;
0342 return *this;
0343 }
0344 public:
0345 key_code key() const {return m_key;}
0346 protected:
0347 key_code m_key;
0348 };
0349
0350 class key_up_event : public event {
0351 typedef event parent;
0352 public:
0353 #ifdef TOOLS_SG_EVENT_ID_CAST
0354 static cid id_class() {return parent::id_class()+7;}
0355 virtual void* cast(cid a_class) const {
0356 if(void* p = cmp_cast<key_up_event>(this,a_class)) return p;
0357 return 0;
0358 }
0359 #else
0360 TOOLS_SCLASS(tools::sg::key_up_event)
0361 virtual void* cast(const std::string& a_class) const {
0362 if(void* p = cmp_cast<key_up_event>(this,a_class)) {return p;}
0363 return 0;
0364 }
0365 #endif
0366 virtual event* copy() const {return new key_up_event(*this);}
0367 public:
0368 key_up_event(key_code a_key)
0369 :m_key(a_key)
0370 {}
0371 virtual ~key_up_event(){}
0372 public:
0373 key_up_event(const key_up_event& a_from)
0374 :event(a_from)
0375 ,m_key(a_from.m_key)
0376 {}
0377 key_up_event& operator=(const key_up_event& a_from){
0378 event::operator=(a_from);
0379 m_key = a_from.m_key;
0380 return *this;
0381 }
0382 public:
0383 key_code key() const {return m_key;}
0384 protected:
0385 key_code m_key;
0386 };
0387
0388 class wheel_rotate_event : public event {
0389 typedef event parent;
0390 public:
0391 #ifdef TOOLS_SG_EVENT_ID_CAST
0392 static cid id_class() {return parent::id_class()+8;}
0393 virtual void* cast(cid a_class) const {
0394 if(void* p = cmp_cast<wheel_rotate_event>(this,a_class)) return p;
0395 return 0;
0396 }
0397 #else
0398 TOOLS_SCLASS(tools::sg::wheel_rotate_event)
0399 virtual void* cast(const std::string& a_class) const {
0400 if(void* p = cmp_cast<wheel_rotate_event>(this,a_class)) {return p;}
0401 return 0;
0402 }
0403 #endif
0404 virtual event* copy() const {return new wheel_rotate_event(*this);}
0405 public:
0406 wheel_rotate_event(int a_angle)
0407 :m_angle(a_angle)
0408 {}
0409 virtual ~wheel_rotate_event(){}
0410 public:
0411 wheel_rotate_event(const wheel_rotate_event& a_from)
0412 :event(a_from)
0413 ,m_angle(a_from.m_angle)
0414 {}
0415 wheel_rotate_event& operator=(const wheel_rotate_event& a_from){
0416 event::operator=(a_from);
0417 m_angle = a_from.m_angle;
0418 return *this;
0419 }
0420 public:
0421 int angle() const {return m_angle;}
0422 protected:
0423 int m_angle;
0424 };
0425
0426 #ifdef TOOLS_SG_EVENT_ID_CAST
0427 template <class FROM,class TO> inline TO* event_cast(FROM& a_o) {return id_cast<FROM,TO>(a_o);}
0428 template <class FROM,class TO> inline const TO* event_cast(const FROM& a_o) {return id_cast<FROM,TO>(a_o);}
0429 #else
0430 template <class FROM,class TO> inline TO* event_cast(FROM& a_o) {return safe_cast<FROM,TO>(a_o);}
0431 template <class FROM,class TO> inline const TO* event_cast(const FROM& a_o) {return safe_cast<FROM,TO>(a_o);}
0432 #endif
0433
0434 inline bool get_event_xy(const sg::event& a_event,int& a_x,int& a_y) {
0435 typedef sg::event evt_t;
0436 typedef sg::mouse_up_event up_evt_t;
0437 typedef sg::mouse_down_event dn_evt_t;
0438 if(const dn_evt_t* devt = event_cast<evt_t,dn_evt_t>(a_event)) {
0439 a_x = devt->x();
0440 a_y = devt->y();
0441 return true;
0442
0443 } else if(const up_evt_t* uevt = event_cast<evt_t,up_evt_t>(a_event)) {
0444 a_x = uevt->x();
0445 a_y = uevt->y();
0446 return true;
0447
0448 }
0449 a_x = 0;
0450 a_y = 0;
0451 return false;
0452 }
0453
0454 }}
0455
0456 #endif