Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef toolx_X11_sg_viewer 5 #define toolx_X11_sg_viewer 6 7 // not pure X11 version. The class inherits to 8 9 #include "session" 10 11 #include "../sg/GL_viewer" 12 13 #include "simple_dispatcher" 14 15 namespace tools{namespace sg{class device_inte 16 17 namespace toolx { 18 namespace X11 { 19 20 class sg_viewer : public sg::GL_viewer { 21 typedef sg::GL_viewer parent; 22 private: 23 class dispatcher : public simple_dispatcher 24 typedef simple_dispatcher parent; 25 public: 26 virtual void win_render() {m_sg_viewer.win 27 virtual void set_size(unsigned int a_width 28 virtual dispatcher* copy() const {return n 29 public: 30 dispatcher(sg_viewer& a_sg_viewer) 31 :parent(a_sg_viewer.m_session,a_sg_viewer. 32 ,m_sg_viewer(a_sg_viewer){} 33 virtual ~dispatcher(){} 34 protected: 35 dispatcher(const dispatcher& a_from) 36 :parent(a_from) 37 ,m_sg_viewer(a_from.m_sg_viewer) 38 {} 39 dispatcher& operator=(const dispatcher& a_ 40 parent::operator=(a_from); 41 return *this; 42 } 43 protected: 44 sg_viewer& m_sg_viewer; 45 }; 46 47 public: 48 sg_viewer(session& a_session, 49 int a_x = 0,int a_y = 0, 50 unsigned int a_width = 500,unsigne 51 const std::string& a_win_title = " 52 :parent(a_session.out(),a_width,a_height) 53 ,m_session(a_session) 54 ,m_win(0) 55 { 56 if(!m_session.display()) return; //throw 57 m_win = m_session.create_window(a_win_titl 58 if(!m_win) return; //throw 59 m_session.add_dispatcher(new dispatcher(*t 60 } 61 virtual ~sg_viewer() { 62 if(m_win) { 63 m_session.remove_dispatchers_with_window 64 m_session.delete_window(m_win); 65 m_session.sync(); 66 } 67 } 68 public: 69 sg_viewer(const sg_viewer& a_from) 70 :parent(a_from) 71 ,m_session(a_from.m_session) 72 ,m_win(a_from.m_win) 73 {} 74 sg_viewer& operator=(const sg_viewer& a_from 75 parent::operator=(a_from); 76 m_win = a_from.m_win; 77 return *this; 78 } 79 public: 80 bool has_window() const {return m_win?true:f 81 82 Window window() const {return m_win;} 83 84 bool show() { 85 if(!m_win) return false; 86 m_session.show_window(m_win); 87 return true; 88 } 89 90 void win_render() { 91 if(!m_win) return; 92 if(::glXMakeCurrent(m_session.display(),m_ 93 m_session.out() << "toolx::X11::sg_viewe 94 return; 95 } 96 render(); //viewer::render() 97 ::glXSwapBuffers(m_session.display(),m_win 98 if(::glXMakeCurrent(m_session.display(),No 99 m_session.out() << "toolx::X11::sg_viewe 100 } 101 } 102 103 public: 104 void set_device_interactor(tools::sg::device 105 protected: 106 session& m_session; 107 Window m_win; 108 }; 109 110 }} 111 112 #endif 113