mirror of
https://github.com/Relintai/ui_extensions.git
synced 2024-11-12 10:25:27 +01:00
Initial commit.
This commit is contained in:
commit
6112c32a83
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.import
|
||||
*.d
|
||||
*.o
|
||||
*.meta
|
||||
|
5
SCsub
Normal file
5
SCsub
Normal file
@ -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")
|
5
config.py
Normal file
5
config.py
Normal file
@ -0,0 +1,5 @@
|
||||
def can_build(env, platform):
|
||||
return True
|
||||
|
||||
def configure(env):
|
||||
pass
|
BIN
config.pyc
Normal file
BIN
config.pyc
Normal file
Binary file not shown.
12
register_types.cpp
Normal file
12
register_types.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
#include "register_types.h"
|
||||
|
||||
#include "touch_button.h"
|
||||
|
||||
void register_ui_extensions_types() {
|
||||
ClassDB::register_class<TouchButton>();
|
||||
}
|
||||
|
||||
void unregister_ui_extensions_types() {
|
||||
|
||||
}
|
||||
|
3
register_types.h
Normal file
3
register_types.h
Normal file
@ -0,0 +1,3 @@
|
||||
|
||||
void register_ui_extensions_types();
|
||||
void unregister_ui_extensions_types();
|
103
touch_button.cpp
Normal file
103
touch_button.cpp
Normal file
@ -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<InputEvent> 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<InputEventScreenTouch> b = p_event;
|
||||
|
||||
if (b.is_valid() && _is_point_inside(b->get_position())) {
|
||||
get_viewport()->set_input_as_handled();
|
||||
|
||||
Ref<InputEventMouseButton> 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<InputEventScreenDrag> mm = p_event;
|
||||
|
||||
if (mm.is_valid() && _is_point_inside(mm->get_position())) {
|
||||
Ref<InputEventMouseMotion> 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<InputEvent> p_event) {
|
||||
if (p_event->get_device() == -1) {
|
||||
accept_event();
|
||||
return;
|
||||
}
|
||||
|
||||
BaseButton::_gui_input(p_event);
|
||||
}
|
||||
|
||||
void TouchButton::_unhandled_input(Ref<InputEvent> 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);
|
||||
}
|
25
touch_button.h
Normal file
25
touch_button.h
Normal file
@ -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<InputEvent> p_event);
|
||||
virtual void _unhandled_input(Ref<InputEvent> p_event);
|
||||
void _input(Ref<InputEvent> p_event);
|
||||
static void _bind_methods();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user