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

  1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
  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 tools::sg::viewer that uses GL.
  8 
  9 #include "session"
 10 
 11 #include "../sg/GL_viewer"
 12 
 13 #include "simple_dispatcher"
 14 
 15 namespace tools{namespace sg{class device_interactor;}}
 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_render();}
 27     virtual void set_size(unsigned int a_width,unsigned int a_height) {m_sg_viewer.set_size(a_width,a_height);}
 28     virtual dispatcher* copy() const {return new dispatcher(*this);}
 29   public:
 30     dispatcher(sg_viewer& a_sg_viewer)
 31     :parent(a_sg_viewer.m_session,a_sg_viewer.m_win)
 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_from) {
 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,unsigned int a_height = 500,
 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_title.c_str(),a_x,a_y,a_width,a_height);
 58     if(!m_win) return; //throw
 59     m_session.add_dispatcher(new dispatcher(*this));
 60   }
 61   virtual ~sg_viewer() {
 62     if(m_win) {
 63       m_session.remove_dispatchers_with_window(m_win);
 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:false;} //for SWIG
 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_win,m_session.context())==False){
 93       m_session.out() << "toolx::X11::sg_viewer::win_render : glXMakeCurrent failed." << std::endl;
 94       return;
 95     }
 96     render(); //viewer::render()
 97     ::glXSwapBuffers(m_session.display(),m_win);
 98     if(::glXMakeCurrent(m_session.display(),None,NULL)==False){
 99       m_session.out() << "toolx::X11::sg_viewer::win_render : glXMakeCurrent(None,NULL) failed." << std::endl;
100     }
101   }
102 
103 public:
104   void set_device_interactor(tools::sg::device_interactor*) {}
105 protected:
106   session& m_session;
107   Window m_win;
108 };
109 
110 }}
111 
112 #endif
113