Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/toolx/X11/zb_viewer 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 toolx_X11_zb_viewer
0005 #define toolx_X11_zb_viewer
0006 
0007 #include "base_session"
0008 #include "pixwin"
0009 #include "simple_dispatcher"
0010 
0011 #include <tools/sg/zb_viewer>
0012 #include <tools/sg/device_interactor>
0013 
0014 namespace toolx {
0015 namespace X11 {
0016 
0017 class zb_viewer
0018 :public tools::sg::zb_viewer, protected pixwin {
0019   typedef tools::sg::zb_viewer parent;
0020   typedef pixwin parent_pixwin;
0021 private:
0022   class dispatcher : public simple_dispatcher {
0023     typedef simple_dispatcher parent;
0024   public:
0025     virtual bool dispatch(XEvent& a_event) {
0026       if(parent::dispatch(a_event)) return true;
0027       if(a_event.type==ButtonPress && a_event.xbutton.button==1) {
0028         if(!m_viewer.device_interactor()) return false;
0029         tools::sg::mouse_down_event event(a_event.xbutton.x,a_event.xbutton.y);
0030         m_viewer.device_interactor()->mouse_press(event);
0031         return true;
0032       } else if(a_event.type==ButtonRelease && a_event.xbutton.button==1) {
0033         if(!m_viewer.device_interactor()) return false;
0034         tools::sg::mouse_up_event event(a_event.xbutton.x,a_event.xbutton.y);
0035         m_viewer.device_interactor()->mouse_release(event);
0036         return true;
0037       } else if(a_event.type==MotionNotify) {
0038         if(!m_viewer.device_interactor()) return false;
0039         if((a_event.xmotion.state & Button1MotionMask)==Button1MotionMask) {
0040           tools::sg::mouse_move_event event(a_event.xmotion.x,a_event.xmotion.y,0,0,false);
0041           m_viewer.device_interactor()->mouse_move(event);
0042         }
0043       } else if((a_event.type==ButtonPress)&&(a_event.xbutton.button==4)) { // mouse scrollwheel down :
0044         if(!m_viewer.device_interactor()) return false;
0045         tools::sg::wheel_rotate_event event(8);  //8=cooking.
0046         m_viewer.device_interactor()->wheel_rotate(event);
0047         return true;
0048       } else if((a_event.type==ButtonPress)&&(a_event.xbutton.button==5)) { // mouse scrollwheel up :
0049         if(!m_viewer.device_interactor()) return false;
0050         tools::sg::wheel_rotate_event event(-8);  //8=cooking.
0051         m_viewer.device_interactor()->wheel_rotate(event);
0052         return true;
0053       }
0054       return false;
0055     }
0056     virtual void win_render() {m_viewer.win_render();}
0057     virtual void set_size(unsigned int a_width,unsigned int a_height) {m_viewer.set_size(a_width,a_height);}
0058     virtual dispatcher* copy() const {return new dispatcher(*this);}
0059   public:
0060     dispatcher(zb_viewer& a_viewer)
0061     :parent(a_viewer.m_session,a_viewer.m_win)
0062     ,m_viewer(a_viewer){}
0063     virtual ~dispatcher(){}
0064   protected:
0065     dispatcher(const dispatcher& a_from)
0066     :parent(a_from)
0067     ,m_viewer(a_from.m_viewer)
0068     {}
0069     dispatcher& operator=(const dispatcher& a_from) {
0070       parent::operator=(a_from);
0071       return *this;
0072     }
0073   protected:
0074     zb_viewer& m_viewer;
0075   };
0076 
0077 public:
0078   virtual void set_size(unsigned int a_w,unsigned int a_h) {
0079     parent::set_size(a_w,a_h);
0080     free_XImage();
0081     alloc_XImage(a_w,a_h);
0082   }
0083 public:
0084   zb_viewer(base_session& a_session,
0085             int a_x = 0,int a_y = 0,
0086             unsigned int a_width = 500,unsigned int a_height = 500,
0087             const std::string& a_win_title = "")
0088   :parent(a_session.out(),a_width,a_height)
0089   ,parent_pixwin(a_session.out(),a_session.monitor(),a_session.display())
0090   ,m_session(a_session)
0091   ,m_win(0)
0092   ,m_interactor(0)
0093   {
0094     if(!m_session.display()) return; //throw
0095     m_win = m_session.create_window(a_win_title.c_str(),a_x,a_y,a_width,a_height);
0096     if(!m_win) return; //throw
0097     m_session.add_dispatcher(new dispatcher(*this));
0098   }
0099   virtual ~zb_viewer() {
0100     if(m_win) {
0101       m_session.remove_dispatchers_with_window(m_win);
0102       m_session.delete_window(m_win);
0103       m_session.sync();
0104     }
0105   }
0106 protected:
0107   zb_viewer(const zb_viewer& a_from)
0108   :parent(a_from)
0109   ,parent_pixwin(a_from)
0110   ,m_session(a_from.m_session)
0111   ,m_win(a_from.m_win)
0112   ,m_interactor(0)
0113   {}
0114   zb_viewer& operator=(const zb_viewer& a_from){
0115     parent::operator=(a_from);
0116     parent_pixwin::operator=(a_from);
0117     m_win = a_from.m_win;
0118     return *this;
0119   }
0120 public:
0121   bool has_window() const {return m_win?true:false;} //for SWIG
0122 
0123   Window window() const {return m_win;}
0124 
0125   bool show() {
0126     if(!m_win) return false;
0127     m_session.show_window(m_win);
0128     return true;
0129   }
0130 
0131   void win_render() {
0132     if(!m_win) return;
0133     if(!render(get_rgbas,false)) return;
0134     put_buffer(m_win,m_ww,m_wh,tools::vec_data(m_out_buffer));
0135     m_out_buffer.clear();
0136   }
0137 
0138   void set_device_interactor(tools::sg::device_interactor* a_interactor) {m_interactor = a_interactor;}
0139 public:
0140   tools::sg::device_interactor* device_interactor() {return m_interactor;}
0141 protected:
0142   base_session& m_session;
0143   Window m_win;  
0144   tools::sg::device_interactor* m_interactor;
0145 };
0146 
0147 }}
0148 
0149 
0150 #endif
0151