core/vgui/vgui_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_tableau.h
00002 #ifndef vgui_tableau_h_
00003 #define vgui_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00010 // \date   11 Sep 99
00011 // \brief  Base class for all tableaux in vgui.
00012 //
00013 //  Contains classes: vgui_tableau.
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   21-SEP-1999 fsm various changes.
00018 //   05-OCT-1999 fsm
00019 //   11-OCT-1999 fsm. removed old build_chain code.
00020 //   12-OCT-1999 fsm. added type_name() method. various cleanup.
00021 //   13-OCT-1999 fsm. deprecated draw_impl() and draw_overlay_impl().
00022 //   16-OCT-1999 fsm. deprecated draw(), draw_overlay() + two minor
00023 //                    methods. added get_popup().
00024 //   11-NOV-1999 fsm. added add_popup() now that get_popup() has a
00025 //                    different meaning. Added exists().
00026 //   07-AUG-2002 K.Y.McGaul - Changed to and added Doxygen style comments.
00027 //   08-OCT-2002 K.Y.McGaul - Removed unused adopt and disown functions.
00028 // \endverbatim
00029 
00030 #include <vcl_string.h>
00031 #include <vcl_vector.h>
00032 #include <vcl_iosfwd.h>
00033 
00034 #include <vgui/vgui_event.h>
00035 #include <vgui/internals/vgui_parent_child_link_data.h>
00036 #include "dll.h"
00037 
00038 class vgui_menu;
00039 class vgui_popup_params;
00040 struct vgui_tableau_sptr;
00041 
00042 //: Base class for all tableaux in vgui.
00043 //
00044 //  WHAT'S A TABLEAU?
00045 //  A tableau is a rectangular area of the screen on which OpenGL may be
00046 //  used to draw and from which events (mouse, key presses etc) are received.
00047 //
00048 //  WHAT SORT OF THINGS CAN TABLEAUX DO?
00049 //  Currently VGUI provides several example tableaux derived from this
00050 //  class, sufficient to construct complex user interfaces combining 2D and
00051 //  3D with manipulators and zoom. So for example an `image' tableau could
00052 //  display an image, a `zoomer' tableau could provide a function to zoom
00053 //  an image in and out. We could also make a `deck' tableau to hold a deck
00054 //  of images and display one image at a time (this would be useful for
00055 //  playing a series of images as a movie).
00056 //
00057 //  WHAT ARE PARENT AND CHILD TABLEAUX?
00058 //  One tableau can be included as a child of another (parent) tableau. This
00059 //  creates a new tableau with the functionality of both tableaux making it
00060 //  up. So the new tableau could, for example, display a deck of images and
00061 //  provide zooming.
00062 //
00063 //  The order in which the inclusion is done will affect the functionality,
00064 //  so if the `zoomer' tableau contains the `deck' tableau then all images
00065 //  will change size together. If however the inclusion is done the other way
00066 //  around and each child tableau of the `deck' contains its own `zoomer'
00067 //  tableau then each image will change size independently.
00068 //
00069 //  WHAT'S ALL THIS SPTR BUSINESS THEN?
00070 //  When you make a new tableau it is recommended that you don't create
00071 //  it from the constructor for that tableau (eg, vgui_wibble_tableau()),
00072 //  but instead call vgui_wibble_tableau_new().  This returns a smart
00073 //  pointer to your tableau (vgui_wibble_tableau_sptr) and means that
00074 //  you don't need to worry about deleting your tableau once you are
00075 //  finished using it.
00076 //
00077 //  SO HOW DO I USE A TABLEAU?
00078 //  Once-off adaptor code (see vgui_adaptor) is provided that plugs a
00079 //  tableau into any supported GUI toolkit.  So to use a tableau you make
00080 //  a window, add an adaptor and set the tableau in that adaptor to be
00081 //  your top level (highest parent) tableau. See the examples on the VXL
00082 //  webpage to see this done.
00083 class vgui_tableau : public vgui_parent_child_link_data
00084 {
00085  public:
00086   //: Constructor - in general you should not use this, use vgui_tableau_new.
00087   vgui_tableau();
00088 
00089   //: Return the name of the tableau.
00090   virtual vcl_string name() const { return file_name(); }
00091 
00092   //: Return the name of a file associated with some tableau below (if meaningful).
00093   virtual vcl_string file_name() const { return "(none)"; }
00094 
00095   //: Used to provide an informative name for printouts, debugging etc.
00096   //  Often it's type_name() + some representation of the essential state.
00097   virtual vcl_string pretty_name() const { return type_name(); }
00098 
00099   //: Return name of most derived class (for RTTI purposes).
00100   virtual vcl_string type_name() const;
00101 
00102   //: Get the parent tableaux for this tableau.
00103   void get_parents (vcl_vector<vgui_tableau_sptr> *out) const;
00104 
00105   //: Get the child tableaux for this tableau.
00106   void get_children(vcl_vector<vgui_tableau_sptr> *out) const;
00107 
00108   //: Get the ith child or return 0.
00109   vgui_tableau_sptr get_child(unsigned i) const;
00110 
00111   //: Add the given tableau to the list of child tableaux.
00112   //  Virtual overridden by consenting parents.
00113   virtual bool add_child(vgui_tableau_sptr const &);
00114 
00115   //: Remove the given child from the list of child tableaux.
00116   virtual bool remove_child(vgui_tableau_sptr const &);
00117 
00118   //: Push all tableaux onto the given vector.
00119   static void get_all(vcl_vector<vgui_tableau_sptr> *out);
00120 
00121   //: Returns true if the given address points to a valid tableau.
00122   static bool exists(vgui_tableau_sptr const &);
00123 
00124   //: Called whenever a child of this tableau is about to be forcibly replaced
00125   virtual bool notify_replaced_child(vgui_tableau_sptr const & old_child,
00126                                      vgui_tableau_sptr const & new_child);
00127 
00128   //: Add the given menu to the popup menu for the tableau.
00129   virtual void add_popup(vgui_menu &);
00130 
00131   //: Get the default popup menu for the tableau.
00132   virtual void get_popup(vgui_popup_params const &, vgui_menu &);
00133 
00134   //: Post a message event.
00135   //  The fact that this is virtual does not imply that you should
00136   //  go and override it.
00137   virtual void post_message(char const *, void const *);
00138 
00139   //: Post a draw event.
00140   //  The fact that this is virtual does not imply that you should
00141   //  go and override it.
00142   virtual void post_redraw();
00143 
00144   //: Post an overlay-redraw event.
00145   //  The fact that this is virtual does not imply that you should
00146   //  go and override it.
00147   virtual void post_overlay_redraw();
00148 
00149   //: Post an idle request event.
00150   //  The fact that this is virtual does not imply that you should
00151   //  go and override it.
00152   //
00153   //  Posting an idle event request means that your tableau has some
00154   //  idle processing that it'd like to do. This means that your
00155   //  tableau will continue to receive vgui_IDLE events until the
00156   //  event handler returns false (i.e. all idle processing is
00157   //  complete). The idle event handler should return false when it
00158   //  has no idle processing, or has completed its idle processing. It
00159   //  may return true if has only partially completed its idle
00160   //  processing; in this case, it will receive more idle event to
00161   //  allow it to complete processing.
00162   //
00163   virtual void post_idle_request();
00164 
00165   //: Handle all events sent to this tableau.
00166   //  Override in subclass to give the tableau some appearance and behaviour.
00167   virtual bool handle(vgui_event const &);
00168 
00169   //: Get the bounding box of this tableau.
00170   //  If infinite in extent, or nothing is drawn, or you can't be bothered to
00171   //  implement it, return false.
00172   //  const. if you need to cache, cast away const.
00173   virtual bool get_bounding_box(float low[3], float high[3]) const;
00174 
00175   //: Called by default handle when it receives a draw event.
00176   virtual bool draw();
00177 
00178   //: Called by default handle when it receives a mouse down event.
00179   virtual bool mouse_down(int x, int y, vgui_button, vgui_modifier);
00180 
00181   //: Called by default handle when it receives a mouse up event.
00182   virtual bool mouse_up(int x, int y, vgui_button, vgui_modifier);
00183 
00184   //: Called by handle when it receives a mouse motion event.
00185   virtual bool motion(int x, int y);
00186 
00187   //: Called by default handle when it receives a key-press event.
00188   virtual bool key_press(int x, int y, vgui_key, vgui_modifier);
00189 
00190   //: Called by default handle when it receives a '?' pressed event.
00191   virtual bool help(); // this is called if '?' is pressed
00192 
00193   //: Called when the application is otherwise idle.
00194   // Override if you want to do idle processing.
00195   // Return false once your idle processing is complete,
00196   // or if you have no need for more idle processing.
00197   // Return true if you need more idle processing time.
00198   virtual bool idle();
00199 
00200   //: Increase the reference count by one (for smart pointers).
00201   //  "const" is for convenience, it is cast away internally.
00202   void ref() const;
00203 
00204   //: Decrease the reference count by one (for smart pointers).
00205   //  "const" is for convenience, it is cast away internally.
00206   //  If the reference count reaches zero then delete the object.
00207   void unref() const;
00208 
00209  protected:
00210   //: Destructor - called by vgui_tableau_sptr.
00211   virtual ~vgui_tableau();
00212 
00213  private:
00214   friend struct vgui_parent_child_link;
00215   friend struct vgui_parent_child_link_impl;
00216   friend class vgui_adaptor;
00217 
00218   //: Reference count - starts at 0.
00219   int references;
00220 };
00221 
00222 //: Print some indication of what the tableau is.
00223 vcl_ostream &operator<<(vcl_ostream &os, vgui_tableau_sptr const &t);
00224 
00225 #include "vgui_tableau_sptr.h"
00226 
00227 #endif // vgui_tableau_h_