From 6112c32a831773fc7dfabed88c336a9c6de2bc21 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 20 Apr 2019 14:54:22 +0200 Subject: [PATCH] Initial commit. --- .gitignore | 5 +++ SCsub | 5 +++ config.py | 5 +++ config.pyc | Bin 0 -> 415 bytes register_types.cpp | 12 ++++++ register_types.h | 3 ++ touch_button.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++ touch_button.h | 25 +++++++++++ 8 files changed, 158 insertions(+) create mode 100644 .gitignore create mode 100644 SCsub create mode 100644 config.py create mode 100644 config.pyc create mode 100644 register_types.cpp create mode 100644 register_types.h create mode 100644 touch_button.cpp create mode 100644 touch_button.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5230b5a --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.import +*.d +*.o +*.meta + diff --git a/SCsub b/SCsub new file mode 100644 index 0000000..5fdab32 --- /dev/null +++ b/SCsub @@ -0,0 +1,5 @@ +Import('env') + +env.add_source_files(env.modules_sources,"register_types.cpp") + +env.add_source_files(env.modules_sources,"touch_button.cpp") diff --git a/config.py b/config.py new file mode 100644 index 0000000..1c8cd12 --- /dev/null +++ b/config.py @@ -0,0 +1,5 @@ +def can_build(env, platform): + return True + +def configure(env): + pass diff --git a/config.pyc b/config.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8e757aa66ea1f87b2199fcb1d71db2b8f9f62bd1 GIT binary patch literal 415 zcmbVHI|{-;5SM$AE|s}}h+v;0T8R*Jvyniu3E5rI-Ya+uZ|4Pkvzl1z!n}FR z&gVVV@W2|O`v61u=1SzyaBbUI z8E~iJIjPQOfLs>`lT}R_fRh6~1Dl6smD)n;(B_G}7^!q#DIJPRW%+4dU(FC*;-HeF z%?rrFVct!iVBSV22o737+~rio-1XmGr@}UpeSPjm&RfjhVlICd|Ke(Z$;I3HvNJXG EUnp`+YybcN literal 0 HcmV?d00001 diff --git a/register_types.cpp b/register_types.cpp new file mode 100644 index 0000000..f87c8ce --- /dev/null +++ b/register_types.cpp @@ -0,0 +1,12 @@ +#include "register_types.h" + +#include "touch_button.h" + +void register_ui_extensions_types() { + ClassDB::register_class(); +} + +void unregister_ui_extensions_types() { + +} + diff --git a/register_types.h b/register_types.h new file mode 100644 index 0000000..fa1cd41 --- /dev/null +++ b/register_types.h @@ -0,0 +1,3 @@ + +void register_ui_extensions_types(); +void unregister_ui_extensions_types(); diff --git a/touch_button.cpp b/touch_button.cpp new file mode 100644 index 0000000..4334ddc --- /dev/null +++ b/touch_button.cpp @@ -0,0 +1,103 @@ +#include "touch_button.h" + +void TouchButton::_notification(int p_what) { + + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + + if (!Engine::get_singleton()->is_editor_hint()) { + set_process_input(is_visible_in_tree()); + } + + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) + break; + if (is_visible_in_tree()) { + set_process_input(true); + } else { + set_process_input(false); + } + } break; + } + + Button::_notification(p_what); +} + +void TouchButton::_input(Ref p_event) { + + if (!get_tree()) + return; + + if (p_event->get_device() == -1) + return; + + ERR_FAIL_COND(!is_visible_in_tree()); + + if (is_disabled()) // no interaction with disabled button + return; + + Ref b = p_event; + + if (b.is_valid() && _is_point_inside(b->get_position())) { + get_viewport()->set_input_as_handled(); + + Ref ev; + ev.instance(); + + ev->set_button_index(BUTTON_LEFT); + ev->set_pressed(b->is_pressed()); + ev->set_position(b->get_position()); + ev->set_global_position(b->get_position()); + + BaseButton::_gui_input(ev); + update(); + } + /* + Ref mm = p_event; + + if (mm.is_valid() && _is_point_inside(mm->get_position())) { + Ref ev; + ev.instance(); + + ev->set_relative(mm->get_relative()); + ev->set_speed(mm->get_speed()); + ev->set_position(b->get_position()); + ev->set_global_position(b->get_position()); + + BaseButton::_gui_input(ev); + update(); + }*/ +} + + +void TouchButton::_gui_input(Ref p_event) { + if (p_event->get_device() == -1) { + accept_event(); + return; + } + + BaseButton::_gui_input(p_event); +} + +void TouchButton::_unhandled_input(Ref p_event) { + + if (p_event->get_device() == -1) { + //accept_event(); + return; + } + + Button::_unhandled_input(p_event); +} + +void TouchButton::_bind_methods() { + ClassDB::bind_method(D_METHOD("_input"), &TouchButton::_input); +} + +bool TouchButton::_is_point_inside(const Vector2 &vec) { + Point2 point; + point.x = vec.x; + point.y = vec.y; + + return get_global_rect().has_point(point); +} diff --git a/touch_button.h b/touch_button.h new file mode 100644 index 0000000..0933464 --- /dev/null +++ b/touch_button.h @@ -0,0 +1,25 @@ +#ifndef TOUCH_BUTTON_H +#define TOUCH_BUTTON_H + +#include "core/engine.h" +#include "core/os/os.h" +#include "scene/gui/button.h" +#include "scene/main/viewport.h" + +class TouchButton : public Button { + GDCLASS(TouchButton, Button); + +public: + TouchButton() {} + + bool _is_point_inside(const Point2 &p_point); + +protected: + void _notification(int p_what); + virtual void _gui_input(Ref p_event); + virtual void _unhandled_input(Ref p_event); + void _input(Ref p_event); + static void _bind_methods(); +}; + +#endif