Back to home page

EIC code displayed by LXR

 
 

    


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     //parent_viewer::m_out << "toolx::Windows::zb_viewer::paint " << parent_viewer::m_ww << " " << parent_viewer::m_wh << std::endl;
0026     if(!render(get_bgras,false)) return;
0027     HDC hDC = ::GetDC(parent_render_area::m_hwnd);
0028     HDC bitmap_DC = ::CreateCompatibleDC(hDC);
0029     HBITMAP bitmap = ::CreateBitmap(parent_viewer::m_ww,parent_viewer::m_wh, 1, 32, tools::vec_data(m_out_buffer));
0030     HBITMAP old_bitmap = (HBITMAP)::SelectObject(bitmap_DC, bitmap);
0031     ::BitBlt(hDC,0,0,parent_viewer::m_ww,parent_viewer::m_wh,bitmap_DC,0,0,SRCCOPY);
0032     ::SelectObject(bitmap_DC, old_bitmap);
0033     ::DeleteObject(bitmap);
0034     ::DeleteDC(bitmap_DC);
0035     ::ReleaseDC(parent_render_area::m_hwnd,hDC);
0036     ::ValidateRect(parent_render_area::m_hwnd,NULL);
0037     m_out_buffer.clear();
0038   }
0039   virtual void resize(unsigned int a_w,unsigned int a_h){  //NOTE: it is not called at startup.
0040     //parent_viewer::m_out << "toolx::Windows::zb_viewer::resize " << a_w << " " << a_h << std::endl;
0041     set_size(a_w,a_h);
0042   }
0043 public:  
0044   virtual void close() {}
0045 public:
0046   zb_viewer(session& a_session,
0047             int a_x = 0,int a_y = 0,
0048             unsigned int a_width = 500,unsigned int a_height = 500,
0049             const std::string& a_title = "")
0050   :parent_window(a_title.c_str(),a_x,a_y,a_width,a_height)
0051   ,parent_render_area(parent_window::m_hwnd,a_width,a_height)
0052   ,parent_viewer(a_session.out(),a_width,a_height)
0053   ,m_session(a_session)
0054   {
0055     parent_window::set_focus_hwnd(parent_render_area::m_hwnd);
0056   }
0057   virtual ~zb_viewer() {}
0058 protected:
0059   zb_viewer(const zb_viewer& a_from)
0060   :parent_window(a_from)
0061   ,parent_render_area(a_from)
0062   ,parent_viewer(a_from)
0063   ,m_session(a_from.m_session)
0064   {}
0065   zb_viewer& operator=(const zb_viewer& a_from){
0066     parent_window::operator=(a_from);
0067     return *this;
0068   }
0069 public:
0070   bool has_window() const {return parent_window::m_hwnd?true:false;} //for SWIG
0071 
0072   HWND window() const {return parent_window::m_hwnd;}
0073 
0074   bool show() {
0075     if(!parent_window::m_hwnd) return false;
0076     m_session.show_window(parent_window::m_hwnd);
0077     return true;
0078   }
0079 
0080   void win_render() {parent_render_area::wm_paint();}
0081   void set_device_interactor(tools::sg::device_interactor* a_interactor) {  //we do not have ownership.
0082     parent_render_area::set_device_interactor(a_interactor);
0083   }
0084 protected:
0085   session& m_session;
0086 };
0087 
0088 }}
0089 
0090 
0091 #endif