1 // This is core/vgui/vgui_selector_tableau.h
2 #ifndef vgui_selector_tableau_h_
3 #define vgui_selector_tableau_h_
4 //:
5 // \file
6 // \brief  Tableau that allows the selection of one active child but displays all children
7 // \author Matthew Leotta (mleotta@brown.lems.edu)
8 // \date   November 5, 2003
9 //
10 // \verbatim
11 //  Modifications
12 //   <none yet>
13 // \endverbatim
14 
15 #include <vector>
16 #include <map>
17 #ifdef _MSC_VER
18 #  include <vcl_msvc_warnings.h>
19 #endif
20 
21 #include "vgui_tableau.h"
22 #include "vgui_parent_child_link.h"
23 class vgui_event;
24 
25 #include "vgui_selector_tableau_sptr.h"
26 
27 //: Tableau that allows the selection of one active child but displays all children
28 //
29 //  The vgui_selector_tableau class can have any number of children, indexed
30 //  from 0 upwards.  The draw action of vgui_selector_tableau is to draw each
31 //  of its children, in order, into  the current context if they are marked visible.
32 //  Events reaching the vgui_selector_tableau are passed on to the active child only.
33 //
34 //  The exceptions to this rule are :
35 //  [a] the DRAW, DRAW_OVERLAY events which are sent to all children.
36 class vgui_selector_tableau : public vgui_tableau
37 {
38  public:
39   //: Constructor - don't use this, use vgui_selector_tableau_new.
40   //  Creates an empty composite tableau.
41   vgui_selector_tableau();
42 
43   //: Constructor - don't use this, use vgui_selector_tableau_new.
44   //  Takes a vector of child tableaux.
45   vgui_selector_tableau(std::vector<vgui_tableau_sptr> const& children);
46 
47   //: Handle all events sent to this tableau.
48   //  Key-press '?' prints info on this file, before being sent to the children.
49   virtual bool handle(const vgui_event&);
50 
51   //: Returns the type of this tableau ('vgui_selector_tableau').
type_name()52   std::string type_name() const { return "vgui_selector_tableau"; }
53 
54   //: There is no obvious filename, so this just returns the type.
55   std::string file_name() const;
56 
57   //: Returns a nice version of the name, including info on the children.
58   std::string pretty_name() const;
59 
60   //: Builds a popup menu for the user to select the active child and set visibility.
61   //  Over-rides function in vgui_tableau.
62   virtual void get_popup(const vgui_popup_params&, vgui_menu &m);
63 
64   //: Add a tableau to the list of child tableaux.
65   void add(vgui_tableau_sptr const& tab, std::string name = "");
66 
67   //: Remove a tableau from the list of child tableaux.
68   void remove(vgui_tableau_sptr const& tab);
69 
70   //: Remove a tableau from the list of child tableaux by name.
71   bool remove(const std::string name);
72 
73   //: Clear the list of child tableaux.
74   void clear();
75 
76   //: Returns a smart pointer to the active tableau
77   vgui_tableau_sptr active_tableau() const;
78 
79   //: Returns the name of the active tableau
active_name()80   const std::string& active_name() const { return active_child_; }
81 
82   //: Returns a smart pointer to the tableau with the given name
83   vgui_tableau_sptr get_tableau(const std::string& name) const;
84 
85   //: Make the child tableau with the given name the active child.
86   void set_active(const std::string& name);
87 
88   //: Toggle the child tableau with the given name between visible/invisible.
89   bool toggle(const std::string& name);
90 
91   //: Returns true if the child tableau with the given name is active.
92   bool is_visible(const std::string& name) const;
93 
94   //: Move the active tableau to the top of the display list.
95   void active_to_top();
96 
97   //: Move the active tableau up one position in the display list.
98   void active_raise();
99 
100   //: Move the active tableau down one position in the display list.
101   void active_lower();
102 
103   //: Move the active tableau to the bottom of the display list.
104   void active_to_bottom();
105 
106   //: Returns the number of children
num_children()107   int num_children() const { return child_map_.size(); }
108 
109   //: Returns a vector containing the names of all children (in rendering order)
child_names()110   const std::vector<std::string>& child_names() const { return render_order_; }
111 
112   //: for subclasses to add additional menus
add_to_menu(vgui_menu &)113   virtual void add_to_menu(vgui_menu& ){}
114 
115  protected:
116   //: Destructor - called by vgui_selector_tableau_sptr.
117   virtual ~vgui_selector_tableau();
118 
119   //: Returns a bounding box large enough to contain all child bounding boxes.
120   bool get_bounding_box(float low[3], float high[3]) const;
121 
122   //: Add to list of child tableaux.
123   bool add_child(vgui_tableau_sptr const& t);
124 
125   //: Remove given tableau from list of child tableaux.
126   bool remove_child(vgui_tableau_sptr const& );
127 
128   // data
129   // ----
130 
131   //: Whether each child is visible or not (ie. using events).
132   std::map<std::string, bool> visible_;
133 
134   //: The unique child names sorted in rendering order
135   std::vector<std::string> render_order_;
136 
137   //: A map from unique names to children
138   std::map<std::string, vgui_parent_child_link> child_map_;
139 
140   //: The name of the active tableau
141   std::string active_child_;
142 };
143 
144 //: Creates a smart-pointer to a vgui_selector_tableau tableau.
145 struct vgui_selector_tableau_new : public vgui_selector_tableau_sptr
146 {
147   typedef vgui_selector_tableau_sptr base;
148 
149   //: Constructor - creates a pointer to an empty vgui_selector_tableau.
vgui_selector_tableau_newvgui_selector_tableau_new150   vgui_selector_tableau_new() : base(new vgui_selector_tableau()) { }
151 
152 
153   //: Constructor - creates pointer to a composite with the given children.
154   //  Takes a vector of child tableaux.
vgui_selector_tableau_newvgui_selector_tableau_new155   vgui_selector_tableau_new(std::vector<vgui_tableau_sptr> const& children)
156     : base(new vgui_selector_tableau(children)) {}
157 };
158 
159 #endif // vgui_selector_tableau_h_
160