Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef toolx_Windows_zb_viewer 4 #ifndef toolx_Windows_zb_viewer 5 #define toolx_Windows_zb_viewer 5 #define toolx_Windows_zb_viewer 6 6 7 #include "session" 7 #include "session" 8 #include "window" 8 #include "window" 9 9 10 #include "pixwin" 10 #include "pixwin" 11 #include <tools/sg/zb_viewer> 11 #include <tools/sg/zb_viewer> 12 12 13 // disable the warning about the usage of "thi 13 // disable the warning about the usage of "this" in the constructor. 14 #pragma warning(disable:4355) 14 #pragma warning(disable:4355) 15 15 16 namespace toolx { 16 namespace toolx { 17 namespace Windows { 17 namespace Windows { 18 18 19 class zb_viewer : public window, protected pix 19 class zb_viewer : public window, protected pixwin, public tools::sg::zb_viewer { 20 typedef window parent_window; 20 typedef window parent_window; 21 typedef pixwin parent_render_area; 21 typedef pixwin parent_render_area; 22 typedef tools::sg::zb_viewer parent_viewer; 22 typedef tools::sg::zb_viewer parent_viewer; 23 protected: 23 protected: 24 virtual void paint() { 24 virtual void paint() { 25 //parent_viewer::m_out << "toolx::Windows: 25 //parent_viewer::m_out << "toolx::Windows::zb_viewer::paint " << parent_viewer::m_ww << " " << parent_viewer::m_wh << std::endl; 26 if(!render(get_bgras,false)) return; 26 if(!render(get_bgras,false)) return; 27 HDC hDC = ::GetDC(parent_render_area::m_hw 27 HDC hDC = ::GetDC(parent_render_area::m_hwnd); 28 HDC bitmap_DC = ::CreateCompatibleDC(hDC); 28 HDC bitmap_DC = ::CreateCompatibleDC(hDC); 29 HBITMAP bitmap = ::CreateBitmap(parent_vie 29 HBITMAP bitmap = ::CreateBitmap(parent_viewer::m_ww,parent_viewer::m_wh, 1, 32, tools::vec_data(m_out_buffer)); 30 HBITMAP old_bitmap = (HBITMAP)::SelectObje 30 HBITMAP old_bitmap = (HBITMAP)::SelectObject(bitmap_DC, bitmap); 31 ::BitBlt(hDC,0,0,parent_viewer::m_ww,paren 31 ::BitBlt(hDC,0,0,parent_viewer::m_ww,parent_viewer::m_wh,bitmap_DC,0,0,SRCCOPY); 32 ::SelectObject(bitmap_DC, old_bitmap); 32 ::SelectObject(bitmap_DC, old_bitmap); 33 ::DeleteObject(bitmap); 33 ::DeleteObject(bitmap); 34 ::DeleteDC(bitmap_DC); 34 ::DeleteDC(bitmap_DC); 35 ::ReleaseDC(parent_render_area::m_hwnd,hDC 35 ::ReleaseDC(parent_render_area::m_hwnd,hDC); 36 ::ValidateRect(parent_render_area::m_hwnd, 36 ::ValidateRect(parent_render_area::m_hwnd,NULL); 37 m_out_buffer.clear(); 37 m_out_buffer.clear(); 38 } 38 } 39 virtual void resize(unsigned int a_w,unsigne 39 virtual void resize(unsigned int a_w,unsigned int a_h){ //NOTE: it is not called at startup. 40 //parent_viewer::m_out << "toolx::Windows: 40 //parent_viewer::m_out << "toolx::Windows::zb_viewer::resize " << a_w << " " << a_h << std::endl; 41 set_size(a_w,a_h); 41 set_size(a_w,a_h); 42 } 42 } 43 public: 43 public: 44 virtual void close() {} 44 virtual void close() {} 45 public: 45 public: 46 zb_viewer(session& a_session, 46 zb_viewer(session& a_session, 47 int a_x = 0,int a_y = 0, 47 int a_x = 0,int a_y = 0, 48 unsigned int a_width = 500,unsigne 48 unsigned int a_width = 500,unsigned int a_height = 500, 49 const std::string& a_title = "") 49 const std::string& a_title = "") 50 :parent_window(a_title.c_str(),a_x,a_y,a_wid 50 :parent_window(a_title.c_str(),a_x,a_y,a_width,a_height) 51 ,parent_render_area(parent_window::m_hwnd,a_ 51 ,parent_render_area(parent_window::m_hwnd,a_width,a_height) 52 ,parent_viewer(a_session.out(),a_width,a_hei 52 ,parent_viewer(a_session.out(),a_width,a_height) 53 ,m_session(a_session) 53 ,m_session(a_session) 54 { 54 { 55 parent_window::set_focus_hwnd(parent_rende 55 parent_window::set_focus_hwnd(parent_render_area::m_hwnd); 56 } 56 } 57 virtual ~zb_viewer() {} 57 virtual ~zb_viewer() {} 58 protected: 58 protected: 59 zb_viewer(const zb_viewer& a_from) 59 zb_viewer(const zb_viewer& a_from) 60 :parent_window(a_from) 60 :parent_window(a_from) 61 ,parent_render_area(a_from) 61 ,parent_render_area(a_from) 62 ,parent_viewer(a_from) 62 ,parent_viewer(a_from) 63 ,m_session(a_from.m_session) 63 ,m_session(a_from.m_session) 64 {} 64 {} 65 zb_viewer& operator=(const zb_viewer& a_from 65 zb_viewer& operator=(const zb_viewer& a_from){ 66 parent_window::operator=(a_from); 66 parent_window::operator=(a_from); 67 return *this; 67 return *this; 68 } 68 } 69 public: 69 public: 70 bool has_window() const {return parent_windo 70 bool has_window() const {return parent_window::m_hwnd?true:false;} //for SWIG 71 71 72 HWND window() const {return parent_window::m 72 HWND window() const {return parent_window::m_hwnd;} 73 73 74 bool show() { 74 bool show() { 75 if(!parent_window::m_hwnd) return false; 75 if(!parent_window::m_hwnd) return false; 76 m_session.show_window(parent_window::m_hwn 76 m_session.show_window(parent_window::m_hwnd); 77 return true; 77 return true; 78 } 78 } 79 79 80 void win_render() {parent_render_area::wm_pa 80 void win_render() {parent_render_area::wm_paint();} 81 void set_device_interactor(tools::sg::device 81 void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership. 82 parent_render_area::set_device_interactor( 82 parent_render_area::set_device_interactor(a_interactor); 83 } 83 } 84 protected: 84 protected: 85 session& m_session; 85 session& m_session; 86 }; 86 }; 87 87 88 }} 88 }} 89 89 90 90 91 #endif 91 #endif