cgv
gui_group.h
1 #pragma once
2 
3 #include <cgv/base/group.h>
4 #include <cgv/type/cond/is_enum.h>
5 #include <cgv/type/info/type_name.h>
6 #include <cgv/base/register.h>
7 #include "button.h"
8 #include "view.h"
9 #include "control.h"
10 
11 #include "lib_begin.h"
12 
14 
15 template <typename T, bool is_enum = cgv::type::cond::is_enum<T>::value>
16 struct enum_aware_type_name : public cgv::type::info::type_name<T>
17 {
18 };
19 
20 template <typename T>
21 struct enum_aware_type_name<T,true>
22 {
23  static const char* get_name() { return "enum"; }
24 };
25 
26 namespace cgv {
27  namespace gui {
28 
29 class CGV_API gui_group;
30 class CGV_API provider;
31 
34 
37 
40 {
41 protected:
42  friend class provider;
44  std::vector<cgv::base::base_ptr> managed_objects;
46  static void set_provider_parent(provider* p, gui_group_ptr g);
48  static gui_group_ptr get_provider_parent(const provider* p);
49 public:
51  void register_object(cgv::base::base_ptr object, const std::string& options);
53  void unregister_object(cgv::base::base_ptr object, const std::string& options);
55  gui_group(const std::string& name = "");
57  std::string get_type_name() const;
58 
61 
68  void add_managed_objects(cgv::base::base_ptr object);
70  void release_all_managed_objects();
72  void release_managed_objects(cgv::base::base_ptr object);
74  bool is_managed_object(cgv::base::base_ptr object);
75  //@/
78  virtual bool multiple_selection() const;
81 
84  virtual void select_child(unsigned ci, bool exclusive = false);
86  virtual void select_child(base_ptr ci, bool exclusive = false);
88 
90  virtual bool unselect_child(unsigned ci);
92  virtual bool unselect_child(base_ptr ci);
94 
96  virtual int get_selected_child_index() const;
98 
101  virtual base_ptr get_selected_child() const;
103  virtual bool is_selected(base_ptr c) const;
105 
106  bool is_selected(unsigned ci) const;
108 
110  cgv::signal::signal<base_ptr, bool> on_selection_change;
112 
115  virtual bool can_open_and_close() const;
118  virtual bool is_open_child_group(gui_group_ptr g) const;
120  bool is_open_child_group(unsigned ci) const;
122  virtual bool open_child_group(gui_group_ptr g);
124  virtual bool close_child_group(gui_group_ptr g);
126 
128  cgv::signal::signal<gui_group_ptr,bool> on_open_state_change;
130 
133  virtual void align(const std::string& _align);
136  virtual gui_group_ptr add_group(const std::string& label, const std::string& group_type, const std::string& options, const std::string& align);
138  virtual base_ptr add_decorator(const std::string& label, const std::string& decorator_type, const std::string& options, const std::string& align);
140  virtual button_ptr add_button(const std::string& label, const std::string& options, const std::string& align);
142  virtual view_ptr add_view_void(const std::string& label, const void* value_ptr, const std::string& value_type, const std::string& gui_type, const std::string& options, const std::string& align);
144  virtual control_ptr add_control_void(const std::string& label, void* value_ptr, abst_control_provider* acp, const std::string& value_type, const std::string& gui_type, const std::string& options, const std::string& align, void* user_data);
146  template <typename T>
147  inline data::ref_ptr<view<T> > add_view(const std::string& label, const T& value, const std::string& gui_type = "", const std::string& options = "", const std::string& align = "\n") {
148  view_ptr vp = add_view_void(label, &value,
149  enum_aware_type_name<T>::get_name(),
150  gui_type, options, align);
151  return vp.up_cast<view<T> >();
152  }
154  template <typename T>
155  inline data::ref_ptr<control<T> > add_control(const std::string& label, T& value, const std::string& gui_type = "", const std::string& options = "", const std::string& align = "\n") {
156  control_ptr cp = add_control_void(label, &value, 0,
157  enum_aware_type_name<T>::get_name(),
158  gui_type, options, align, 0);
159  return cp.up_cast<control<T> >();
160  }
162  template <typename T>
163  inline data::ref_ptr<control<T> > add_control(const std::string& label,
164  control_provider<T>* provider, const std::string& gui_type = "",
165  const std::string& options = "", const std::string& align = "\n", void* user_data = 0) {
166  control_ptr cp = add_control_void(label, 0, provider,
167  enum_aware_type_name<T>::get_name(),
168  gui_type, options, align, user_data);
169  return cp.up_cast<control<T> >();
170  }
172 
175  base_ptr find_element(const std::string& name);
178  view_ptr find_view_void(const void* value_ptr, int* idx_ptr);
180  control_ptr find_control_void(void* value_ptr, int* idx_ptr);
182 
185  template <typename T>
186  inline data::ref_ptr<view<T> > find_view(const T& value, int* idx_ptr=0) {
187  view_ptr vp = find_view_void(&value,idx_ptr);
188  return vp.up_cast<view<T> >();
189  }
191 
194  template <typename T>
195  inline data::ref_ptr<control<T> > find_control(T& value, int* idx_ptr=0) {
196  control_ptr cp = find_control_void(&value,idx_ptr);
197  return cp.up_cast<control<T> >();
198  }
200 };
201 
202 
203 #if _MSC_VER >= 1400
204 CGV_TEMPLATE template class CGV_API data::ref_ptr<gui_group>;
205 CGV_TEMPLATE template class CGV_API data::ref_ptr<const gui_group>;
206 #endif
207 
208 
209  }
210 }
211 
212 #include <cgv/config/lib_end.h>
cgv::gui::gui_group::add_control
data::ref_ptr< control< T > > add_control(const std::string &label, control_provider< T > *provider, const std::string &gui_type="", const std::string &options="", const std::string &align="\n", void *user_data=0)
add a newly created control to the group which is controlled by a control_provider
Definition: gui_group.h:163
cgv::base::group
Definition: group.h:18
cgv::gui::gui_group::find_view
data::ref_ptr< view< T > > find_view(const T &value, int *idx_ptr=0)
find the next view of the given value in the current group.
Definition: gui_group.h:186
cgv::gui::gui_group::on_open_state_change
cgv::signal::signal< gui_group_ptr, bool > on_open_state_change
this signal is emitted, when a child group is opened or closed
Definition: gui_group.h:128
cgv::gui::abst_control_provider
type independent base class of control provider interface
Definition: control.h:37
cgv::data::ref_ptr::up_cast
ref_ptr< S, is_ref_counted > up_cast() const
use static cast to convert from T to S if T is a base class of S and has a virtual destructor
Definition: ref_ptr.h:180
cgv::gui::gui_group::on_selection_change
cgv::signal::signal< base_ptr, bool > on_selection_change
This signal is emitted for every change of the selection of a child.
Definition: gui_group.h:110
cgv::data::ref_ptr< gui_group, true >
cgv::base::base_ptr
data::ref_ptr< base, true > base_ptr
ref counted pointer to base
Definition: base.h:37
cgv::type::info::type_name::get_name
static const char * get_name()
return special name for standard types or type name from RTTI cleaned from keywords for all other typ...
Definition: type_name.h:56
cgv::gui::provider
derive from this class to provide a gui to the current viewer
Definition: provider.h:64
cgv::gui::control_provider
Definition: control.h:52
cgv::gui::control
Definition: control.h:82
cgv::gui::view
class for gui elements that view values of the type specified in the template argument
Definition: view.h:45
cgv::gui::gui_group::add_view
data::ref_ptr< view< T > > add_view(const std::string &label, const T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add a newly created view to the group for the given value with the given gui type,...
Definition: gui_group.h:147
cgv::gui::gui_group::managed_objects
std::vector< cgv::base::base_ptr > managed_objects
managed objects can be add to the group such that
Definition: gui_group.h:44
cgv::gui::gui_group::add_control
data::ref_ptr< control< T > > add_control(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add a newly created control to the group for the given value with the given gui type,...
Definition: gui_group.h:155
cgv::gui::gui_group_ptr
data::ref_ptr< gui_group, true > gui_group_ptr
ref counted pointer to a gui group
Definition: gui_group.h:33
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::gui::gui_group
gui independent group class which is a container for gui elements
Definition: gui_group.h:40
cgv::base::registration_listener
interfaces that allows to listen to registration events.
Definition: register.h:216
cgv::gui::gui_group::find_control
data::ref_ptr< control< T > > find_control(T &value, int *idx_ptr=0)
find the next control of the given value in the current group.
Definition: gui_group.h:195
cgv::gui::const_gui_group_ptr
data::ref_ptr< const gui_group, true > const_gui_group_ptr
ref counted pointer to const gui group
Definition: gui_group.h:36
cgv::type::info::type_name
Definition: type_name.h:54