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