core/vgui/vgui_selector_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_selector_tableau.h
00002 #ifndef vgui_selector_tableau_h_
00003 #define vgui_selector_tableau_h_
00004 //:
00005 // \file
00006 // \brief  Tableau that allows the selection of one active child but displays all children
00007 // \author Matthew Leotta (mleotta@brown.lems.edu)
00008 // \date   November 5, 2003
00009 //
00010 // \verbatim
00011 //  Modifications
00012 //   <none yet>
00013 // \endverbatim
00014 
00015 #include <vcl_vector.h>
00016 #include <vcl_map.h>
00017 
00018 #include <vgui/vgui_tableau.h>
00019 #include <vgui/vgui_parent_child_link.h>
00020 class vgui_event;
00021 
00022 #include "vgui_selector_tableau_sptr.h"
00023 
00024 //: Tableau that allows the selection of one active child but displays all children
00025 //
00026 //  The vgui_selector_tableau class can have any number of children, indexed
00027 //  from 0 upwards.  The draw action of vgui_selector_tableau is to draw each
00028 //  of its children, in order, into  the current context if they are marked visible.
00029 //  Events reaching the vgui_selector_tableau are passed on to the active child only.
00030 //
00031 //  The exceptions to this rule are :
00032 //  [a] the DRAW, DRAW_OVERLAY events which are sent to all children.
00033 class vgui_selector_tableau : public vgui_tableau
00034 {
00035  public:
00036   //: Constructor - don't use this, use vgui_selector_tableau_new.
00037   //  Creates an empty composite tableau.
00038   vgui_selector_tableau();
00039 
00040   //: Constructor - don't use this, use vgui_selector_tableau_new.
00041   //  Takes a vector of child tableaux.
00042   vgui_selector_tableau(vcl_vector<vgui_tableau_sptr> const& children);
00043 
00044   //: Handle all events sent to this tableau.
00045   //  Key-press '?' prints info on this file, before being sent to the children.
00046   virtual bool handle(const vgui_event&);
00047 
00048   //: Returns the type of this tableau ('vgui_selector_tableau').
00049   vcl_string type_name() const { return "vgui_selector_tableau"; }
00050 
00051   //: There is no obvious filename, so this just returns the type.
00052   vcl_string file_name() const;
00053 
00054   //: Returns a nice version of the name, including info on the children.
00055   vcl_string pretty_name() const;
00056 
00057   //: Builds a popup menu for the user to select the active child and set visibility.
00058   //  Over-rides function in vgui_tableau.
00059   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
00060 
00061   //: Add a tableau to the list of child tableaux.
00062   void add(vgui_tableau_sptr const& tab, vcl_string name = "");
00063 
00064   //: Remove a tableau from the list of child tableaux.
00065   void remove(vgui_tableau_sptr const& tab);
00066 
00067   //: Remove a tableau from the list of child tableaux by name.
00068   bool remove(const vcl_string name);
00069 
00070   //: Clear the list of child tableaux.
00071   void clear();
00072 
00073   //: Returns a smart pointer to the active tableau
00074   vgui_tableau_sptr active_tableau() const;
00075 
00076   //: Returns the name of the active tableau
00077   const vcl_string& active_name() const { return active_child_; }
00078 
00079   //: Returns a smart pointer to the tableau with the given name
00080   vgui_tableau_sptr get_tableau(const vcl_string& name) const;
00081 
00082   //: Make the child tableau with the given name the active child.
00083   void set_active(const vcl_string& name);
00084 
00085   //: Toggle the child tableau with the given name between visible/invisible.
00086   bool toggle(const vcl_string& name);
00087 
00088   //: Returns true if the child tableau with the given name is active.
00089   bool is_visible(const vcl_string& name) const;
00090 
00091   //: Move the active tableau to the top of the display list.
00092   void active_to_top();
00093 
00094   //: Move the active tableau up one position in the display list.
00095   void active_raise();
00096 
00097   //: Move the active tableau down one position in the display list.
00098   void active_lower();
00099 
00100   //: Move the active tableau to the bottom of the display list.
00101   void active_to_bottom();
00102 
00103   //: Returns the number of children
00104   int num_children() const { return child_map_.size(); }
00105 
00106   //: Returns a vector containing the names of all children (in rendering order)
00107   const vcl_vector<vcl_string>& child_names() const { return render_order_; }
00108 
00109   //: for subclasses to add additional menus
00110   virtual void add_to_menu(vgui_menu& ){}
00111 
00112  protected:
00113   //: Destructor - called by vgui_selector_tableau_sptr.
00114   virtual ~vgui_selector_tableau();
00115 
00116   //: Returns a bounding box large enough to contain all child bounding boxes.
00117   bool get_bounding_box(float low[3], float high[3]) const;
00118 
00119   //: Add to list of child tableaux.
00120   bool add_child(vgui_tableau_sptr const& t);
00121 
00122   //: Remove given tableau from list of child tableaux.
00123   bool remove_child(vgui_tableau_sptr const& );
00124 
00125   // data
00126   // ----
00127 
00128   //: Whether each child is visible or not (ie. using events).
00129   vcl_map<vcl_string, bool> visible_;
00130 
00131   //: The unique child names sorted in rendering order
00132   vcl_vector<vcl_string> render_order_;
00133 
00134   //: A map from unique names to children
00135   vcl_map<vcl_string, vgui_parent_child_link> child_map_;
00136 
00137   //: The name of the active tableau
00138   vcl_string active_child_;
00139 };
00140 
00141 //: Creates a smart-pointer to a vgui_selector_tableau tableau.
00142 struct vgui_selector_tableau_new : public vgui_selector_tableau_sptr
00143 {
00144   typedef vgui_selector_tableau_sptr base;
00145 
00146   //: Constructor - creates a pointer to an empty vgui_selector_tableau.
00147   vgui_selector_tableau_new() : base(new vgui_selector_tableau()) { }
00148 
00149 
00150   //: Constructor - creates pointer to a composite with the given children.
00151   //  Takes a vector of child tableaux.
00152   vgui_selector_tableau_new(vcl_vector<vgui_tableau_sptr> const& children)
00153     : base(new vgui_selector_tableau(children)) {}
00154 };
00155 
00156 #endif // vgui_selector_tableau_h_