core/vgui/vgui_composite_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_composite_tableau.h
00002 #ifndef vgui_composite_tableau_h_
00003 #define vgui_composite_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau which treats it children as a stack of acetates
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date   15 Sep 99
00012 //
00013 // \verbatim
00014 //  Modifications
00015 //   18-Sep-2000 capes@robots - Added set_enable_key_bindings.
00016 //                              Key bindings are OFF by default.
00017 //   09-Feb-2001 awf@robots   - Add Alt-C to re-enable key bindings.
00018 //   26-APR-2002 K.Y.McGaul   - Converted to doxygen style comments.
00019 //   01-OCT-2002 K.Y.McGaul   - Moved vgui_composite to vgui_composite_tableau.
00020 // \endverbatim
00021 
00022 #include <vcl_vector.h>
00023 
00024 #include <vgui/vgui_composite_tableau_sptr.h>
00025 #include <vgui/vgui_tableau.h>
00026 #include <vgui/vgui_parent_child_link.h>
00027 #include <vgui/vgui_event_condition.h>
00028 #include <vgui/vgui_observable.h>
00029 
00030 class vgui_event;
00031 
00032 //: Tableau which treats it children as a stack of acetates
00033 //
00034 //  The vgui_composite_tableau class can have any number of children, indexed
00035 //  from 0 upwards.  The draw action of vgui_composite_tableau is to draw each
00036 //  of its children, in order, into  the current context.  Events reaching the
00037 //  vgui_composite_tableau are passed on to each child in turn, till it is
00038 //  handled, so that child 0, the first added, is the "top" tableau.
00039 //
00040 //  The exceptions to this rule are :
00041 //  [a] key presses '0'-'9', which toggle the activeness of the children and
00042 //  [b] the DRAW, DRAW_OVERLAY events which are sent to all children.
00043 class vgui_composite_tableau : public vgui_tableau
00044 {
00045  public:
00046   //: Constructor - don't use this, use vgui_composite_tableau_new.
00047   //  Creates an empty composite tableau.
00048   vgui_composite_tableau();
00049 
00050   //: Constructor - don't use this, use vgui_composite_tableau_new.
00051   //  Creates a composite with two child tableaux.
00052   vgui_composite_tableau(vgui_tableau_sptr const& child0,
00053                          vgui_tableau_sptr const& child1);
00054 
00055   //: Constructor - don't use this, use vgui_composite_tableau_new.
00056   //  Creates a composite with three child tableaux.
00057   vgui_composite_tableau(vgui_tableau_sptr const& child0,
00058                          vgui_tableau_sptr const& child1,
00059                          vgui_tableau_sptr const& child2);
00060 
00061   //: Constructor - don't use this, use vgui_composite_tableau_new.
00062   //  Takes a vector of child tableaux.
00063   vgui_composite_tableau(vcl_vector<vgui_tableau_sptr> const& children);
00064 
00065   //: Handle all events sent to this tableau.
00066   //  All events (except key-presses '0'-'9' and draw events) are passed
00067   //  to each child until the event is handled.
00068   //  Key presses '0'-'9' toggle the activeness of the children and
00069   //  draw events are sent to all children.
00070   //  Key-press '?' prints info on this file, before being sent to the children.
00071   virtual bool handle(const vgui_event&);
00072 
00073   //: Prints info about this tableau - called when '?'is pressed.
00074   virtual bool help();
00075 
00076   //: Returns the type of this tableau ('vgui_composite_tableau').
00077   vcl_string type_name() const { return "vgui_composite_tableau"; }
00078 
00079   //: There is no obvious filename, so this just returns the type.
00080   vcl_string file_name() const { return type_name(); }
00081 
00082   //: Returns a nice version of the name, including info on the children.
00083   vcl_string pretty_name() const;
00084 
00085   //: Calls notify for the observers.
00086   virtual void notify() const;
00087 
00088   //: Conceptually, this is a list on which observers can put themselves.
00089   vgui_observable observers;
00090 
00091   //: Add a tableau to the list of child tableaux.
00092   //  Same as add_child().
00093   void add(vgui_tableau_sptr const& t) { add_child(t); }
00094 
00095   //: Remove a tableau from the list of child tableaux.
00096   void remove(vgui_tableau_sptr const&);
00097 
00098   //: Clear the list of child tableaux.
00099   void clear();
00100 
00101   //: Toggle the child tableau in the given position between active/inactive.
00102   bool toggle(int);
00103 
00104   //: Returns true if the child tableau in the given position is active.
00105   bool is_active(int);
00106 
00107   //: Enable (if true) or disable (if false) key bindings.
00108   //  If key bindings is enabled then key presses '0'-'9' will be used
00109   //  by this tableau to toggle the activeness of child tableaux.
00110   void set_enable_key_bindings(bool on) { enable_key_bindings = on; }
00111 
00112   //: The event which occurs to toggle enable/disable key bindings.
00113   //  Default is Alt-C enables / disables key bindings
00114   vgui_event_condition c_enable_key_bindings;
00115 
00116  protected:
00117   //: Destructor - called by vgui_composite_tableau_sptr.
00118   virtual ~vgui_composite_tableau() {}
00119 
00120   //: Returns a bounding box large enough to contain all child bounding boxes.
00121   bool get_bounding_box(float low[3], float high[3]) const;
00122 
00123   //: Add to list of child tableaux.
00124   bool add_child(vgui_tableau_sptr const& t);
00125 
00126   //: Remove given tableau from list of child tableaux.
00127   bool remove_child(vgui_tableau_sptr const& );
00128 
00129   //: Returns true if the given integer could be an index to the child tableaux.
00130   bool index_ok(int);
00131 
00132   // data
00133   // ----
00134 
00135   //: List of child tableaux.
00136   vcl_vector<vgui_parent_child_link> children;
00137 
00138   //: Whether each child is active or not (ie. using events).
00139   vcl_vector<bool> active;
00140 
00141   bool enable_key_bindings;
00142 };
00143 
00144 //: Creates a smart-pointer to a vgui_composite_tableau tableau.
00145 struct vgui_composite_tableau_new : public vgui_composite_tableau_sptr
00146 {
00147   typedef vgui_composite_tableau_sptr base;
00148 
00149   //: Constructor - creates a pointer to an empty vgui_composite_tableau.
00150   vgui_composite_tableau_new() : base(new vgui_composite_tableau()) {}
00151 
00152   //: Constructor - creates a pointer to a composite with two children.
00153   vgui_composite_tableau_new(vgui_tableau_sptr const& child0,
00154                              vgui_tableau_sptr const& child1)
00155     : base(new vgui_composite_tableau(child0, child1)) {}
00156 
00157   //: Constructor - creates a pointer to a composite with three children.
00158   vgui_composite_tableau_new(vgui_tableau_sptr const& child0,
00159                              vgui_tableau_sptr const& child1,
00160                              vgui_tableau_sptr const& child2)
00161     : base(new vgui_composite_tableau(child0, child1, child2)) {}
00162 
00163   //: Constructor - creates pointer to a composite with the given children.
00164   //  Takes a vector of child tableaux.
00165   vgui_composite_tableau_new(vcl_vector<vgui_tableau_sptr> const& children)
00166     : base(new vgui_composite_tableau(children)) {}
00167 };
00168 
00169 #endif // vgui_composite_tableau_h_