inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_event_action 00005 #define inlib_sg_event_action 00006 00007 #include "win_action" 00008 00009 #include "../scast" 00010 00011 namespace inlib { 00012 namespace sg { 00013 00014 class event { 00015 public: 00016 virtual void* cast(const std::string&) const = 0; 00017 public: 00018 #ifdef INLIB_MEM 00019 static const std::string& s_class() { 00020 static const std::string s_v("inlib::sg::event"); 00021 return s_v; 00022 } 00023 #endif 00024 public: 00025 event(){ 00026 #ifdef INLIB_MEM 00027 mem::increment(s_class().c_str()); 00028 #endif 00029 } 00030 virtual ~event(){ 00031 #ifdef INLIB_MEM 00032 mem::decrement(s_class().c_str()); 00033 #endif 00034 } 00035 public: 00036 event(const event&){ 00037 #ifdef INLIB_MEM 00038 mem::increment(s_class().c_str()); 00039 #endif 00040 } 00041 event& operator=(const event&){return *this;} 00042 }; 00043 00044 class size_event : public event { 00045 public: 00046 static const std::string& s_class() { 00047 static const std::string s_v("inlib::sg::size_event"); 00048 return s_v; 00049 } 00050 virtual void* cast(const std::string& a_class) const { 00051 if(void* p = inlib::cmp_cast<size_event>(this,a_class)) {return p;} 00052 return 0; 00053 } 00054 public: 00055 size_event(unsigned int a_w,unsigned int a_h) 00056 :m_w(a_w),m_h(a_h) 00057 {} 00058 virtual ~size_event(){} 00059 public: 00060 size_event(const size_event& a_from) 00061 :event(a_from) 00062 ,m_w(a_from.m_w) 00063 ,m_h(a_from.m_h) 00064 {} 00065 size_event& operator=(const size_event& a_from){ 00066 event::operator=(a_from); 00067 m_w = a_from.m_w; 00068 m_h = a_from.m_h; 00069 return *this; 00070 } 00071 public: 00072 unsigned int width() const {return m_w;} 00073 unsigned int height() const {return m_h;} 00074 protected: 00075 unsigned int m_w; 00076 unsigned int m_h; 00077 }; 00078 00079 class move_event : public event { 00080 public: 00081 static const std::string& s_class() { 00082 static const std::string s_v("inlib::sg::move_event"); 00083 return s_v; 00084 } 00085 virtual void* cast(const std::string& a_class) const { 00086 if(void* p = inlib::cmp_cast<move_event>(this,a_class)) {return p;} 00087 return 0; 00088 } 00089 public: 00090 move_event(unsigned int a_x,unsigned int a_y, 00091 int a_dx,int a_dy, 00092 float a_wdx,float a_wdy) //for sliders. 00093 :m_x(a_x),m_y(a_y) 00094 ,m_dx(a_dx),m_dy(a_dy) 00095 ,m_wdx(a_wdx),m_wdy(a_wdy) 00096 {} 00097 virtual ~move_event(){} 00098 public: 00099 move_event(const move_event& a_from) 00100 :event(a_from) 00101 ,m_x(a_from.m_x),m_y(a_from.m_y) 00102 ,m_dx(a_from.m_dx),m_dy(a_from.m_dy) 00103 ,m_wdx(a_from.m_wdx),m_wdy(a_from.m_wdy) 00104 {} 00105 move_event& operator=(const move_event& a_from){ 00106 event::operator=(a_from); 00107 m_x = a_from.m_x;m_y = a_from.m_y; 00108 m_dx = a_from.m_dx;m_dy = a_from.m_dy; 00109 m_wdx = a_from.m_wdx;m_wdy = a_from.m_wdy; 00110 return *this; 00111 } 00112 public: 00113 unsigned int x() const {return m_x;} 00114 unsigned int y() const {return m_y;} 00115 int dx() const {return m_dx;} 00116 int dy() const {return m_dy;} 00117 float wdx() const {return m_wdx;} 00118 float wdy() const {return m_wdy;} 00119 protected: 00120 unsigned int m_x; 00121 unsigned int m_y; 00122 int m_dx; 00123 int m_dy; //+ = up. 00124 // in word coordinate : 00125 float m_wdx; 00126 float m_wdy; 00127 }; 00128 00129 }} 00130 00131 namespace inlib { 00132 namespace sg { 00133 00134 class event_action : public win_action { 00135 public: 00136 event_action(std::ostream& a_out, 00137 unsigned int a_ww,unsigned int a_wh, 00138 event* a_event) 00139 : win_action(a_out,a_ww,a_wh) 00140 //,m_handled(false) 00141 ,m_event(a_event) //not owner. 00142 {} 00143 virtual ~event_action(){} 00144 private: 00145 event_action(const inlib::sg::event_action& a_from) 00146 : win_action(a_from) 00147 {} 00148 inlib::sg::event_action& operator=(const inlib::sg::event_action& a_from){ 00149 win_action::operator=(a_from); 00150 return *this; 00151 } 00152 public: 00153 //void reset() {m_handled = false;} 00154 //void set_handled(bool a_value) {m_handled = a_value;} 00155 //bool handled() const {return m_handled;} 00156 const inlib::sg::event* get_event() const {return m_event;} 00157 private: 00158 //bool m_handled; 00159 event* m_event; 00160 }; 00161 00162 }} 00163 00164 #endif