contrib/brl/bbas/bgui/bgui_selector_tableau.h

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

Generated on Thu Nov 20 05:22:07 2008 for contrib/brl/bbas/bgui by  doxygen 1.5.1