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
0012 namespace tools {
0013 namespace sg {
0014
0015 class event {
0016 public:
0017 static cid id_class() {return 0;}
0018 virtual void* cast(cid) const = 0;
0019 virtual event* copy() const = 0;
0020 public:
0021 event(){
0022 }
0023 virtual ~event(){
0024 }
0025 public:
0026 event(const event&){
0027 }
0028 event& operator=(const event&){return *this;}
0029 };
0030
0031 class size_event : public event {
0032 typedef event parent;
0033 public:
0034 static cid id_class() {return parent::id_class()+1;}
0035 virtual void* cast(cid a_class) const {
0036 if(void* p = cmp_cast<size_event>(this,a_class)) return p;
0037 return 0;
0038 }
0039 virtual event* copy() const {return new size_event(*this);}
0040 public:
0041 size_event(unsigned int a_ow,unsigned int a_oh,
0042 unsigned int a_w,unsigned int a_h)
0043 :m_ow(a_ow)
0044 ,m_oh(a_oh)
0045 ,m_w(a_w)
0046 ,m_h(a_h)
0047 {}
0048 virtual ~size_event(){}
0049 public:
0050 size_event(const size_event& a_from)
0051 :event(a_from)
0052 ,m_ow(a_from.m_ow)
0053 ,m_oh(a_from.m_oh)
0054 ,m_w(a_from.m_w)
0055 ,m_h(a_from.m_h)
0056 {}
0057 size_event& operator=(const size_event& a_from){
0058 event::operator=(a_from);
0059 m_ow = a_from.m_ow;
0060 m_oh = a_from.m_oh;
0061 m_w = a_from.m_w;
0062 m_h = a_from.m_h;
0063 return *this;
0064 }
0065 public:
0066 unsigned int old_width() const {return m_ow;}
0067 unsigned int old_height() const {return m_oh;}
0068 unsigned int width() const {return m_w;}
0069 unsigned int height() const {return m_h;}
0070 protected:
0071 unsigned int m_ow;
0072 unsigned int m_oh;
0073 unsigned int m_w;
0074 unsigned int m_h;
0075 };
0076
0077 class position_modifiers {
0078 public:
0079 position_modifiers(int a_x,int a_y,bool a_shift_modifier,bool a_control_modifier)
0080 :m_x(a_x)
0081 ,m_y(a_y)
0082 ,m_shift_modifier(a_shift_modifier)
0083 ,m_control_modifier(a_control_modifier)
0084 {}
0085 virtual ~position_modifiers(){}
0086 public:
0087 position_modifiers(const position_modifiers& a_from)
0088 :m_x(a_from.m_x)
0089 ,m_y(a_from.m_y)
0090 ,m_shift_modifier(a_from.m_shift_modifier)
0091 ,m_control_modifier(a_from.m_control_modifier)
0092 {}
0093 position_modifiers& operator=(const position_modifiers& a_from){
0094 m_x = a_from.m_x;
0095 m_y = a_from.m_y;
0096 m_shift_modifier = a_from.m_shift_modifier;
0097 m_control_modifier = a_from.m_control_modifier;
0098 return *this;
0099 }
0100 public:
0101 int x() const {return m_x;}
0102 int y() const {return m_y;}
0103 bool shift_modifier() const {return m_shift_modifier;}
0104 bool control_modifier() const {return m_control_modifier;}
0105 protected:
0106 int m_x;
0107 int m_y;
0108 bool m_shift_modifier;
0109 bool m_control_modifier;
0110 };
0111
0112 class mouse_down_event : public event, public position_modifiers {
0113 typedef event parent;
0114 typedef position_modifiers parent_pos_mod;
0115 public:
0116 static cid id_class() {return parent::id_class()+2;}
0117 virtual void* cast(cid a_class) const {
0118 if(void* p = cmp_cast<mouse_down_event>(this,a_class)) return p;
0119 return 0;
0120 }
0121 virtual event* copy() const {return new mouse_down_event(*this);}
0122 public:
0123 mouse_down_event(int a_x,int a_y,bool a_shift_modifier,bool a_control_modifier)
0124 :parent_pos_mod(a_x,a_y,a_shift_modifier,a_control_modifier)
0125 {}
0126 virtual ~mouse_down_event(){}
0127 public:
0128 mouse_down_event(const mouse_down_event& a_from)
0129 :parent(a_from)
0130 ,parent_pos_mod(a_from)
0131 {}
0132 mouse_down_event& operator=(const mouse_down_event& a_from){
0133 parent::operator=(a_from);
0134 parent_pos_mod::operator=(a_from);
0135 return *this;
0136 }
0137 };
0138
0139 class mouse_up_event : public event, public position_modifiers {
0140 typedef event parent;
0141 typedef position_modifiers parent_pos_mod;
0142 public:
0143 static cid id_class() {return parent::id_class()+3;}
0144 virtual void* cast(cid a_class) const {
0145 if(void* p = cmp_cast<mouse_up_event>(this,a_class)) return p;
0146 return 0;
0147 }
0148 virtual event* copy() const {return new mouse_up_event(*this);}
0149 public:
0150 mouse_up_event(int a_x,int a_y,bool a_shift_modifier,bool a_control_modifier)
0151 :parent_pos_mod(a_x,a_y,a_shift_modifier,a_control_modifier)
0152 {}
0153 virtual ~mouse_up_event(){}
0154 public:
0155 mouse_up_event(const mouse_up_event& a_from)
0156 :parent(a_from)
0157 ,parent_pos_mod(a_from)
0158 {}
0159 mouse_up_event& operator=(const mouse_up_event& a_from){
0160 parent::operator=(a_from);
0161 parent_pos_mod::operator=(a_from);
0162 return *this;
0163 }
0164 };
0165
0166 class mouse_move_event : public event, public position_modifiers {
0167 typedef event parent;
0168 typedef position_modifiers parent_pos_mod;
0169 public:
0170 static cid id_class() {return parent::id_class()+4;}
0171 virtual void* cast(cid a_class) const {
0172 if(void* p = cmp_cast<mouse_move_event>(this,a_class)) return p;
0173 return 0;
0174 }
0175 virtual event* copy() const {return new mouse_move_event(*this);}
0176 public:
0177 mouse_move_event(int a_x,int a_y,bool a_shift_modifier,bool a_control_modifier,
0178 int a_ox,int a_oy,
0179 bool a_touch) //for sliders.
0180 :parent_pos_mod(a_x,a_y,a_shift_modifier,a_control_modifier)
0181 ,m_ox(a_ox)
0182 ,m_oy(a_oy)
0183 ,m_touch(a_touch)
0184 {}
0185 virtual ~mouse_move_event(){}
0186 public:
0187 mouse_move_event(const mouse_move_event& a_from)
0188 :parent(a_from)
0189 ,parent_pos_mod(a_from)
0190 ,m_ox(a_from.m_ox)
0191 ,m_oy(a_from.m_oy)
0192 ,m_touch(a_from.m_touch)
0193 {}
0194 mouse_move_event& operator=(const mouse_move_event& a_from){
0195 parent::operator=(a_from);
0196 parent_pos_mod::operator=(a_from);
0197
0198 m_ox = a_from.m_ox;
0199 m_oy = a_from.m_oy;
0200
0201 m_touch = a_from.m_touch;
0202 return *this;
0203 }
0204 public:
0205 int ox() const {return m_ox;}
0206 int oy() const {return m_oy;}
0207 bool is_touch() const {return m_touch;}
0208 protected:
0209 int m_ox;
0210 int m_oy; //+ = up.
0211 // etc :
0212 bool m_touch;
0213 };
0214
0215 class anim_event : public event {
0216 typedef event parent;
0217 public:
0218 static cid id_class() {return parent::id_class()+5;}
0219 virtual void* cast(cid a_class) const {
0220 if(void* p = cmp_cast<anim_event>(this,a_class)) return p;
0221 return 0;
0222 }
0223 virtual event* copy() const {return new anim_event(*this);}
0224 public:
0225 typedef uint64 num_t;
0226 anim_event(num_t a_secs,num_t a_micro_secs)
0227 :m_secs(a_secs),m_micro_secs(a_micro_secs)
0228 ,m_some_found(false)
0229 {}
0230 virtual ~anim_event(){}
0231 public:
0232 anim_event(const anim_event& a_from)
0233 :event(a_from)
0234 ,m_secs(a_from.m_secs)
0235 ,m_micro_secs(a_from.m_micro_secs)
0236 ,m_some_found(a_from.m_some_found)
0237 {}
0238 anim_event& operator=(const anim_event& a_from){
0239 event::operator=(a_from);
0240 m_secs = a_from.m_secs;
0241 m_micro_secs = a_from.m_micro_secs;
0242 m_some_found = a_from.m_some_found;
0243 return *this;
0244 }
0245 public:
0246 num_t seconds() const {return m_secs;}
0247 num_t micro_seconds() const {return m_micro_secs;}
0248
0249 void set_some_found(bool a_v) {m_some_found = a_v;}
0250 bool some_found() const {return m_some_found;}
0251 protected:
0252 num_t m_secs;
0253 num_t m_micro_secs;
0254 bool m_some_found;
0255 };
0256
0257 class key_down_event : public event {
0258 typedef event parent;
0259 public:
0260 static cid id_class() {return parent::id_class()+6;}
0261 virtual void* cast(cid a_class) const {
0262 if(void* p = cmp_cast<key_down_event>(this,a_class)) return p;
0263 return 0;
0264 }
0265 virtual event* copy() const {return new key_down_event(*this);}
0266 public:
0267 key_down_event(key_code a_key)
0268 :m_key(a_key)
0269 {}
0270 virtual ~key_down_event(){}
0271 public:
0272 key_down_event(const key_down_event& a_from)
0273 :event(a_from)
0274 ,m_key(a_from.m_key)
0275 {}
0276 key_down_event& operator=(const key_down_event& a_from){
0277 event::operator=(a_from);
0278 m_key = a_from.m_key;
0279 return *this;
0280 }
0281 public:
0282 key_code key() const {return m_key;}
0283 protected:
0284 key_code m_key;
0285 };
0286
0287 class key_up_event : public event {
0288 typedef event parent;
0289 public:
0290 static cid id_class() {return parent::id_class()+7;}
0291 virtual void* cast(cid a_class) const {
0292 if(void* p = cmp_cast<key_up_event>(this,a_class)) return p;
0293 return 0;
0294 }
0295 virtual event* copy() const {return new key_up_event(*this);}
0296 public:
0297 key_up_event(key_code a_key)
0298 :m_key(a_key)
0299 {}
0300 virtual ~key_up_event(){}
0301 public:
0302 key_up_event(const key_up_event& a_from)
0303 :event(a_from)
0304 ,m_key(a_from.m_key)
0305 {}
0306 key_up_event& operator=(const key_up_event& a_from){
0307 event::operator=(a_from);
0308 m_key = a_from.m_key;
0309 return *this;
0310 }
0311 public:
0312 key_code key() const {return m_key;}
0313 protected:
0314 key_code m_key;
0315 };
0316
0317 class wheel_rotate_event : public event, public position_modifiers {
0318 typedef event parent;
0319 typedef position_modifiers parent_pos_mod;
0320 public:
0321 static cid id_class() {return parent::id_class()+8;}
0322 virtual void* cast(cid a_class) const {
0323 if(void* p = cmp_cast<wheel_rotate_event>(this,a_class)) return p;
0324 return 0;
0325 }
0326 virtual event* copy() const {return new wheel_rotate_event(*this);}
0327 public:
0328 wheel_rotate_event(int a_angle,int a_x,int a_y,bool a_shift_modifier,bool a_control_modifier)
0329 :parent_pos_mod(a_x,a_y,a_shift_modifier,a_control_modifier)
0330 ,m_angle(a_angle)
0331 {}
0332 virtual ~wheel_rotate_event(){}
0333 public:
0334 wheel_rotate_event(const wheel_rotate_event& a_from)
0335 :parent(a_from)
0336 ,parent_pos_mod(a_from)
0337 ,m_angle(a_from.m_angle)
0338 {}
0339 wheel_rotate_event& operator=(const wheel_rotate_event& a_from){
0340 parent::operator=(a_from);
0341 parent_pos_mod::operator=(a_from);
0342 m_angle = a_from.m_angle;
0343 return *this;
0344 }
0345 public:
0346 int angle() const {return m_angle;}
0347 protected:
0348 int m_angle;
0349 };
0350
0351 template <class FROM,class TO> inline TO* event_cast(FROM& a_o) {return id_cast<FROM,TO>(a_o);}
0352 template <class FROM,class TO> inline const TO* event_cast(const FROM& a_o) {return id_cast<FROM,TO>(a_o);}
0353
0354 inline bool get_event_xy(const sg::event& a_event,int& a_x,int& a_y) {
0355 typedef sg::event evt_t;
0356 typedef sg::mouse_up_event up_evt_t;
0357 typedef sg::mouse_down_event dn_evt_t;
0358 if(const dn_evt_t* devt = event_cast<evt_t,dn_evt_t>(a_event)) {
0359 a_x = devt->x();
0360 a_y = devt->y();
0361 return true;
0362
0363 } else if(const up_evt_t* uevt = event_cast<evt_t,up_evt_t>(a_event)) {
0364 a_x = uevt->x();
0365 a_y = uevt->y();
0366 return true;
0367
0368 }
0369 a_x = 0;
0370 a_y = 0;
0371 return false;
0372 }
0373
0374 }}
0375
0376 #endif