mirror of
https://github.com/Relintai/ui_extensions.git
synced 2024-11-12 10:25:27 +01:00
Added my InputEventKey implementation, to tailor the logic of action_match to my needs.
This commit is contained in:
parent
8c7537c3cb
commit
4c6f83b2f9
1
SCsub
1
SCsub
@ -3,3 +3,4 @@ Import('env')
|
||||
env.add_source_files(env.modules_sources,"register_types.cpp")
|
||||
|
||||
env.add_source_files(env.modules_sources,"touch_button.cpp")
|
||||
env.add_source_files(env.modules_sources,"bs_input_event_key.cpp")
|
||||
|
42
bs_input_event_key.cpp
Normal file
42
bs_input_event_key.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "bs_input_event_key.h"
|
||||
|
||||
void BSInputEventKey::from_input_event_key(const Ref<InputEventKey> event) {
|
||||
set_device(event->get_device());
|
||||
|
||||
set_shift(event->get_shift());
|
||||
set_alt(event->get_alt());
|
||||
set_control(event->get_control());
|
||||
set_metakey(event->get_metakey());
|
||||
set_command(event->get_command());
|
||||
|
||||
set_pressed(event->is_pressed());
|
||||
set_scancode(event->get_scancode());
|
||||
set_unicode(event->get_unicode());
|
||||
set_echo(event->is_echo());
|
||||
}
|
||||
|
||||
bool BSInputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const {
|
||||
|
||||
Ref<InputEventKey> key = p_event;
|
||||
if (key.is_null())
|
||||
return false;
|
||||
|
||||
uint32_t code = get_scancode_with_modifiers();
|
||||
uint32_t event_code = key->get_scancode_with_modifiers();
|
||||
|
||||
bool match = code == event_code;
|
||||
if (match) {
|
||||
if (p_pressed != NULL)
|
||||
*p_pressed = key->is_pressed();
|
||||
if (p_strength != NULL)
|
||||
*p_strength = (p_pressed != NULL && *p_pressed) ? 1.0f : 0.0f;
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
BSInputEventKey::BSInputEventKey() {
|
||||
}
|
||||
|
||||
void BSInputEventKey::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("from_input_event_key", "event"), &BSInputEventKey::from_input_event_key);
|
||||
}
|
19
bs_input_event_key.h
Normal file
19
bs_input_event_key.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef BS_INPUT_EVENT_KEY_H
|
||||
#define BS_INPUT_EVENT_KEY_H
|
||||
|
||||
#include "core/os/input_event.h"
|
||||
|
||||
class BSInputEventKey : public InputEventKey {
|
||||
GDCLASS(BSInputEventKey, InputEventKey);
|
||||
|
||||
public:
|
||||
void from_input_event_key(const Ref<InputEventKey> p_event);
|
||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const;
|
||||
|
||||
BSInputEventKey();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif
|
@ -1,9 +1,11 @@
|
||||
#include "register_types.h"
|
||||
|
||||
#include "touch_button.h"
|
||||
#include "bs_input_event_key.h"
|
||||
|
||||
void register_ui_extensions_types() {
|
||||
ClassDB::register_class<TouchButton>();
|
||||
ClassDB::register_class<BSInputEventKey>();
|
||||
}
|
||||
|
||||
void unregister_ui_extensions_types() {
|
||||
|
Loading…
Reference in New Issue
Block a user