Warning, /include/Geant4/toolx/Windows/zb_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_zb_viewer
0005 #define toolx_Windows_zb_viewer
0006
0007 #include "session"
0008 #include "window"
0009
0010 #include "pixwin"
0011 #include <tools/sg/zb_viewer>
0012
0013 // disable the warning about the usage of "this" in the constructor.
0014 #pragma warning(disable:4355)
0015
0016 namespace toolx {
0017 namespace Windows {
0018
0019 class zb_viewer : public window, protected pixwin, public tools::sg::zb_viewer {
0020 typedef window parent_window;
0021 typedef pixwin parent_render_area;
0022 typedef tools::sg::zb_viewer parent_viewer;
0023 protected:
0024 virtual void paint() {
0025 if(!render(get_bgras,false)) return;
0026 HDC hDC = ::GetDC(parent_render_area::m_hwnd);
0027 HDC bitmap_DC = ::CreateCompatibleDC(hDC);
0028 HBITMAP bitmap = ::CreateBitmap(parent_viewer::m_ww,parent_viewer::m_wh, 1, 32, m_out_buffer.data());
0029 HBITMAP old_bitmap = (HBITMAP)::SelectObject(bitmap_DC, bitmap);
0030 ::BitBlt(hDC,0,0,parent_viewer::m_ww,parent_viewer::m_wh,bitmap_DC,0,0,SRCCOPY);
0031 ::SelectObject(bitmap_DC, old_bitmap);
0032 ::DeleteObject(bitmap);
0033 ::DeleteDC(bitmap_DC);
0034 ::ReleaseDC(parent_render_area::m_hwnd,hDC);
0035 ::ValidateRect(parent_render_area::m_hwnd,NULL);
0036 m_out_buffer.clear();
0037 }
0038 virtual void resize(unsigned int a_w,unsigned int a_h){ //NOTE: it is not called at startup.
0039 set_size(a_w,a_h);
0040 }
0041 public:
0042 virtual void close() {}
0043 public:
0044 zb_viewer(session& a_session,
0045 int a_x = 0,int a_y = 0,
0046 unsigned int a_width = 500,unsigned int a_height = 500,
0047 const std::string& a_title = "")
0048 :parent_window(a_title.c_str(),a_x,a_y,a_width,a_height)
0049 ,parent_render_area(parent_window::m_hwnd,a_width,a_height)
0050 ,parent_viewer(a_session.out(),a_width,a_height)
0051 ,m_session(a_session)
0052 {
0053 parent_window::set_focus_hwnd(parent_render_area::m_hwnd);
0054 }
0055 virtual ~zb_viewer() {}
0056 protected:
0057 zb_viewer(const zb_viewer& a_from)
0058 :parent_window(a_from)
0059 ,parent_render_area(a_from)
0060 ,parent_viewer(a_from)
0061 ,m_session(a_from.m_session)
0062 {}
0063 zb_viewer& operator=(const zb_viewer& a_from){
0064 parent_window::operator=(a_from);
0065 return *this;
0066 }
0067 public:
0068 bool has_window() const {return parent_window::m_hwnd?true:false;} //for SWIG
0069
0070 HWND window() const {return parent_window::m_hwnd;}
0071
0072 bool show() {
0073 if(!parent_window::m_hwnd) return false;
0074 m_session.show_window(parent_window::m_hwnd);
0075 return true;
0076 }
0077
0078 void win_render() {
0079 parent_render_area::wm_paint();
0080 m_session.sync();
0081 }
0082
0083 void emit_win_render() {parent_render_area::post_WM_PAINT();}
0084
0085 bool window_size(unsigned int& a_w,unsigned int& a_h) {
0086 if(!parent_render_area::m_hwnd) {a_w = 0;a_h = 0;return false;}
0087 RECT wrect;
0088 ::GetWindowRect(parent_render_area::m_hwnd,&wrect);
0089 a_w = wrect.right-wrect.left;
0090 a_h = wrect.bottom-wrect.top;
0091 return true;
0092 }
0093 void render_area_size(unsigned int& a_w,unsigned int& a_h) {
0094 a_w = parent_viewer::width();
0095 a_h = parent_viewer::height();
0096 }
0097
0098 void set_device_interactor(tools::sg::device_interactor* a_interactor) { //we do not have ownership.
0099 parent_render_area::set_device_interactor(a_interactor);
0100 }
0101 protected:
0102 session& m_session;
0103 };
0104
0105 }}
0106
0107
0108 #endif