Warning, /include/Geant4/toolx/Windows/sg_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_Windows_sg_viewer
0005 #define toolx_Windows_sg_viewer
0006
0007 #include "session"
0008 #include "window"
0009 #include "glarea"
0010
0011 #include <GL/gl.h>
0012
0013 #include "gl_functions"
0014
0015 #include "../sg/GL_action"
0016 #include "../sg/GL_viewer"
0017
0018 namespace toolx {
0019 namespace sg {
0020 using GL_action = GL_action_T<Windows::gl_functions>;
0021 using GL_manager = GL_manager_T<Windows::gl_functions>;
0022 using GL_viewer = GL_viewer_T<GL_manager,GL_action>;
0023 }}
0024
0025 // disable the warning about the usage of "this" in the constructor.
0026 #pragma warning(disable:4355)
0027
0028 namespace toolx {
0029 namespace Windows {
0030
0031 class sg_viewer : public window, public sg::GL_viewer {
0032 typedef window parent_window;
0033 typedef sg::GL_viewer parent_viewer;
0034 public:
0035 sg_viewer(session& a_session,
0036 int a_x = 0,int a_y = 0,
0037 unsigned int a_width = 500,unsigned int a_height = 500,
0038 const std::string& a_title = "")
0039 :parent_window(a_title.c_str(),a_x,a_y,a_width,a_height)
0040 ,parent_viewer(a_session.out(),a_width,a_height)
0041 ,m_session(a_session)
0042 ,m_glarea(m_hwnd,*this)
0043 {
0044 parent_window::set_focus_hwnd(m_glarea.hwnd());
0045 }
0046 virtual ~sg_viewer() {}
0047 protected:
0048 sg_viewer(const sg_viewer& a_from)
0049 :parent_window(a_from)
0050 ,parent_viewer(a_from)
0051 ,m_session(a_from.m_session)
0052 ,m_glarea(a_from.m_glarea)
0053 {}
0054 sg_viewer& operator=(const sg_viewer& a_from){
0055 parent_window::operator=(a_from);
0056 return *this;
0057 }
0058 public:
0059 bool has_window() const {return m_hwnd?true:false;} //for SWIG
0060
0061 HWND window() const {return m_hwnd;}
0062
0063 bool show() {
0064 if(!m_hwnd) return false;
0065 m_session.show_window(m_hwnd);
0066 return true;
0067 }
0068
0069 void win_render() {
0070 m_glarea.wm_paint();
0071 m_session.sync();
0072 }
0073
0074 void emit_win_render() {m_glarea.post_WM_PAINT();}
0075
0076 bool window_size(unsigned int& a_w,unsigned int& a_h) {
0077 if(!m_glarea.hwnd()) {a_w = 0;a_h = 0;return false;}
0078 RECT wrect;
0079 ::GetWindowRect(m_glarea.hwnd(),&wrect);
0080 a_w = wrect.right-wrect.left;
0081 a_h = wrect.bottom-wrect.top;
0082 return true;
0083 }
0084 void render_area_size(unsigned int& a_w,unsigned int& a_h) {
0085 a_w = parent_viewer::width();
0086 a_h = parent_viewer::height();
0087 }
0088
0089 public:
0090 void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership.
0091 m_glarea.set_device_interactor(a_interactor);
0092 }
0093 protected:
0094 class _glarea : public glarea {
0095 public:
0096 virtual void paint(unsigned int a_w,unsigned int a_h) {
0097 m_viewer.set_size(a_w,a_h);
0098 m_viewer.render();
0099 }
0100 public:
0101 _glarea(HWND a_parent,parent_viewer& a_viewer)
0102 :glarea(a_parent)
0103 ,m_viewer(a_viewer)
0104 {}
0105 protected:
0106 parent_viewer& m_viewer;
0107 };
0108
0109 protected:
0110 session& m_session;
0111 _glarea m_glarea;
0112 };
0113
0114 }}
0115
0116 #endif