cgv
Loading...
Searching...
No Matches
event_handler.cxx
1#include "event_handler.h"
2#include "key_control.h"
3#include <cgv/base/group.h>
4#include <cgv/type/info/type_name.h>
5#include <cgv/signal/rebind.h>
6
7namespace cgv {
8 namespace gui {
9
11event_handler::event_handler() : traverse_policy(base::TP_AUTO_FOCUS+base::TP_STOP_ON_SUCCESS)
12{
13}
14
17{
18 return base::grab_focus(this);
19}
20
22bool event_handler::add_key_control(const std::string& property, const std::string& options, cgv::base::group_ptr gp)
23{
25 if (gp.empty())
26 g = dynamic_cast<cgv::base::group*>(this);
27 else
28 g = &(*gp);
29 if (!g)
30 return false;
31
32 std::string type_name;
33 void* property_ptr = g->find_member_ptr(property, &type_name);
34 if (!property_ptr)
35 return false;
37 cgv::data::ref_ptr<control<float> > cp = new key_control<float>(property+" key_control", *((float*)property_ptr), options);
38 g->append_child(cp);
39 connect_copy(cp->value_change, cgv::signal::rebind(static_cast<cgv::base::base*>(g), &cgv::base::base::on_set, property_ptr));
40 }
41 else if (type_name == cgv::type::info::type_name<double>::get_name()) {
42 cgv::data::ref_ptr<control<double> > cp = new key_control<double>(property+" key_control", *((double*)property_ptr), options);
43 g->append_child(cp);
44 connect_copy(cp->value_change, cgv::signal::rebind(static_cast<cgv::base::base*>(g), &cgv::base::base::on_set, property_ptr));
45 }
46 else if (type_name == cgv::type::info::type_name<bool>::get_name()) {
47 cgv::data::ref_ptr<control<bool> > cp = new key_control<bool>(property+" key_control", *((bool*)property_ptr), options);
48 g->append_child(cp);
49 connect_copy(cp->value_change, cgv::signal::rebind(static_cast<cgv::base::base*>(g), &cgv::base::base::on_set, property_ptr));
50 }
51 else
52 return false;
53 return true;
54}
55 }
56}
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
virtual void on_set(void *member_ptr)
this callback is called when the set_void method has changed a member and can be overloaded in derive...
Definition base.cxx:210
void * find_member_ptr(const std::string &property_name, std::string *type_name=0)
find a member pointer by name.
Definition base.cxx:360
The group class is a node with children.
Definition group.h:20
virtual unsigned int append_child(base_ptr child)
append child and return index of appended child
Definition group.cxx:41
bool empty() const
check if pointer is not yet set
Definition ref_ptr.h:230
bool add_key_control(const std::string &property, const std::string &options, cgv::base::group_ptr group=cgv::base::group_ptr())
add a key control for the given property with the given options.
event_handler()
default construction
bool grab_focus()
grab the focus in all parent nodes
bool grab_focus(X *instance)
try to grab the focus in the path of this node to the root of the tree
Definition traverser.h:52
the cgv namespace
Definition print.h:11
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54