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5 ] [ 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_Windows_zb_viewer
  5 #define toolx_Windows_zb_viewer
  6 
  7 #include "session"
  8 #include "window"
  9 
 10 #include "pixwin"
 11 #include <tools/sg/zb_viewer>
 12 
 13 // disable the warning about the usage of "this" in the constructor.
 14 #pragma warning(disable:4355)
 15 
 16 namespace toolx {
 17 namespace Windows {
 18 
 19 class zb_viewer : public window, protected pixwin, public tools::sg::zb_viewer {
 20   typedef window parent_window;
 21   typedef pixwin parent_render_area;
 22   typedef tools::sg::zb_viewer parent_viewer;
 23 protected:
 24   virtual void paint() {
 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;
 27     HDC hDC = ::GetDC(parent_render_area::m_hwnd);
 28     HDC bitmap_DC = ::CreateCompatibleDC(hDC);
 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)::SelectObject(bitmap_DC, bitmap);
 31     ::BitBlt(hDC,0,0,parent_viewer::m_ww,parent_viewer::m_wh,bitmap_DC,0,0,SRCCOPY);
 32     ::SelectObject(bitmap_DC, old_bitmap);
 33     ::DeleteObject(bitmap);
 34     ::DeleteDC(bitmap_DC);
 35     ::ReleaseDC(parent_render_area::m_hwnd,hDC);
 36     ::ValidateRect(parent_render_area::m_hwnd,NULL);
 37     m_out_buffer.clear();
 38   }
 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::zb_viewer::resize " << a_w << " " << a_h << std::endl;
 41     set_size(a_w,a_h);
 42   }
 43 public:  
 44   virtual void close() {}
 45 public:
 46   zb_viewer(session& a_session,
 47             int a_x = 0,int a_y = 0,
 48             unsigned int a_width = 500,unsigned int a_height = 500,
 49             const std::string& a_title = "")
 50   :parent_window(a_title.c_str(),a_x,a_y,a_width,a_height)
 51   ,parent_render_area(parent_window::m_hwnd,a_width,a_height)
 52   ,parent_viewer(a_session.out(),a_width,a_height)
 53   ,m_session(a_session)
 54   {
 55     parent_window::set_focus_hwnd(parent_render_area::m_hwnd);
 56   }
 57   virtual ~zb_viewer() {}
 58 protected:
 59   zb_viewer(const zb_viewer& a_from)
 60   :parent_window(a_from)
 61   ,parent_render_area(a_from)
 62   ,parent_viewer(a_from)
 63   ,m_session(a_from.m_session)
 64   {}
 65   zb_viewer& operator=(const zb_viewer& a_from){
 66     parent_window::operator=(a_from);
 67     return *this;
 68   }
 69 public:
 70   bool has_window() const {return parent_window::m_hwnd?true:false;} //for SWIG
 71 
 72   HWND window() const {return parent_window::m_hwnd;}
 73 
 74   bool show() {
 75     if(!parent_window::m_hwnd) return false;
 76     m_session.show_window(parent_window::m_hwnd);
 77     return true;
 78   }
 79 
 80   void win_render() {parent_render_area::wm_paint();}
 81   void set_device_interactor(tools::sg::device_interactor* a_interactor) {  //we do not have ownership.
 82     parent_render_area::set_device_interactor(a_interactor);
 83   }
 84 protected:
 85   session& m_session;
 86 };
 87 
 88 }}
 89 
 90 
 91 #endif