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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 ]

Diff markup

Differences between /externals/g4tools/include/toolx/X11/zb_viewer (Version 11.3.0) and /externals/g4tools/include/toolx/X11/zb_viewer (Version 11.2)


  1 // Copyright (C) 2010, Guy Barrand. All rights      1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  2 // See the file tools.license for terms.            2 // See the file tools.license for terms.
  3                                                     3 
  4 #ifndef toolx_X11_zb_viewer                         4 #ifndef toolx_X11_zb_viewer
  5 #define toolx_X11_zb_viewer                         5 #define toolx_X11_zb_viewer
  6                                                     6 
  7 #include "base_session"                             7 #include "base_session"
  8 #include "pixwin"                                   8 #include "pixwin"
  9 #include "simple_dispatcher"                        9 #include "simple_dispatcher"
 10                                                    10 
 11 #include <tools/sg/zb_viewer>                      11 #include <tools/sg/zb_viewer>
 12 #include <tools/sg/device_interactor>              12 #include <tools/sg/device_interactor>
 13                                                    13 
 14 namespace toolx {                                  14 namespace toolx {
 15 namespace X11 {                                    15 namespace X11 {
 16                                                    16 
 17 class zb_viewer                                    17 class zb_viewer
 18 :public tools::sg::zb_viewer, protected pixwin     18 :public tools::sg::zb_viewer, protected pixwin {
 19   typedef tools::sg::zb_viewer parent;             19   typedef tools::sg::zb_viewer parent;
 20   typedef pixwin parent_pixwin;                    20   typedef pixwin parent_pixwin;
 21 private:                                           21 private:
 22   class dispatcher : public simple_dispatcher      22   class dispatcher : public simple_dispatcher {
 23     typedef simple_dispatcher parent;              23     typedef simple_dispatcher parent;
 24   public:                                          24   public:
 25     virtual bool dispatch(XEvent& a_event) {       25     virtual bool dispatch(XEvent& a_event) {
 26       if(parent::dispatch(a_event)) return tru     26       if(parent::dispatch(a_event)) return true;
 27       if(a_event.type==ButtonPress && a_event.     27       if(a_event.type==ButtonPress && a_event.xbutton.button==1) {
 28         if(!m_viewer.device_interactor()) retu     28         if(!m_viewer.device_interactor()) return false;
 29         tools::sg::mouse_down_event event(a_ev     29         tools::sg::mouse_down_event event(a_event.xbutton.x,a_event.xbutton.y);
 30         m_viewer.device_interactor()->mouse_pr     30         m_viewer.device_interactor()->mouse_press(event);
 31         return true;                               31         return true;
 32       } else if(a_event.type==ButtonRelease &&     32       } else if(a_event.type==ButtonRelease && a_event.xbutton.button==1) {
 33         if(!m_viewer.device_interactor()) retu     33         if(!m_viewer.device_interactor()) return false;
 34         tools::sg::mouse_up_event event(a_even     34         tools::sg::mouse_up_event event(a_event.xbutton.x,a_event.xbutton.y);
 35         m_viewer.device_interactor()->mouse_re     35         m_viewer.device_interactor()->mouse_release(event);
 36         return true;                               36         return true;
 37       } else if(a_event.type==MotionNotify) {      37       } else if(a_event.type==MotionNotify) {
 38         if(!m_viewer.device_interactor()) retu     38         if(!m_viewer.device_interactor()) return false;
 39         if((a_event.xmotion.state & Button1Mot     39         if((a_event.xmotion.state & Button1MotionMask)==Button1MotionMask) {
 40           tools::sg::mouse_move_event event(a_     40           tools::sg::mouse_move_event event(a_event.xmotion.x,a_event.xmotion.y,0,0,false);
 41           m_viewer.device_interactor()->mouse_     41           m_viewer.device_interactor()->mouse_move(event);
 42         }                                          42         }
 43       } else if((a_event.type==ButtonPress)&&(     43       } else if((a_event.type==ButtonPress)&&(a_event.xbutton.button==4)) { // mouse scrollwheel down :
 44         if(!m_viewer.device_interactor()) retu     44         if(!m_viewer.device_interactor()) return false;
 45         tools::sg::wheel_rotate_event event(8)     45         tools::sg::wheel_rotate_event event(8);  //8=cooking.
 46         m_viewer.device_interactor()->wheel_ro     46         m_viewer.device_interactor()->wheel_rotate(event);
 47         return true;                               47         return true;
 48       } else if((a_event.type==ButtonPress)&&(     48       } else if((a_event.type==ButtonPress)&&(a_event.xbutton.button==5)) { // mouse scrollwheel up :
 49         if(!m_viewer.device_interactor()) retu     49         if(!m_viewer.device_interactor()) return false;
 50         tools::sg::wheel_rotate_event event(-8     50         tools::sg::wheel_rotate_event event(-8);  //8=cooking.
 51         m_viewer.device_interactor()->wheel_ro     51         m_viewer.device_interactor()->wheel_rotate(event);
 52         return true;                               52         return true;
 53       }                                            53       }
 54       return false;                                54       return false;
 55     }                                              55     }
 56     virtual void win_render() {m_viewer.win_re     56     virtual void win_render() {m_viewer.win_render();}
 57     virtual void set_size(unsigned int a_width     57     virtual void set_size(unsigned int a_width,unsigned int a_height) {m_viewer.set_size(a_width,a_height);}
 58     virtual dispatcher* copy() const {return n     58     virtual dispatcher* copy() const {return new dispatcher(*this);}
 59   public:                                          59   public:
 60     dispatcher(zb_viewer& a_viewer)                60     dispatcher(zb_viewer& a_viewer)
 61     :parent(a_viewer.m_session,a_viewer.m_win)     61     :parent(a_viewer.m_session,a_viewer.m_win)
 62     ,m_viewer(a_viewer){}                          62     ,m_viewer(a_viewer){}
 63     virtual ~dispatcher(){}                        63     virtual ~dispatcher(){}
 64   protected:                                       64   protected:
 65     dispatcher(const dispatcher& a_from)           65     dispatcher(const dispatcher& a_from)
 66     :parent(a_from)                                66     :parent(a_from)
 67     ,m_viewer(a_from.m_viewer)                     67     ,m_viewer(a_from.m_viewer)
 68     {}                                             68     {}
 69     dispatcher& operator=(const dispatcher& a_     69     dispatcher& operator=(const dispatcher& a_from) {
 70       parent::operator=(a_from);                   70       parent::operator=(a_from);
 71       return *this;                                71       return *this;
 72     }                                              72     }
 73   protected:                                       73   protected:
 74     zb_viewer& m_viewer;                           74     zb_viewer& m_viewer;
 75   };                                               75   };
 76                                                    76 
 77 public:                                            77 public:
 78   virtual void set_size(unsigned int a_w,unsig     78   virtual void set_size(unsigned int a_w,unsigned int a_h) {
 79     parent::set_size(a_w,a_h);                     79     parent::set_size(a_w,a_h);
 80     free_XImage();                                 80     free_XImage();
 81     alloc_XImage(a_w,a_h);                         81     alloc_XImage(a_w,a_h);
 82   }                                                82   }
 83 public:                                            83 public:
 84   zb_viewer(base_session& a_session,               84   zb_viewer(base_session& a_session,
 85             int a_x = 0,int a_y = 0,               85             int a_x = 0,int a_y = 0,
 86             unsigned int a_width = 500,unsigne     86             unsigned int a_width = 500,unsigned int a_height = 500,
 87             const std::string& a_win_title = "     87             const std::string& a_win_title = "")
 88   :parent(a_session.out(),a_width,a_height)        88   :parent(a_session.out(),a_width,a_height)
 89   ,parent_pixwin(a_session.out(),a_session.mon     89   ,parent_pixwin(a_session.out(),a_session.monitor(),a_session.display())
 90   ,m_session(a_session)                            90   ,m_session(a_session)
 91   ,m_win(0)                                        91   ,m_win(0)
 92   ,m_interactor(0)                                 92   ,m_interactor(0)
 93   {                                                93   {
 94     if(!m_session.display()) return; //throw       94     if(!m_session.display()) return; //throw
 95     m_win = m_session.create_window(a_win_titl     95     m_win = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
 96     if(!m_win) return; //throw                     96     if(!m_win) return; //throw
 97     m_session.add_dispatcher(new dispatcher(*t     97     m_session.add_dispatcher(new dispatcher(*this));
 98   }                                                98   }
 99   virtual ~zb_viewer() {                           99   virtual ~zb_viewer() {
100     if(m_win) {                                   100     if(m_win) {
101       m_session.remove_dispatchers_with_window    101       m_session.remove_dispatchers_with_window(m_win);
102       m_session.delete_window(m_win);             102       m_session.delete_window(m_win);
103       m_session.sync();                           103       m_session.sync();
104     }                                             104     }
105   }                                               105   }
106 protected:                                        106 protected:
107   zb_viewer(const zb_viewer& a_from)              107   zb_viewer(const zb_viewer& a_from)
108   :parent(a_from)                                 108   :parent(a_from)
109   ,parent_pixwin(a_from)                          109   ,parent_pixwin(a_from)
110   ,m_session(a_from.m_session)                    110   ,m_session(a_from.m_session)
111   ,m_win(a_from.m_win)                            111   ,m_win(a_from.m_win)
112   ,m_interactor(0)                                112   ,m_interactor(0)
113   {}                                              113   {}
114   zb_viewer& operator=(const zb_viewer& a_from    114   zb_viewer& operator=(const zb_viewer& a_from){
115     parent::operator=(a_from);                    115     parent::operator=(a_from);
116     parent_pixwin::operator=(a_from);             116     parent_pixwin::operator=(a_from);
117     m_win = a_from.m_win;                         117     m_win = a_from.m_win;
118     return *this;                                 118     return *this;
119   }                                               119   }
120 public:                                           120 public:
121   bool has_window() const {return m_win?true:f    121   bool has_window() const {return m_win?true:false;} //for SWIG
122                                                   122 
123   Window window() const {return m_win;}           123   Window window() const {return m_win;}
124                                                   124 
125   bool show() {                                   125   bool show() {
126     if(!m_win) return false;                      126     if(!m_win) return false;
127     m_session.show_window(m_win);                 127     m_session.show_window(m_win);
128     return true;                                  128     return true;
129   }                                               129   }
130                                                   130 
131   void win_render() {                             131   void win_render() {
132     if(!m_win) return;                            132     if(!m_win) return;
133     if(!render(get_rgbas,false)) return;          133     if(!render(get_rgbas,false)) return;
134     put_buffer(m_win,m_ww,m_wh,tools::vec_data    134     put_buffer(m_win,m_ww,m_wh,tools::vec_data(m_out_buffer));
135     m_out_buffer.clear();                         135     m_out_buffer.clear();
136   }                                               136   }
137                                                   137 
138   void set_device_interactor(tools::sg::device    138   void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;}
139 public:                                           139 public:
140   tools::sg::device_interactor* device_interac    140   tools::sg::device_interactor* device_interactor() {return m_interactor;}
141 protected:                                        141 protected:
142   base_session& m_session;                        142   base_session& m_session;
143   Window m_win;                                   143   Window m_win;  
144   tools::sg::device_interactor* m_interactor;     144   tools::sg::device_interactor* m_interactor;
145 };                                                145 };
146                                                   146 
147 }}                                                147 }}
148                                                   148 
149                                                   149 
150 #endif                                            150 #endif
151                                                   151