1#define _USE_MATH_DEFINES
3#include "key_control.h"
6#include <cgv/type/variant.h>
7#include <cgv/type/info/type_name.h>
8#include <cgv/utils/convert.h>
43 if (property ==
"more") {
44 if (value_type ==
"cgv::gui::shortcut")
45 more = *((
const shortcut*)value_ptr);
46 else if (value_type ==
"string")
47 return from_string(more, *((
const std::string*)value_ptr));
52 if (property ==
"less") {
53 if (value_type ==
"cgv::gui::shortcut")
54 less = *((
const shortcut*)value_ptr);
55 else if (value_type ==
"string")
56 return from_string(less, *((
const std::string*)value_ptr));
73 if (member_ptr == &min_value || member_ptr == &max_value)
87 increase_pressed_time = 0;
88 decrease_pressed_time = 0;
94void key_control<T>::change_value(
double dt)
99 nv *= (T)exp(speed*dt);
105 else if (nv < min_value)
109 this->check_and_set_value(nv);
121 if (increase_pressed_time == 0)
122 increase_pressed_time = e.
get_time();
126 if (decrease_pressed_time == 0)
127 decrease_pressed_time = e.
get_time();
132 if (ke.
get_key() == more.get_key() && increase_pressed_time != 0) {
133 change_value(ke.
get_time()-increase_pressed_time);
134 increase_pressed_time = 0;
137 if (ke.
get_key() == less.get_key() && decrease_pressed_time != 0) {
138 change_value(decrease_pressed_time-ke.
get_time());
139 decrease_pressed_time = 0;
150 os << this->get_name() <<
": <" << less <<
"," << more <<
">" << std::endl;
156 if (increase_pressed_time != 0) {
158 change_value(
time-increase_pressed_time);
159 increase_pressed_time =
time;
161 if (decrease_pressed_time != 0) {
163 change_value(decrease_pressed_time-
time);
164 decrease_pressed_time =
time;
170 return "key_control<bool>";
175 return "toggle:shortcut";
180 if (property ==
"toggle") {
181 if (value_type ==
"shortcut")
182 toggle = *((
const shortcut*)value_ptr);
183 else if (value_type ==
"string")
184 return from_string(toggle, *((
const std::string*)value_ptr));
210 check_and_set_value(!get_value());
218 os <<
"toggle " << get_name() <<
": <" << toggle <<
">" << std::endl;
222#include "lib_begin.h"
225#include <cgv/config/lib_end.h>
virtual std::string get_property_declarations()
return a semicolon separated list of property declarations
virtual bool set_void(const std::string &property, const std::string &value_type, const void *value_ptr)
abstract interface for the setter of a dynamic property.
virtual bool get_void(const std::string &property, const std::string &value_type, void *value_ptr)
abstract interface for the getter of a dynamic property.
void multi_set(const std::string &property_assignments, bool report_error=true)
set several properties
const T get_value() const
return a reference to the current value
double get_time() const
return the time of the event in seconds
unsigned get_kind() const
return, what kind of event this is, typically a value from the EventId enum
unsigned char get_modifiers() const
return the active modifiers as values from EventModifier combined with a logical or-operation
std::string get_property_declarations()
return a semicolon separated list of property declarations
void stream_help(std::ostream &os)
overload to stream help information to the given output stream
bool self_reflect(cgv::reflect::reflection_handler &rh)
used for simple self reflection
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...
bool set_void(const std::string &property, const std::string &value_type, const void *value_ptr)
abstract interface for the setter of a dynamic property.
std::string get_type_name() const
overload to return the type name of this object
bool handle(event &e)
overload and implement this method to handle events
bool get_void(const std::string &property, const std::string &value_type, void *value_ptr)
abstract interface for the getter of a dynamic property.
class to represent all possible keyboard events with the EID_KEY
unsigned short get_key() const
return the key being a capital letter, digit or a value from the Keys enum
KeyAction get_action() const
return the key event action
the shortcut class encapsulates a key with modifiers
static double get_current_time()
return the current time
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
@ KA_PRESS
key press action
@ EID_KEY
id for key event
trigger & get_animation_trigger()
return the global trigger used for animation, which runs by default with 60 Hz
namespace that holds tools that dont fit any other namespace
bool from_string(std::string &v, const std::string &s)
specialization to extract string value from string
traits class with a static function get_name() of type const char* that returns the type name of the ...