core/vgui/vgui_deck_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_deck_tableau.h
00002 #ifndef vgui_deck_tableau_h_
00003 #define vgui_deck_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau holding many child tableaux, but only one receives events.
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date   13 Sep 99
00012 //
00013 //  Contains classes  vgui_deck_tableau  vgui_deck_tableau_new
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   13-SEP-1999 P.Pritchett - Initial version.
00018 //   26-APR-2002 K.Y.McGaul - Converted to and added doxygen style comments.
00019 // \endverbatim
00020 
00021 #include "vgui_deck_tableau_sptr.h"
00022 #include <vgui/vgui_observable.h>
00023 #include <vgui/vgui_tableau.h>
00024 #include <vgui/vgui_parent_child_link.h>
00025 #include <vcl_string.h>
00026 
00027 //: Tableau holding many child tableaux, but only one receives events.
00028 //
00029 //  vgui_deck_tableau holds an ordered collection of child tableaux, only one
00030 //  of which is passed all events that the vgui_deck_tableau receives. The
00031 //  effect is a flick-book of tableaux where the currently active tableau can
00032 //  be changed using PageUp and PageDown
00033 class vgui_deck_tableau : public vgui_tableau
00034 {
00035  public:
00036   //: Constructor - don't use this, use vgui_deck_tableau_new.
00037   //  Make an empty deck
00038   vgui_deck_tableau() : index_(-1) {}
00039 
00040   //: Constructor - don't use this, use vgui_deck_tableau_new.
00041   //  Make a deck with two children, listed top to bottom
00042   vgui_deck_tableau(vgui_tableau_sptr const& child0, vgui_tableau_sptr const& child1);
00043 
00044   //: Constructor - don't use this, use vgui_deck_tableau_new.
00045   //  Make a deck with three children, listed top to bottom
00046   vgui_deck_tableau(vgui_tableau_sptr const& child0, vgui_tableau_sptr const& child1, vgui_tableau_sptr const& child2);
00047 
00048   //: Add a tableau to the deck
00049   //  It is placed on top, and made current.
00050   void add(vgui_tableau_sptr const& t) { add_child(t); }
00051 
00052   //: Remove the tableau pointed to by P.
00053   //  The one below is then made current.
00054   void remove(vgui_tableau_sptr const& p);
00055 
00056   //: Return a pointer to the current tableau
00057   vgui_tableau_sptr current();
00058 
00059   //: Return a pointer to the tableau at a given location
00060   vgui_tableau_sptr get_tableau_at(int);
00061 
00062   //: Return number of child tableaux in the deck.
00063   int size();
00064 
00065   //: Say which tableau is current
00066   int index() const {return index_;}
00067 
00068   //: Make a particular tableau current.
00069   void index(int);
00070 
00071   //: Make the top tableau current
00072   void begin();
00073 
00074   //: Make the next tableau down the list current
00075   void next();
00076 
00077   //: Make the next higher tableau current
00078   void prev();
00079 
00080   //: Returns the file_name of the active child.
00081   //  Over-rides function in vgui_tableau.
00082   virtual vcl_string file_name() const;
00083 
00084   //: Returns a nice version of the name, including info on the active child.
00085   //  Over-rides function in vgui_tableau.
00086   virtual vcl_string pretty_name() const;
00087 
00088   //: Returns the type of this tableau ('vgui_deck_tableau').
00089   //  Over-rides function in vgui_tableau.
00090   virtual vcl_string type_name() const;
00091 
00092   //: Builds a popup menu for the user to select the active child.
00093   //  Over-rides function in vgui_tableau.
00094   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
00095 
00096   //: Send info to cerr - called when user presses '?' in the rendering area.
00097   //  Over-rides function in vgui_tableau.
00098   //  This function is called by the default handle() function in vgui_tableau.
00099   bool help();
00100 
00101   //: Uses PageUp and PageDown events - called when user presses a key.
00102   //  Over-rides function in vgui_tableau.
00103   //  This function is called by the default handle() function in vgui_tableau.
00104   bool key_press(int x, int y, vgui_key key, vgui_modifier);
00105 
00106   //: Conceptually, this is a list on which observers can put themselves.
00107   vgui_observable observers;
00108 
00109  protected:
00110   //: Destructor - called by vgui_deck_tableau_sptr.
00111   virtual ~vgui_deck_tableau();
00112 
00113   //: Handle events by passing to the current child tableau.
00114   virtual bool handle(const vgui_event&);
00115 
00116   //: Add a tableau to the deck
00117   //  It is placed on top, and made current.
00118   //  Overrides virtual base class method.
00119   bool add_child(vgui_tableau_sptr const& t);
00120 
00121   //: Remove the given child tableau from the deck.
00122   bool remove_child(vgui_tableau_sptr const& );
00123 
00124   //: Returns true if given integer could be an index to the list of children.
00125   bool index_ok(int) const;
00126 
00127   // data
00128   //-----
00129 
00130   //: List of child tableaux.
00131   vcl_vector<vgui_parent_child_link> children;
00132 
00133   //: Currently active child tableau.
00134   int index_;
00135 };
00136 
00137 //: Create a smart-pointer to a vgui_deck_tableau.
00138 struct vgui_deck_tableau_new : public vgui_deck_tableau_sptr
00139 {
00140   typedef vgui_deck_tableau_sptr base;
00141 
00142   //: Constructor - creates a pointer to an empty vgui_deck_tableau.
00143   vgui_deck_tableau_new() : base(new vgui_deck_tableau()) {}
00144 
00145   //: Constructor - creates a pointer to a vgui_deck_tableau with two children.
00146   //  Children are given top to bottom.
00147   vgui_deck_tableau_new(vgui_tableau_sptr const& child0,vgui_tableau_sptr const& child1)
00148     : base(new vgui_deck_tableau(child0, child1)) {}
00149 
00150   //: Constructor - creates a pointer to a vgui_deck_tableau with 3 children.
00151   //  Children are given top to bottom.
00152   vgui_deck_tableau_new(vgui_tableau_sptr const& child0, vgui_tableau_sptr const& child1, vgui_tableau_sptr const& child2)
00153     : base(new vgui_deck_tableau(child0, child1, child2)) {}
00154 };
00155 
00156 #endif // vgui_deck_tableau_h_