core/vgui/vgui_adaptor.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_adaptor.h
00002 #ifndef vgui_adaptor_h_
00003 #define vgui_adaptor_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 // \brief  Provides an abstract interface to an OpenGL rendering state.
00008 //
00009 // \verbatim
00010 // Modifications
00011 // 20 October  1999 pcp@robots. removed derivation from tableau.
00012 // 20 October  1999 fsm. detach()ed the adaptor from the tableau in
00013 //                  the destructor to avoid leaving a dangling pointer in the
00014 //                  tableau.
00015 // 28 October  1999 fsm. added more menu support (as agreed with pcp).
00016 //  7 January  1999 fsm. new observer/observable method of getting
00017 //                  redraw from tableau to adaptor.
00018 //  2 February 1999 fsm. more overlay documentation.
00019 // 23-AUG-2000      Marko Bacic,Oxford RRG - Added post_message
00020 // 31 August   2000 u97mb@robots. Support for mfc acceleration
00021 // 07-SEP-2000      Marko Bacic,Oxford RRG - Added pure virtual method "draw"
00022 // 20 Sept     2000 capes@robots. added post_destroy() method.
00023 // Feb.2002         Peter Vanroose - brief doxygen comment placed on single line
00024 // 08-OCT-2002 K.Y.McGaul - Added use_double_buffering.
00025 // 23-DEC-2002 J.L.Mundy - Added access for the window
00026 // 23-DEC-2002 A.Perera - Removed access for the window. It doesn't belong at this level.
00027 // \endverbatim
00028 
00029 #include "dll.h"
00030 #include <vgui/vgui_menu.h>
00031 #include <vgui/vgui_event.h>
00032 class vgui_window;
00033 class vgui_tableau;
00034 struct vgui_tableau_sptr;
00035 class vgui_popup_params;
00036 class vgui_adaptor_tableau;
00037 
00038 //: Provides an abstract interface to an OpenGL rendering state.
00039 //
00040 // Provides an abstract interface to an OpenGL rendering state (context)
00041 // producing events. Events from adaptor (eg. when someone presses a
00042 // mouse button over the window) will be dispatched to the associated
00043 // vgui_tableau in a vgui_event structure. Draw requests will be dispatched
00044 // to the tableau as vgui_DRAW and vgui_DRAW_OVERLAY events.
00045 //
00046 // Note. When the set_tableau() method is called, the adaptor will attach itself
00047 // to the tableau as an observer. The tableau may detach that observer if it so
00048 // chooses, but that would be a bad idea as it would stop post()s from tableaux
00049 // reaching the adaptor.
00050 class vgui_adaptor
00051 {
00052  public:
00053   //: Constructor - create a default adaptor.
00054   vgui_adaptor();
00055 
00056   //: Destructor - quits application if all adaptors have been deleted.
00057   virtual ~vgui_adaptor();
00058 
00059   //: Get the vgui_tableau associated with this vgui_adaptor.
00060   vgui_tableau_sptr get_tableau() const;
00061 
00062   //: Set the vgui_tableau associated with this vgui_adaptor.
00063   void set_tableau(vgui_tableau_sptr const& t);
00064 
00065   //: True to use double buffering, false to not use it.
00066   void set_double_buffering(bool b) { use_double_buffering = b; }
00067 
00068   //: Return the concatenation of the adaptor's menu with the tableau's menu.
00069   vgui_menu get_total_popup(vgui_popup_params &) const;
00070 
00071   //: Pop up a dialog for changing the popup modifier and button bindings.
00072   void config_dialog();
00073 
00074   //: Return the popup menu for this adaptor.
00075   vgui_menu &get_popup() { return menu; }
00076 
00077   //: Set the popup menu for this adaptor.
00078   void set_popup(vgui_menu const &m) { get_popup() = m; }
00079 
00080   //: Add the given menu to the popup menu for this adaptor.
00081   void include_in_popup(vgui_menu const &m) { get_popup().include(m); }
00082 
00083   //: Dispatches the given event to the tableau.
00084   //  This method performs various checks which can be performed generically for
00085   //  all tableaux. It is not the responsibility of this method to take care of
00086   //  overlay handling - the derived class must sort that out.
00087   bool dispatch_to_tableau(vgui_event const &);
00088 
00089   //: This static datum points to the adaptor that last received a mouse event.
00090   //  It is set to zero if its pointer receives a LEAVE event.  It will
00091   // often point to the adaptor which was current when a popup menu was
00092   // triggered, which is often what one wants it for.
00093   static vgui_DLLDATA vgui_adaptor *current;
00094 
00095   // ---------- virtuals ----------
00096   // only the pure virtuals need be implemented.
00097   // the rest is quality-of-implementation stuff.
00098 
00099   //: Return width of rendering area.
00100   //  *Not* the width of the viewport. There seems to be no OpenGL
00101   //  mechanism for doing this.
00102   virtual unsigned get_width() const =0;
00103 
00104   //: Return height of rendering area.
00105   //  *Not* the height of the viewport. There seems to be no OpenGL
00106   //  mechanism for doing this.
00107   virtual unsigned get_height() const =0;
00108 
00109   // These methods are called by vgui_adaptor (in its capacity as a base class)
00110   // when a post arrives.
00111   // The single-argument version calls the two-argument one with increasing
00112   // counter value on subsequent calls.  The used counter value is returned.
00113   // The two-argument version must be implemented by the derived class.
00114   virtual void post_timer(float, int );
00115           int  post_timer(float);
00116   //: Redraw the rendering area.
00117   virtual void post_redraw() =0;
00118   virtual void post_overlay_redraw() =0;
00119   virtual void post_idle_request();
00120   virtual void post_message(char const *, void const *);
00121   virtual void post_destroy();
00122 
00123   //: kill an existing timer
00124   virtual void kill_timer(int);
00125   
00126   //: Bind the given modifier/button combination to the popup menu.
00127   virtual void bind_popups(vgui_modifier=vgui_MODIFIER_NULL, vgui_button=vgui_RIGHT);
00128 
00129   //: Return the modifier/button which pops up the popup menu.
00130   virtual void get_popup_bindings(vgui_modifier &, vgui_button &) const;
00131 
00132   // getting the window.
00133   virtual vgui_window *get_window() const;
00134 
00135   // various buffer behaviour.
00136   virtual void swap_buffers();
00137   virtual void make_current();
00138 
00139  protected:
00140   //: Parameters controlling the popup menu style.
00141   // These are put onto a popup_params object and passed to tableau::get_popup()
00142   bool nested_popups;
00143   bool default_items;
00144 
00145   //: Whether or not to use double buffering.
00146   bool use_double_buffering;
00147 
00148  private:
00149   vgui_adaptor_tableau *the_tableau;
00150 
00151   //: this menu is put before the tableau's popup menu.
00152   vgui_menu menu;
00153 };
00154 
00155 #endif // vgui_adaptor_h_