core/vgui/impl/wx/vgui_wx_adaptor.h
Go to the documentation of this file.
00001 // This is core/vgui/impl/wx/vgui_wx_adaptor.h
00002 #ifndef vgui_wx_adaptor_h_
00003 #define vgui_wx_adaptor_h_
00004 //=========================================================================
00005 //:
00006 // \file
00007 // \brief  wxWidgets implementation of vgui_adaptor.
00008 // \author Miguel A. Figueroa-Villanueva (miguelfv)
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   03/22/2006 - File created. (miguelfv)
00013 // \endverbatim
00014 //=========================================================================
00015 
00016 #include <vgui/vgui_adaptor.h>
00017 #include <vgui/internals/vgui_adaptor_mixin.h>
00018 
00019 #include <wx/docview.h>
00020 #include <wx/glcanvas.h>
00021 class wxMenu;
00022 
00023 #include <vcl_map.h>
00024 
00025 //-------------------------------------------------------------------------
00026 //: wxWidgets implementation of vgui_adaptor.
00027 //
00028 // The adaptor allows you to draw an OpenGL area in your wxWidgets
00029 // application (i.e., embedding the adaptor in wxWidgets) or in a vgui
00030 // application (i.e., extending the adaptor to use wxWidgets as your
00031 // vgui_toolkit).
00032 //-------------------------------------------------------------------------
00033 class vgui_wx_adaptor
00034   : public wxGLCanvas
00035   , public vgui_adaptor
00036   , public vgui_adaptor_mixin
00037 {
00038   DECLARE_CLASS(vgui_wx_adaptor)
00039   DECLARE_EVENT_TABLE()
00040 
00041   typedef vgui_adaptor_mixin mixin;
00042 
00043  public:
00044   //: Constructor - used by dynamic creation.
00045   vgui_wx_adaptor(wxWindow* parent,
00046                   wxWindowID id = wxID_ANY,
00047                   const wxPoint& pos = wxDefaultPosition,
00048                   const wxSize& size = wxDefaultSize,
00049                   long style = 0,
00050                   const wxString& name = wxT("vgui_wx_adaptor"),
00051                   int* attributes = 0);
00052 
00053   //: Destructor.
00054   virtual ~vgui_wx_adaptor();
00055 
00056   void set_view(wxView* view) { view_ = view; }
00057 
00058   //-----------------------------------------------------------------------
00059   // vgui_adaptor virtual implementations
00060   //-----------------------------------------------------------------------
00061 
00062   //: Return width of rendering area.
00063   virtual unsigned int get_width() const { return GetClientSize().GetWidth(); }
00064 
00065   //: Return height of rendering area.
00066   virtual unsigned int get_height() const { return GetClientSize().GetHeight(); }
00067 
00068   //: Redraw the rendering area.
00069   virtual void post_redraw();
00070 
00071   //: Redraws overlay buffer.
00072   virtual void post_overlay_redraw();
00073 
00074   //: Flags that a child requests idle processing.
00075   virtual void post_idle_request();
00076 
00077   //: ***** What is this for???
00078   virtual void post_message(char const *, void const *);
00079 
00080   //: Schedules destruction of parent vgui_window.
00081   virtual void post_destroy();
00082 
00083   //: Sets timer 'id' to dispatch a WM_TIMER event every 'timeout' ms.
00084   virtual void post_timer(float timeout, int id);
00085 
00086   //: Stop timer 'id'.
00087   virtual void kill_timer(int id);
00088 
00089   //: Bind the given modifier/button combination to the popup menu.
00090   virtual void bind_popups(vgui_modifier m, vgui_button b)
00091   {
00092     mixin::popup_modifier = m;
00093     mixin::popup_button   = b;
00094   }
00095 
00096   //: Return the modifier/button which displayed the popup menu.
00097   virtual void get_popup_bindings(vgui_modifier &m, vgui_button &b) const
00098   {
00099     m = mixin::popup_modifier;
00100     b = mixin::popup_button;
00101   }
00102 
00103   //: ***** Return window that contains this adaptor.
00104   virtual vgui_window* get_window() const { return 0; }
00105 
00106   //: Swap buffers if using double buffering.
00107   virtual void swap_buffers();
00108 
00109   //: Make this the current GL rendering context.
00110   virtual void make_current();
00111 
00112   //-----------------------------------------------------------------------
00113   //-----------------------------------------------------------------------
00114  private:
00115   //: Called when canvas is resized.
00116   void on_size(wxSizeEvent& event);
00117 
00118   //: Called when a window needs to be repainted.
00119   void on_paint(wxPaintEvent& WXUNUSED(event));
00120 
00121   //: Called when the background needs erasing (i.e., before repainting).
00122   void on_erase_background(wxEraseEvent& WXUNUSED(event));
00123 
00124   //: Helper used by on_key_up/down to reduce code duplication.
00125   void on_key(vgui_event& ve, wxKeyEvent& event);
00126 
00127   //: Called when a key is pressed.
00128   void on_key_down(wxKeyEvent& event);
00129 
00130   //: Called when a key is released.
00131   void on_key_up(wxKeyEvent& event);
00132 
00133   //: Called when a key is pressed, but carries a translated ascii code.
00134   //
00135   // To catch this event after a key_down has been caught, call
00136   // event.skip() from the on_key_down handler. Note that the char event
00137   // is always generated after the key_down event in wxWidgets.
00138   void on_char(wxKeyEvent& event);
00139 
00140   //: Called for all types of mouse events (e.g., button-up, motion, etc.).
00141   void on_mouse_event(wxMouseEvent& event);
00142 
00143   //: Called when the system becomes idle.
00144   void on_idle(wxIdleEvent& event);
00145 
00146   //: Called when the user tries to close a frame or dialog box.
00147   // The event can be generated programmatically or when the user tries to
00148   // close using the window manager (X) or system menu (Windows).
00149   void on_close(wxCloseEvent& event);
00150 
00151   //: Called at fixed intervals when using a timer.
00152   void on_timer(wxEvent& event);
00153 
00154   //: Generates a wxPaintEvent for the window to be repainted.
00155   void invalidate_canvas();
00156 
00157   //-----------------------------------------------------------------------
00158   //-----------------------------------------------------------------------
00159  private:
00160   wxView* view_;
00161 
00162   static vgui_menu last_popup_;
00163 
00164   //: True while a redraw event has been requested but not implemented.
00165   bool redraw_posted_;
00166 
00167   //: True while an overlay redraw event has been requested but not implemented.
00168   bool overlay_redraw_posted_;
00169 
00170   //: True while an idle time has been requested but not implemented.
00171   bool idle_request_posted_;
00172 
00173   //: True when destruction of parent vgui_window has been scheduled.
00174   bool destroy_posted_;
00175 
00176   int last_key_down_;
00177   vcl_map<int,int> ascii_code_;
00178 };
00179 
00180 #endif // vgui_wx_adaptor_h_