summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-05-20 12:38:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-05-20 17:05:38 -0300
commit5b3709d3096df737b8bb2344446be818b0389bfe (patch)
tree649a0989b1494f3c4687d59e503310f4e6bbeb40
parent93f9a83062dbe74474a4a7928758c5cf5588238e (diff)
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
-rw-r--r--core/global_config.cpp69
-rw-r--r--core/global_constants.cpp6
-rw-r--r--core/input_map.cpp138
-rw-r--r--core/input_map.h18
-rw-r--r--core/io/marshalls.cpp137
-rw-r--r--core/io/resource_format_binary.cpp14
-rw-r--r--core/method_bind.h1
-rw-r--r--core/method_ptrcall.h1
-rw-r--r--core/os/input.h4
-rw-r--r--core/os/input_event.cpp981
-rw-r--r--core/os/input_event.h315
-rw-r--r--core/os/main_loop.cpp4
-rw-r--r--core/os/main_loop.h2
-rw-r--r--core/packed_data_container.cpp1
-rw-r--r--core/register_core_types.cpp12
-rw-r--r--core/variant.cpp41
-rw-r--r--core/variant.h6
-rw-r--r--core/variant_call.cpp26
-rw-r--r--core/variant_op.cpp714
-rw-r--r--core/variant_parser.cpp181
-rw-r--r--doc/base/classes.xml2
-rw-r--r--editor/animation_editor.cpp1582
-rw-r--r--editor/animation_editor.h2
-rw-r--r--editor/code_editor.cpp31
-rw-r--r--editor/code_editor.h4
-rw-r--r--editor/create_dialog.cpp13
-rw-r--r--editor/create_dialog.h2
-rw-r--r--editor/doc/doc_data.cpp128
-rw-r--r--editor/doc/doc_dump.cpp3
-rw-r--r--editor/editor_audio_buses.cpp11
-rw-r--r--editor/editor_audio_buses.h2
-rw-r--r--editor/editor_file_dialog.cpp8
-rw-r--r--editor/editor_file_dialog.h2
-rw-r--r--editor/editor_help.cpp42
-rw-r--r--editor/editor_help.h8
-rw-r--r--editor/editor_name_dialog.cpp10
-rw-r--r--editor/editor_name_dialog.h2
-rw-r--r--editor/editor_node.cpp21
-rw-r--r--editor/editor_node.h8
-rw-r--r--editor/editor_path.cpp5
-rw-r--r--editor/editor_path.h2
-rw-r--r--editor/editor_plugin.cpp8
-rw-r--r--editor/editor_plugin.h4
-rw-r--r--editor/editor_profiler.cpp14
-rw-r--r--editor/editor_profiler.h2
-rw-r--r--editor/editor_settings.cpp25
-rw-r--r--editor/editor_settings.h2
-rw-r--r--editor/pane_drag.cpp7
-rw-r--r--editor/pane_drag.h2
-rw-r--r--editor/plugins/animation_player_editor_plugin.cpp13
-rw-r--r--editor/plugins/animation_player_editor_plugin.h4
-rw-r--r--editor/plugins/animation_tree_editor_plugin.cpp212
-rw-r--r--editor/plugins/animation_tree_editor_plugin.h2
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp125
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h6
-rw-r--r--editor/plugins/collision_polygon_2d_editor_plugin.cpp287
-rw-r--r--editor/plugins/collision_polygon_2d_editor_plugin.h4
-rw-r--r--editor/plugins/collision_polygon_editor_plugin.cpp16
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.cpp82
-rw-r--r--editor/plugins/collision_shape_2d_editor_plugin.h4
-rw-r--r--editor/plugins/curve_editor_plugin.cpp19
-rw-r--r--editor/plugins/curve_editor_plugin.h2
-rw-r--r--editor/plugins/gradient_texture_editor_plugin.cpp33
-rw-r--r--editor/plugins/gradient_texture_editor_plugin.h2
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.cpp302
-rw-r--r--editor/plugins/light_occluder_2d_editor_plugin.h4
-rw-r--r--editor/plugins/line_2d_editor_plugin.cpp123
-rw-r--r--editor/plugins/line_2d_editor_plugin.h4
-rw-r--r--editor/plugins/mesh_editor_plugin.cpp6
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.cpp361
-rw-r--r--editor/plugins/navigation_polygon_editor_plugin.h4
-rw-r--r--editor/plugins/path_2d_editor_plugin.cpp557
-rw-r--r--editor/plugins/path_2d_editor_plugin.h4
-rw-r--r--editor/plugins/path_editor_plugin.cpp6
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.cpp329
-rw-r--r--editor/plugins/polygon_2d_editor_plugin.h6
-rw-r--r--editor/plugins/resource_preloader_editor_plugin.cpp2
-rw-r--r--editor/plugins/resource_preloader_editor_plugin.h2
-rw-r--r--editor/plugins/script_editor_plugin.cpp18
-rw-r--r--editor/plugins/script_editor_plugin.h4
-rw-r--r--editor/plugins/script_text_editor.cpp16
-rw-r--r--editor/plugins/script_text_editor.h2
-rw-r--r--editor/plugins/shader_graph_editor_plugin.cpp18
-rw-r--r--editor/plugins/spatial_editor_plugin.cpp1277
-rw-r--r--editor/plugins/spatial_editor_plugin.h10
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.cpp2
-rw-r--r--editor/plugins/sprite_frames_editor_plugin.h2
-rw-r--r--editor/plugins/texture_editor_plugin.cpp2
-rw-r--r--editor/plugins/texture_editor_plugin.h2
-rw-r--r--editor/plugins/texture_region_editor_plugin.cpp53
-rw-r--r--editor/plugins/texture_region_editor_plugin.h2
-rw-r--r--editor/plugins/tile_map_editor_plugin.cpp603
-rw-r--r--editor/plugins/tile_map_editor_plugin.h6
-rw-r--r--editor/project_manager.cpp32
-rw-r--r--editor/project_manager.h4
-rw-r--r--editor/project_settings.cpp227
-rw-r--r--editor/project_settings.h15
-rw-r--r--editor/property_editor.cpp28
-rw-r--r--editor/property_editor.h2
-rw-r--r--editor/property_selector.cpp41
-rw-r--r--editor/property_selector.h5
-rw-r--r--editor/quick_open.cpp9
-rw-r--r--editor/quick_open.h2
-rw-r--r--editor/scene_tree_dock.cpp10
-rw-r--r--editor/scene_tree_dock.h4
-rw-r--r--editor/settings_config_dialog.cpp41
-rw-r--r--editor/settings_config_dialog.h4
-rw-r--r--main/input_default.cpp178
-rw-r--r--main/input_default.h4
-rw-r--r--main/tests/test_image.cpp2
-rw-r--r--main/tests/test_physics.cpp28
-rw-r--r--main/tests/test_physics_2d.cpp25
-rw-r--r--main/tests/test_render.cpp4
-rw-r--r--modules/gdscript/gd_editor.cpp69
-rw-r--r--modules/gdscript/gd_tokenizer.cpp1
-rw-r--r--modules/gridmap/grid_map_editor_plugin.cpp206
-rw-r--r--modules/gridmap/grid_map_editor_plugin.h4
-rw-r--r--modules/visual_script/register_types.cpp2
-rw-r--r--modules/visual_script/visual_script.h2
-rw-r--r--modules/visual_script/visual_script_editor.cpp13
-rw-r--r--modules/visual_script/visual_script_editor.h2
-rw-r--r--modules/visual_script/visual_script_flow_control.cpp285
-rw-r--r--modules/visual_script/visual_script_flow_control.h5
-rw-r--r--modules/visual_script/visual_script_func_nodes.cpp105
-rw-r--r--modules/visual_script/visual_script_func_nodes.h8
-rw-r--r--modules/visual_script/visual_script_nodes.cpp38
-rw-r--r--modules/visual_script/visual_script_nodes.h4
-rw-r--r--platform/android/java_glue.cpp33
-rw-r--r--platform/android/os_android.cpp140
-rw-r--r--platform/android/os_android.h2
-rw-r--r--platform/haiku/haiku_direct_window.cpp72
-rw-r--r--platform/iphone/os_iphone.cpp98
-rw-r--r--platform/iphone/os_iphone.h4
-rw-r--r--platform/javascript/os_javascript.cpp120
-rw-r--r--platform/javascript/os_javascript.h2
-rw-r--r--platform/osx/os_osx.h2
-rw-r--r--platform/osx/os_osx.mm140
-rw-r--r--platform/uwp/app.cpp38
-rw-r--r--platform/uwp/os_uwp.cpp16
-rw-r--r--platform/uwp/os_uwp.h2
-rw-r--r--platform/windows/os_windows.cpp263
-rw-r--r--platform/windows/os_windows.h1
-rw-r--r--platform/x11/os_x11.cpp117
-rw-r--r--platform/x11/os_x11.h2
-rw-r--r--scene/2d/canvas_item.cpp4
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/2d/collision_object_2d.cpp6
-rw-r--r--scene/2d/collision_object_2d.h2
-rw-r--r--scene/2d/screen_button.cpp70
-rw-r--r--scene/2d/screen_button.h3
-rw-r--r--scene/3d/collision_object.cpp6
-rw-r--r--scene/3d/collision_object.h2
-rw-r--r--scene/gui/base_button.cpp249
-rw-r--r--scene/gui/base_button.h4
-rw-r--r--scene/gui/button_array.cpp26
-rw-r--r--scene/gui/button_array.h2
-rw-r--r--scene/gui/color_picker.cpp97
-rw-r--r--scene/gui/color_picker.h8
-rw-r--r--scene/gui/color_ramp_edit.cpp34
-rw-r--r--scene/gui/color_ramp_edit.h2
-rw-r--r--scene/gui/control.cpp4
-rw-r--r--scene/gui/dialogs.cpp18
-rw-r--r--scene/gui/dialogs.h2
-rw-r--r--scene/gui/file_dialog.cpp13
-rw-r--r--scene/gui/file_dialog.h2
-rw-r--r--scene/gui/graph_edit.cpp81
-rw-r--r--scene/gui/graph_edit.h4
-rw-r--r--scene/gui/graph_node.cpp16
-rw-r--r--scene/gui/graph_node.h2
-rw-r--r--scene/gui/input_action.cpp77
-rw-r--r--scene/gui/input_action.h9
-rw-r--r--scene/gui/item_list.cpp73
-rw-r--r--scene/gui/item_list.h2
-rw-r--r--scene/gui/line_edit.cpp599
-rw-r--r--scene/gui/line_edit.h2
-rw-r--r--scene/gui/menu_button.cpp10
-rw-r--r--scene/gui/menu_button.h4
-rw-r--r--scene/gui/popup.cpp2
-rw-r--r--scene/gui/popup.h2
-rw-r--r--scene/gui/popup_menu.cpp257
-rw-r--r--scene/gui/popup_menu.h4
-rw-r--r--scene/gui/rich_text_label.cpp229
-rw-r--r--scene/gui/rich_text_label.h2
-rw-r--r--scene/gui/scroll_bar.cpp388
-rw-r--r--scene/gui/scroll_bar.h4
-rw-r--r--scene/gui/scroll_container.cpp156
-rw-r--r--scene/gui/scroll_container.h2
-rw-r--r--scene/gui/slider.cpp45
-rw-r--r--scene/gui/slider.h2
-rw-r--r--scene/gui/spin_box.cpp31
-rw-r--r--scene/gui/spin_box.h4
-rw-r--r--scene/gui/split_container.cpp24
-rw-r--r--scene/gui/split_container.h2
-rw-r--r--scene/gui/tab_container.cpp10
-rw-r--r--scene/gui/tab_container.h2
-rw-r--r--scene/gui/tabs.cpp30
-rw-r--r--scene/gui/tabs.h2
-rw-r--r--scene/gui/text_edit.cpp1817
-rw-r--r--scene/gui/text_edit.h2
-rw-r--r--scene/gui/tree.cpp809
-rw-r--r--scene/gui/tree.h4
-rwxr-xr-xscene/main/node.cpp6
-rw-r--r--scene/main/scene_main_loop.cpp34
-rw-r--r--scene/main/scene_main_loop.h4
-rw-r--r--scene/main/viewport.cpp759
-rw-r--r--scene/main/viewport.h16
206 files changed, 8543 insertions, 9163 deletions
diff --git a/core/global_config.cpp b/core/global_config.cpp
index 81b923f01e..896384d9c8 100644
--- a/core/global_config.cpp
+++ b/core/global_config.cpp
@@ -846,10 +846,8 @@ GlobalConfig::GlobalConfig() {
registering_order = true;
Array va;
- InputEvent key;
- key.type = InputEvent::KEY;
- InputEvent joyb;
- joyb.type = InputEvent::JOYPAD_BUTTON;
+ Ref<InputEventKey> key;
+ Ref<InputEventJoypadButton> joyb;
GLOBAL_DEF("application/name", "");
GLOBAL_DEF("application/main_scene", "");
@@ -858,87 +856,106 @@ GlobalConfig::GlobalConfig() {
GLOBAL_DEF("application/disable_stderr", false);
GLOBAL_DEF("application/use_shared_user_dir", true);
- key.key.scancode = KEY_RETURN;
+ key.instance();
+ key->set_scancode(KEY_RETURN);
va.push_back(key);
- key.key.scancode = KEY_ENTER;
+ key.instance();
+ key->set_scancode(KEY_ENTER);
va.push_back(key);
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_0;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_0);
va.push_back(joyb);
GLOBAL_DEF("input/ui_accept", va);
input_presets.push_back("input/ui_accept");
va = Array();
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_3;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_3);
va.push_back(joyb);
GLOBAL_DEF("input/ui_select", va);
input_presets.push_back("input/ui_select");
va = Array();
- key.key.scancode = KEY_ESCAPE;
+ key.instance();
+ key->set_scancode(KEY_ESCAPE);
va.push_back(key);
- joyb.joy_button.button_index = JOY_BUTTON_1;
+ joyb.instance();
+ joyb->set_button_index(JOY_BUTTON_1);
va.push_back(joyb);
GLOBAL_DEF("input/ui_cancel", va);
input_presets.push_back("input/ui_cancel");
va = Array();
- key.key.scancode = KEY_TAB;
+ key.instance();
+ key->set_scancode(KEY_TAB);
va.push_back(key);
GLOBAL_DEF("input/ui_focus_next", va);
input_presets.push_back("input/ui_focus_next");
va = Array();
- key.key.scancode = KEY_TAB;
- key.key.mod.shift = true;
+ key.instance();
+ key->set_scancode(KEY_TAB);
+ key->set_shift(true);
va.push_back(key);
GLOBAL_DEF("input/ui_focus_prev", va);
input_presets.push_back("input/ui_focus_prev");
- key.key.mod.shift = false;
va = Array();
- key.key.scancode = KEY_LEFT;
+ key.instance();
+ key->set_scancode(KEY_LEFT);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_LEFT;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_LEFT);
va.push_back(joyb);
GLOBAL_DEF("input/ui_left", va);
input_presets.push_back("input/ui_left");
va = Array();
- key.key.scancode = KEY_RIGHT;
+ key.instance();
+ key->set_scancode(KEY_RIGHT);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_RIGHT;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_RIGHT);
va.push_back(joyb);
GLOBAL_DEF("input/ui_right", va);
input_presets.push_back("input/ui_right");
va = Array();
- key.key.scancode = KEY_UP;
+ key.instance();
+ key->set_scancode(KEY_UP);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_UP;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_UP);
va.push_back(joyb);
GLOBAL_DEF("input/ui_up", va);
input_presets.push_back("input/ui_up");
va = Array();
- key.key.scancode = KEY_DOWN;
+ key.instance();
+ key->set_scancode(KEY_DOWN);
va.push_back(key);
- joyb.joy_button.button_index = JOY_DPAD_DOWN;
+ joyb.instance();
+ joyb->set_button_index(JOY_DPAD_DOWN);
va.push_back(joyb);
GLOBAL_DEF("input/ui_down", va);
input_presets.push_back("input/ui_down");
va = Array();
- key.key.scancode = KEY_PAGEUP;
+ key.instance();
+ key->set_scancode(KEY_PAGEUP);
va.push_back(key);
GLOBAL_DEF("input/ui_page_up", va);
input_presets.push_back("input/ui_page_up");
va = Array();
- key.key.scancode = KEY_PAGEDOWN;
+ key.instance();
+ key->set_scancode(KEY_PAGEDOWN);
va.push_back(key);
GLOBAL_DEF("input/ui_page_down", va);
input_presets.push_back("input/ui_page_down");
diff --git a/core/global_constants.cpp b/core/global_constants.cpp
index 18f34b5d37..4f535fb05e 100644
--- a/core/global_constants.cpp
+++ b/core/global_constants.cpp
@@ -30,6 +30,7 @@
#include "global_constants.h"
#include "object.h"
+#include "os/input_event.h"
#include "os/keyboard.h"
#include "variant.h"
@@ -513,9 +514,8 @@ static _GlobalConstant _global_constants[] = {
{ "TYPE_NODE_PATH", Variant::NODE_PATH }, // 15
{ "TYPE_RID", Variant::_RID },
{ "TYPE_OBJECT", Variant::OBJECT },
- { "TYPE_INPUT_EVENT", Variant::INPUT_EVENT },
- { "TYPE_DICTIONARY", Variant::DICTIONARY },
- { "TYPE_ARRAY", Variant::ARRAY }, // 20
+ { "TYPE_DICTIONARY", Variant::DICTIONARY }, // 20
+ { "TYPE_ARRAY", Variant::ARRAY },
{ "TYPE_RAW_ARRAY", Variant::POOL_BYTE_ARRAY },
{ "TYPE_INT_ARRAY", Variant::POOL_INT_ARRAY },
{ "TYPE_REAL_ARRAY", Variant::POOL_REAL_ARRAY },
diff --git a/core/input_map.cpp b/core/input_map.cpp
index 9f9eba01c7..1307c467e6 100644
--- a/core/input_map.cpp
+++ b/core/input_map.cpp
@@ -37,8 +37,6 @@ InputMap *InputMap::singleton = NULL;
void InputMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_action", "action"), &InputMap::has_action);
- ClassDB::bind_method(D_METHOD("get_action_id", "action"), &InputMap::get_action_id);
- ClassDB::bind_method(D_METHOD("get_action_from_id", "id"), &InputMap::get_action_from_id);
ClassDB::bind_method(D_METHOD("get_actions"), &InputMap::_get_actions);
ClassDB::bind_method(D_METHOD("add_action", "action"), &InputMap::add_action);
ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action);
@@ -57,23 +55,15 @@ void InputMap::add_action(const StringName &p_action) {
input_map[p_action] = Action();
static int last_id = 1;
input_map[p_action].id = last_id;
- input_id_map[last_id] = p_action;
last_id++;
}
void InputMap::erase_action(const StringName &p_action) {
ERR_FAIL_COND(!input_map.has(p_action));
- input_id_map.erase(input_map[p_action].id);
input_map.erase(p_action);
}
-StringName InputMap::get_action_from_id(int p_id) const {
-
- ERR_FAIL_COND_V(!input_id_map.has(p_id), StringName());
- return input_id_map[p_id];
-}
-
Array InputMap::_get_actions() {
Array ret;
@@ -103,49 +93,18 @@ List<StringName> InputMap::get_actions() const {
return actions;
}
-List<InputEvent>::Element *InputMap::_find_event(List<InputEvent> &p_list, const InputEvent &p_event, bool p_action_test) const {
-
- for (List<InputEvent>::Element *E = p_list.front(); E; E = E->next()) {
-
- const InputEvent &e = E->get();
- if (e.type != p_event.type)
- continue;
- if (e.type != InputEvent::KEY && e.device != p_event.device)
- continue;
-
- bool same = false;
-
- switch (p_event.type) {
-
- case InputEvent::KEY: {
-
- if (p_action_test) {
- uint32_t code = e.key.get_scancode_with_modifiers();
- uint32_t event_code = p_event.key.get_scancode_with_modifiers();
- same = (e.key.scancode == p_event.key.scancode && (!p_event.key.pressed || ((code & event_code) == code)));
- } else {
- same = (e.key.scancode == p_event.key.scancode && e.key.mod == p_event.key.mod);
- }
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
+List<Ref<InputEvent> >::Element *InputMap::_find_event(List<Ref<InputEvent> > &p_list, const Ref<InputEvent> &p_event, bool p_action_test) const {
- same = (e.joy_button.button_index == p_event.joy_button.button_index);
+ for (List<Ref<InputEvent> >::Element *E = p_list.front(); E; E = E->next()) {
- } break;
- case InputEvent::MOUSE_BUTTON: {
+ const Ref<InputEvent> e = E->get();
- same = (e.mouse_button.button_index == p_event.mouse_button.button_index);
+ //if (e.type != Ref<InputEvent>::KEY && e.device != p_event.device) -- unsure about the KEY comparison, why is this here?
+ // continue;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- same = (e.joy_motion.axis == p_event.joy_motion.axis && (e.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
-
- } break;
- }
-
- if (same)
+ if (e->get_device() != p_event->get_device())
+ continue;
+ if (e->action_match(p_event))
return E;
}
@@ -157,9 +116,9 @@ bool InputMap::has_action(const StringName &p_action) const {
return input_map.has(p_action);
}
-void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_event) {
+void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
- ERR_FAIL_COND(p_event.type == InputEvent::ACTION);
+ ERR_FAIL_COND(p_event.is_null());
ERR_FAIL_COND(!input_map.has(p_action));
if (_find_event(input_map[p_action].inputs, p_event))
return; //already gots
@@ -167,23 +126,17 @@ void InputMap::action_add_event(const StringName &p_action, const InputEvent &p_
input_map[p_action].inputs.push_back(p_event);
}
-int InputMap::get_action_id(const StringName &p_action) const {
-
- ERR_FAIL_COND_V(!input_map.has(p_action), -1);
- return input_map[p_action].id;
-}
-
-bool InputMap::action_has_event(const StringName &p_action, const InputEvent &p_event) {
+bool InputMap::action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_V(!input_map.has(p_action), false);
return (_find_event(input_map[p_action].inputs, p_event) != NULL);
}
-void InputMap::action_erase_event(const StringName &p_action, const InputEvent &p_event) {
+void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!input_map.has(p_action));
- List<InputEvent>::Element *E = _find_event(input_map[p_action].inputs, p_event);
+ List<Ref<InputEvent> >::Element *E = _find_event(input_map[p_action].inputs, p_event);
if (E)
input_map[p_action].inputs.erase(E);
}
@@ -191,9 +144,9 @@ void InputMap::action_erase_event(const StringName &p_action, const InputEvent &
Array InputMap::_get_action_list(const StringName &p_action) {
Array ret;
- const List<InputEvent> *al = get_action_list(p_action);
+ const List<Ref<InputEvent> > *al = get_action_list(p_action);
if (al) {
- for (const List<InputEvent>::Element *E = al->front(); E; E = E->next()) {
+ for (const List<Ref<InputEvent> >::Element *E = al->front(); E; E = E->next()) {
ret.push_back(E->get());
}
@@ -202,7 +155,7 @@ Array InputMap::_get_action_list(const StringName &p_action) {
return ret;
}
-const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
+const List<Ref<InputEvent> > *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E)
@@ -211,7 +164,7 @@ const List<InputEvent> *InputMap::get_action_list(const StringName &p_action) {
return &E->get().inputs;
}
-bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_action) const {
+bool InputMap::event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const {
Map<StringName, Action>::Element *E = input_map.find(p_action);
if (!E) {
@@ -219,9 +172,9 @@ bool InputMap::event_is_action(const InputEvent &p_event, const StringName &p_ac
ERR_FAIL_COND_V(!E, false);
}
- if (p_event.type == InputEvent::ACTION) {
-
- return p_event.action.action == E->get().id;
+ Ref<InputEventAction> iea = p_event;
+ if (iea.is_valid()) {
+ return iea->get_action() == p_action;
}
return _find_event(E->get().inputs, p_event, true) != NULL;
@@ -252,8 +205,8 @@ void InputMap::load_from_globals() {
for (int i = 0; i < va.size(); i++) {
- InputEvent ie = va[i];
- if (ie.type == InputEvent::NONE)
+ Ref<InputEvent> ie = va[i];
+ if (ie.is_null())
continue;
action_add_event(name, ie);
}
@@ -262,57 +215,70 @@ void InputMap::load_from_globals() {
void InputMap::load_default() {
- InputEvent key;
- key.type = InputEvent::KEY;
+ Ref<InputEventKey> key;
add_action("ui_accept");
- key.key.scancode = KEY_RETURN;
+ key.instance();
+ key->set_scancode(KEY_RETURN);
action_add_event("ui_accept", key);
- key.key.scancode = KEY_ENTER;
+
+ key.instance();
+ key->set_scancode(KEY_ENTER);
action_add_event("ui_accept", key);
- key.key.scancode = KEY_SPACE;
+
+ key.instance();
+ key->set_scancode(KEY_SPACE);
action_add_event("ui_accept", key);
add_action("ui_select");
- key.key.scancode = KEY_SPACE;
+ key.instance();
+ key->set_scancode(KEY_SPACE);
action_add_event("ui_select", key);
add_action("ui_cancel");
- key.key.scancode = KEY_ESCAPE;
+ key.instance();
+ key->set_scancode(KEY_ESCAPE);
action_add_event("ui_cancel", key);
add_action("ui_focus_next");
- key.key.scancode = KEY_TAB;
+ key.instance();
+ key->set_scancode(KEY_TAB);
action_add_event("ui_focus_next", key);
add_action("ui_focus_prev");
- key.key.scancode = KEY_TAB;
- key.key.mod.shift = true;
+ key.instance();
+ key->set_scancode(KEY_TAB);
+ key->set_shift(true);
action_add_event("ui_focus_prev", key);
- key.key.mod.shift = false;
add_action("ui_left");
- key.key.scancode = KEY_LEFT;
+ key.instance();
+ key->set_scancode(KEY_LEFT);
action_add_event("ui_left", key);
add_action("ui_right");
- key.key.scancode = KEY_RIGHT;
+ key.instance();
+ key->set_scancode(KEY_RIGHT);
action_add_event("ui_right", key);
add_action("ui_up");
- key.key.scancode = KEY_UP;
+ key.instance();
+ key->set_scancode(KEY_UP);
action_add_event("ui_up", key);
add_action("ui_down");
- key.key.scancode = KEY_DOWN;
+ key.instance();
+ key->set_scancode(KEY_DOWN);
action_add_event("ui_down", key);
add_action("ui_page_up");
- key.key.scancode = KEY_PAGEUP;
+ key.instance();
+ key->set_scancode(KEY_PAGEUP);
action_add_event("ui_page_up", key);
add_action("ui_page_down");
- key.key.scancode = KEY_PAGEDOWN;
+ key.instance();
+ key->set_scancode(KEY_PAGEDOWN);
action_add_event("ui_page_down", key);
//set("display/handheld/orientation", "landscape");
diff --git a/core/input_map.h b/core/input_map.h
index a25255da2d..ba93e61f5f 100644
--- a/core/input_map.h
+++ b/core/input_map.h
@@ -31,6 +31,7 @@
#define INPUT_MAP_H
#include "object.h"
+#include "os/input_event.h"
class InputMap : public Object {
@@ -39,16 +40,15 @@ class InputMap : public Object {
public:
struct Action {
int id;
- List<InputEvent> inputs;
+ List<Ref<InputEvent> > inputs;
};
private:
static InputMap *singleton;
mutable Map<StringName, Action> input_map;
- mutable Map<int, StringName> input_id_map;
- List<InputEvent>::Element *_find_event(List<InputEvent> &p_list, const InputEvent &p_event, bool p_action_test = false) const;
+ List<Ref<InputEvent> >::Element *_find_event(List<Ref<InputEvent> > &p_list, const Ref<InputEvent> &p_event, bool p_action_test = false) const;
Array _get_action_list(const StringName &p_action);
Array _get_actions();
@@ -60,18 +60,16 @@ public:
static _FORCE_INLINE_ InputMap *get_singleton() { return singleton; }
bool has_action(const StringName &p_action) const;
- int get_action_id(const StringName &p_action) const;
- StringName get_action_from_id(int p_id) const;
List<StringName> get_actions() const;
void add_action(const StringName &p_action);
void erase_action(const StringName &p_action);
- void action_add_event(const StringName &p_action, const InputEvent &p_event);
- bool action_has_event(const StringName &p_action, const InputEvent &p_event);
- void action_erase_event(const StringName &p_action, const InputEvent &p_event);
+ void action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event);
+ bool action_has_event(const StringName &p_action, const Ref<InputEvent> &p_event);
+ void action_erase_event(const StringName &p_action, const Ref<InputEvent> &p_event);
- const List<InputEvent> *get_action_list(const StringName &p_action);
- bool event_is_action(const InputEvent &p_event, const StringName &p_action) const;
+ const List<Ref<InputEvent> > *get_action_list(const StringName &p_action);
+ bool event_is_action(const Ref<InputEvent> &p_event, const StringName &p_action) const;
const Map<StringName, Action> &get_action_map() const;
void load_from_globals();
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index fd14011a81..dccf70ad7a 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -365,66 +365,6 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = (Object *)NULL;
} break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ie;
-
- ie.type = decode_uint32(&buf[0]);
- ie.device = decode_uint32(&buf[4]);
-
- if (r_len)
- (*r_len) += 12;
-
- switch (ie.type) {
-
- case InputEvent::KEY: {
-
- uint32_t mods = decode_uint32(&buf[12]);
- if (mods & KEY_MASK_SHIFT)
- ie.key.mod.shift = true;
- if (mods & KEY_MASK_CTRL)
- ie.key.mod.control = true;
- if (mods & KEY_MASK_ALT)
- ie.key.mod.alt = true;
- if (mods & KEY_MASK_META)
- ie.key.mod.meta = true;
- ie.key.scancode = decode_uint32(&buf[16]);
-
- if (r_len)
- (*r_len) += 8;
-
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- ie.mouse_button.button_index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- ie.joy_button.button_index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- ie.screen_touch.index = decode_uint32(&buf[12]);
- if (r_len)
- (*r_len) += 4;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- ie.joy_motion.axis = decode_uint32(&buf[12]);
- ie.joy_motion.axis_value = decode_float(&buf[16]);
- if (r_len)
- (*r_len) += 8;
- } break;
- }
-
- r_variant = ie;
-
- } break;
case Variant::DICTIONARY: {
ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
@@ -1055,83 +995,6 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len) {
case Variant::OBJECT: {
} break;
- case Variant::INPUT_EVENT: {
-
- InputEvent ie = p_variant;
-
- if (buf) {
-
- encode_uint32(ie.type, &buf[0]);
- encode_uint32(ie.device, &buf[4]);
- encode_uint32(0, &buf[8]);
- }
-
- int llen = 12;
-
- switch (ie.type) {
-
- case InputEvent::KEY: {
-
- if (buf) {
-
- uint32_t mods = 0;
- if (ie.key.mod.shift)
- mods |= KEY_MASK_SHIFT;
- if (ie.key.mod.control)
- mods |= KEY_MASK_CTRL;
- if (ie.key.mod.alt)
- mods |= KEY_MASK_ALT;
- if (ie.key.mod.meta)
- mods |= KEY_MASK_META;
-
- encode_uint32(mods, &buf[llen]);
- encode_uint32(ie.key.scancode, &buf[llen + 4]);
- }
- llen += 8;
-
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- if (buf) {
-
- encode_uint32(ie.mouse_button.button_index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- if (buf) {
-
- encode_uint32(ie.joy_button.button_index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- if (buf) {
-
- encode_uint32(ie.screen_touch.index, &buf[llen]);
- }
- llen += 4;
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- if (buf) {
-
- int axis = ie.joy_motion.axis;
- encode_uint32(axis, &buf[llen]);
- encode_float(ie.joy_motion.axis_value, &buf[llen + 4]);
- }
- llen += 8;
- } break;
- }
-
- if (buf)
- encode_uint32(llen, &buf[8]);
- r_len += llen;
-
- // not supported
- } break;
case Variant::DICTIONARY: {
Dictionary d = p_variant;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index 4ad3d261b2..26b53c2a31 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -359,13 +359,6 @@ Error ResourceInteractiveLoaderBinary::parse_variant(Variant &r_v) {
}
} break;
- case VARIANT_INPUT_EVENT: {
-
- InputEvent ev;
- ev.type = f->get_32(); //will only work for null though.
- r_v = ev;
-
- } break;
case VARIANT_DICTIONARY: {
uint32_t len = f->get_32();
@@ -1446,13 +1439,6 @@ void ResourceFormatSaverBinaryInstance::write_variant(const Variant &p_property,
}
} break;
- case Variant::INPUT_EVENT: {
-
- f->store_32(VARIANT_INPUT_EVENT);
- InputEvent event = p_property;
- f->store_32(0); //event type none, nothing else suported for now.
-
- } break;
case Variant::DICTIONARY: {
f->store_32(VARIANT_DICTIONARY);
diff --git a/core/method_bind.h b/core/method_bind.h
index 5b8a458736..8d72c8573a 100644
--- a/core/method_bind.h
+++ b/core/method_bind.h
@@ -154,7 +154,6 @@ VARIANT_ENUM_CAST(Orientation);
VARIANT_ENUM_CAST(HAlign);
VARIANT_ENUM_CAST(Variant::Type);
VARIANT_ENUM_CAST(Variant::Operator);
-VARIANT_ENUM_CAST(InputEvent::Type);
class MethodBind {
diff --git a/core/method_ptrcall.h b/core/method_ptrcall.h
index d3f6143638..bcbf2e4531 100644
--- a/core/method_ptrcall.h
+++ b/core/method_ptrcall.h
@@ -105,7 +105,6 @@ MAKE_PTRARG(Transform);
MAKE_PTRARG(Color);
MAKE_PTRARG(NodePath);
MAKE_PTRARG(RID);
-MAKE_PTRARG(InputEvent);
MAKE_PTRARG(Dictionary);
MAKE_PTRARG(Array);
MAKE_PTRARG(PoolByteArray);
diff --git a/core/os/input.h b/core/os/input.h
index 4f26f097c2..6759c624e3 100644
--- a/core/os/input.h
+++ b/core/os/input.h
@@ -82,7 +82,7 @@ public:
virtual int get_mouse_button_mask() const = 0;
virtual void warp_mouse_pos(const Vector2 &p_to) = 0;
- virtual Point2i warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect) = 0;
+ virtual Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) = 0;
virtual Vector3 get_gravity() const = 0;
virtual Vector3 get_accelerometer() const = 0;
@@ -104,7 +104,7 @@ public:
virtual int get_joy_button_index_from_string(String p_button) = 0;
virtual int get_joy_axis_index_from_string(String p_axis) = 0;
- virtual void parse_input_event(const InputEvent &p_event) = 0;
+ virtual void parse_input_event(const Ref<InputEvent> &p_event) = 0;
Input();
};
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp
index 474bc33b41..2538e8dad2 100644
--- a/core/os/input_event.cpp
+++ b/core/os/input_event.cpp
@@ -34,275 +34,794 @@
*
*/
-bool InputEvent::operator==(const InputEvent &p_event) const {
- if (type != p_event.type) {
- return false;
- }
+void InputEvent::set_id(uint32_t p_id) {
+ id = p_id;
+}
- switch (type) {
- /** Current clang-format style doesn't play well with the aligned return values of that switch. */
- /* clang-format off */
- case NONE:
- return true;
- case KEY:
- return key.unicode == p_event.key.unicode
- && key.scancode == p_event.key.scancode
- && key.echo == p_event.key.echo
- && key.pressed == p_event.key.pressed
- && key.mod == p_event.key.mod;
- case MOUSE_MOTION:
- return mouse_motion.x == p_event.mouse_motion.x
- && mouse_motion.y == p_event.mouse_motion.y
- && mouse_motion.relative_x == p_event.mouse_motion.relative_x
- && mouse_motion.relative_y == p_event.mouse_motion.relative_y
- && mouse_motion.button_mask == p_event.mouse_motion.button_mask
- && key.mod == p_event.key.mod;
- case MOUSE_BUTTON:
- return mouse_button.pressed == p_event.mouse_button.pressed
- && mouse_button.x == p_event.mouse_button.x
- && mouse_button.y == p_event.mouse_button.y
- && mouse_button.button_index == p_event.mouse_button.button_index
- && mouse_button.button_mask == p_event.mouse_button.button_mask
- && key.mod == p_event.key.mod;
- case JOYPAD_MOTION:
- return joy_motion.axis == p_event.joy_motion.axis
- && joy_motion.axis_value == p_event.joy_motion.axis_value;
- case JOYPAD_BUTTON:
- return joy_button.pressed == p_event.joy_button.pressed
- && joy_button.button_index == p_event.joy_button.button_index
- && joy_button.pressure == p_event.joy_button.pressure;
- case SCREEN_TOUCH:
- return screen_touch.pressed == p_event.screen_touch.pressed
- && screen_touch.index == p_event.screen_touch.index
- && screen_touch.x == p_event.screen_touch.x
- && screen_touch.y == p_event.screen_touch.y;
- case SCREEN_DRAG:
- return screen_drag.index == p_event.screen_drag.index
- && screen_drag.x == p_event.screen_drag.x
- && screen_drag.y == p_event.screen_drag.y;
- case ACTION:
- return action.action == p_event.action.action
- && action.pressed == p_event.action.pressed;
- /* clang-format on */
- default:
- ERR_PRINT("No logic to compare InputEvents of this type, this shouldn't happen.");
- }
+uint32_t InputEvent::get_id() const {
+ return id;
+}
- return false;
+void InputEvent::set_device(int p_device) {
+ device = p_device;
}
-InputEvent::operator String() const {
-
- String str = "Device " + itos(device) + " ID " + itos(ID) + " ";
-
- switch (type) {
-
- case NONE: {
-
- return "Event: None";
- } break;
- case KEY: {
-
- str += "Event: Key ";
- str = str + "Unicode: " + String::chr(key.unicode) + " Scan: " + itos(key.scancode) + " Echo: " + String(key.echo ? "True" : "False") + " Pressed" + String(key.pressed ? "True" : "False") + " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- return str;
- } break;
- case MOUSE_MOTION: {
-
- str += "Event: Motion ";
- str = str + " Pos: " + itos(mouse_motion.x) + "," + itos(mouse_motion.y) + " Rel: " + itos(mouse_motion.relative_x) + "," + itos(mouse_motion.relative_y) + " Mask: ";
- for (int i = 0; i < 8; i++) {
-
- if ((1 << i) & mouse_motion.button_mask)
- str += itos(i + 1);
- }
- str += " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- return str;
- } break;
- case MOUSE_BUTTON: {
- str += "Event: Button ";
- str = str + "Pressed: " + itos(mouse_button.pressed) + " Pos: " + itos(mouse_button.x) + "," + itos(mouse_button.y) + " Button: " + itos(mouse_button.button_index) + " Mask: ";
- for (int i = 0; i < 8; i++) {
-
- if ((1 << i) & mouse_button.button_mask)
- str += itos(i + 1);
- }
- str += " Mod: ";
- if (key.mod.shift)
- str += "S";
- if (key.mod.control)
- str += "C";
- if (key.mod.alt)
- str += "A";
- if (key.mod.meta)
- str += "M";
-
- str += String(" DoubleClick: ") + (mouse_button.doubleclick ? "Yes" : "No");
-
- return str;
-
- } break;
- case JOYPAD_MOTION: {
- str += "Event: JoypadMotion ";
- str = str + "Axis: " + itos(joy_motion.axis) + " Value: " + rtos(joy_motion.axis_value);
- return str;
-
- } break;
- case JOYPAD_BUTTON: {
- str += "Event: JoypadButton ";
- str = str + "Pressed: " + itos(joy_button.pressed) + " Index: " + itos(joy_button.button_index) + " pressure " + rtos(joy_button.pressure);
- return str;
-
- } break;
- case SCREEN_TOUCH: {
- str += "Event: ScreenTouch ";
- str = str + "Pressed: " + itos(screen_touch.pressed) + " Index: " + itos(screen_touch.index) + " pos " + rtos(screen_touch.x) + "," + rtos(screen_touch.y);
- return str;
-
- } break;
- case SCREEN_DRAG: {
- str += "Event: ScreenDrag ";
- str = str + " Index: " + itos(screen_drag.index) + " pos " + rtos(screen_drag.x) + "," + rtos(screen_drag.y);
- return str;
-
- } break;
- case ACTION: {
- str += "Event: Action: " + InputMap::get_singleton()->get_action_from_id(action.action) + " Pressed: " + itos(action.pressed);
- return str;
-
- } break;
- }
- return "";
+int InputEvent::get_device() const {
+ return device;
}
-void InputEvent::set_as_action(const String &p_action, bool p_pressed) {
+bool InputEvent::is_pressed() const {
- type = ACTION;
- action.action = InputMap::get_singleton()->get_action_id(p_action);
- action.pressed = p_pressed;
+ return false;
}
-bool InputEvent::is_pressed() const {
+bool InputEvent::is_action(const StringName &p_action) const {
- switch (type) {
+ return InputMap::get_singleton()->event_is_action(Ref<InputEvent>(this), p_action);
+}
- case KEY: return key.pressed;
- case MOUSE_BUTTON: return mouse_button.pressed;
- case JOYPAD_BUTTON: return joy_button.pressed;
- case SCREEN_TOUCH: return screen_touch.pressed;
- case JOYPAD_MOTION: return ABS(joy_motion.axis_value) > 0.5;
- case ACTION: return action.pressed;
- default: {}
- }
+bool InputEvent::is_action_pressed(const StringName &p_action) const {
+
+ return false; // InputMap::get_singleton()->event_is_action(Ref<InputEvent>(this),p_action);
+}
+bool InputEvent::is_action_released(const StringName &p_action) const {
return false;
}
bool InputEvent::is_echo() const {
- return (type == KEY && key.echo);
+ return false;
+}
+
+Ref<InputEvent> InputEvent::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ return Ref<InputEvent>((InputEvent *)this);
+}
+
+String InputEvent::as_text() const {
+
+ return String();
+}
+
+bool InputEvent::action_match(const Ref<InputEvent> &p_event) const {
+
+ return false;
+}
+
+bool InputEvent::is_action_type() const {
+
+ return false;
+}
+
+#if 0
+if (String(p_method) == "is_action" && p_argidx == 0) {
+
+ List<PropertyInfo> pinfo;
+ GlobalConfig::get_singleton()->get_property_list(&pinfo);
+
+ for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
+ const PropertyInfo &pi = E->get();
+
+ if (!pi.name.begins_with("input/"))
+ continue;
+
+ String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
+ result.insert("\"" + name + "\"");
+ }
+
+} else
+#endif
+
+void InputEvent::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_id", "id"), &InputEvent::set_id);
+ ClassDB::bind_method(D_METHOD("get_id"), &InputEvent::get_id);
+
+ ClassDB::bind_method(D_METHOD("set_device", "device"), &InputEvent::set_device);
+ ClassDB::bind_method(D_METHOD("get_device"), &InputEvent::get_device);
+
+ ClassDB::bind_method(D_METHOD("is_pressed"), &InputEvent::is_pressed);
+ ClassDB::bind_method(D_METHOD("is_action", "action"), &InputEvent::is_action);
+ ClassDB::bind_method(D_METHOD("is_action_pressed", "action"), &InputEvent::is_action_pressed);
+ ClassDB::bind_method(D_METHOD("is_action_released", "action"), &InputEvent::is_action_released);
+ ClassDB::bind_method(D_METHOD("is_echo"), &InputEvent::is_echo);
+
+ ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text);
+
+ ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match);
+
+ ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type);
+
+ ClassDB::bind_method(D_METHOD("xformed_by:InputEvent", "xform", "local_ofs"), &InputEvent::xformed_by, DEFVAL(Vector2()));
+}
+
+InputEvent::InputEvent() {
+
+ id = 0;
+ device = 0;
+}
+
+//////////////////
+
+void InputEventWithModifiers::set_shift(bool p_enabled) {
+
+ shift = p_enabled;
+}
+
+bool InputEventWithModifiers::get_shift() const {
+
+ return shift;
+}
+
+void InputEventWithModifiers::set_alt(bool p_enabled) {
+
+ alt = p_enabled;
+}
+bool InputEventWithModifiers::get_alt() const {
+
+ return alt;
+}
+
+void InputEventWithModifiers::set_control(bool p_enabled) {
+
+ control = p_enabled;
+}
+bool InputEventWithModifiers::get_control() const {
+
+ return control;
+}
+
+void InputEventWithModifiers::set_metakey(bool p_enabled) {
+
+ meta = p_enabled;
+}
+bool InputEventWithModifiers::get_metakey() const {
+
+ return meta;
+}
+
+void InputEventWithModifiers::set_command(bool p_enabled) {
+
+ command = p_enabled;
+}
+bool InputEventWithModifiers::get_command() const {
+
+ return command;
+}
+
+void InputEventWithModifiers::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt);
+ ClassDB::bind_method(D_METHOD("get_alt"), &InputEventWithModifiers::get_alt);
+
+ ClassDB::bind_method(D_METHOD("set_shift", "enable"), &InputEventWithModifiers::set_shift);
+ ClassDB::bind_method(D_METHOD("get_shift"), &InputEventWithModifiers::get_shift);
+
+ ClassDB::bind_method(D_METHOD("set_control", "enable"), &InputEventWithModifiers::set_control);
+ ClassDB::bind_method(D_METHOD("get_control"), &InputEventWithModifiers::get_control);
+
+ ClassDB::bind_method(D_METHOD("set_metakey", "enable"), &InputEventWithModifiers::set_metakey);
+ ClassDB::bind_method(D_METHOD("get_metakey"), &InputEventWithModifiers::get_metakey);
+
+ ClassDB::bind_method(D_METHOD("set_command", "enable"), &InputEventWithModifiers::set_command);
+ ClassDB::bind_method(D_METHOD("get_command"), &InputEventWithModifiers::get_command);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "alt"), "set_alt", "get_alt");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shift"), "set_shift", "get_shift");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "control"), "set_control", "get_control");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta"), "set_metakey", "get_metakey");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command"), "set_command", "get_command");
+}
+
+InputEventWithModifiers::InputEventWithModifiers() {
+
+ alt = false;
+ shift = false;
+ control = false;
+ meta = false;
+}
+
+//////////////////////////////////
+
+void InputEventKey::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+
+bool InputEventKey::is_pressed() {
+
+ return pressed;
}
-bool InputEvent::is_action(const String &p_action) const {
+void InputEventKey::set_scancode(uint32_t p_scancode) {
+
+ scancode = p_scancode;
+}
+uint32_t InputEventKey::get_scancode() const {
- return InputMap::get_singleton()->event_is_action(*this, p_action);
+ return scancode;
}
-bool InputEvent::is_action_pressed(const String &p_action) const {
+void InputEventKey::set_unicode(uint32_t p_unicode) {
- return is_action(p_action) && is_pressed() && !is_echo();
+ unicode = p_unicode;
}
+uint32_t InputEventKey::get_unicode() const {
-bool InputEvent::is_action_released(const String &p_action) const {
+ return unicode;
+}
+
+void InputEventKey::set_echo(bool p_enable) {
+
+ echo = p_enable;
+}
+bool InputEventKey::is_echo() const {
- return is_action(p_action) && !is_pressed();
+ return echo;
}
uint32_t InputEventKey::get_scancode_with_modifiers() const {
uint32_t sc = scancode;
- if (mod.control)
+ if (get_control())
sc |= KEY_MASK_CTRL;
- if (mod.alt)
+ if (get_alt())
sc |= KEY_MASK_ALT;
- if (mod.shift)
+ if (get_shift())
sc |= KEY_MASK_SHIFT;
- if (mod.meta)
+ if (get_metakey())
sc |= KEY_MASK_META;
return sc;
}
-InputEvent InputEvent::xform_by(const Transform2D &p_xform) const {
-
- InputEvent ev = *this;
-
- switch (ev.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- Vector2 g = p_xform.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y));
- Vector2 l = p_xform.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y));
- ev.mouse_button.x = l.x;
- ev.mouse_button.y = l.y;
- ev.mouse_button.global_x = g.x;
- ev.mouse_button.global_y = g.y;
-
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- Vector2 g = p_xform.xform(Vector2(ev.mouse_motion.global_x, ev.mouse_motion.global_y));
- Vector2 l = p_xform.xform(Vector2(ev.mouse_motion.x, ev.mouse_motion.y));
- Vector2 r = p_xform.basis_xform(Vector2(ev.mouse_motion.relative_x, ev.mouse_motion.relative_y));
- Vector2 s = p_xform.basis_xform(Vector2(ev.mouse_motion.speed_x, ev.mouse_motion.speed_y));
- ev.mouse_motion.x = l.x;
- ev.mouse_motion.y = l.y;
- ev.mouse_motion.global_x = g.x;
- ev.mouse_motion.global_y = g.y;
- ev.mouse_motion.relative_x = r.x;
- ev.mouse_motion.relative_y = r.y;
- ev.mouse_motion.speed_x = s.x;
- ev.mouse_motion.speed_y = s.y;
-
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- Vector2 t = p_xform.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y));
- ev.screen_touch.x = t.x;
- ev.screen_touch.y = t.y;
-
- } break;
- case InputEvent::SCREEN_DRAG: {
-
- Vector2 t = p_xform.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y));
- Vector2 r = p_xform.basis_xform(Vector2(ev.screen_drag.relative_x, ev.screen_drag.relative_y));
- Vector2 s = p_xform.basis_xform(Vector2(ev.screen_drag.speed_x, ev.screen_drag.speed_y));
- ev.screen_drag.x = t.x;
- ev.screen_drag.y = t.y;
- ev.screen_drag.relative_x = r.x;
- ev.screen_drag.relative_y = r.y;
- ev.screen_drag.speed_x = s.x;
- ev.screen_drag.speed_y = s.y;
- } break;
- }
+bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventKey> key = p_event;
+ if (key.is_null())
+ return false;
+
+ return get_scancode_with_modifiers() == key->get_scancode_with_modifiers();
+}
+
+void InputEventKey::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed);
+
+ ClassDB::bind_method(D_METHOD("set_scancode", "scancode"), &InputEventKey::set_scancode);
+ ClassDB::bind_method(D_METHOD("get_scancode"), &InputEventKey::get_scancode);
+
+ ClassDB::bind_method(D_METHOD("set_unicode", "unicode"), &InputEventKey::set_unicode);
+ ClassDB::bind_method(D_METHOD("get_unicode"), &InputEventKey::get_unicode);
+
+ ClassDB::bind_method(D_METHOD("set_echo", "echo"), &InputEventKey::set_echo);
+
+ ClassDB::bind_method(D_METHOD("get_scancode_with_modifiers"), &InputEventKey::get_scancode_with_modifiers);
+
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "scancode"), "set_scancode", "get_scancode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "unicode"), "set_unicode", "get_unicode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "echo"), "set_echo", "is_echo");
+}
+
+InputEventKey::InputEventKey() {
+
+ pressed = false;
+ scancode = 0;
+ unicode = 0; ///unicode
+ echo = false;
+}
+
+////////////////////////////////////////
+
+void InputEventMouse::set_button_mask(int p_mask) {
+
+ button_mask = p_mask;
+}
+int InputEventMouse::get_button_mask() const {
+
+ return button_mask;
+}
+
+void InputEventMouse::set_pos(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventMouse::get_pos() const {
+
+ return pos;
+}
+
+void InputEventMouse::set_global_pos(const Vector2 &p_global_pos) {
+
+ global_pos = p_global_pos;
+}
+Vector2 InputEventMouse::get_global_pos() const {
+
+ return global_pos;
+}
+
+void InputEventMouse::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_button_mask", "button_mask"), &InputEventMouse::set_button_mask);
+ ClassDB::bind_method(D_METHOD("get_button_mask"), &InputEventMouse::get_button_mask);
+
+ ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventMouse::set_pos);
+ ClassDB::bind_method(D_METHOD("get_pos"), &InputEventMouse::get_pos);
+
+ ClassDB::bind_method(D_METHOD("set_global_pos", "global_pos"), &InputEventMouse::set_global_pos);
+ ClassDB::bind_method(D_METHOD("get_global_pos"), &InputEventMouse::get_global_pos);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_mask"), "set_button_mask", "get_button_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_pos"), "set_global_pos", "get_global_pos");
+}
+
+InputEventMouse::InputEventMouse() {
+
+ button_mask = 0;
+}
+
+///////////////////////////////////////
+
+void InputEventMouseButton::set_factor(float p_factor) {
+
+ factor = p_factor;
+}
+
+float InputEventMouseButton::get_factor() {
+
+ return factor;
+}
+
+void InputEventMouseButton::set_button_index(int p_index) {
+
+ button_index = p_index;
+}
+int InputEventMouseButton::get_button_index() const {
+
+ return button_index;
+}
+
+void InputEventMouseButton::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventMouseButton::is_pressed() const {
+
+ return pressed;
+}
+
+void InputEventMouseButton::set_doubleclick(bool p_doubleclick) {
+
+ doubleclick = p_doubleclick;
+}
+bool InputEventMouseButton::is_doubleclick() const {
+
+ return doubleclick;
+}
+
+Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Vector2 g = p_xform.xform(get_global_pos());
+ Vector2 l = p_xform.xform(get_pos() + p_local_ofs);
+
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+
+ mb->set_id(get_id());
+ mb->set_device(get_device());
+
+ mb->set_alt(get_alt());
+ mb->set_shift(get_shift());
+ mb->set_control(get_control());
+ mb->set_metakey(get_metakey());
+
+ mb->set_pos(l);
+ mb->set_global_pos(g);
+
+ mb->set_button_mask(get_button_mask());
+ mb->set_pressed(pressed);
+ mb->set_doubleclick(doubleclick);
+ mb->set_factor(factor);
+ mb->set_button_index(button_index);
+
+ return mb;
+}
+
+bool InputEventMouseButton::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_null())
+ return false;
+
+ return mb->button_index == button_index;
+}
+
+void InputEventMouseButton::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_factor", "factor"), &InputEventMouseButton::set_factor);
+ ClassDB::bind_method(D_METHOD("get_factor"), &InputEventMouseButton::get_factor);
+
+ ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventMouseButton::set_button_index);
+ ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventMouseButton::get_button_index);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventMouseButton::set_pressed);
+ // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventMouseButton::is_pressed);
+
+ ClassDB::bind_method(D_METHOD("set_doubleclick", "doubleclick"), &InputEventMouseButton::set_doubleclick);
+ ClassDB::bind_method(D_METHOD("is_doubleclick"), &InputEventMouseButton::is_doubleclick);
+
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "factor"), "set_factor", "get_factor");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "doubleclick"), "set_doubleclick", "is_doubleclick");
+}
+
+InputEventMouseButton::InputEventMouseButton() {
+
+ factor = 0;
+ button_index = 0;
+ pressed = false;
+ doubleclick = false;
+}
+
+////////////////////////////////////////////
+
+void InputEventMouseMotion::set_relative(const Vector2 &p_relative) {
+
+ relative = p_relative;
+}
+Vector2 InputEventMouseMotion::get_relative() const {
+
+ return relative;
+}
+
+void InputEventMouseMotion::set_speed(const Vector2 &p_speed) {
+
+ speed = p_speed;
+}
+Vector2 InputEventMouseMotion::get_speed() const {
+
+ return speed;
+}
+
+Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Vector2 g = p_xform.xform(get_global_pos());
+ Vector2 l = p_xform.xform(get_pos() + p_local_ofs);
+ Vector2 r = p_xform.basis_xform(get_relative());
+ Vector2 s = p_xform.basis_xform(get_speed());
+
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
+
+ mm->set_id(get_id());
+ mm->set_device(get_device());
+
+ mm->set_alt(get_alt());
+ mm->set_shift(get_shift());
+ mm->set_control(get_control());
+ mm->set_metakey(get_metakey());
+
+ mm->set_pos(l);
+ mm->set_global_pos(g);
+
+ mm->set_button_mask(get_button_mask());
+ mm->set_relative(r);
+ mm->set_speed(s);
+
+ return mm;
+}
+
+void InputEventMouseMotion::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventMouseMotion::set_relative);
+ ClassDB::bind_method(D_METHOD("get_relative"), &InputEventMouseMotion::get_relative);
+
+ ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventMouseMotion::set_speed);
+ ClassDB::bind_method(D_METHOD("get_speed"), &InputEventMouseMotion::get_speed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
+}
+
+InputEventMouseMotion::InputEventMouseMotion() {
+}
+
+////////////////////////////////////////
+
+void InputEventJoypadMotion::set_axis(int p_axis) {
+
+ axis = p_axis;
+}
+
+int InputEventJoypadMotion::get_axis() const {
+
+ return axis;
+}
+
+void InputEventJoypadMotion::set_axis_value(float p_value) {
+
+ axis_value = p_value;
+}
+float InputEventJoypadMotion::get_axis_value() const {
+
+ return axis_value;
+}
+
+bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventJoypadMotion> jm = p_event;
+ if (jm.is_null())
+ return false;
+
+ return (axis == jm->axis && (axis_value < 0) == (jm->axis_value < 0));
+}
+
+void InputEventJoypadMotion::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_axis", "axis"), &InputEventJoypadMotion::set_axis);
+ ClassDB::bind_method(D_METHOD("get_axis"), &InputEventJoypadMotion::get_axis);
+
+ ClassDB::bind_method(D_METHOD("set_axis_value", "axis_value"), &InputEventJoypadMotion::set_axis_value);
+ ClassDB::bind_method(D_METHOD("get_axis_value"), &InputEventJoypadMotion::get_axis_value);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "axis"), "set_axis", "get_axis");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
+}
+
+InputEventJoypadMotion::InputEventJoypadMotion() {
+
+ axis = 0;
+ axis_value = 0;
+}
+/////////////////////////////////
+
+void InputEventJoypadButton::set_button_index(int p_index) {
+
+ button_index = p_index;
+}
+
+int InputEventJoypadButton::get_button_index() const {
+
+ return button_index;
+}
+
+void InputEventJoypadButton::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventJoypadButton::is_pressed() const {
+
+ return pressed;
+}
+
+void InputEventJoypadButton::set_pressure(float p_pressure) {
+
+ pressure = p_pressure;
+}
+float InputEventJoypadButton::get_pressure() const {
+
+ return pressure;
+}
+
+bool InputEventJoypadButton::action_match(const Ref<InputEvent> &p_event) const {
+
+ Ref<InputEventJoypadButton> jb = p_event;
+ if (jb.is_null())
+ return false;
+
+ return button_index == jb->button_index;
+}
+
+void InputEventJoypadButton::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
+ ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);
+
+ ClassDB::bind_method(D_METHOD("set_pressure", "pressure"), &InputEventJoypadButton::set_pressure);
+ ClassDB::bind_method(D_METHOD("get_pressure"), &InputEventJoypadButton::get_pressure);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventJoypadButton::set_pressed);
+ // ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventJoypadButton::is_pressed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "button_index"), "set_button_index", "get_button_index");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "pressure"), "set_pressure", "get_pressure");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
+
+InputEventJoypadButton::InputEventJoypadButton() {
+
+ button_index = 0;
+ pressure = 0;
+ pressed = false;
+}
+
+//////////////////////////////////////////////
+
+void InputEventScreenTouch::set_index(int p_index) {
+
+ index = p_index;
+}
+int InputEventScreenTouch::get_index() const {
+
+ return index;
+}
+
+void InputEventScreenTouch::set_pos(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventScreenTouch::get_pos() const {
+
+ return pos;
+}
+
+void InputEventScreenTouch::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventScreenTouch::is_pressed() const {
+
+ return pressed;
+}
+
+Ref<InputEvent> InputEventScreenTouch::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Ref<InputEventScreenTouch> st;
+ st.instance();
+ st->set_id(get_id());
+ st->set_device(get_device());
+ st->set_index(index);
+ st->set_pos(p_xform.xform(pos + p_local_ofs));
+ st->set_pressed(pressed);
+
+ return st;
+}
+
+void InputEventScreenTouch::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenTouch::set_index);
+ ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenTouch::get_index);
+
+ ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenTouch::set_pos);
+ ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenTouch::get_pos);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventScreenTouch::set_pressed);
+ //ClassDB::bind_method(D_METHOD("is_pressed"),&InputEventScreenTouch::is_pressed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
+
+InputEventScreenTouch::InputEventScreenTouch() {
+
+ index = 0;
+ pressed = false;
+}
+
+/////////////////////////////
+
+void InputEventScreenDrag::set_index(int p_index) {
+
+ index = p_index;
+}
+
+int InputEventScreenDrag::get_index() const {
+
+ return index;
+}
+
+void InputEventScreenDrag::set_pos(const Vector2 &p_pos) {
+
+ pos = p_pos;
+}
+Vector2 InputEventScreenDrag::get_pos() const {
+
+ return pos;
+}
+
+void InputEventScreenDrag::set_relative(const Vector2 &p_relative) {
+
+ relative = p_relative;
+}
+Vector2 InputEventScreenDrag::get_relative() const {
+
+ return relative;
+}
+
+void InputEventScreenDrag::set_speed(const Vector2 &p_speed) {
+
+ speed = p_speed;
+}
+Vector2 InputEventScreenDrag::get_speed() const {
+
+ return speed;
+}
+
+Ref<InputEvent> InputEventScreenDrag::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const {
+
+ Ref<InputEventScreenDrag> sd;
+
+ sd.instance();
+
+ sd->set_id(get_id());
+ sd->set_device(get_device());
+
+ sd->set_index(index);
+ sd->set_pos(p_xform.xform(pos + p_local_ofs));
+ sd->set_relative(p_xform.basis_xform(relative));
+ sd->set_speed(p_xform.basis_xform(speed));
+
+ return sd;
+}
+
+void InputEventScreenDrag::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_index", "index"), &InputEventScreenDrag::set_index);
+ ClassDB::bind_method(D_METHOD("get_index"), &InputEventScreenDrag::get_index);
+
+ ClassDB::bind_method(D_METHOD("set_pos", "pos"), &InputEventScreenDrag::set_pos);
+ ClassDB::bind_method(D_METHOD("get_pos"), &InputEventScreenDrag::get_pos);
+
+ ClassDB::bind_method(D_METHOD("set_relative", "relative"), &InputEventScreenDrag::set_relative);
+ ClassDB::bind_method(D_METHOD("get_relative"), &InputEventScreenDrag::get_relative);
+
+ ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InputEventScreenDrag::set_speed);
+ ClassDB::bind_method(D_METHOD("get_speed"), &InputEventScreenDrag::get_speed);
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "index"), "set_index", "get_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pos"), "set_pos", "get_pos");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "relative"), "set_relative", "get_relative");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "speed"), "set_speed", "get_speed");
+}
+
+InputEventScreenDrag::InputEventScreenDrag() {
+
+ index = 0;
+}
+/////////////////////////////
+
+void InputEventAction::set_action(const StringName &p_action) {
+
+ action = p_action;
+}
+StringName InputEventAction::get_action() const {
+
+ return action;
+}
+
+void InputEventAction::set_pressed(bool p_pressed) {
+
+ pressed = p_pressed;
+}
+bool InputEventAction::is_pressed() const {
+
+ return pressed;
+}
+
+bool InputEventAction::is_action(const StringName &p_action) const {
+
+ return action == p_action;
+}
+
+void InputEventAction::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_action", "action"), &InputEventAction::set_action);
+ ClassDB::bind_method(D_METHOD("get_action"), &InputEventAction::get_action);
+
+ ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventAction::set_pressed);
+ //ClassDB::bind_method(D_METHOD("is_pressed"), &InputEventAction::is_pressed);
+
+ ClassDB::bind_method(D_METHOD("is_action", "name"), &InputEventAction::is_action);
+
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
+}
- return ev;
+InputEventAction::InputEventAction() {
+ pressed = false;
}
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 93cceac27c..b94f0ef46a 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -32,6 +32,7 @@
#include "math_2d.h"
#include "os/copymem.h"
+#include "resource.h"
#include "typedefs.h"
#include "ustring.h"
/**
@@ -137,7 +138,40 @@ enum {
* Input Modifier Status
* for keyboard/mouse events.
*/
-struct InputModifierState {
+
+class InputEvent : public Resource {
+ GDCLASS(InputEvent, Resource)
+
+ uint32_t id;
+ int device;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_id(uint32_t p_id);
+ uint32_t get_id() const;
+
+ void set_device(int p_device);
+ int get_device() const;
+
+ virtual bool is_pressed() const;
+ virtual bool is_action(const StringName &p_action) const;
+ virtual bool is_action_pressed(const StringName &p_action) const;
+ virtual bool is_action_released(const StringName &p_action) const;
+ virtual bool is_echo() const;
+ virtual String as_text() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+ virtual bool is_action_type() const;
+
+ InputEvent();
+};
+
+class InputEventWithModifiers : public InputEvent {
+ GDCLASS(InputEventWithModifiers, InputEvent)
bool shift;
bool alt;
@@ -157,126 +191,267 @@ struct InputModifierState {
#endif
- bool operator==(const InputModifierState &rvalue) const {
+protected:
+ static void _bind_methods();
+
+public:
+ void set_shift(bool p_enabled);
+ bool get_shift() const;
+
+ void set_alt(bool p_enabled);
+ bool get_alt() const;
+
+ void set_control(bool p_enabled);
+ bool get_control() const;
+
+ void set_metakey(bool p_enabled);
+ bool get_metakey() const;
+
+ void set_command(bool p_enabled);
+ bool get_command() const;
- return ((shift == rvalue.shift) && (alt == rvalue.alt) && (control == rvalue.control) && (meta == rvalue.meta));
- }
+ InputEventWithModifiers();
};
-struct InputEventKey {
+class InputEventKey : public InputEventWithModifiers {
- InputModifierState mod;
+ GDCLASS(InputEventKey, InputEventWithModifiers)
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t unicode; ///unicode
+ bool echo; /// true if this is an echo key
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_pressed(bool p_pressed);
+ bool is_pressed();
+
+ void set_scancode(uint32_t p_scancode);
+ uint32_t get_scancode() const;
+
+ void set_unicode(uint32_t p_unicode);
+ uint32_t get_unicode() const;
+
+ void set_echo(bool p_enable);
+ bool is_echo() const;
+
uint32_t get_scancode_with_modifiers() const;
- bool echo; /// true if this is an echo key
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventKey();
};
-struct InputEventMouse {
+class InputEventMouse : public InputEventWithModifiers {
+
+ GDCLASS(InputEventMouse, InputEventWithModifiers)
- InputModifierState mod;
int button_mask;
- float x, y;
- float global_x, global_y;
- int pointer_index;
+
+ Vector2 pos;
+ Vector2 global_pos;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_mask(int p_mask);
+ int get_button_mask() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_global_pos(const Vector2 &p_global_pos);
+ Vector2 get_global_pos() const;
+
+ InputEventMouse();
};
-struct InputEventMouseButton : public InputEventMouse {
+class InputEventMouseButton : public InputEventMouse {
+
+ GDCLASS(InputEventMouseButton, InputEventMouse)
- double factor;
+ float factor;
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_factor(float p_factor);
+ float get_factor();
+
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_doubleclick(bool p_doubleclick);
+ bool is_doubleclick() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventMouseButton();
};
-struct InputEventMouseMotion : public InputEventMouse {
+class InputEventMouseMotion : public InputEventMouse {
+
+ GDCLASS(InputEventMouseMotion, InputEventMouse)
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ InputEventMouseMotion();
};
-struct InputEventJoypadMotion {
+class InputEventJoypadMotion : public InputEvent {
+ GDCLASS(InputEventJoypadMotion, InputEvent)
int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_axis(int p_axis);
+ int get_axis() const;
+
+ void set_axis_value(float p_value);
+ float get_axis_value() const;
+
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadMotion();
};
-struct InputEventJoypadButton {
+class InputEventJoypadButton : public InputEvent {
+ GDCLASS(InputEventJoypadButton, InputEvent)
int button_index;
bool pressed;
float pressure; //0 to 1
-};
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_pressure(float p_pressure);
+ float get_pressure() const;
-struct InputEventScreenTouch {
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadButton();
+};
+
+struct InputEventScreenTouch : public InputEvent {
+ GDCLASS(InputEventScreenTouch, InputEvent)
int index;
- float x, y;
+ Vector2 pos;
bool pressed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenTouch();
};
-struct InputEventScreenDrag {
+class InputEventScreenDrag : public InputEvent {
+
+ GDCLASS(InputEventScreenDrag, InputEvent)
int index;
- float x, y;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ Vector2 pos;
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenDrag();
};
-struct InputEventAction {
+class InputEventAction : public InputEvent {
+
+ GDCLASS(InputEventAction, InputEvent)
- int action;
+ StringName action;
bool pressed;
-};
-struct InputEvent {
-
- enum Type {
- NONE,
- KEY,
- MOUSE_MOTION,
- MOUSE_BUTTON,
- JOYPAD_MOTION,
- JOYPAD_BUTTON,
- SCREEN_TOUCH,
- SCREEN_DRAG,
- ACTION,
- TYPE_MAX
- };
+protected:
+ static void _bind_methods();
- uint32_t ID;
- int type;
- int device;
+public:
+ void set_action(const StringName &p_action);
+ StringName get_action() const;
- union {
- InputEventMouseMotion mouse_motion;
- InputEventMouseButton mouse_button;
- InputEventJoypadMotion joy_motion;
- InputEventJoypadButton joy_button;
- InputEventKey key;
- InputEventScreenTouch screen_touch;
- InputEventScreenDrag screen_drag;
- InputEventAction action;
- };
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
- bool is_pressed() const;
- bool is_action(const String &p_action) const;
- bool is_action_pressed(const String &p_action) const;
- bool is_action_released(const String &p_action) const;
- bool is_echo() const;
- void set_as_action(const String &p_action, bool p_pressed);
-
- InputEvent xform_by(const Transform2D &p_xform) const;
- bool operator==(const InputEvent &p_event) const;
- operator String() const;
- InputEvent() {
- zeromem(this, sizeof(InputEvent));
- mouse_button.factor = 1;
- }
+ virtual bool is_action(const StringName &p_action) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventAction();
};
#endif
diff --git a/core/os/main_loop.cpp b/core/os/main_loop.cpp
index 9f8fcccd82..248f5537c6 100644
--- a/core/os/main_loop.cpp
+++ b/core/os/main_loop.cpp
@@ -39,7 +39,7 @@ void MainLoop::_bind_methods() {
ClassDB::bind_method(D_METHOD("idle", "delta"), &MainLoop::idle);
ClassDB::bind_method(D_METHOD("finish"), &MainLoop::finish);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::INPUT_EVENT, "ev")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo("_input_text", PropertyInfo(Variant::STRING, "text")));
BIND_VMETHOD(MethodInfo("_initialize"));
BIND_VMETHOD(MethodInfo("_iteration", PropertyInfo(Variant::REAL, "delta")));
@@ -73,7 +73,7 @@ void MainLoop::input_text(const String &p_text) {
get_script_instance()->call("_input_text", p_text);
}
-void MainLoop::input_event(const InputEvent &p_event) {
+void MainLoop::input_event(const Ref<InputEvent> &p_event) {
if (get_script_instance())
get_script_instance()->call("_input_event", p_event);
diff --git a/core/os/main_loop.h b/core/os/main_loop.h
index a53137afa4..23b352468e 100644
--- a/core/os/main_loop.h
+++ b/core/os/main_loop.h
@@ -59,7 +59,7 @@ public:
NOTIFICATION_TRANSLATION_CHANGED = 10,
};
- virtual void input_event(const InputEvent &p_event);
+ virtual void input_event(const Ref<InputEvent> &p_event);
virtual void input_text(const String &p_text);
virtual void init();
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 836bcb7287..0565d0d3f5 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -237,7 +237,6 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::RECT3:
case Variant::BASIS:
case Variant::TRANSFORM:
- case Variant::INPUT_EVENT:
case Variant::POOL_BYTE_ARRAY:
case Variant::POOL_INT_ARRAY:
case Variant::POOL_REAL_ARRAY:
diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp
index 634751b0bb..b089ba9129 100644
--- a/core/register_core_types.cpp
+++ b/core/register_core_types.cpp
@@ -110,6 +110,18 @@ void register_core_types() {
ClassDB::register_class<Resource>();
ClassDB::register_class<Image>();
+ ClassDB::register_virtual_class<InputEvent>();
+ ClassDB::register_virtual_class<InputEventWithModifiers>();
+ ClassDB::register_class<InputEventKey>();
+ ClassDB::register_virtual_class<InputEventMouse>();
+ ClassDB::register_class<InputEventMouseButton>();
+ ClassDB::register_class<InputEventMouseMotion>();
+ ClassDB::register_class<InputEventJoypadButton>();
+ ClassDB::register_class<InputEventJoypadMotion>();
+ ClassDB::register_class<InputEventScreenDrag>();
+ ClassDB::register_class<InputEventScreenTouch>();
+ ClassDB::register_class<InputEventAction>();
+
ClassDB::register_class<FuncRef>();
ClassDB::register_virtual_class<StreamPeer>();
ClassDB::register_class<StreamPeerBuffer>();
diff --git a/core/variant.cpp b/core/variant.cpp
index 9c05dbaca0..ae5141b8bf 100644
--- a/core/variant.cpp
+++ b/core/variant.cpp
@@ -133,11 +133,6 @@ String Variant::get_type_name(Variant::Type p_type) {
return "NodePath";
} break;
- case INPUT_EVENT: {
-
- return "InputEvent";
-
- } break;
case DICTIONARY: {
return "Dictionary";
@@ -798,11 +793,6 @@ bool Variant::is_zero() const {
return reinterpret_cast<const NodePath *>(_data._mem)->is_empty();
} break;
- case INPUT_EVENT: {
-
- return _data._input_event->type == InputEvent::NONE;
-
- } break;
case DICTIONARY: {
return reinterpret_cast<const Dictionary *>(_data._mem)->empty();
@@ -1018,11 +1008,6 @@ void Variant::reference(const Variant &p_variant) {
memnew_placement(_data._mem, NodePath(*reinterpret_cast<const NodePath *>(p_variant._data._mem)));
} break;
- case INPUT_EVENT: {
-
- _data._input_event = memnew(InputEvent(*p_variant._data._input_event));
-
- } break;
case DICTIONARY: {
memnew_placement(_data._mem, Dictionary(*reinterpret_cast<const Dictionary *>(p_variant._data._mem)));
@@ -1149,12 +1134,6 @@ void Variant::clear() {
reinterpret_cast<Array *>(_data._mem)->~Array();
} break;
- case INPUT_EVENT: {
-
- memdelete(_data._input_event);
-
- } break;
-
// arrays
case POOL_BYTE_ARRAY: {
@@ -1503,7 +1482,6 @@ Variant::operator String() const {
} break;
case TRANSFORM: return operator Transform();
case NODE_PATH: return operator NodePath();
- case INPUT_EVENT: return operator InputEvent();
case COLOR: return String::num(operator Color().r) + "," + String::num(operator Color().g) + "," + String::num(operator Color().b) + "," + String::num(operator Color().a);
case DICTIONARY: {
@@ -1798,14 +1776,6 @@ Variant::operator Control *() const {
return NULL;
}
-Variant::operator InputEvent() const {
-
- if (type == INPUT_EVENT)
- return *reinterpret_cast<const InputEvent *>(_data._input_event);
- else
- return InputEvent();
-}
-
Variant::operator Dictionary() const {
if (type == DICTIONARY)
@@ -2285,12 +2255,6 @@ Variant::Variant(const NodePath &p_node_path) {
memnew_placement(_data._mem, NodePath(p_node_path));
}
-Variant::Variant(const InputEvent &p_input_event) {
-
- type = INPUT_EVENT;
- _data._input_event = memnew(InputEvent(p_input_event));
-}
-
Variant::Variant(const RefPtr &p_resource) {
type = OBJECT;
@@ -2690,11 +2654,6 @@ uint32_t Variant::hash() const {
return reinterpret_cast<const NodePath *>(_data._mem)->hash();
} break;
- case INPUT_EVENT: {
-
- return hash_djb2_buffer((uint8_t *)_data._input_event, sizeof(InputEvent));
-
- } break;
case DICTIONARY: {
return reinterpret_cast<const Dictionary *>(_data._mem)->hash();
diff --git a/core/variant.h b/core/variant.h
index 76097dfbdd..661d31cf16 100644
--- a/core/variant.h
+++ b/core/variant.h
@@ -42,7 +42,6 @@
#include "io/ip_address.h"
#include "math_2d.h"
#include "matrix3.h"
-#include "os/input_event.h"
#include "os/power.h"
#include "path_db.h"
#include "plane.h"
@@ -100,7 +99,6 @@ public:
NODE_PATH, // 15
_RID,
OBJECT,
- INPUT_EVENT,
DICTIONARY,
ARRAY, // 20
@@ -143,7 +141,6 @@ private:
Basis *_basis;
Transform *_transform;
RefPtr *_resource;
- InputEvent *_input_event;
void *_ptr; //generic pointer
uint8_t _mem[sizeof(ObjData) > (sizeof(real_t) * 4) ? sizeof(ObjData) : (sizeof(real_t) * 4)];
} _data;
@@ -207,7 +204,7 @@ public:
operator NodePath() const;
operator RefPtr() const;
operator RID() const;
- operator InputEvent() const;
+
operator Object *() const;
operator Node *() const;
operator Control *() const;
@@ -276,7 +273,6 @@ public:
Variant(const RefPtr &p_resource);
Variant(const RID &p_rid);
Variant(const Object *p_object);
- Variant(const InputEvent &p_input_event);
Variant(const Dictionary &p_dictionary);
Variant(const Array &p_array);
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index df81d2111e..6568dc877e 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -737,13 +737,6 @@ struct _VariantCall {
VCALL_PTR1( Transform, translate );
VCALL_PTR0( Transform, orthonormalize ); */
- VCALL_PTR0R(InputEvent, is_pressed);
- VCALL_PTR1R(InputEvent, is_action);
- VCALL_PTR1R(InputEvent, is_action_pressed);
- VCALL_PTR1R(InputEvent, is_action_released);
- VCALL_PTR0R(InputEvent, is_echo);
- VCALL_PTR2(InputEvent, set_as_action);
-
struct ConstructData {
int arg_count;
@@ -1036,7 +1029,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
return NodePath(); // 15
case _RID: return RID();
case OBJECT: return (Object *)NULL;
- case INPUT_EVENT: return InputEvent();
case DICTIONARY: return Dictionary();
case ARRAY:
return Array(); // 20
@@ -1117,7 +1109,6 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
return (NodePath(p_args[0]->operator NodePath())); // 15
case _RID: return (RID(*p_args[0]));
case OBJECT: return ((Object *)(p_args[0]->operator Object *()));
- case INPUT_EVENT: return (InputEvent(*p_args[0]));
case DICTIONARY: return p_args[0]->operator Dictionary();
case ARRAY:
return p_args[0]->operator Array(); // 20
@@ -1690,13 +1681,6 @@ void register_variant_methods() {
_VariantCall::type_funcs[Variant::TRANSFORM].functions["xform_inv"].returns = true;
#endif
- ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_pressed, varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action, STRING, "action", varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_pressed, STRING, "action", varray());
- ADDFUNC1(INPUT_EVENT, BOOL, InputEvent, is_action_released, STRING, "action", varray());
- ADDFUNC0(INPUT_EVENT, BOOL, InputEvent, is_echo, varray());
- ADDFUNC2(INPUT_EVENT, NIL, InputEvent, set_as_action, STRING, "action", BOOL, "pressed", varray());
-
/* REGISTER CONSTRUCTORS */
_VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
@@ -1733,16 +1717,6 @@ void register_variant_methods() {
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_X", Vector3::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_Y", Vector3::AXIS_Y);
_VariantCall::add_constant(Variant::VECTOR3, "AXIS_Z", Vector3::AXIS_Z);
-
- _VariantCall::add_constant(Variant::INPUT_EVENT, "NONE", InputEvent::NONE);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "KEY", InputEvent::KEY);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_MOTION", InputEvent::MOUSE_MOTION);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "MOUSE_BUTTON", InputEvent::MOUSE_BUTTON);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYPAD_MOTION", InputEvent::JOYPAD_MOTION);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "JOYPAD_BUTTON", InputEvent::JOYPAD_BUTTON);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_TOUCH", InputEvent::SCREEN_TOUCH);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "SCREEN_DRAG", InputEvent::SCREEN_DRAG);
- _VariantCall::add_constant(Variant::INPUT_EVENT, "ACTION", InputEvent::ACTION);
}
void unregister_variant_methods() {
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 8bae6a168b..7b9b7abd9e 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -61,7 +61,6 @@ bool Variant::booleanize(bool &r_valid) const {
case _RID: return (*reinterpret_cast<const RID *>(_data._mem)).is_valid();
case OBJECT: return _get_obj().obj;
case NODE_PATH: return (*reinterpret_cast<const NodePath *>(_data._mem)) != NodePath();
- case INPUT_EVENT:
case DICTIONARY:
case ARRAY:
case POOL_BYTE_ARRAY:
@@ -291,7 +290,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == NIL)
_RETURN(!p_a._get_obj().obj);
} break;
- DEFAULT_OP_PTRREF(==, INPUT_EVENT, _input_event);
case DICTIONARY: {
@@ -378,7 +376,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == OBJECT)
_RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
} break;
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
case ARRAY: {
@@ -443,7 +440,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
if (p_b.type == OBJECT)
_RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
} break;
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -502,7 +498,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
case ARRAY: {
@@ -559,7 +554,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -656,7 +650,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -729,7 +722,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -771,7 +763,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -811,7 +802,6 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &
DEFAULT_OP_FAIL(NODE_PATH);
DEFAULT_OP_FAIL(_RID);
DEFAULT_OP_FAIL(OBJECT);
- DEFAULT_OP_FAIL(INPUT_EVENT);
DEFAULT_OP_FAIL(DICTIONARY);
DEFAULT_OP_FAIL(ARRAY);
DEFAULT_OP_FAIL(POOL_BYTE_ARRAY);
@@ -1507,389 +1497,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
return obj->set(p_index, p_value, r_valid);
}
} break;
- case INPUT_EVENT: {
-
- InputEvent &ie = *_data._input_event;
-
- if (p_index.get_type() != Variant::STRING)
- return;
-
- const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
-
- if (str == "type") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- int type = p_value;
- if (type < 0 || type >= InputEvent::TYPE_MAX)
- return; //fail
- valid = true;
- ie.type = InputEvent::Type(type);
- return;
- } else if (str == "device") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.device = p_value;
- return;
- } else if (str == "ID") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.ID = p_value;
- return;
- }
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "shift") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.shift = p_value;
- return;
- }
- if (str == "alt") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.alt = p_value;
- return;
- }
- if (str == "control") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.control = p_value;
- return;
- }
- if (str == "meta") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.mod.meta = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::KEY) {
-
- if (str == "pressed") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.pressed = p_value;
- return;
- } else if (str == "scancode") {
-
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
-
- valid = true;
- ie.key.scancode = p_value;
- return;
- } else if (str == "unicode") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.key.unicode = p_value;
- return;
- } else if (str == "echo") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.key.echo = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_mask") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.button_mask = p_value;
- return;
- } else if (str == "x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.x = p_value;
- return;
- } else if (str == "y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.y = p_value;
- return;
- } else if (str == "pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_button.x = value.x;
- ie.mouse_button.y = value.y;
- return;
- } else if (str == "global_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.global_x = p_value;
- return;
- } else if (str == "global_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.global_y = p_value;
- return;
- } else if (str == "global_pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_button.global_x = value.x;
- ie.mouse_button.global_y = value.y;
- return;
- } /*else if (str=="pointer_index") {
- valid=true;
- return ie.mouse_button.pointer_index;
- }*/
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "relative_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.relative_x = p_value;
- return;
- } else if (str == "relative_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.relative_y = p_value;
- return;
- } else if (str == "relative_pos") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_motion.relative_x = value.x;
- ie.mouse_motion.relative_y = value.y;
- return;
- }
-
- if (str == "speed_x") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.speed_x = p_value;
- return;
- } else if (str == "speed_y") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_motion.speed_y = p_value;
- return;
- } else if (str == "speed") {
- if (p_value.type != Variant::VECTOR2)
- return;
- valid = true;
- Point2 value = p_value;
- ie.mouse_motion.speed_x = value.x;
- ie.mouse_motion.speed_y = value.y;
- return;
- }
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_index") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
- return;
- valid = true;
- ie.mouse_button.button_index = p_value;
- return;
- } else if (str == "pressed") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
- valid = true;
- ie.mouse_button.pressed = p_value;
- return;
- } else if (str == "doubleclick") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
- valid = true;
- ie.mouse_button.doubleclick = p_value;
- return;
- }
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- if (str == "button_index") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_button.button_index = p_value;
- return;
- }
- if (str == "pressed") {
- if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
- return;
-
- valid = true;
- ie.joy_button.pressed = p_value;
- return;
- }
- if (str == "pressure") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_button.pressure = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- if (str == "axis") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_motion.axis = p_value;
- return;
- }
- if (str == "value") {
- if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
- return;
- valid = true;
- ie.joy_motion.axis_value = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- if (str == "index") {
- valid = true;
- ie.screen_touch.index = p_value;
- return;
- }
- if (str == "x") {
- valid = true;
- ie.screen_touch.x = p_value;
- return;
- }
- if (str == "y") {
- valid = true;
- ie.screen_touch.y = p_value;
- return;
- }
- if (str == "pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_touch.x = v.x;
- ie.screen_touch.y = v.y;
- return;
- }
- if (str == "pressed") {
- valid = true;
- ie.screen_touch.pressed = p_value;
- return;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- if (str == "index") {
- valid = true;
- ie.screen_drag.index = p_value;
- return;
- }
- if (str == "x") {
- valid = true;
- ie.screen_drag.x = p_value;
- return;
- }
- if (str == "y") {
- valid = true;
- ie.screen_drag.y = p_value;
- return;
- }
- if (str == "pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.x = v.x;
- ie.screen_drag.y = v.y;
- return;
- }
- if (str == "relative_x") {
- valid = true;
- ie.screen_drag.relative_x = p_value;
- return;
- }
- if (str == "relative_y") {
- valid = true;
- ie.screen_drag.relative_y = p_value;
- return;
- }
- if (str == "relative_pos") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.relative_x = v.x;
- ie.screen_drag.relative_y = v.y;
- return;
- }
- if (str == "speed_x") {
- valid = true;
- ie.screen_drag.speed_x = p_value;
- return;
- }
- if (str == "speed_y") {
- valid = true;
- ie.screen_drag.speed_y = p_value;
- return;
- }
- if (str == "speed") {
- valid = true;
- Vector2 v = p_value;
- ie.screen_drag.speed_x = v.x;
- ie.screen_drag.speed_y = v.y;
- return;
- }
- }
- if (ie.type == InputEvent::ACTION) {
-
- if (str == "action") {
- valid = true;
- ie.action.action = p_value;
- return;
- } else if (str == "pressed") {
- valid = true;
- ie.action.pressed = p_value;
- return;
- }
- }
-
- } break;
case DICTIONARY: {
Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
@@ -2261,235 +1868,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
}
} break;
- case INPUT_EVENT: {
-
- InputEvent ie = operator InputEvent();
-
- if (p_index.get_type() != Variant::STRING)
- break;
-
- const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
-
- if (str == "type") {
- valid = true;
- return ie.type;
- } else if (str == "device") {
- valid = true;
- return ie.device;
- } else if (str == "ID") {
- valid = true;
- return ie.ID;
- }
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "shift") {
- valid = true;
- return ie.key.mod.shift;
- }
- if (str == "alt") {
- valid = true;
- return ie.key.mod.alt;
- }
- if (str == "control") {
- valid = true;
- return ie.key.mod.control;
- }
- if (str == "meta") {
- valid = true;
- return ie.key.mod.meta;
- }
- }
-
- if (ie.type == InputEvent::KEY) {
-
- if (str == "pressed") {
- valid = true;
- return ie.key.pressed;
- } else if (str == "scancode") {
- valid = true;
- return ie.key.scancode;
- } else if (str == "unicode") {
- valid = true;
- return ie.key.unicode;
- } else if (str == "echo") {
- valid = true;
- return ie.key.echo;
- }
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_mask") {
- valid = true;
- return ie.mouse_button.button_mask;
- } else if (str == "x") {
- valid = true;
- return ie.mouse_button.x;
- } else if (str == "y") {
- valid = true;
- return ie.mouse_button.y;
- } else if (str == "pos") {
- valid = true;
- return Point2(ie.mouse_button.x, ie.mouse_button.y);
- } else if (str == "global_x") {
- valid = true;
- return ie.mouse_button.global_x;
- } else if (str == "global_y") {
- valid = true;
- return ie.mouse_button.global_y;
- } else if (str == "global_pos") {
- valid = true;
- return Point2(ie.mouse_button.global_x, ie.mouse_button.global_y);
- } /*else if (str=="pointer_index") {
- valid=true;
- return ie.mouse_button.pointer_index;
- }*/
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- if (str == "relative_x") {
- valid = true;
- return ie.mouse_motion.relative_x;
- } else if (str == "relative_y") {
- valid = true;
- return ie.mouse_motion.relative_y;
- } else if (str == "relative_pos") {
- valid = true;
- return Point2(ie.mouse_motion.relative_x, ie.mouse_motion.relative_y);
- } else if (str == "speed_x") {
- valid = true;
- return ie.mouse_motion.speed_x;
- } else if (str == "speed_y") {
- valid = true;
- return ie.mouse_motion.speed_y;
- } else if (str == "speed") {
- valid = true;
- return Point2(ie.mouse_motion.speed_x, ie.mouse_motion.speed_y);
- }
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- if (str == "button_index") {
- valid = true;
- return ie.mouse_button.button_index;
- } else if (str == "pressed") {
- valid = true;
- return ie.mouse_button.pressed;
- } else if (str == "doubleclick") {
- valid = true;
- return ie.mouse_button.doubleclick;
- }
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- if (str == "button_index") {
- valid = true;
- return ie.joy_button.button_index;
- }
- if (str == "pressed") {
- valid = true;
- return ie.joy_button.pressed;
- }
- if (str == "pressure") {
- valid = true;
- return ie.joy_button.pressure;
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- if (str == "axis") {
- valid = true;
- return ie.joy_motion.axis;
- }
- if (str == "value") {
- valid = true;
- return ie.joy_motion.axis_value;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- if (str == "index") {
- valid = true;
- return ie.screen_touch.index;
- }
- if (str == "x") {
- valid = true;
- return ie.screen_touch.x;
- }
- if (str == "y") {
- valid = true;
- return ie.screen_touch.y;
- }
- if (str == "pos") {
- valid = true;
- return Vector2(ie.screen_touch.x, ie.screen_touch.y);
- }
- if (str == "pressed") {
- valid = true;
- return ie.screen_touch.pressed;
- }
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- if (str == "index") {
- valid = true;
- return ie.screen_drag.index;
- }
- if (str == "x") {
- valid = true;
- return ie.screen_drag.x;
- }
- if (str == "y") {
- valid = true;
- return ie.screen_drag.y;
- }
- if (str == "pos") {
- valid = true;
- return Vector2(ie.screen_drag.x, ie.screen_drag.y);
- }
- if (str == "relative_x") {
- valid = true;
- return ie.screen_drag.relative_x;
- }
- if (str == "relative_y") {
- valid = true;
- return ie.screen_drag.relative_y;
- }
- if (str == "relative_pos") {
- valid = true;
- return Vector2(ie.screen_drag.relative_x, ie.screen_drag.relative_y);
- }
- if (str == "speed_x") {
- valid = true;
- return ie.screen_drag.speed_x;
- }
- if (str == "speed_y") {
- valid = true;
- return ie.screen_drag.speed_y;
- }
- if (str == "speed") {
- valid = true;
- return Vector2(ie.screen_drag.speed_x, ie.screen_drag.speed_y);
- }
- }
- if (ie.type == InputEvent::ACTION) {
-
- if (str == "action") {
- valid = true;
- return ie.action.action;
- } else if (str == "pressed") {
- valid = true;
- return ie.action.pressed;
- }
- }
-
- } break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
@@ -2823,94 +2201,6 @@ void Variant::get_property_list(List<PropertyInfo> *p_list) const {
}
} break;
- case INPUT_EVENT: {
-
- InputEvent ie = operator InputEvent();
-
- p_list->push_back(PropertyInfo(Variant::INT, "type"));
- p_list->push_back(PropertyInfo(Variant::INT, "device"));
- p_list->push_back(PropertyInfo(Variant::INT, "ID"));
-
- if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::BOOL, "shift"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "alt"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "control"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "meta"));
- }
-
- if (ie.type == InputEvent::KEY) {
-
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "echo"));
- p_list->push_back(PropertyInfo(Variant::INT, "scancode"));
- p_list->push_back(PropertyInfo(Variant::INT, "unicode"));
- }
-
- if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_mask"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "global_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "global_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "global_pos"));
-
- if (ie.type == InputEvent::MOUSE_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
-
- } else if (ie.type == InputEvent::MOUSE_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "doubleclick"));
- }
- }
-
- if (ie.type == InputEvent::JOYPAD_BUTTON) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- p_list->push_back(PropertyInfo(Variant::REAL, "pressure"));
- }
-
- if (ie.type == InputEvent::JOYPAD_MOTION) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "axis"));
- p_list->push_back(PropertyInfo(Variant::REAL, "value"));
- }
-
- if (ie.type == InputEvent::SCREEN_TOUCH) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "index"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
- }
-
- if (ie.type == InputEvent::SCREEN_DRAG) {
-
- p_list->push_back(PropertyInfo(Variant::INT, "index"));
- p_list->push_back(PropertyInfo(Variant::REAL, "x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "relative_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
- p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
- p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
- }
-
- } break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
@@ -3636,10 +2926,6 @@ void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &
r_dst = a;
}
return;
- case INPUT_EVENT: {
- r_dst = a;
- }
- return;
case DICTIONARY: {
}
return;
diff --git a/core/variant_parser.cpp b/core/variant_parser.cpp
index 798a830dd0..0d4d0429e7 100644
--- a/core/variant_parser.cpp
+++ b/core/variant_parser.cpp
@@ -30,6 +30,7 @@
#include "variant_parser.h"
#include "io/resource_loader.h"
+#include "os/input_event.h"
#include "os/keyboard.h"
CharType VariantParser::StreamFile::get_char() {
@@ -760,7 +761,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
return OK;
-
+#ifndef DISABLE_DEPRECATED
} else if (id == "InputEvent") {
get_token(p_stream, token, line, r_err_str);
@@ -778,12 +779,10 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
String id = token.value;
- InputEvent ie;
+ Ref<InputEvent> ie;
if (id == "NONE") {
- ie.type = InputEvent::NONE;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -793,21 +792,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "KEY") {
+ Ref<InputEventKey> key;
+ key.instance();
+ ie = key;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::KEY;
-
get_token(p_stream, token, line, r_err_str);
if (token.type == TK_IDENTIFIER) {
String name = token.value;
- ie.key.scancode = find_keycode(name);
+ key->set_scancode(find_keycode(name));
} else if (token.type == TK_NUMBER) {
- ie.key.scancode = token.value;
+ key->set_scancode(token.value);
} else {
r_err_str = "Expected string or integer for keycode";
@@ -828,13 +829,13 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
String mods = token.value;
if (mods.findn("C") != -1)
- ie.key.mod.control = true;
+ key->set_control(true);
if (mods.findn("A") != -1)
- ie.key.mod.alt = true;
+ key->set_alt(true);
if (mods.findn("S") != -1)
- ie.key.mod.shift = true;
+ key->set_shift(true);
if (mods.findn("M") != -1)
- ie.key.mod.meta = true;
+ key->set_metakey(true);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -850,21 +851,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "MBUTTON") {
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+ ie = mb;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::MOUSE_BUTTON;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected button index";
return ERR_PARSE_ERROR;
}
- ie.mouse_button.button_index = token.value;
+ mb->set_button_index(token.value);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -874,21 +877,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "JBUTTON") {
+ Ref<InputEventJoypadButton> jb;
+ jb.instance();
+ ie = jb;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::JOYPAD_BUTTON;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected button index";
return ERR_PARSE_ERROR;
}
- ie.joy_button.button_index = token.value;
+ jb->set_button_index(token.value);
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_PARENTHESIS_CLOSE) {
@@ -898,21 +903,23 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
} else if (id == "JAXIS") {
+ Ref<InputEventJoypadMotion> jm;
+ jm.instance();
+ ie = jm;
+
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_COMMA) {
r_err_str = "Expected ','";
return ERR_PARSE_ERROR;
}
- ie.type = InputEvent::JOYPAD_MOTION;
-
get_token(p_stream, token, line, r_err_str);
if (token.type != TK_NUMBER) {
r_err_str = "Expected axis index";
return ERR_PARSE_ERROR;
}
- ie.joy_motion.axis = token.value;
+ jm->set_axis(token.value);
get_token(p_stream, token, line, r_err_str);
@@ -927,7 +934,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
return ERR_PARSE_ERROR;
}
- ie.joy_motion.axis_value = token.value;
+ jm->set_axis_value(token.value);
get_token(p_stream, token, line, r_err_str);
@@ -945,7 +952,7 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = ie;
return OK;
-
+#endif
} else if (id == "PoolByteArray" || id == "ByteArray") {
Vector<uint8_t> args;
@@ -1121,91 +1128,6 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = arr;
return OK;
- } else if (id == "key") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 1 && params.size() != 2, ERR_PARSE_ERROR);
-
- int scode = 0;
-
- if (params[0].is_numeric()) {
- scode = params[0].to_int();
- if (scode < 10) {
- scode = KEY_0 + scode;
- }
- } else
- scode = find_keycode(params[0]);
-
- InputEvent ie;
- ie.type = InputEvent::KEY;
- ie.key.scancode = scode;
-
- if (params.size() == 2) {
- String mods = params[1];
- if (mods.findn("C") != -1)
- ie.key.mod.control = true;
- if (mods.findn("A") != -1)
- ie.key.mod.alt = true;
- if (mods.findn("S") != -1)
- ie.key.mod.shift = true;
- if (mods.findn("M") != -1)
- ie.key.mod.meta = true;
- }
- value = ie;
- return OK;
-
- } else if (id == "mbutton") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
-
- InputEvent ie;
- ie.type = InputEvent::MOUSE_BUTTON;
- ie.device = params[0].to_int();
- ie.mouse_button.button_index = params[1].to_int();
-
- value = ie;
- return OK;
- } else if (id == "jbutton") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
- InputEvent ie;
- ie.type = InputEvent::JOYPAD_BUTTON;
- ie.device = params[0].to_int();
- ie.joy_button.button_index = params[1].to_int();
-
- value = ie;
-
- return OK;
- } else if (id == "jaxis") { // compatibility with project.godot
-
- Vector<String> params;
- Error err = _parse_enginecfg(p_stream, params, line, r_err_str);
- if (err)
- return err;
- ERR_FAIL_COND_V(params.size() != 2, ERR_PARSE_ERROR);
-
- InputEvent ie;
- ie.type = InputEvent::JOYPAD_MOTION;
- ie.device = params[0].to_int();
- int axis = params[1].to_int();
- ie.joy_motion.axis = axis >> 1;
- ie.joy_motion.axis_value = axis & 1 ? 1 : -1;
-
- value = ie;
-
- return OK;
-
} else {
r_err_str = "Unexpected identifier: '" + id + "'.";
return ERR_PARSE_ERROR;
@@ -1715,50 +1637,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, res_text);
} break;
- case Variant::INPUT_EVENT: {
-
- String str = "InputEvent(";
-
- InputEvent ev = p_variant;
- switch (ev.type) {
- case InputEvent::KEY: {
-
- str += "KEY," + itos(ev.key.scancode);
- String mod;
- if (ev.key.mod.alt)
- mod += "A";
- if (ev.key.mod.shift)
- mod += "S";
- if (ev.key.mod.control)
- mod += "C";
- if (ev.key.mod.meta)
- mod += "M";
-
- if (mod != String())
- str += "," + mod;
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- str += "MBUTTON," + itos(ev.mouse_button.button_index);
- } break;
- case InputEvent::JOYPAD_BUTTON: {
- str += "JBUTTON," + itos(ev.joy_button.button_index);
-
- } break;
- case InputEvent::JOYPAD_MOTION: {
- str += "JAXIS," + itos(ev.joy_motion.axis) + "," + itos(ev.joy_motion.axis_value);
- } break;
- case InputEvent::NONE: {
- str += "NONE";
- } break;
- default: {}
- }
- str += ")";
-
- p_store_string_func(p_store_string_ud, str); //will be added later
-
- } break;
case Variant::DICTIONARY: {
Dictionary dict = p_variant;
diff --git a/doc/base/classes.xml b/doc/base/classes.xml
index af0a494a84..a04890d4fd 100644
--- a/doc/base/classes.xml
+++ b/doc/base/classes.xml
@@ -20360,7 +20360,7 @@
Singleton that manages actions.
</brief_description>
<description>
- Singleton that manages actions. InputMap has a list of the actions used in InputEvent, which can be modified.
+ Singleton that manages actions. InputMap has a list of the actions used in Ref<InputEvent>, which can be modified.
</description>
<methods>
<method name="action_add_event">
diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp
index e4ae1993ab..7c29162e67 100644
--- a/editor/animation_editor.cpp
+++ b/editor/animation_editor.cpp
@@ -154,13 +154,15 @@ private:
}
}
- void _gui_input(const InputEvent &p_ev) {
- if (p_ev.type == InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ void _gui_input(const Ref<InputEvent> &p_ev) {
+
+ Ref<InputEventMouseMotion> mm = p_ev;
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
if (mode == MODE_DISABLED)
return;
- float rel = p_ev.mouse_motion.relative_x;
+ float rel = mm->get_relative().x;
if (rel == 0)
return;
@@ -1746,7 +1748,7 @@ void AnimationKeyEditor::_anim_delete_keys() {
}
}
-void AnimationKeyEditor::_track_editor_gui_input(const InputEvent &p_input) {
+void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) {
Control *te = track_editor;
Ref<StyleBox> style = get_stylebox("normal", "TextEdit");
@@ -1804,1087 +1806,1083 @@ void AnimationKeyEditor::_track_editor_gui_input(const InputEvent &p_input) {
int settings_limit = size.width - right_separator_ofs;
int name_limit = settings_limit * name_column_ratio;
- switch (p_input.type) {
+ Ref<InputEventKey> key = p_input;
+ if (key.is_valid()) {
- case InputEvent::KEY: {
+ if (key->get_scancode() == KEY_D && key->is_pressed() && key->get_command()) {
- if (p_input.key.scancode == KEY_D && p_input.key.pressed && p_input.key.mod.command) {
+ if (key->get_shift())
+ _menu_track(TRACK_MENU_DUPLICATE_TRANSPOSE);
+ else
+ _menu_track(TRACK_MENU_DUPLICATE);
- if (p_input.key.mod.shift)
- _menu_track(TRACK_MENU_DUPLICATE_TRANSPOSE);
- else
- _menu_track(TRACK_MENU_DUPLICATE);
+ accept_event();
- accept_event();
+ } else if (key->get_scancode() == KEY_DELETE && key->is_pressed() && click.click == ClickOver::CLICK_NONE) {
- } else if (p_input.key.scancode == KEY_DELETE && p_input.key.pressed && click.click == ClickOver::CLICK_NONE) {
+ _anim_delete_keys();
+ } else if (animation.is_valid() && animation->get_track_count() > 0) {
- _anim_delete_keys();
- } else if (animation.is_valid() && animation->get_track_count() > 0) {
-
- if (p_input.is_pressed() && (p_input.is_action("ui_up") || p_input.is_action("ui_page_up"))) {
+ if (key->is_pressed() && (key->is_action("ui_up") || key->is_action("ui_page_up"))) {
- if (p_input.is_action("ui_up"))
- selected_track--;
- if (v_scroll->is_visible_in_tree() && p_input.is_action("ui_page_up"))
- selected_track--;
+ if (key->is_action("ui_up"))
+ selected_track--;
+ if (v_scroll->is_visible_in_tree() && key->is_action("ui_page_up"))
+ selected_track--;
- if (selected_track < 0)
- selected_track = 0;
+ if (selected_track < 0)
+ selected_track = 0;
- if (v_scroll->is_visible_in_tree()) {
- if (v_scroll->get_value() > selected_track)
- v_scroll->set_value(selected_track);
- }
-
- track_editor->update();
- accept_event();
+ if (v_scroll->is_visible_in_tree()) {
+ if (v_scroll->get_value() > selected_track)
+ v_scroll->set_value(selected_track);
}
- if (p_input.is_pressed() && (p_input.is_action("ui_down") || p_input.is_action("ui_page_down"))) {
+ track_editor->update();
+ accept_event();
+ }
- if (p_input.is_action("ui_down"))
- selected_track++;
- else if (v_scroll->is_visible_in_tree() && p_input.is_action("ui_page_down"))
- selected_track += v_scroll->get_page();
+ if (key->is_pressed() && (key->is_action("ui_down") || key->is_action("ui_page_down"))) {
- if (selected_track >= animation->get_track_count())
- selected_track = animation->get_track_count() - 1;
+ if (key->is_action("ui_down"))
+ selected_track++;
+ else if (v_scroll->is_visible_in_tree() && key->is_action("ui_page_down"))
+ selected_track += v_scroll->get_page();
- if (v_scroll->is_visible_in_tree() && v_scroll->get_page() + v_scroll->get_value() < selected_track + 1) {
- v_scroll->set_value(selected_track - v_scroll->get_page() + 1);
- }
+ if (selected_track >= animation->get_track_count())
+ selected_track = animation->get_track_count() - 1;
- track_editor->update();
- accept_event();
+ if (v_scroll->is_visible_in_tree() && v_scroll->get_page() + v_scroll->get_value() < selected_track + 1) {
+ v_scroll->set_value(selected_track - v_scroll->get_page() + 1);
}
+
+ track_editor->update();
+ accept_event();
}
+ }
+ }
- } break;
- case InputEvent::MOUSE_BUTTON: {
+ Ref<InputEventMouseButton> mb = p_input;
- const InputEventMouseButton &mb = p_input.mouse_button;
+ if (mb.is_valid()) {
- if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
- if (mb.mod.command) {
+ if (mb->get_command()) {
- zoom->set_value(zoom->get_value() + zoom->get_step());
- } else {
+ zoom->set_value(zoom->get_value() + zoom->get_step());
+ } else {
- v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb.factor / 8);
- }
+ v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb->get_factor() / 8);
}
+ }
- if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
- if (mb.mod.command) {
+ if (mb->get_command()) {
- zoom->set_value(zoom->get_value() - zoom->get_step());
- } else {
+ zoom->set_value(zoom->get_value() - zoom->get_step());
+ } else {
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb.factor / 8);
- }
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
}
+ }
- if (mb.button_index == BUTTON_WHEEL_RIGHT && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_WHEEL_RIGHT && mb->is_pressed()) {
- h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * mb.factor / 8);
- }
+ h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * mb->get_factor() / 8);
+ }
- if (mb.button_index == BUTTON_WHEEL_LEFT && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_WHEEL_LEFT && mb->is_pressed()) {
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb.factor / 8);
- }
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
+ }
- if (mb.button_index == BUTTON_RIGHT && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
- Point2 mpos = Point2(mb.x, mb.y) - ofs;
+ Point2 mpos = mb->get_pos() - ofs;
- if (selection.size() == 0) {
- // Auto-select on right-click if nothing is selected
- // Note: This code is pretty much duplicated from the left click code,
- // both codes could be moved into a function to avoid the duplicated code.
- Point2 mpos = Point2(mb.x, mb.y) - ofs;
+ if (selection.size() == 0) {
+ // Auto-select on right-click if nothing is selected
+ // Note: This code is pretty much duplicated from the left click code,
+ // both codes could be moved into a function to avoid the duplicated code.
+ Point2 mpos = mb->get_pos() - ofs;
- if (mpos.y < h) {
- return;
- }
+ if (mpos.y < h) {
+ return;
+ }
- mpos.y -= h;
+ mpos.y -= h;
- int idx = mpos.y / h;
- idx += v_scroll->get_value();
- if (idx < 0 || idx >= animation->get_track_count())
- break;
+ int idx = mpos.y / h;
+ idx += v_scroll->get_value();
+ if (idx < 0 || idx >= animation->get_track_count())
+ return;
- if (mpos.x < name_limit) {
- } else if (mpos.x < settings_limit) {
- float pos = mpos.x - name_limit;
- pos /= _get_zoom_scale();
- pos += h_scroll->get_value();
- float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
+ if (mpos.x < name_limit) {
+ } else if (mpos.x < settings_limit) {
+ float pos = mpos.x - name_limit;
+ pos /= _get_zoom_scale();
+ pos += h_scroll->get_value();
+ float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
- int kidx = animation->track_find_key(idx, pos);
- int kidx_n = kidx + 1;
- int key = -1;
+ int kidx = animation->track_find_key(idx, pos);
+ int kidx_n = kidx + 1;
+ int key = -1;
- if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
+ if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
- float kpos = animation->track_get_key_time(idx, kidx);
- if (ABS(pos - kpos) <= w_time) {
+ float kpos = animation->track_get_key_time(idx, kidx);
+ if (ABS(pos - kpos) <= w_time) {
- key = kidx;
- }
+ key = kidx;
}
+ }
- if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
+ if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
- float kpos = animation->track_get_key_time(idx, kidx_n);
- if (ABS(pos - kpos) <= w_time) {
+ float kpos = animation->track_get_key_time(idx, kidx_n);
+ if (ABS(pos - kpos) <= w_time) {
- key = kidx_n;
- }
+ key = kidx_n;
}
+ }
- if (key == -1) {
+ if (key == -1) {
- click.click = ClickOver::CLICK_SELECT_KEYS;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- click.shift = mb.mod.shift;
- selected_track = idx;
- track_editor->update();
- //drag select region
- return;
- }
+ click.click = ClickOver::CLICK_SELECT_KEYS;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ click.shift = mb->get_shift();
+ selected_track = idx;
+ track_editor->update();
+ //drag select region
+ return;
+ }
- SelectedKey sk;
- sk.track = idx;
- sk.key = key;
- KeyInfo ki;
- ki.pos = animation->track_get_key_time(idx, key);
- click.shift = mb.mod.shift;
- click.selk = sk;
+ SelectedKey sk;
+ sk.track = idx;
+ sk.key = key;
+ KeyInfo ki;
+ ki.pos = animation->track_get_key_time(idx, key);
+ click.shift = mb->get_shift();
+ click.selk = sk;
- if (!mb.mod.shift && !selection.has(sk))
- _clear_selection();
+ if (!mb->get_shift() && !selection.has(sk))
+ _clear_selection();
- selection.insert(sk, ki);
+ selection.insert(sk, ki);
- click.click = ClickOver::CLICK_MOVE_KEYS;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- update();
- selected_track = idx;
- track_editor->update();
+ click.click = ClickOver::CLICK_MOVE_KEYS;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ update();
+ selected_track = idx;
+ track_editor->update();
- if (_edit_if_single_selection() && mb.mod.command) {
- edit_button->set_pressed(true);
- key_editor_tab->show();
- }
+ if (_edit_if_single_selection() && mb->get_command()) {
+ edit_button->set_pressed(true);
+ key_editor_tab->show();
}
}
+ }
- if (selection.size()) {
- // User has right clicked and we have a selection, show a popup menu with options
- track_menu->clear();
- track_menu->set_size(Point2(1, 1));
- track_menu->add_item(TTR("Duplicate Selection"), RIGHT_MENU_DUPLICATE);
- track_menu->add_item(TTR("Duplicate Transposed"), RIGHT_MENU_DUPLICATE_TRANSPOSE);
- track_menu->add_item(TTR("Remove Selection"), RIGHT_MENU_REMOVE);
+ if (selection.size()) {
+ // User has right clicked and we have a selection, show a popup menu with options
+ track_menu->clear();
+ track_menu->set_size(Point2(1, 1));
+ track_menu->add_item(TTR("Duplicate Selection"), RIGHT_MENU_DUPLICATE);
+ track_menu->add_item(TTR("Duplicate Transposed"), RIGHT_MENU_DUPLICATE_TRANSPOSE);
+ track_menu->add_item(TTR("Remove Selection"), RIGHT_MENU_REMOVE);
- track_menu->set_position(te->get_global_position() + mpos);
+ track_menu->set_position(te->get_global_position() + mpos);
- interp_editing = -1;
- cont_editing = -1;
- wrap_editing = -1;
+ interp_editing = -1;
+ cont_editing = -1;
+ wrap_editing = -1;
- track_menu->popup();
- }
+ track_menu->popup();
}
+ }
- if (mb.button_index == BUTTON_LEFT && !(mb.button_mask & ~BUTTON_MASK_LEFT)) {
+ if (mb->get_button_index() == BUTTON_LEFT && !(mb->get_button_mask() & ~BUTTON_MASK_LEFT)) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
- Point2 mpos = Point2(mb.x, mb.y) - ofs;
+ Point2 mpos = mb->get_pos() - ofs;
- if (mpos.y < h) {
+ if (mpos.y < h) {
- if (mpos.x < name_limit && mpos.x > (name_limit - hsep - hsize_icon->get_width())) {
+ if (mpos.x < name_limit && mpos.x > (name_limit - hsep - hsize_icon->get_width())) {
- click.click = ClickOver::CLICK_RESIZE_NAMES;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- click.at.y = name_limit;
- }
+ click.click = ClickOver::CLICK_RESIZE_NAMES;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ click.at.y = name_limit;
+ }
- if (mpos.x >= name_limit && mpos.x < settings_limit) {
- //seek
- //int zoomw = settings_limit-name_limit;
- float scale = _get_zoom_scale();
- float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
- if (animation->get_step())
- pos = Math::stepify(pos, animation->get_step());
-
- if (pos < 0)
- pos = 0;
- if (pos >= animation->get_length())
- pos = animation->get_length();
- timeline_pos = pos;
- click.click = ClickOver::CLICK_DRAG_TIMELINE;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- emit_signal("timeline_changed", pos, false);
- }
+ if (mpos.x >= name_limit && mpos.x < settings_limit) {
+ //seek
+ //int zoomw = settings_limit-name_limit;
+ float scale = _get_zoom_scale();
+ float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
+ if (animation->get_step())
+ pos = Math::stepify(pos, animation->get_step());
- return;
+ if (pos < 0)
+ pos = 0;
+ if (pos >= animation->get_length())
+ pos = animation->get_length();
+ timeline_pos = pos;
+ click.click = ClickOver::CLICK_DRAG_TIMELINE;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ emit_signal("timeline_changed", pos, false);
}
- mpos.y -= h;
+ return;
+ }
- int idx = mpos.y / h;
- idx += v_scroll->get_value();
- if (idx < 0)
- break;
+ mpos.y -= h;
- if (idx >= animation->get_track_count()) {
+ int idx = mpos.y / h;
+ idx += v_scroll->get_value();
+ if (idx < 0)
+ return;
- if (mpos.x >= name_limit && mpos.x < settings_limit) {
+ if (idx >= animation->get_track_count()) {
- click.click = ClickOver::CLICK_SELECT_KEYS;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- //drag select region
- }
+ if (mpos.x >= name_limit && mpos.x < settings_limit) {
- break;
+ click.click = ClickOver::CLICK_SELECT_KEYS;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ //drag select region
}
- if (mpos.x < name_limit) {
- //name column
-
- // area
- if (idx != selected_track) {
-
- selected_track = idx;
- track_editor->update();
- break;
- }
+ return;
+ }
- Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h);
- track_name->set_text(animation->track_get_path(idx));
- track_name->set_position(te->get_global_position() + area.pos);
- track_name->set_size(area.size);
- track_name->show_modal();
- track_name->grab_focus();
- track_name->select_all();
- track_name_editing = idx;
+ if (mpos.x < name_limit) {
+ //name column
- } else if (mpos.x < settings_limit) {
+ // area
+ if (idx != selected_track) {
- float pos = mpos.x - name_limit;
- pos /= _get_zoom_scale();
- pos += h_scroll->get_value();
- float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
+ selected_track = idx;
+ track_editor->update();
+ return;
+ }
- int kidx = animation->track_find_key(idx, pos);
- int kidx_n = kidx + 1;
- int key = -1;
+ Rect2 area(ofs.x, ofs.y + ((int(mpos.y) / h) + 1) * h, name_limit, h);
+ track_name->set_text(animation->track_get_path(idx));
+ track_name->set_position(te->get_global_position() + area.pos);
+ track_name->set_size(area.size);
+ track_name->show_modal();
+ track_name->grab_focus();
+ track_name->select_all();
+ track_name_editing = idx;
- if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
+ } else if (mpos.x < settings_limit) {
- float kpos = animation->track_get_key_time(idx, kidx);
- if (ABS(pos - kpos) <= w_time) {
+ float pos = mpos.x - name_limit;
+ pos /= _get_zoom_scale();
+ pos += h_scroll->get_value();
+ float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
- key = kidx;
- }
- }
+ int kidx = animation->track_find_key(idx, pos);
+ int kidx_n = kidx + 1;
+ int key = -1;
- if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
+ if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
- float kpos = animation->track_get_key_time(idx, kidx_n);
- if (ABS(pos - kpos) <= w_time) {
+ float kpos = animation->track_get_key_time(idx, kidx);
+ if (ABS(pos - kpos) <= w_time) {
- key = kidx_n;
- }
+ key = kidx;
}
+ }
- if (key == -1) {
+ if (key == -1 && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
- click.click = ClickOver::CLICK_SELECT_KEYS;
- click.at = Point2(mb.x, mb.y);
- click.to = click.at;
- click.shift = mb.mod.shift;
- selected_track = idx;
- track_editor->update();
- //drag select region
- return;
- }
-
- SelectedKey sk;
- sk.track = idx;
- sk.key = key;
- KeyInfo ki;
- ki.pos = animation->track_get_key_time(idx, key);
- click.shift = mb.mod.shift;
- click.selk = sk;
+ float kpos = animation->track_get_key_time(idx, kidx_n);
+ if (ABS(pos - kpos) <= w_time) {
- if (!mb.mod.shift && !selection.has(sk))
- _clear_selection();
+ key = kidx_n;
+ }
+ }
- selection.insert(sk, ki);
+ if (key == -1) {
- click.click = ClickOver::CLICK_MOVE_KEYS;
- click.at = Point2(mb.x, mb.y);
+ click.click = ClickOver::CLICK_SELECT_KEYS;
+ click.at = mb->get_pos();
click.to = click.at;
- update();
+ click.shift = mb->get_shift();
selected_track = idx;
track_editor->update();
+ //drag select region
+ return;
+ }
- if (_edit_if_single_selection() && mb.mod.command) {
- edit_button->set_pressed(true);
- key_editor_tab->show();
- }
- } else {
- //button column
- int ofsx = size.width - mpos.x;
- if (ofsx < 0)
- break;
- /*
- if (ofsx < remove_icon->get_width()) {
-
- undo_redo->create_action("Remove Anim Track");
- undo_redo->add_do_method(animation.ptr(),"remove_track",idx);
- undo_redo->add_undo_method(animation.ptr(),"add_track",animation->track_get_type(idx),idx);
- undo_redo->add_undo_method(animation.ptr(),"track_set_path",idx,animation->track_get_path(idx));
- //todo interpolation
- for(int i=0;i<animation->track_get_key_count(idx);i++) {
+ SelectedKey sk;
+ sk.track = idx;
+ sk.key = key;
+ KeyInfo ki;
+ ki.pos = animation->track_get_key_time(idx, key);
+ click.shift = mb->get_shift();
+ click.selk = sk;
- Variant v = animation->track_get_key_value(idx,i);
- float time = animation->track_get_key_time(idx,i);
- float trans = animation->track_get_key_transition(idx,i);
+ if (!mb->get_shift() && !selection.has(sk))
+ _clear_selection();
- undo_redo->add_undo_method(animation.ptr(),"track_insert_key",idx,time,v);
- undo_redo->add_undo_method(animation.ptr(),"track_set_key_transition",idx,i,trans);
+ selection.insert(sk, ki);
- }
+ click.click = ClickOver::CLICK_MOVE_KEYS;
+ click.at = mb->get_pos();
+ click.to = click.at;
+ update();
+ selected_track = idx;
+ track_editor->update();
- undo_redo->add_undo_method(animation.ptr(),"track_set_interpolation_type",idx,animation->track_get_interpolation_type(idx));
- if (animation->track_get_type(idx)==Animation::TYPE_VALUE) {
- undo_redo->add_undo_method(animation.ptr(),"value_track_set_continuous",idx,animation->value_track_is_continuous(idx));
+ if (_edit_if_single_selection() && mb->get_command()) {
+ edit_button->set_pressed(true);
+ key_editor_tab->show();
+ }
+ } else {
+ //button column
+ int ofsx = size.width - mpos.x;
+ if (ofsx < 0)
+ return;
+ /*
+ if (ofsx < remove_icon->get_width()) {
- }
+ undo_redo->create_action("Remove Anim Track");
+ undo_redo->add_do_method(animation.ptr(),"remove_track",idx);
+ undo_redo->add_undo_method(animation.ptr(),"add_track",animation->track_get_type(idx),idx);
+ undo_redo->add_undo_method(animation.ptr(),"track_set_path",idx,animation->track_get_path(idx));
+ //todo interpolation
+ for(int i=0;i<animation->track_get_key_count(idx);i++) {
- undo_redo->commit_action();
+ Variant v = animation->track_get_key_value(idx,i);
+ float time = animation->track_get_key_time(idx,i);
+ float trans = animation->track_get_key_transition(idx,i);
+ undo_redo->add_undo_method(animation.ptr(),"track_insert_key",idx,time,v);
+ undo_redo->add_undo_method(animation.ptr(),"track_set_key_transition",idx,i,trans);
- return;
}
- ofsx-=hsep+remove_icon->get_width();
-
- if (ofsx < move_down_icon->get_width()) {
+ undo_redo->add_undo_method(animation.ptr(),"track_set_interpolation_type",idx,animation->track_get_interpolation_type(idx));
+ if (animation->track_get_type(idx)==Animation::TYPE_VALUE) {
+ undo_redo->add_undo_method(animation.ptr(),"value_track_set_continuous",idx,animation->value_track_is_continuous(idx));
- if (idx < animation->get_track_count() -1) {
- undo_redo->create_action("Move Anim Track Down");
- undo_redo->add_do_method(animation.ptr(),"track_move_up",idx);
- undo_redo->add_undo_method(animation.ptr(),"track_move_down",idx+1);
- undo_redo->commit_action();
- }
- return;
}
- ofsx-=hsep+move_down_icon->get_width();
+ undo_redo->commit_action();
- if (ofsx < move_up_icon->get_width()) {
- if (idx >0) {
- undo_redo->create_action("Move Anim Track Up");
- undo_redo->add_do_method(animation.ptr(),"track_move_down",idx);
- undo_redo->add_undo_method(animation.ptr(),"track_move_up",idx-1);
- undo_redo->commit_action();
- }
- return;
- }
+ return;
+ }
+ ofsx-=hsep+remove_icon->get_width();
- ofsx-=hsep*3+move_up_icon->get_width();
- */
+ if (ofsx < move_down_icon->get_width()) {
- if (ofsx < track_ofs[1]) {
+ if (idx < animation->get_track_count() -1) {
+ undo_redo->create_action("Move Anim Track Down");
+ undo_redo->add_do_method(animation.ptr(),"track_move_up",idx);
+ undo_redo->add_undo_method(animation.ptr(),"track_move_down",idx+1);
+ undo_redo->commit_action();
+ }
+ return;
+ }
- track_menu->clear();
- track_menu->set_size(Point2(1, 1));
- static const char *interp_name[2] = { "Clamp Loop Interp", "Wrap Loop Interp" };
- for (int i = 0; i < 2; i++) {
- track_menu->add_icon_item(wrap_icon[i], interp_name[i]);
- }
+ ofsx-=hsep+move_down_icon->get_width();
- int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
- int popup_x = size.width - track_ofs[1];
+ if (ofsx < move_up_icon->get_width()) {
- track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
+ if (idx >0) {
+ undo_redo->create_action("Move Anim Track Up");
+ undo_redo->add_do_method(animation.ptr(),"track_move_down",idx);
+ undo_redo->add_undo_method(animation.ptr(),"track_move_up",idx-1);
+ undo_redo->commit_action();
+ }
+ return;
+ }
- wrap_editing = idx;
- interp_editing = -1;
- cont_editing = -1;
- track_menu->popup();
+ ofsx-=hsep*3+move_up_icon->get_width();
+ */
- return;
+ if (ofsx < track_ofs[1]) {
+
+ track_menu->clear();
+ track_menu->set_size(Point2(1, 1));
+ static const char *interp_name[2] = { "Clamp Loop Interp", "Wrap Loop Interp" };
+ for (int i = 0; i < 2; i++) {
+ track_menu->add_icon_item(wrap_icon[i], interp_name[i]);
}
- if (ofsx < track_ofs[2]) {
+ int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
+ int popup_x = size.width - track_ofs[1];
- track_menu->clear();
- track_menu->set_size(Point2(1, 1));
- static const char *interp_name[3] = { "Nearest", "Linear", "Cubic" };
- for (int i = 0; i < 3; i++) {
- track_menu->add_icon_item(interp_icon[i], interp_name[i]);
- }
+ track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
- int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
- int popup_x = size.width - track_ofs[2];
+ wrap_editing = idx;
+ interp_editing = -1;
+ cont_editing = -1;
- track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
+ track_menu->popup();
- interp_editing = idx;
- cont_editing = -1;
- wrap_editing = -1;
+ return;
+ }
- track_menu->popup();
+ if (ofsx < track_ofs[2]) {
- return;
+ track_menu->clear();
+ track_menu->set_size(Point2(1, 1));
+ static const char *interp_name[3] = { "Nearest", "Linear", "Cubic" };
+ for (int i = 0; i < 3; i++) {
+ track_menu->add_icon_item(interp_icon[i], interp_name[i]);
}
- if (ofsx < track_ofs[3]) {
+ int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
+ int popup_x = size.width - track_ofs[2];
- track_menu->clear();
- track_menu->set_size(Point2(1, 1));
- String cont_name[3] = { TTR("Continuous"), TTR("Discrete"), TTR("Trigger") };
- for (int i = 0; i < 3; i++) {
- track_menu->add_icon_item(cont_icon[i], cont_name[i]);
- }
+ track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
- int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
- int popup_x = size.width - track_ofs[3];
+ interp_editing = idx;
+ cont_editing = -1;
+ wrap_editing = -1;
- track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
+ track_menu->popup();
- interp_editing = -1;
- wrap_editing = -1;
- cont_editing = idx;
+ return;
+ }
- track_menu->popup();
+ if (ofsx < track_ofs[3]) {
- return;
+ track_menu->clear();
+ track_menu->set_size(Point2(1, 1));
+ String cont_name[3] = { TTR("Continuous"), TTR("Discrete"), TTR("Trigger") };
+ for (int i = 0; i < 3; i++) {
+ track_menu->add_icon_item(cont_icon[i], cont_name[i]);
}
- if (ofsx < track_ofs[4]) {
+ int popup_y = ofs.y + ((int(mpos.y) / h) + 2) * h;
+ int popup_x = size.width - track_ofs[3];
- Animation::TrackType tt = animation->track_get_type(idx);
+ track_menu->set_position(te->get_global_position() + Point2(popup_x, popup_y));
- float pos = timeline_pos;
- int existing = animation->track_find_key(idx, pos, true);
+ interp_editing = -1;
+ wrap_editing = -1;
+ cont_editing = idx;
- Variant newval;
+ track_menu->popup();
- if (tt == Animation::TYPE_TRANSFORM) {
- Dictionary d;
- d["loc"] = Vector3();
- d["rot"] = Quat();
- d["scale"] = Vector3();
- newval = d;
+ return;
+ }
- } else if (tt == Animation::TYPE_METHOD) {
+ if (ofsx < track_ofs[4]) {
- Dictionary d;
- d["method"] = "";
- d["args"] = Vector<Variant>();
+ Animation::TrackType tt = animation->track_get_type(idx);
- newval = d;
- } else if (tt == Animation::TYPE_VALUE) {
+ float pos = timeline_pos;
+ int existing = animation->track_find_key(idx, pos, true);
- NodePath np;
- PropertyInfo inf = _find_hint_for_track(idx, np);
- if (inf.type != Variant::NIL) {
+ Variant newval;
- Variant::CallError err;
- newval = Variant::construct(inf.type, NULL, 0, err);
- }
+ if (tt == Animation::TYPE_TRANSFORM) {
+ Dictionary d;
+ d["loc"] = Vector3();
+ d["rot"] = Quat();
+ d["scale"] = Vector3();
+ newval = d;
- if (newval.get_type() == Variant::NIL) {
- //popup a new type
- cvi_track = idx;
- cvi_pos = pos;
+ } else if (tt == Animation::TYPE_METHOD) {
- type_menu->set_position(get_global_position() + mpos + ofs);
- type_menu->popup();
- return;
- }
- }
+ Dictionary d;
+ d["method"] = "";
+ d["args"] = Vector<Variant>();
- undo_redo->create_action(TTR("Anim Add Key"));
+ newval = d;
+ } else if (tt == Animation::TYPE_VALUE) {
- undo_redo->add_do_method(animation.ptr(), "track_insert_key", idx, pos, newval, 1);
- undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_pos", idx, pos);
+ NodePath np;
+ PropertyInfo inf = _find_hint_for_track(idx, np);
+ if (inf.type != Variant::NIL) {
- if (existing != -1) {
- Variant v = animation->track_get_key_value(idx, existing);
- float trans = animation->track_get_key_transition(idx, existing);
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", idx, pos, v, trans);
+ Variant::CallError err;
+ newval = Variant::construct(inf.type, NULL, 0, err);
}
- undo_redo->commit_action();
+ if (newval.get_type() == Variant::NIL) {
+ //popup a new type
+ cvi_track = idx;
+ cvi_pos = pos;
- return;
+ type_menu->set_position(get_global_position() + mpos + ofs);
+ type_menu->popup();
+ return;
+ }
}
- }
- } else {
+ undo_redo->create_action(TTR("Anim Add Key"));
- switch (click.click) {
- case ClickOver::CLICK_SELECT_KEYS: {
+ undo_redo->add_do_method(animation.ptr(), "track_insert_key", idx, pos, newval, 1);
+ undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_pos", idx, pos);
- float zoom_scale = _get_zoom_scale();
- float keys_from = h_scroll->get_value();
- float keys_to = keys_from + (settings_limit - name_limit) / zoom_scale;
+ if (existing != -1) {
+ Variant v = animation->track_get_key_value(idx, existing);
+ float trans = animation->track_get_key_transition(idx, existing);
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", idx, pos, v, trans);
+ }
- float from_time = keys_from + (click.at.x - (name_limit + ofs.x)) / zoom_scale;
- float to_time = keys_from + (click.to.x - (name_limit + ofs.x)) / zoom_scale;
+ undo_redo->commit_action();
- if (to_time < from_time)
- SWAP(from_time, to_time);
+ return;
+ }
+ }
- if (from_time > keys_to || to_time < keys_from)
- break;
+ } else {
- if (from_time < keys_from)
- from_time = keys_from;
+ switch (click.click) {
+ case ClickOver::CLICK_SELECT_KEYS: {
- if (to_time >= keys_to)
- to_time = keys_to;
+ float zoom_scale = _get_zoom_scale();
+ float keys_from = h_scroll->get_value();
+ float keys_to = keys_from + (settings_limit - name_limit) / zoom_scale;
- int from_track = int(click.at.y - ofs.y - h - sep) / h + v_scroll->get_value();
- int to_track = int(click.to.y - ofs.y - h - sep) / h + v_scroll->get_value();
- int from_mod = int(click.at.y - ofs.y - sep) % h;
- int to_mod = int(click.to.y - ofs.y - sep) % h;
+ float from_time = keys_from + (click.at.x - (name_limit + ofs.x)) / zoom_scale;
+ float to_time = keys_from + (click.to.x - (name_limit + ofs.x)) / zoom_scale;
- if (to_track < from_track) {
+ if (to_time < from_time)
+ SWAP(from_time, to_time);
- SWAP(from_track, to_track);
- SWAP(from_mod, to_mod);
- }
+ if (from_time > keys_to || to_time < keys_from)
+ break;
- if ((from_mod > (h / 2)) && ((click.at.y - ofs.y) >= (h + sep))) {
- from_track++;
- }
+ if (from_time < keys_from)
+ from_time = keys_from;
- if (to_mod < h / 2) {
- to_track--;
- }
+ if (to_time >= keys_to)
+ to_time = keys_to;
- if (from_track > to_track) {
- if (!click.shift)
- _clear_selection();
- _edit_if_single_selection();
- break;
- }
+ int from_track = int(click.at.y - ofs.y - h - sep) / h + v_scroll->get_value();
+ int to_track = int(click.to.y - ofs.y - h - sep) / h + v_scroll->get_value();
+ int from_mod = int(click.at.y - ofs.y - sep) % h;
+ int to_mod = int(click.to.y - ofs.y - sep) % h;
+
+ if (to_track < from_track) {
- int tracks_from = v_scroll->get_value();
- int tracks_to = v_scroll->get_value() + fit - 1;
- if (tracks_to >= animation->get_track_count())
- tracks_to = animation->get_track_count() - 1;
+ SWAP(from_track, to_track);
+ SWAP(from_mod, to_mod);
+ }
+
+ if ((from_mod > (h / 2)) && ((click.at.y - ofs.y) >= (h + sep))) {
+ from_track++;
+ }
- tracks_from = 0;
+ if (to_mod < h / 2) {
+ to_track--;
+ }
+
+ if (from_track > to_track) {
+ if (!click.shift)
+ _clear_selection();
+ _edit_if_single_selection();
+ break;
+ }
+
+ int tracks_from = v_scroll->get_value();
+ int tracks_to = v_scroll->get_value() + fit - 1;
+ if (tracks_to >= animation->get_track_count())
tracks_to = animation->get_track_count() - 1;
- if (to_track > tracks_to)
- to_track = tracks_to;
- if (from_track < tracks_from)
- from_track = tracks_from;
-
- if (from_track > tracks_to || to_track < tracks_from) {
- if (!click.shift)
- _clear_selection();
- _edit_if_single_selection();
- break;
- }
+ tracks_from = 0;
+ tracks_to = animation->get_track_count() - 1;
+ if (to_track > tracks_to)
+ to_track = tracks_to;
+ if (from_track < tracks_from)
+ from_track = tracks_from;
+
+ if (from_track > tracks_to || to_track < tracks_from) {
if (!click.shift)
_clear_selection();
+ _edit_if_single_selection();
+ break;
+ }
- int higher_track = 0x7FFFFFFF;
- for (int i = from_track; i <= to_track; i++) {
+ if (!click.shift)
+ _clear_selection();
- int kc = animation->track_get_key_count(i);
- for (int j = 0; j < kc; j++) {
+ int higher_track = 0x7FFFFFFF;
+ for (int i = from_track; i <= to_track; i++) {
- float t = animation->track_get_key_time(i, j);
- if (t < from_time)
- continue;
- if (t > to_time)
- break;
+ int kc = animation->track_get_key_count(i);
+ for (int j = 0; j < kc; j++) {
- if (i < higher_track)
- higher_track = i;
+ float t = animation->track_get_key_time(i, j);
+ if (t < from_time)
+ continue;
+ if (t > to_time)
+ break;
- SelectedKey sk;
- sk.track = i;
- sk.key = j;
- KeyInfo ki;
- ki.pos = t;
- selection[sk] = ki;
- }
- }
+ if (i < higher_track)
+ higher_track = i;
- if (higher_track != 0x7FFFFFFF) {
- selected_track = higher_track;
- track_editor->update();
+ SelectedKey sk;
+ sk.track = i;
+ sk.key = j;
+ KeyInfo ki;
+ ki.pos = t;
+ selection[sk] = ki;
}
+ }
- _edit_if_single_selection();
+ if (higher_track != 0x7FFFFFFF) {
+ selected_track = higher_track;
+ track_editor->update();
+ }
- } break;
- case ClickOver::CLICK_MOVE_KEYS: {
+ _edit_if_single_selection();
- if (selection.empty())
- break;
- if (click.at == click.to) {
+ } break;
+ case ClickOver::CLICK_MOVE_KEYS: {
- if (!click.shift) {
+ if (selection.empty())
+ break;
+ if (click.at == click.to) {
- KeyInfo ki = selection[click.selk];
- _clear_selection();
- selection[click.selk] = ki;
- _edit_if_single_selection();
- }
+ if (!click.shift) {
- break;
+ KeyInfo ki = selection[click.selk];
+ _clear_selection();
+ selection[click.selk] = ki;
+ _edit_if_single_selection();
}
- float from_t = 1e20;
+ break;
+ }
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
- float t = animation->track_get_key_time(E->key().track, E->key().key);
- if (t < from_t)
- from_t = t;
- }
+ float from_t = 1e20;
- float motion = from_t + (click.to.x - click.at.x) / _get_zoom_scale();
- if (step->get_value())
- motion = Math::stepify(motion, step->get_value());
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.front(); E; E = E->next()) {
+ float t = animation->track_get_key_time(E->key().track, E->key().key);
+ if (t < from_t)
+ from_t = t;
+ }
- undo_redo->create_action(TTR("Anim Move Keys"));
+ float motion = from_t + (click.to.x - click.at.x) / _get_zoom_scale();
+ if (step->get_value())
+ motion = Math::stepify(motion, step->get_value());
- List<_AnimMoveRestore> to_restore;
+ undo_redo->create_action(TTR("Anim Move Keys"));
- // 1-remove the keys
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ List<_AnimMoveRestore> to_restore;
- undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key);
- }
- // 2- remove overlapped keys
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ // 1-remove the keys
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
- float newtime = E->get().pos - from_t + motion;
- int idx = animation->track_find_key(E->key().track, newtime, true);
- if (idx == -1)
- continue;
- SelectedKey sk;
- sk.key = idx;
- sk.track = E->key().track;
- if (selection.has(sk))
- continue; //already in selection, don't save
+ undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->key().track, E->key().key);
+ }
+ // 2- remove overlapped keys
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+
+ float newtime = E->get().pos - from_t + motion;
+ int idx = animation->track_find_key(E->key().track, newtime, true);
+ if (idx == -1)
+ continue;
+ SelectedKey sk;
+ sk.key = idx;
+ sk.track = E->key().track;
+ if (selection.has(sk))
+ continue; //already in selection, don't save
+
+ undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_pos", E->key().track, newtime);
+ _AnimMoveRestore amr;
+
+ amr.key = animation->track_get_key_value(E->key().track, idx);
+ amr.track = E->key().track;
+ amr.time = newtime;
+ amr.transition = animation->track_get_key_transition(E->key().track, idx);
+
+ to_restore.push_back(amr);
+ }
- undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_pos", E->key().track, newtime);
- _AnimMoveRestore amr;
+ // 3-move the keys (re insert them)
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
- amr.key = animation->track_get_key_value(E->key().track, idx);
- amr.track = E->key().track;
- amr.time = newtime;
- amr.transition = animation->track_get_key_transition(E->key().track, idx);
+ float newpos = E->get().pos - from_t + motion;
+ /*
+ if (newpos<0)
+ continue; //no add at the beginning
+ */
+ undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->key().track, newpos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
+ }
- to_restore.push_back(amr);
- }
+ // 4-(undo) remove inserted keys
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
- // 3-move the keys (re insert them)
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ float newpos = E->get().pos + -from_t + motion;
+ /*
+ if (newpos<0)
+ continue; //no remove what no inserted
+ */
+ undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_pos", E->key().track, newpos);
+ }
- float newpos = E->get().pos - from_t + motion;
- /*
- if (newpos<0)
- continue; //no add at the beginning
- */
- undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->key().track, newpos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
- }
+ // 5-(undo) reinsert keys
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
- // 4-(undo) remove inserted keys
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->key().track, E->get().pos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
+ }
- float newpos = E->get().pos + -from_t + motion;
- /*
- if (newpos<0)
- continue; //no remove what no inserted
- */
- undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_pos", E->key().track, newpos);
- }
+ // 6-(undo) reinsert overlapped keys
+ for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
- // 5-(undo) reinsert keys
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ _AnimMoveRestore &amr = E->get();
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
+ }
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->key().track, E->get().pos, animation->track_get_key_value(E->key().track, E->key().key), animation->track_get_key_transition(E->key().track, E->key().key));
- }
+ // 6-(undo) reinsert overlapped keys
+ for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
- // 6-(undo) reinsert overlapped keys
- for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
+ _AnimMoveRestore &amr = E->get();
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
+ }
- _AnimMoveRestore &amr = E->get();
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
- }
+ undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
+ undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
- // 6-(undo) reinsert overlapped keys
- for (List<_AnimMoveRestore>::Element *E = to_restore.front(); E; E = E->next()) {
+ // 7-reselect
- _AnimMoveRestore &amr = E->get();
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, amr.transition);
- }
+ for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
- undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
- undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
+ float oldpos = E->get().pos;
+ float newpos = oldpos - from_t + motion;
+ //if (newpos>=0)
+ undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
+ }
- // 7-reselect
+ undo_redo->commit_action();
+ _edit_if_single_selection();
- for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
+ } break;
+ default: {}
+ }
- float oldpos = E->get().pos;
- float newpos = oldpos - from_t + motion;
- //if (newpos>=0)
- undo_redo->add_do_method(this, "_select_at_anim", animation, E->key().track, newpos);
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->key().track, oldpos);
- }
+ //button released
+ click.click = ClickOver::CLICK_NONE;
+ track_editor->update();
+ }
+ }
+ }
- undo_redo->commit_action();
- _edit_if_single_selection();
+ Ref<InputEventMouseMotion> mm = p_input;
- } break;
- default: {}
- }
+ if (mm.is_valid()) {
- //button released
- click.click = ClickOver::CLICK_NONE;
- track_editor->update();
- }
- }
+ mouse_over.over = MouseOver::OVER_NONE;
+ mouse_over.track = -1;
+ te->update();
+ track_editor->set_tooltip("");
- } break;
+ if (!track_editor->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
+ track_editor->call_deferred("grab_focus");
- case InputEvent::MOUSE_MOTION: {
+ if (click.click != ClickOver::CLICK_NONE) {
- const InputEventMouseMotion &mb = p_input.mouse_motion;
+ switch (click.click) {
+ case ClickOver::CLICK_RESIZE_NAMES: {
- mouse_over.over = MouseOver::OVER_NONE;
- mouse_over.track = -1;
- te->update();
- track_editor->set_tooltip("");
+ float base = click.at.y;
+ float clickp = click.at.x - ofs.x;
+ float dif = base - clickp;
- if (!track_editor->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
- track_editor->call_deferred("grab_focus");
+ float target = mb->get_pos().x + dif - ofs.x;
- if (click.click != ClickOver::CLICK_NONE) {
+ float ratio = target / settings_limit;
- switch (click.click) {
- case ClickOver::CLICK_RESIZE_NAMES: {
+ if (ratio > 0.9)
+ ratio = 0.9;
+ else if (ratio < 0.2)
+ ratio = 0.2;
- float base = click.at.y;
- float clickp = click.at.x - ofs.x;
- float dif = base - clickp;
+ name_column_ratio = ratio;
- float target = mb.x + dif - ofs.x;
+ } break;
+ case ClickOver::CLICK_DRAG_TIMELINE: {
- float ratio = target / settings_limit;
+ Point2 mpos = mb->get_pos() - ofs;
+ /*
+ if (mpos.x<name_limit)
+ mpos.x=name_limit;
+ if (mpos.x>settings_limit)
+ mpos.x=settings_limit;
+ */
- if (ratio > 0.9)
- ratio = 0.9;
- else if (ratio < 0.2)
- ratio = 0.2;
+ //int zoomw = settings_limit-name_limit;
+ float scale = _get_zoom_scale();
+ float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
+ if (animation->get_step()) {
+ pos = Math::stepify(pos, animation->get_step());
+ }
+ if (pos < 0)
+ pos = 0;
+ if (pos >= animation->get_length())
+ pos = animation->get_length();
+
+ if (pos < h_scroll->get_value()) {
+ h_scroll->set_value(pos);
+ } else if (pos > h_scroll->get_value() + (settings_limit - name_limit) / scale) {
+ h_scroll->set_value(pos - (settings_limit - name_limit) / scale);
+ }
- name_column_ratio = ratio;
+ timeline_pos = pos;
+ emit_signal("timeline_changed", pos, true);
- } break;
- case ClickOver::CLICK_DRAG_TIMELINE: {
-
- Point2 mpos = Point2(mb.x, mb.y) - ofs;
- /*
- if (mpos.x<name_limit)
- mpos.x=name_limit;
- if (mpos.x>settings_limit)
- mpos.x=settings_limit;
- */
+ } break;
+ case ClickOver::CLICK_SELECT_KEYS: {
- //int zoomw = settings_limit-name_limit;
- float scale = _get_zoom_scale();
- float pos = h_scroll->get_value() + (mpos.x - name_limit) / scale;
- if (animation->get_step()) {
- pos = Math::stepify(pos, animation->get_step());
- }
- if (pos < 0)
- pos = 0;
- if (pos >= animation->get_length())
- pos = animation->get_length();
+ click.to = mb->get_pos();
+ if (click.to.y < h && click.at.y > h && mm->get_relative().y < 0) {
- if (pos < h_scroll->get_value()) {
- h_scroll->set_value(pos);
- } else if (pos > h_scroll->get_value() + (settings_limit - name_limit) / scale) {
- h_scroll->set_value(pos - (settings_limit - name_limit) / scale);
- }
+ float prev = v_scroll->get_value();
+ v_scroll->set_value(v_scroll->get_value() - 1);
+ if (prev != v_scroll->get_value())
+ click.at.y += h;
+ }
+ if (click.to.y > size.height && click.at.y < size.height && mm->get_relative().y > 0) {
- timeline_pos = pos;
- emit_signal("timeline_changed", pos, true);
+ float prev = v_scroll->get_value();
+ v_scroll->set_value(v_scroll->get_value() + 1);
+ if (prev != v_scroll->get_value())
+ click.at.y -= h;
+ }
- } break;
- case ClickOver::CLICK_SELECT_KEYS: {
+ } break;
+ case ClickOver::CLICK_MOVE_KEYS: {
- click.to = Point2(mb.x, mb.y);
- if (click.to.y < h && click.at.y > h && mb.relative_y < 0) {
+ click.to = mb->get_pos();
+ } break;
+ default: {}
+ }
- float prev = v_scroll->get_value();
- v_scroll->set_value(v_scroll->get_value() - 1);
- if (prev != v_scroll->get_value())
- click.at.y += h;
- }
- if (click.to.y > size.height && click.at.y < size.height && mb.relative_y > 0) {
+ return;
+ } else if (mb->get_button_mask() & BUTTON_MASK_MIDDLE) {
- float prev = v_scroll->get_value();
- v_scroll->set_value(v_scroll->get_value() + 1);
- if (prev != v_scroll->get_value())
- click.at.y -= h;
- }
+ int rel = mm->get_relative().x;
+ float relf = rel / _get_zoom_scale();
+ h_scroll->set_value(h_scroll->get_value() - relf);
+ }
- } break;
- case ClickOver::CLICK_MOVE_KEYS: {
+ if (mb->get_button_mask() == 0) {
- click.to = Point2(mb.x, mb.y);
- } break;
- default: {}
- }
+ Point2 mpos = mb->get_pos() - ofs;
+ if (mpos.y < h) {
+#if 0
+ //seek
+ //int zoomw = settings_limit-name_limit;
+ float scale = _get_zoom_scale();
+ float pos = h_scroll->get_val() + (mpos.y-name_limit) / scale;
+ if (pos<0 )
+ pos=0;
+ if (pos>=animation->get_length())
+ pos=animation->get_length();
+ timeline->set_val(pos);
+#endif
return;
- } else if (mb.button_mask & BUTTON_MASK_MIDDLE) {
-
- int rel = mb.relative_x;
- float relf = rel / _get_zoom_scale();
- h_scroll->set_value(h_scroll->get_value() - relf);
}
- if (mb.button_mask == 0) {
+ mpos.y -= h;
- Point2 mpos = Point2(mb.x, mb.y) - ofs;
+ int idx = mpos.y / h;
+ idx += v_scroll->get_value();
+ if (idx < 0 || idx >= animation->get_track_count())
+ return;
- if (mpos.y < h) {
-#if 0
- //seek
- //int zoomw = settings_limit-name_limit;
- float scale = _get_zoom_scale();
- float pos = h_scroll->get_val() + (mpos.y-name_limit) / scale;
- if (pos<0 )
- pos=0;
- if (pos>=animation->get_length())
- pos=animation->get_length();
- timeline->set_val(pos);
-#endif
- return;
- }
+ mouse_over.track = idx;
- mpos.y -= h;
+ if (mpos.x < name_limit) {
+ //name column
- int idx = mpos.y / h;
- idx += v_scroll->get_value();
- if (idx < 0 || idx >= animation->get_track_count())
- break;
+ mouse_over.over = MouseOver::OVER_NAME;
- mouse_over.track = idx;
+ } else if (mpos.x < settings_limit) {
- if (mpos.x < name_limit) {
- //name column
+ float pos = mpos.x - name_limit;
+ pos /= _get_zoom_scale();
+ pos += h_scroll->get_value();
+ float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
- mouse_over.over = MouseOver::OVER_NAME;
+ int kidx = animation->track_find_key(idx, pos);
+ int kidx_n = kidx + 1;
- } else if (mpos.x < settings_limit) {
+ bool found = false;
- float pos = mpos.x - name_limit;
- pos /= _get_zoom_scale();
- pos += h_scroll->get_value();
- float w_time = (type_icon[0]->get_width() / _get_zoom_scale()) / 2.0;
+ if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
- int kidx = animation->track_find_key(idx, pos);
- int kidx_n = kidx + 1;
+ float kpos = animation->track_get_key_time(idx, kidx);
+ if (ABS(pos - kpos) <= w_time) {
- bool found = false;
+ mouse_over.over = MouseOver::OVER_KEY;
+ mouse_over.track = idx;
+ mouse_over.over_key = kidx;
+ found = true;
+ }
+ }
- if (kidx >= 0 && kidx < animation->track_get_key_count(idx)) {
+ if (!found && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
- float kpos = animation->track_get_key_time(idx, kidx);
- if (ABS(pos - kpos) <= w_time) {
+ float kpos = animation->track_get_key_time(idx, kidx_n);
+ if (ABS(pos - kpos) <= w_time) {
- mouse_over.over = MouseOver::OVER_KEY;
- mouse_over.track = idx;
- mouse_over.over_key = kidx;
- found = true;
- }
+ mouse_over.over = MouseOver::OVER_KEY;
+ mouse_over.track = idx;
+ mouse_over.over_key = kidx_n;
+ found = true;
}
+ }
- if (!found && kidx_n >= 0 && kidx_n < animation->track_get_key_count(idx)) {
+ if (found) {
- float kpos = animation->track_get_key_time(idx, kidx_n);
- if (ABS(pos - kpos) <= w_time) {
+ String text;
+ text = "time: " + rtos(animation->track_get_key_time(idx, mouse_over.over_key)) + "\n";
- mouse_over.over = MouseOver::OVER_KEY;
- mouse_over.track = idx;
- mouse_over.over_key = kidx_n;
- found = true;
- }
- }
+ switch (animation->track_get_type(idx)) {
- if (found) {
-
- String text;
- text = "time: " + rtos(animation->track_get_key_time(idx, mouse_over.over_key)) + "\n";
-
- switch (animation->track_get_type(idx)) {
-
- case Animation::TYPE_TRANSFORM: {
-
- Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
- if (d.has("loc"))
- text += "loc: " + String(d["loc"]) + "\n";
- if (d.has("rot"))
- text += "rot: " + String(d["rot"]) + "\n";
- if (d.has("scale"))
- text += "scale: " + String(d["scale"]) + "\n";
- } break;
- case Animation::TYPE_VALUE: {
-
- Variant v = animation->track_get_key_value(idx, mouse_over.over_key);
- //text+="value: "+String(v)+"\n";
-
- bool prop_exists = false;
- Variant::Type valid_type = Variant::NIL;
- Object *obj = NULL;
-
- RES res;
- Node *node = root->get_node_and_resource(animation->track_get_path(idx), res);
-
- if (res.is_valid()) {
- obj = res.ptr();
- } else if (node) {
- obj = node;
- }
-
- if (obj) {
- valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists);
- }
-
- text += "type: " + Variant::get_type_name(v.get_type()) + "\n";
- if (prop_exists && !Variant::can_convert(v.get_type(), valid_type)) {
- text += "value: " + String(v) + " (Invalid, expected type: " + Variant::get_type_name(valid_type) + ")\n";
- } else {
- text += "value: " + String(v) + "\n";
- }
-
- } break;
- case Animation::TYPE_METHOD: {
-
- Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
- if (d.has("method"))
- text += String(d["method"]);
- text += "(";
- Vector<Variant> args;
- if (d.has("args"))
- args = d["args"];
- for (int i = 0; i < args.size(); i++) {
-
- if (i > 0)
- text += ", ";
- text += String(args[i]);
- }
- text += ")\n";
-
- } break;
- }
- text += "easing: " + rtos(animation->track_get_key_transition(idx, mouse_over.over_key));
+ case Animation::TYPE_TRANSFORM: {
- track_editor->set_tooltip(text);
- return;
- }
+ Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
+ if (d.has("loc"))
+ text += "loc: " + String(d["loc"]) + "\n";
+ if (d.has("rot"))
+ text += "rot: " + String(d["rot"]) + "\n";
+ if (d.has("scale"))
+ text += "scale: " + String(d["scale"]) + "\n";
+ } break;
+ case Animation::TYPE_VALUE: {
- } else {
- //button column
- int ofsx = size.width - mpos.x;
- if (ofsx < 0)
- break;
- /*
- if (ofsx < remove_icon->get_width()) {
+ Variant v = animation->track_get_key_value(idx, mouse_over.over_key);
+ //text+="value: "+String(v)+"\n";
- mouse_over.over=MouseOver::OVER_REMOVE;
+ bool prop_exists = false;
+ Variant::Type valid_type = Variant::NIL;
+ Object *obj = NULL;
- return;
- }
+ RES res;
+ Node *node = root->get_node_and_resource(animation->track_get_path(idx), res);
- ofsx-=hsep+remove_icon->get_width();
+ if (res.is_valid()) {
+ obj = res.ptr();
+ } else if (node) {
+ obj = node;
+ }
- if (ofsx < move_down_icon->get_width()) {
+ if (obj) {
+ valid_type = obj->get_static_property_type(animation->track_get_path(idx).get_property(), &prop_exists);
+ }
- mouse_over.over=MouseOver::OVER_DOWN;
- return;
+ text += "type: " + Variant::get_type_name(v.get_type()) + "\n";
+ if (prop_exists && !Variant::can_convert(v.get_type(), valid_type)) {
+ text += "value: " + String(v) + " (Invalid, expected type: " + Variant::get_type_name(valid_type) + ")\n";
+ } else {
+ text += "value: " + String(v) + "\n";
+ }
+
+ } break;
+ case Animation::TYPE_METHOD: {
+
+ Dictionary d = animation->track_get_key_value(idx, mouse_over.over_key);
+ if (d.has("method"))
+ text += String(d["method"]);
+ text += "(";
+ Vector<Variant> args;
+ if (d.has("args"))
+ args = d["args"];
+ for (int i = 0; i < args.size(); i++) {
+
+ if (i > 0)
+ text += ", ";
+ text += String(args[i]);
+ }
+ text += ")\n";
+
+ } break;
}
+ text += "easing: " + rtos(animation->track_get_key_transition(idx, mouse_over.over_key));
- ofsx-=hsep+move_down_icon->get_width();
+ track_editor->set_tooltip(text);
+ return;
+ }
- if (ofsx < move_up_icon->get_width()) {
+ } else {
+ //button column
+ int ofsx = size.width - mpos.x;
+ if (ofsx < 0)
+ return;
+ /*
+ if (ofsx < remove_icon->get_width()) {
- mouse_over.over=MouseOver::OVER_UP;
- return;
- }
+ mouse_over.over=MouseOver::OVER_REMOVE;
- ofsx-=hsep*3+move_up_icon->get_width();
+ return;
+ }
- */
+ ofsx-=hsep+remove_icon->get_width();
- if (ofsx < down_icon->get_width() + wrap_icon[0]->get_width() + hsep * 3) {
+ if (ofsx < move_down_icon->get_width()) {
- mouse_over.over = MouseOver::OVER_WRAP;
- return;
- }
+ mouse_over.over=MouseOver::OVER_DOWN;
+ return;
+ }
- ofsx -= hsep * 3 + wrap_icon[0]->get_width() + down_icon->get_width();
+ ofsx-=hsep+move_down_icon->get_width();
- if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep * 3) {
+ if (ofsx < move_up_icon->get_width()) {
- mouse_over.over = MouseOver::OVER_INTERP;
- return;
- }
+ mouse_over.over=MouseOver::OVER_UP;
+ return;
+ }
- ofsx -= hsep * 2 + interp_icon[0]->get_width() + down_icon->get_width();
+ ofsx-=hsep*3+move_up_icon->get_width();
- if (ofsx < down_icon->get_width() + cont_icon[0]->get_width() + hsep * 3) {
+*/
- mouse_over.over = MouseOver::OVER_VALUE;
- return;
- }
+ if (ofsx < down_icon->get_width() + wrap_icon[0]->get_width() + hsep * 3) {
- ofsx -= hsep * 3 + cont_icon[0]->get_width() + down_icon->get_width();
+ mouse_over.over = MouseOver::OVER_WRAP;
+ return;
+ }
- if (ofsx < add_key_icon->get_width()) {
+ ofsx -= hsep * 3 + wrap_icon[0]->get_width() + down_icon->get_width();
- mouse_over.over = MouseOver::OVER_ADD_KEY;
- return;
- }
+ if (ofsx < down_icon->get_width() + interp_icon[0]->get_width() + hsep * 3) {
+
+ mouse_over.over = MouseOver::OVER_INTERP;
+ return;
}
- }
- } break;
+ ofsx -= hsep * 2 + interp_icon[0]->get_width() + down_icon->get_width();
+
+ if (ofsx < down_icon->get_width() + cont_icon[0]->get_width() + hsep * 3) {
+
+ mouse_over.over = MouseOver::OVER_VALUE;
+ return;
+ }
+
+ ofsx -= hsep * 3 + cont_icon[0]->get_width() + down_icon->get_width();
+
+ if (ofsx < add_key_icon->get_width()) {
+
+ mouse_over.over = MouseOver::OVER_ADD_KEY;
+ return;
+ }
+ }
+ }
}
}
diff --git a/editor/animation_editor.h b/editor/animation_editor.h
index 0f6cc95634..128481c837 100644
--- a/editor/animation_editor.h
+++ b/editor/animation_editor.h
@@ -273,7 +273,7 @@ class AnimationKeyEditor : public VBoxContainer {
float _get_zoom_scale() const;
void _track_editor_draw();
- void _track_editor_gui_input(const InputEvent &p_input);
+ void _track_editor_gui_input(const Ref<InputEvent> &p_input);
void _track_pos_draw();
void _track_name_changed(const String &p_name);
diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp
index a84d65de0e..2e406fb23d 100644
--- a/editor/code_editor.cpp
+++ b/editor/code_editor.cpp
@@ -94,17 +94,16 @@ void FindReplaceBar::_notification(int p_what) {
}
}
-void FindReplaceBar::_unhandled_input(const InputEvent &p_event) {
+void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid()) {
- const InputEventKey &k = p_event.key;
-
- if (k.pressed && (text_edit->has_focus() || text_vbc->is_a_parent_of(get_focus_owner()))) {
+ if (k->is_pressed() && (text_edit->has_focus() || text_vbc->is_a_parent_of(get_focus_owner()))) {
bool accepted = true;
- switch (k.scancode) {
+ switch (k->get_scancode()) {
case KEY_ESCAPE: {
@@ -957,23 +956,27 @@ FindReplaceDialog::FindReplaceDialog() {
/*** CODE EDITOR ****/
-void CodeTextEditor::_text_editor_gui_input(const InputEvent &p_event) {
+void CodeTextEditor::_text_editor_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_event;
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid()) {
- if (mb.pressed && mb.mod.command) {
+ if (mb->is_pressed() && mb->get_command()) {
- if (mb.button_index == BUTTON_WHEEL_UP) {
+ if (mb->get_button_index() == BUTTON_WHEEL_UP) {
_zoom_in();
- } else if (mb.button_index == BUTTON_WHEEL_DOWN) {
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
_zoom_out();
}
}
- } else if (p_event.type == InputEvent::KEY) {
+ }
+
+ Ref<InputEventKey> k = p_event;
+
+ if (k.is_valid()) {
- if (p_event.key.pressed) {
+ if (k->is_pressed()) {
if (ED_IS_SHORTCUT("script_editor/zoom_in", p_event)) {
_zoom_in();
}
diff --git a/editor/code_editor.h b/editor/code_editor.h
index 44d526fda9..8d48c56503 100644
--- a/editor/code_editor.h
+++ b/editor/code_editor.h
@@ -100,7 +100,7 @@ class FindReplaceBar : public HBoxContainer {
protected:
void _notification(int p_what);
- void _unhandled_input(const InputEvent &p_event);
+ void _unhandled_input(const Ref<InputEvent> &p_event);
bool _search(uint32_t p_flags, int p_from_line, int p_from_col);
@@ -213,7 +213,7 @@ class CodeTextEditor : public VBoxContainer {
void _complete_request();
void _font_resize_timeout();
- void _text_editor_gui_input(const InputEvent &p_event);
+ void _text_editor_gui_input(const Ref<InputEvent> &p_event);
void _zoom_in();
void _zoom_out();
void _reset_zoom();
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp
index dc28fc9020..c5cfea0b95 100644
--- a/editor/create_dialog.cpp
+++ b/editor/create_dialog.cpp
@@ -109,14 +109,15 @@ void CreateDialog::_text_changed(const String &p_newtext) {
_update_search();
}
-void CreateDialog::_sbox_input(const InputEvent &p_ie) {
+void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP ||
- p_ie.key.scancode == KEY_DOWN ||
- p_ie.key.scancode == KEY_PAGEUP ||
- p_ie.key.scancode == KEY_PAGEDOWN)) {
+ Ref<InputEventKey> k = p_ie;
+ if (k.is_valid() && (k->get_scancode() == KEY_UP ||
+ k->get_scancode() == KEY_DOWN ||
+ k->get_scancode() == KEY_PAGEUP ||
+ k->get_scancode() == KEY_PAGEDOWN)) {
- search_options->call("_gui_input", p_ie);
+ search_options->call("_gui_input", k);
search_box->accept_event();
}
}
diff --git a/editor/create_dialog.h b/editor/create_dialog.h
index 6170149c6b..02ce762726 100644
--- a/editor/create_dialog.h
+++ b/editor/create_dialog.h
@@ -69,7 +69,7 @@ class CreateDialog : public ConfirmationDialog {
void _history_activated();
void _favorite_activated();
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _confirmed();
void _text_changed(const String &p_newtext);
diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp
index 75d8721756..6a79f99354 100644
--- a/editor/doc/doc_data.cpp
+++ b/editor/doc/doc_data.cpp
@@ -331,8 +331,7 @@ void DocData::generate(bool p_basic_types) {
default_arg_text = "NULL";
break;
}
- case Variant::INPUT_EVENT:
- case Variant::DICTIONARY:
+ case Variant::DICTIONARY: // 20
case Variant::ARRAY:
case Variant::_RID:
@@ -477,97 +476,78 @@ void DocData::generate(bool p_basic_types) {
if (i == Variant::OBJECT)
continue; //use the core type instead
- int loops = 1;
+ String cname = Variant::get_type_name(Variant::Type(i));
- if (i == Variant::INPUT_EVENT)
- loops = InputEvent::TYPE_MAX;
-
- for (int j = 0; j < loops; j++) {
-
- String cname = Variant::get_type_name(Variant::Type(i));
-
- if (i == Variant::INPUT_EVENT) {
- static const char *ie_type[InputEvent::TYPE_MAX] = {
- "", "Key", "MouseMotion", "MouseButton", "JoypadMotion", "JoypadButton", "ScreenTouch", "ScreenDrag", "Action"
- };
- cname += ie_type[j];
- }
-
- class_list[cname] = ClassDoc();
- ClassDoc &c = class_list[cname];
- c.name = cname;
- c.category = "Built-In Types";
-
- Variant::CallError cerror;
- Variant v = Variant::construct(Variant::Type(i), NULL, 0, cerror);
+ class_list[cname] = ClassDoc();
+ ClassDoc &c = class_list[cname];
+ c.name = cname;
+ c.category = "Built-In Types";
- if (i == Variant::INPUT_EVENT) {
- v.set("type", j);
- }
+ Variant::CallError cerror;
+ Variant v = Variant::construct(Variant::Type(i), NULL, 0, cerror);
- List<MethodInfo> method_list;
- v.get_method_list(&method_list);
- method_list.sort();
- Variant::get_constructor_list(Variant::Type(i), &method_list);
+ List<MethodInfo> method_list;
+ v.get_method_list(&method_list);
+ method_list.sort();
+ Variant::get_constructor_list(Variant::Type(i), &method_list);
- for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
+ for (List<MethodInfo>::Element *E = method_list.front(); E; E = E->next()) {
- MethodInfo &mi = E->get();
- MethodDoc method;
+ MethodInfo &mi = E->get();
+ MethodDoc method;
- method.name = mi.name;
+ method.name = mi.name;
- for (int i = 0; i < mi.arguments.size(); i++) {
+ for (int i = 0; i < mi.arguments.size(); i++) {
- ArgumentDoc arg;
- PropertyInfo pi = mi.arguments[i];
+ ArgumentDoc arg;
+ PropertyInfo pi = mi.arguments[i];
- arg.name = pi.name;
- //print_line("arg name: "+arg.name);
- if (pi.type == Variant::NIL)
- arg.type = "var";
- else
- arg.type = Variant::get_type_name(pi.type);
- int defarg = mi.default_arguments.size() - mi.arguments.size() + i;
- if (defarg >= 0)
- arg.default_value = mi.default_arguments[defarg];
-
- method.arguments.push_back(arg);
- }
+ arg.name = pi.name;
+ //print_line("arg name: "+arg.name);
+ if (pi.type == Variant::NIL)
+ arg.type = "var";
+ else
+ arg.type = Variant::get_type_name(pi.type);
+ int defarg = mi.default_arguments.size() - mi.arguments.size() + i;
+ if (defarg >= 0)
+ arg.default_value = mi.default_arguments[defarg];
- if (mi.return_val.type == Variant::NIL) {
- if (mi.return_val.name != "")
- method.return_type = "var";
+ method.arguments.push_back(arg);
+ }
- } else {
- method.return_type = Variant::get_type_name(mi.return_val.type);
- }
+ if (mi.return_val.type == Variant::NIL) {
+ if (mi.return_val.name != "")
+ method.return_type = "var";
- c.methods.push_back(method);
+ } else {
+ method.return_type = Variant::get_type_name(mi.return_val.type);
}
- List<PropertyInfo> properties;
- v.get_property_list(&properties);
- for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
+ c.methods.push_back(method);
+ }
+
+ List<PropertyInfo> properties;
+ v.get_property_list(&properties);
+ for (List<PropertyInfo>::Element *E = properties.front(); E; E = E->next()) {
- PropertyInfo pi = E->get();
- PropertyDoc property;
- property.name = pi.name;
- property.type = Variant::get_type_name(pi.type);
+ PropertyInfo pi = E->get();
+ PropertyDoc property;
+ property.name = pi.name;
+ property.type = Variant::get_type_name(pi.type);
- c.properties.push_back(property);
- }
+ c.properties.push_back(property);
+ }
- List<StringName> constants;
- Variant::get_numeric_constants_for_type(Variant::Type(i), &constants);
+ List<StringName> constants;
+ Variant::get_numeric_constants_for_type(Variant::Type(i), &constants);
- for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
+ for (List<StringName>::Element *E = constants.front(); E; E = E->next()) {
- ConstantDoc constant;
- constant.name = E->get();
- constant.value = itos(Variant::get_numeric_constant_value(Variant::Type(i), E->get()));
- c.constants.push_back(constant);
- }
+ ConstantDoc constant;
+ constant.name = E->get();
+ constant.value = itos(Variant::get_numeric_constant_value(Variant::Type(i), E->get()));
+ c.constants.push_back(constant);
}
}
diff --git a/editor/doc/doc_dump.cpp b/editor/doc/doc_dump.cpp
index 10cd29b814..79a8f79a7c 100644
--- a/editor/doc/doc_dump.cpp
+++ b/editor/doc/doc_dump.cpp
@@ -194,8 +194,7 @@ void DocDump::dump(const String &p_file) {
default_arg_text = Variant::get_type_name(default_arg.get_type()) + "(" + default_arg_text + ")";
break;
case Variant::OBJECT:
- case Variant::INPUT_EVENT:
- case Variant::DICTIONARY:
+ case Variant::DICTIONARY: // 20
case Variant::ARRAY:
case Variant::_RID:
diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp
index 6ef32a6afd..f60186e3b4 100644
--- a/editor/editor_audio_buses.cpp
+++ b/editor/editor_audio_buses.cpp
@@ -385,15 +385,18 @@ void EditorAudioBus::_effect_add(int p_which) {
ur->commit_action();
}
-void EditorAudioBus::_gui_input(const InputEvent &p_event) {
+void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode == KEY_DELETE && !p_event.key.echo) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
accept_event();
emit_signal("delete_request");
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 2 && p_event.mouse_button.pressed) {
- Vector2 pos = Vector2(p_event.mouse_button.x, p_event.mouse_button.y);
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
+
+ Vector2 pos = Vector2(mb->get_pos().x, mb->get_pos().y);
delete_popup->set_position(get_global_position() + pos);
delete_popup->popup();
}
diff --git a/editor/editor_audio_buses.h b/editor/editor_audio_buses.h
index 4a3d784796..f5bf464fd0 100644
--- a/editor/editor_audio_buses.h
+++ b/editor/editor_audio_buses.h
@@ -75,7 +75,7 @@ class EditorAudioBus : public PanelContainer {
bool updating_bus;
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _delete_pressed(int p_option);
void _name_changed(const String &p_new_name);
diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp
index c47e3fc0de..25fade46d6 100644
--- a/editor/editor_file_dialog.cpp
+++ b/editor/editor_file_dialog.cpp
@@ -95,11 +95,13 @@ void EditorFileDialog::_notification(int p_what) {
}
}
-void EditorFileDialog::_unhandled_input(const InputEvent &p_event) {
+void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && is_window_modal_on_top()) {
+ Ref<InputEventKey> k = p_event;
- if (p_event.key.pressed) {
+ if (k.is_valid() && is_window_modal_on_top()) {
+
+ if (k->is_pressed()) {
bool handled = false;
diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h
index f8c85c4ad1..f44193c70b 100644
--- a/editor/editor_file_dialog.h
+++ b/editor/editor_file_dialog.h
@@ -169,7 +169,7 @@ private:
void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata);
void _request_single_thumbnail(const String &p_path);
- void _unhandled_input(const InputEvent &p_event);
+ void _unhandled_input(const Ref<InputEvent> &p_event);
protected:
void _notification(int p_what);
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 11fa9396a0..d550ce93d1 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -61,14 +61,16 @@ void EditorHelpSearch::_text_changed(const String &p_newtext) {
_update_search();
}
-void EditorHelpSearch::_sbox_input(const InputEvent &p_ie) {
+void EditorHelpSearch::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP ||
- p_ie.key.scancode == KEY_DOWN ||
- p_ie.key.scancode == KEY_PAGEUP ||
- p_ie.key.scancode == KEY_PAGEDOWN)) {
+ Ref<InputEventKey> k = p_ie;
- search_options->call("_gui_input", p_ie);
+ if (k.is_valid() && (k->get_scancode() == KEY_UP ||
+ k->get_scancode() == KEY_DOWN ||
+ k->get_scancode() == KEY_PAGEUP ||
+ k->get_scancode() == KEY_PAGEDOWN)) {
+
+ search_options->call("_gui_input", k);
search_box->accept_event();
}
}
@@ -448,14 +450,16 @@ void EditorHelpIndex::_update_class_list() {
}
}
-void EditorHelpIndex::_sbox_input(const InputEvent &p_ie) {
+void EditorHelpIndex::_sbox_input(const Ref<InputEvent> &p_ie) {
+
+ Ref<InputEventKey> k = p_ie;
- if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP ||
- p_ie.key.scancode == KEY_DOWN ||
- p_ie.key.scancode == KEY_PAGEUP ||
- p_ie.key.scancode == KEY_PAGEDOWN)) {
+ if (k.is_valid() && (k->get_scancode() == KEY_UP ||
+ k->get_scancode() == KEY_DOWN ||
+ k->get_scancode() == KEY_PAGEUP ||
+ k->get_scancode() == KEY_PAGEDOWN)) {
- class_list->call("_gui_input", p_ie);
+ class_list->call("_gui_input", k);
search_box->accept_event();
}
}
@@ -499,11 +503,14 @@ EditorHelpIndex::EditorHelpIndex() {
/// /////////////////////////////////
DocData *EditorHelp::doc = NULL;
-void EditorHelp::_unhandled_key_input(const InputEvent &p_ev) {
+void EditorHelp::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
if (!is_visible_in_tree())
return;
- if (p_ev.key.mod.control && p_ev.key.scancode == KEY_F) {
+
+ Ref<InputEventKey> k = p_ev;
+
+ if (k.is_valid() && k->get_control() && k->get_scancode() == KEY_F) {
search->grab_focus();
search->select_all();
@@ -598,8 +605,11 @@ void EditorHelp::_class_desc_select(const String &p_select) {
}
}
-void EditorHelp::_class_desc_input(const InputEvent &p_input) {
- if (p_input.type == InputEvent::MOUSE_BUTTON && p_input.mouse_button.pressed && p_input.mouse_button.button_index == 1) {
+void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) {
+
+ Ref<InputEventMouseButton> mb = p_input;
+
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
class_desc->set_selection_enabled(false);
class_desc->set_selection_enabled(true);
}
diff --git a/editor/editor_help.h b/editor/editor_help.h
index d22d61b91d..d6fc0e3bf2 100644
--- a/editor/editor_help.h
+++ b/editor/editor_help.h
@@ -56,7 +56,7 @@ class EditorHelpSearch : public ConfirmationDialog {
void _update_search();
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _confirmed();
void _text_changed(const String &p_newtext);
@@ -81,7 +81,7 @@ class EditorHelpIndex : public ConfirmationDialog {
void _tree_item_selected();
void _text_changed(const String &p_text);
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _update_class_list();
@@ -147,7 +147,7 @@ class EditorHelp : public VBoxContainer {
void _scroll_changed(double p_scroll);
void _class_list_select(const String &p_select);
void _class_desc_select(const String &p_select);
- void _class_desc_input(const InputEvent &p_input);
+ void _class_desc_input(const Ref<InputEvent> &p_input);
Error _goto_desc(const String &p_class, int p_vscr = -1);
//void _update_history_buttons();
@@ -157,7 +157,7 @@ class EditorHelp : public VBoxContainer {
void _search(const String &p_str);
void _search_cbk();
- void _unhandled_key_input(const InputEvent &p_ev);
+ void _unhandled_key_input(const Ref<InputEvent> &p_ev);
protected:
void _notification(int p_what);
diff --git a/editor/editor_name_dialog.cpp b/editor/editor_name_dialog.cpp
index 29d5dda658..d4c418bfc9 100644
--- a/editor/editor_name_dialog.cpp
+++ b/editor/editor_name_dialog.cpp
@@ -32,14 +32,16 @@
#include "class_db.h"
#include "os/keyboard.h"
-void EditorNameDialog::_line_gui_input(const InputEvent &p_event) {
+void EditorNameDialog::_line_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_event;
- if (!p_event.key.pressed)
+ if (k.is_valid()) {
+
+ if (!k->is_pressed())
return;
- switch (p_event.key.scancode) {
+ switch (k->get_scancode()) {
case KEY_ENTER:
case KEY_RETURN: {
diff --git a/editor/editor_name_dialog.h b/editor/editor_name_dialog.h
index eeeee34d7e..57586951d1 100644
--- a/editor/editor_name_dialog.h
+++ b/editor/editor_name_dialog.h
@@ -41,7 +41,7 @@ class EditorNameDialog : public ConfirmationDialog {
VBoxContainer *makevb;
LineEdit *name;
- void _line_gui_input(const InputEvent &p_event);
+ void _line_gui_input(const Ref<InputEvent> &p_event);
protected:
static void _bind_methods();
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 4a4b720e88..4ecb292027 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -173,12 +173,13 @@ void EditorNode::_update_title() {
OS::get_singleton()->set_window_title(title);
}
-void EditorNode::_unhandled_input(const InputEvent &p_event) {
+void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) {
if (Node::get_viewport()->get_modal_stack_top())
return; //ignore because of modal window
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && !p_event.key.echo && !gui_base->get_viewport()->gui_has_modal_stack()) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_pressed() && !k->is_echo() && !gui_base->get_viewport()->gui_has_modal_stack()) {
if (ED_IS_SHORTCUT("editor/next_tab", p_event)) {
int next_tab = editor_data.get_edited_scene() + 1;
@@ -3710,11 +3711,13 @@ void EditorNode::show_warning(const String &p_text, const String &p_title) {
warning->popup_centered_minsize();
}
-void EditorNode::_dock_select_input(const InputEvent &p_input) {
+void EditorNode::_dock_select_input(const Ref<InputEvent> &p_input) {
- if (p_input.type == InputEvent::MOUSE_BUTTON || p_input.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouse> me = p_input;
- Vector2 point(p_input.mouse_motion.x, p_input.mouse_motion.y);
+ if (me.is_valid()) {
+
+ Vector2 point = me->get_pos();
int nrect = -1;
for (int i = 0; i < DOCK_SLOT_MAX; i++) {
@@ -3732,7 +3735,9 @@ void EditorNode::_dock_select_input(const InputEvent &p_input) {
if (nrect == -1)
return;
- if (p_input.type == InputEvent::MOUSE_BUTTON && p_input.mouse_button.button_index == 1 && p_input.mouse_button.pressed && dock_popup_selected != nrect) {
+ Ref<InputEventMouseButton> mb = me;
+
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && dock_popup_selected != nrect) {
Control *dock = dock_slot[dock_popup_selected]->get_current_tab_control();
if (dock) {
dock_slot[dock_popup_selected]->remove_child(dock);
@@ -6190,7 +6195,7 @@ void EditorPluginList::edit(Object *p_object) {
}
}
-bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) {
+bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) {
bool discard = false;
@@ -6203,7 +6208,7 @@ bool EditorPluginList::forward_gui_input(const Transform2D &p_canvas_xform, cons
return discard;
}
-bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const InputEvent &p_event) {
+bool EditorPluginList::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
bool discard = false;
for (int i = 0; i < plugins_list.size(); i++) {
diff --git a/editor/editor_node.h b/editor/editor_node.h
index 5215809da3..667f58e6da 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -482,7 +482,7 @@ private:
bool convert_old;
- void _unhandled_input(const InputEvent &p_event);
+ void _unhandled_input(const Ref<InputEvent> &p_event);
static void _load_error_notify(void *p_ud, const String &p_text);
@@ -539,7 +539,7 @@ private:
bool _find_scene_in_use(Node *p_node, const String &p_path) const;
- void _dock_select_input(const InputEvent &p_input);
+ void _dock_select_input(const Ref<InputEvent> &p_input);
void _dock_move_left();
void _dock_move_right();
void _dock_select_draw();
@@ -807,8 +807,8 @@ public:
void make_visible(bool p_visible);
void edit(Object *p_object);
- bool forward_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event);
- bool forward_spatial_gui_input(Camera *p_camera, const InputEvent &p_event);
+ bool forward_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
+ bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
void clear();
bool empty();
diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp
index 98e0808ba5..8ce4f88590 100644
--- a/editor/editor_path.cpp
+++ b/editor/editor_path.cpp
@@ -69,9 +69,10 @@ void EditorPath::_add_children_to_popup(Object *p_obj, int p_depth) {
}
}
-void EditorPath::_gui_input(const InputEvent &p_event) {
+void EditorPath::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
Object *obj = ObjectDB::get_instance(history->get_path_object(history->get_path_size() - 1));
if (!obj)
diff --git a/editor/editor_path.h b/editor/editor_path.h
index a142cba44c..7b73e7ebb6 100644
--- a/editor/editor_path.h
+++ b/editor/editor_path.h
@@ -46,7 +46,7 @@ class EditorPath : public Control {
EditorPath();
void _popup_select(int p_idx);
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _add_children_to_popup(Object *p_obj, int p_depth = 0);
protected:
diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp
index 5e5b31aac9..1b8d1b1677 100644
--- a/editor/editor_plugin.cpp
+++ b/editor/editor_plugin.cpp
@@ -156,7 +156,7 @@ Ref<SpatialEditorGizmo> EditorPlugin::create_spatial_gizmo(Spatial *p_spatial) {
return Ref<SpatialEditorGizmo>();
}
-bool EditorPlugin::forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) {
+bool EditorPlugin::forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) {
if (get_script_instance() && get_script_instance()->has_method("forward_canvas_gui_input")) {
return get_script_instance()->call("forward_canvas_gui_input", p_canvas_xform, p_event);
@@ -175,7 +175,7 @@ void EditorPlugin::update_canvas() {
CanvasItemEditor::get_singleton()->get_viewport_control()->update();
}
-bool EditorPlugin::forward_spatial_gui_input(Camera *p_camera, const InputEvent &p_event) {
+bool EditorPlugin::forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (get_script_instance() && get_script_instance()->has_method("forward_spatial_gui_input")) {
return get_script_instance()->call("forward_spatial_gui_input", p_camera, p_event);
@@ -366,9 +366,9 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
ClassDB::bind_method(D_METHOD("edit_resource"), &EditorPlugin::edit_resource);
ClassDB::bind_method(D_METHOD("add_import_plugin"), &EditorPlugin::add_import_plugin);
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::INPUT_EVENT, "event")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_canvas_gui_input", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ClassDB::add_virtual_method(get_class_static(), MethodInfo("forward_draw_over_canvas", PropertyInfo(Variant::TRANSFORM2D, "canvas_xform"), PropertyInfo(Variant::OBJECT, "canvas:Control")));
- ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::INPUT_EVENT, "event")));
+ ClassDB::add_virtual_method(get_class_static(), MethodInfo(Variant::BOOL, "forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
MethodInfo gizmo = MethodInfo(Variant::OBJECT, "create_spatial_gizmo", PropertyInfo(Variant::OBJECT, "for_spatial:Spatial"));
gizmo.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE;
gizmo.return_val.hint_string = "EditorSpatialGizmo";
diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h
index 5f4b47caee..1ef447a6b8 100644
--- a/editor/editor_plugin.h
+++ b/editor/editor_plugin.h
@@ -107,9 +107,9 @@ public:
void remove_tool_menu_item(const String &p_name);
virtual Ref<SpatialEditorGizmo> create_spatial_gizmo(Spatial *p_spatial);
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event);
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event);
virtual void forward_draw_over_canvas(const Transform2D &p_canvas_xform, Control *p_canvas);
- virtual bool forward_spatial_gui_input(Camera *p_camera, const InputEvent &p_event);
+ virtual bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event);
virtual String get_name() const;
virtual bool has_main_screen() const;
virtual void make_visible(bool p_visible);
diff --git a/editor/editor_profiler.cpp b/editor/editor_profiler.cpp
index 9d12ad687e..d427126734 100644
--- a/editor/editor_profiler.cpp
+++ b/editor/editor_profiler.cpp
@@ -483,16 +483,20 @@ void EditorProfiler::_cursor_metric_changed(double) {
_update_frame();
}
-void EditorProfiler::_graph_tex_input(const InputEvent &p_ev) {
+void EditorProfiler::_graph_tex_input(const Ref<InputEvent> &p_ev) {
if (last_metric < 0)
return;
+ Ref<InputEventMouse> me = p_ev;
+ Ref<InputEventMouseButton> mb = p_ev;
+ Ref<InputEventMouseMotion> mm = p_ev;
+
if (
- (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index == BUTTON_LEFT && p_ev.mouse_button.pressed) ||
- (p_ev.type == InputEvent::MOUSE_MOTION)) {
+ (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) ||
+ (mm.is_valid())) {
- int x = p_ev.mouse_button.x;
+ int x = me->get_pos().x;
x = x * frame_metrics.size() / graph->get_size().width;
bool show_hover = x >= 0 && x < frame_metrics.size();
@@ -519,7 +523,7 @@ void EditorProfiler::_graph_tex_input(const InputEvent &p_ev) {
hover_metric = -1;
}
- if (p_ev.type == InputEvent::MOUSE_BUTTON || p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ if (mb.is_valid() || mb->get_button_mask() & BUTTON_MASK_LEFT) {
//cursor_metric=x;
updating_frame = true;
diff --git a/editor/editor_profiler.h b/editor/editor_profiler.h
index 35b5ae366c..4998d45a89 100644
--- a/editor/editor_profiler.h
+++ b/editor/editor_profiler.h
@@ -143,7 +143,7 @@ private:
void _graph_tex_mouse_exit();
void _graph_tex_draw();
- void _graph_tex_input(const InputEvent &p_ev);
+ void _graph_tex_input(const Ref<InputEvent> &p_ev);
int _get_cursor_index() const;
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index cd8e68bc5e..ebd4643537 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -65,7 +65,7 @@ bool EditorSettings::_set(const StringName &p_name, const Variant &p_value) {
for (int i = 0; i < arr.size(); i += 2) {
String name = arr[i];
- InputEvent shortcut = arr[i + 1];
+ Ref<InputEvent> shortcut = arr[i + 1];
Ref<ShortCut> sc;
sc.instance();
@@ -109,8 +109,8 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const {
continue; //this came from settings but is not any longer used
}
- InputEvent original = sc->get_meta("original");
- if (sc->is_shortcut(original) || (original.type == InputEvent::NONE && sc->get_shortcut().type == InputEvent::NONE))
+ Ref<InputEvent> original = sc->get_meta("original");
+ if (sc->is_shortcut(original) || (original.is_null() && sc->get_shortcut().is_null()))
continue; //not changed from default, don't save
}
@@ -984,7 +984,7 @@ void EditorSettings::add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcu
shortcuts[p_name] = p_shortcut;
}
-bool EditorSettings::is_shortcut(const String &p_name, const InputEvent &p_event) const {
+bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const {
const Map<String, Ref<ShortCut> >::Element *E = shortcuts.find(p_name);
if (!E) {
@@ -1101,15 +1101,16 @@ Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path) {
Ref<ShortCut> ED_SHORTCUT(const String &p_path, const String &p_name, uint32_t p_keycode) {
- InputEvent ie;
+ Ref<InputEventKey> ie;
if (p_keycode) {
- ie.type = InputEvent::KEY;
- ie.key.unicode = p_keycode & KEY_CODE_MASK;
- ie.key.scancode = p_keycode & KEY_CODE_MASK;
- ie.key.mod.shift = bool(p_keycode & KEY_MASK_SHIFT);
- ie.key.mod.alt = bool(p_keycode & KEY_MASK_ALT);
- ie.key.mod.control = bool(p_keycode & KEY_MASK_CTRL);
- ie.key.mod.meta = bool(p_keycode & KEY_MASK_META);
+ ie.instance();
+
+ ie->set_unicode(p_keycode & KEY_CODE_MASK);
+ ie->set_scancode(p_keycode & KEY_CODE_MASK);
+ ie->set_shift(bool(p_keycode & KEY_MASK_SHIFT));
+ ie->set_alt(bool(p_keycode & KEY_MASK_ALT));
+ ie->set_control(bool(p_keycode & KEY_MASK_CTRL));
+ ie->set_metakey(bool(p_keycode & KEY_MASK_META));
}
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path);
diff --git a/editor/editor_settings.h b/editor/editor_settings.h
index a876f23134..7b45e28350 100644
--- a/editor/editor_settings.h
+++ b/editor/editor_settings.h
@@ -160,7 +160,7 @@ public:
bool save_text_editor_theme_as(String p_file);
void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut);
- bool is_shortcut(const String &p_name, const InputEvent &p_event) const;
+ bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const;
Ref<ShortCut> get_shortcut(const String &p_name) const;
void get_shortcut_list(List<String> *r_shortcuts);
diff --git a/editor/pane_drag.cpp b/editor/pane_drag.cpp
index 69a1f07fba..22b306f941 100644
--- a/editor/pane_drag.cpp
+++ b/editor/pane_drag.cpp
@@ -29,11 +29,12 @@
/*************************************************************************/
#include "pane_drag.h"
-void PaneDrag::_gui_input(const InputEvent &p_input) {
+void PaneDrag::_gui_input(const Ref<InputEvent> &p_input) {
- if (p_input.type == InputEvent::MOUSE_MOTION && p_input.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ Ref<InputEventMouseMotion> mm = p_input;
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
- emit_signal("dragged", Point2(p_input.mouse_motion.relative_x, p_input.mouse_motion.relative_y));
+ emit_signal("dragged", Point2(mm->get_relative().x, mm->get_relative().y));
}
}
diff --git a/editor/pane_drag.h b/editor/pane_drag.h
index bd26621c83..7bd9feb63b 100644
--- a/editor/pane_drag.h
+++ b/editor/pane_drag.h
@@ -39,7 +39,7 @@ class PaneDrag : public Control {
bool mouse_over;
protected:
- void _gui_input(const InputEvent &p_input);
+ void _gui_input(const Ref<InputEvent> &p_input);
void _notification(int p_what);
virtual Size2 get_minimum_size() const;
static void _bind_methods();
diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp
index 8a1e220fe3..17fb953f3f 100644
--- a/editor/plugins/animation_player_editor_plugin.cpp
+++ b/editor/plugins/animation_player_editor_plugin.cpp
@@ -51,7 +51,7 @@ void AnimationPlayerEditor::_node_removed(Node *p_node) {
}
}
-void AnimationPlayerEditor::_gui_input(InputEvent p_event) {
+void AnimationPlayerEditor::_gui_input(Ref<InputEvent> p_event) {
}
void AnimationPlayerEditor::_notification(int p_what) {
@@ -1160,14 +1160,15 @@ void AnimationPlayerEditor::_animation_save_menu(int p_option) {
}
}
-void AnimationPlayerEditor::_unhandled_key_input(const InputEvent &p_ev) {
+void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
- if (is_visible_in_tree() && p_ev.type == InputEvent::KEY && p_ev.key.pressed && !p_ev.key.echo && !p_ev.key.mod.alt && !p_ev.key.mod.control && !p_ev.key.mod.meta) {
+ Ref<InputEventKey> k = p_ev;
+ if (is_visible_in_tree() && k.is_valid() && k->is_pressed() && !k->is_echo() && !k->get_alt() && !k->get_control() && !k->get_metakey()) {
- switch (p_ev.key.scancode) {
+ switch (k->get_scancode()) {
case KEY_A: {
- if (!p_ev.key.mod.shift)
+ if (!k->get_shift())
_play_bw_from_pressed();
else
_play_bw_pressed();
@@ -1176,7 +1177,7 @@ void AnimationPlayerEditor::_unhandled_key_input(const InputEvent &p_ev) {
_stop_pressed();
} break;
case KEY_D: {
- if (!p_ev.key.mod.shift)
+ if (!k->get_shift())
_play_from_pressed();
else
_play_pressed();
diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h
index ac60090d15..ceaa73569a 100644
--- a/editor/plugins/animation_player_editor_plugin.h
+++ b/editor/plugins/animation_player_editor_plugin.h
@@ -158,7 +158,7 @@ class AnimationPlayerEditor : public VBoxContainer {
void _animation_key_editor_anim_len_changed(float p_new);
void _animation_key_editor_anim_step_changed(float p_len);
- void _unhandled_key_input(const InputEvent &p_ev);
+ void _unhandled_key_input(const Ref<InputEvent> &p_ev);
void _animation_tool_menu(int p_option);
void _animation_save_menu(int p_option);
@@ -166,7 +166,7 @@ class AnimationPlayerEditor : public VBoxContainer {
protected:
void _notification(int p_what);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
void _node_removed(Node *p_node);
static void _bind_methods();
diff --git a/editor/plugins/animation_tree_editor_plugin.cpp b/editor/plugins/animation_tree_editor_plugin.cpp
index e126cdf40f..fccd527ed6 100644
--- a/editor/plugins/animation_tree_editor_plugin.cpp
+++ b/editor/plugins/animation_tree_editor_plugin.cpp
@@ -735,139 +735,139 @@ void AnimationTreeEditor::_node_edit_property(const StringName& p_node) {
}
#endif
-void AnimationTreeEditor::_gui_input(InputEvent p_event) {
+void AnimationTreeEditor::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- if (p_event.mouse_button.pressed) {
+ if (mb->is_pressed()) {
- if (p_event.mouse_button.button_index == 1) {
- click_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y);
- click_motion = click_pos;
- click_type = _locate_click(click_pos, &click_node, &click_slot);
- if (click_type != CLICK_NONE) {
+ if (mb->get_button_index() == 1) {
+ click_pos = Point2(mb->get_pos().x, mb->get_pos().y);
+ click_motion = click_pos;
+ click_type = _locate_click(click_pos, &click_node, &click_slot);
+ if (click_type != CLICK_NONE) {
- order.erase(click_node);
- order.push_back(click_node);
- update();
- }
+ order.erase(click_node);
+ order.push_back(click_node);
+ update();
+ }
- switch (click_type) {
- case CLICK_INPUT_SLOT: {
- click_pos = _get_slot_pos(click_node, true, click_slot);
- } break;
- case CLICK_OUTPUT_SLOT: {
- click_pos = _get_slot_pos(click_node, false, click_slot);
- } break;
- case CLICK_PARAMETER: {
-
- edited_node = click_node;
- renaming_edit = false;
- _popup_edit_dialog();
- //open editor
- //_node_edit_property(click_node);
- } break;
- default: {}
- }
+ switch (click_type) {
+ case CLICK_INPUT_SLOT: {
+ click_pos = _get_slot_pos(click_node, true, click_slot);
+ } break;
+ case CLICK_OUTPUT_SLOT: {
+ click_pos = _get_slot_pos(click_node, false, click_slot);
+ } break;
+ case CLICK_PARAMETER: {
+
+ edited_node = click_node;
+ renaming_edit = false;
+ _popup_edit_dialog();
+ //open editor
+ //_node_edit_property(click_node);
+ } break;
+ default: {}
}
- if (p_event.mouse_button.button_index == 2) {
-
- if (click_type != CLICK_NONE) {
- click_type = CLICK_NONE;
- update();
- } else {
- // try to disconnect/remove
-
- Point2 rclick_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y);
- rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot);
- if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) {
-
- node_popup->clear();
- node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT);
- if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) {
- node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
- if (rclick_type == CLICK_INPUT_SLOT) {
- if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot))
- node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE);
- else
- node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE);
- node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT);
- }
- }
+ }
+ if (mb->get_button_index() == 2) {
- node_popup->set_position(rclick_pos + get_global_position());
- node_popup->popup();
+ if (click_type != CLICK_NONE) {
+ click_type = CLICK_NONE;
+ update();
+ } else {
+ // try to disconnect/remove
+
+ Point2 rclick_pos = Point2(mb->get_pos().x, mb->get_pos().y);
+ rclick_type = _locate_click(rclick_pos, &rclick_node, &rclick_slot);
+ if (rclick_type == CLICK_INPUT_SLOT || rclick_type == CLICK_OUTPUT_SLOT) {
+
+ node_popup->clear();
+ node_popup->add_item(TTR("Disconnect"), NODE_DISCONNECT);
+ if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION) {
+ node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
+ if (rclick_type == CLICK_INPUT_SLOT) {
+ if (anim_tree->transition_node_has_input_auto_advance(rclick_node, rclick_slot))
+ node_popup->add_item(TTR("Clear Auto-Advance"), NODE_CLEAR_AUTOADVANCE);
+ else
+ node_popup->add_item(TTR("Set Auto-Advance"), NODE_SET_AUTOADVANCE);
+ node_popup->add_item(TTR("Delete Input"), NODE_DELETE_INPUT);
+ }
}
- if (rclick_type == CLICK_NODE) {
- node_popup->clear();
- node_popup->add_item(TTR("Rename"), NODE_RENAME);
- node_popup->add_item(TTR("Remove"), NODE_ERASE);
- if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION)
- node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
- node_popup->set_position(rclick_pos + get_global_position());
- node_popup->popup();
- }
+ node_popup->set_position(rclick_pos + get_global_position());
+ node_popup->popup();
}
- }
- } else {
- if (p_event.mouse_button.button_index == 1 && click_type != CLICK_NONE) {
+ if (rclick_type == CLICK_NODE) {
+ node_popup->clear();
+ node_popup->add_item(TTR("Rename"), NODE_RENAME);
+ node_popup->add_item(TTR("Remove"), NODE_ERASE);
+ if (anim_tree->node_get_type(rclick_node) == AnimationTreePlayer::NODE_TRANSITION)
+ node_popup->add_item(TTR("Add Input"), NODE_ADD_INPUT);
+ node_popup->set_position(rclick_pos + get_global_position());
+ node_popup->popup();
+ }
+ }
+ }
+ } else {
- switch (click_type) {
- case CLICK_INPUT_SLOT:
- case CLICK_OUTPUT_SLOT: {
+ if (mb->get_button_index() == 1 && click_type != CLICK_NONE) {
- Point2 dst_click_pos = Point2(p_event.mouse_button.x, p_event.mouse_button.y);
- StringName id;
- int slot;
- ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot);
+ switch (click_type) {
+ case CLICK_INPUT_SLOT:
+ case CLICK_OUTPUT_SLOT: {
- if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) {
+ Point2 dst_click_pos = Point2(mb->get_pos().x, mb->get_pos().y);
+ StringName id;
+ int slot;
+ ClickType dst_click_type = _locate_click(dst_click_pos, &id, &slot);
- anim_tree->connect_nodes(click_node, id, slot);
- }
- if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) {
+ if (dst_click_type == CLICK_INPUT_SLOT && click_type == CLICK_OUTPUT_SLOT) {
- anim_tree->connect_nodes(id, click_node, click_slot);
- }
+ anim_tree->connect_nodes(click_node, id, slot);
+ }
+ if (click_type == CLICK_INPUT_SLOT && dst_click_type == CLICK_OUTPUT_SLOT) {
- } break;
- case CLICK_NODE: {
- Point2 new_pos = anim_tree->node_get_pos(click_node) + (click_motion - click_pos);
- if (new_pos.x < 5)
- new_pos.x = 5;
- if (new_pos.y < 5)
- new_pos.y = 5;
- anim_tree->node_set_pos(click_node, new_pos);
-
- } break;
- default: {}
- }
+ anim_tree->connect_nodes(id, click_node, click_slot);
+ }
- click_type = CLICK_NONE;
- update();
+ } break;
+ case CLICK_NODE: {
+ Point2 new_pos = anim_tree->node_get_pos(click_node) + (click_motion - click_pos);
+ if (new_pos.x < 5)
+ new_pos.x = 5;
+ if (new_pos.y < 5)
+ new_pos.y = 5;
+ anim_tree->node_set_pos(click_node, new_pos);
+
+ } break;
+ default: {}
}
+
+ click_type = CLICK_NONE;
+ update();
}
}
+ }
- case InputEvent::MOUSE_MOTION: {
+ Ref<InputEventMouseMotion> mm = p_event;
- if (p_event.mouse_motion.button_mask & 1 && click_type != CLICK_NONE) {
+ if (mm.is_valid()) {
- click_motion = Point2(p_event.mouse_button.x, p_event.mouse_button.y);
- update();
- }
- if ((p_event.mouse_motion.button_mask & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
+ if (mm->get_button_mask() & 1 && click_type != CLICK_NONE) {
- h_scroll->set_value(h_scroll->get_value() - p_event.mouse_motion.relative_x);
- v_scroll->set_value(v_scroll->get_value() - p_event.mouse_motion.relative_y);
- update();
- }
+ click_motion = Point2(mm->get_pos().x, mm->get_pos().y);
+ update();
+ }
+ if ((mm->get_button_mask() & 4 || Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
- } break;
+ h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
+ v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
+ update();
+ }
}
}
diff --git a/editor/plugins/animation_tree_editor_plugin.h b/editor/plugins/animation_tree_editor_plugin.h
index 8bbe22387b..785f042dd9 100644
--- a/editor/plugins/animation_tree_editor_plugin.h
+++ b/editor/plugins/animation_tree_editor_plugin.h
@@ -155,7 +155,7 @@ class AnimationTreeEditor : public Control {
protected:
void _notification(int p_what);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
static void _bind_methods();
public:
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index efb431839d..2f1a4ce115 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -204,17 +204,19 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) {
undo_redo->commit_action();
}
-void CanvasItemEditor::_unhandled_key_input(const InputEvent &p_ev) {
+void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) {
+
+ Ref<InputEventKey> k = p_ev;
if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
return;
- if (p_ev.key.mod.control)
+ if (k->get_control())
return;
- if (p_ev.key.pressed && !p_ev.key.echo && p_ev.key.scancode == KEY_V && drag == DRAG_NONE && can_move_pivot) {
+ if (k->is_pressed() && !k->is_echo() && k->get_scancode() == KEY_V && drag == DRAG_NONE && can_move_pivot) {
- if (p_ev.key.mod.shift) {
+ if (k->get_shift()) {
//move drag pivot
drag = DRAG_PIVOT;
} else if (!Input::get_singleton()->is_mouse_button_pressed(0)) {
@@ -958,9 +960,9 @@ bool CanvasItemEditor::get_remove_list(List<Node *> *p_list) {
return false; //!p_list->empty();
}
-void CanvasItemEditor::_list_select(const InputEventMouseButton &b) {
+void CanvasItemEditor::_list_select(const Ref<InputEventMouseButton> &b) {
- Point2 click = Point2(b.x, b.y);
+ Point2 click = b->get_pos();
Node *scene = editor->get_edited_scene();
if (!scene)
@@ -982,7 +984,7 @@ void CanvasItemEditor::_list_select(const InputEventMouseButton &b) {
CanvasItem *item = selection_results[0].item;
selection_results.clear();
- additive_selection = b.mod.shift;
+ additive_selection = b->get_shift();
if (!_select(item, click, additive_selection, false))
return;
@@ -1012,9 +1014,9 @@ void CanvasItemEditor::_list_select(const InputEventMouseButton &b) {
"\nType: " + item->get_class() + "\nPath: " + node_path);
}
- additive_selection = b.mod.shift;
+ additive_selection = b->get_shift();
- selection_menu->set_global_position(Vector2(b.global_x, b.global_y));
+ selection_menu->set_global_position(b->get_global_pos());
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
selection_menu->set_invalidate_click_until_motion();
@@ -1023,7 +1025,7 @@ void CanvasItemEditor::_list_select(const InputEventMouseButton &b) {
}
}
-void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
+void CanvasItemEditor::_viewport_gui_input(const Ref<InputEvent> &p_event) {
{
@@ -1039,19 +1041,19 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> b = p_event;
- const InputEventMouseButton &b = p_event.mouse_button;
+ if (b.is_valid()) {
- if (b.button_index == BUTTON_WHEEL_DOWN) {
+ if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
if (zoom < MIN_ZOOM)
return;
float prev_zoom = zoom;
- zoom = zoom * (1 - (0.05 * b.factor));
+ zoom = zoom * (1 - (0.05 * b->get_factor()));
{
- Point2 ofs(b.x, b.y);
+ Point2 ofs = b->get_pos();
ofs = ofs / prev_zoom - ofs / zoom;
h_scroll->set_value(h_scroll->get_value() + ofs.x);
v_scroll->set_value(v_scroll->get_value() + ofs.y);
@@ -1061,15 +1063,15 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
return;
}
- if (b.button_index == BUTTON_WHEEL_UP) {
+ if (b->get_button_index() == BUTTON_WHEEL_UP) {
if (zoom > MAX_ZOOM)
return;
float prev_zoom = zoom;
- zoom = zoom * ((0.95 + (0.05 * b.factor)) / 0.95);
+ zoom = zoom * ((0.95 + (0.05 * b->get_factor())) / 0.95);
{
- Point2 ofs(b.x, b.y);
+ Point2 ofs = b->get_pos();
ofs = ofs / prev_zoom - ofs / zoom;
h_scroll->set_value(h_scroll->get_value() + ofs.x);
v_scroll->set_value(v_scroll->get_value() + ofs.y);
@@ -1080,9 +1082,9 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
return;
}
- if (b.button_index == BUTTON_RIGHT) {
+ if (b->get_button_index() == BUTTON_RIGHT) {
- if (b.pressed && (tool == TOOL_SELECT && b.mod.alt)) {
+ if (b->is_pressed() && (tool == TOOL_SELECT && b->get_alt())) {
_list_select(b);
return;
@@ -1129,7 +1131,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
} else if (box_selecting) {
box_selecting = false;
viewport->update();
- } else if (b.pressed) {
+ } else if (b->is_pressed()) {
#if 0
ref_item = NULL;
Node* scene = get_scene()->get_root_node()->cast_to<EditorNode>()->get_edited_scene();
@@ -1145,16 +1147,16 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
return;
*/
- if (b.button_index == BUTTON_LEFT && tool == TOOL_LIST_SELECT) {
- if (b.pressed)
+ if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_LIST_SELECT) {
+ if (b->is_pressed())
_list_select(b);
return;
}
- if (b.button_index == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) {
- if (b.pressed) {
+ if (b->get_button_index() == BUTTON_LEFT && tool == TOOL_EDIT_PIVOT) {
+ if (b->is_pressed()) {
- Point2 mouse_pos(b.x, b.y);
+ Point2 mouse_pos = b->get_pos();
mouse_pos = transform.affine_inverse().xform(mouse_pos);
mouse_pos = snap_point(mouse_pos);
_edit_set_pivot(mouse_pos);
@@ -1162,10 +1164,10 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
return;
}
- if (tool == TOOL_PAN || b.button_index != BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ if (tool == TOOL_PAN || b->get_button_index() != BUTTON_LEFT || Input::get_singleton()->is_key_pressed(KEY_SPACE))
return;
- if (!b.pressed) {
+ if (!b->is_pressed()) {
if (drag != DRAG_NONE) {
@@ -1227,7 +1229,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
if (box_selecting) {
#if 0
- if ( ! b.mod.shift ) _clear_canvas_items();
+ if ( ! b->get_shift() ) _clear_canvas_items();
if ( box_selection_end() ) return;
#endif
@@ -1272,8 +1274,8 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
E->get().to
};
- Vector2 p = Geometry::get_closest_point_to_segment_2d(Vector2(b.x, b.y), s);
- float d = p.distance_to(Vector2(b.x, b.y));
+ Vector2 p = Geometry::get_closest_point_to_segment_2d(b->get_pos(), s);
+ float d = p.distance_to(b->get_pos());
if (d < bone_width && d < closest_dist) {
Cbone = E;
closest_dist = d;
@@ -1340,9 +1342,9 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
CanvasItemEditorSelectedItem *se = editor_selection->get_node_editor_data<CanvasItemEditorSelectedItem>(canvas_item);
ERR_FAIL_COND(!se);
- Point2 click(b.x, b.y);
+ Point2 click = b->get_pos();
- if ((b.mod.control && tool == TOOL_SELECT) || tool == TOOL_ROTATE) {
+ if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) {
drag = DRAG_ROTATE;
drag_from = transform.affine_inverse().xform(click);
@@ -1361,7 +1363,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
if (tool == TOOL_SELECT) {
drag = _find_drag_type(xform, rect, click, drag_point_from);
- if (b.doubleclick) {
+ if (b->is_doubleclick()) {
if (canvas_item->get_filename() != "" && canvas_item != editor->get_edited_scene()) {
@@ -1386,9 +1388,9 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
//multi canvas_item edit
- Point2 click = Point2(b.x, b.y);
+ Point2 click = b->get_pos();
- if ((b.mod.alt || tool == TOOL_MOVE) && get_item_count()) {
+ if ((b->get_alt() || tool == TOOL_MOVE) && get_item_count()) {
_prepare_drag(click);
viewport->update();
return;
@@ -1433,37 +1435,36 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
};
c = n->cast_to<CanvasItem>();
#if 0
- if ( b.pressed ) box_selection_start( click );
+ if ( b->is_pressed() ) box_selection_start( click );
#endif
- additive_selection = b.mod.shift;
+ additive_selection = b->get_shift();
if (!_select(c, click, additive_selection))
return;
}
- if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> m = p_event;
+ if (m.is_valid()) {
if (!viewport->has_focus() && (!get_focus_owner() || !get_focus_owner()->is_text_field()))
viewport->call_deferred("grab_focus");
- const InputEventMouseMotion &m = p_event.mouse_motion;
-
if (box_selecting) {
- box_selecting_to = transform.affine_inverse().xform(Point2(m.x, m.y));
+ box_selecting_to = transform.affine_inverse().xform(m->get_pos());
viewport->update();
return;
}
if (drag == DRAG_NONE) {
- if ((m.button_mask & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m.button_mask & BUTTON_MASK_MIDDLE || (m.button_mask & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
+ if ((m->get_button_mask() & BUTTON_MASK_LEFT && tool == TOOL_PAN) || m->get_button_mask() & BUTTON_MASK_MIDDLE || (m->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE))) {
Point2i relative;
if (bool(EditorSettings::get_singleton()->get("editors/2d/warped_mouse_panning"))) {
relative = Input::get_singleton()->warp_mouse_motion(m, viewport->get_global_rect());
} else {
- relative = Point2i(m.relative_x, m.relative_y);
+ relative = m->get_relative();
}
h_scroll->set_value(h_scroll->get_value() - relative.x / zoom);
@@ -1496,7 +1497,7 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
}
Vector2 dfrom = drag_from;
- Vector2 dto = transform.affine_inverse().xform(Point2(m.x, m.y));
+ Vector2 dto = transform.affine_inverse().xform(m->get_pos());
if (canvas_item->has_meta("_edit_lock_"))
continue;
@@ -1530,8 +1531,8 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
continue;
}
- bool uniform = m.mod.shift;
- bool symmetric = m.mod.alt;
+ bool uniform = b->get_shift();
+ bool symmetric = b->get_alt();
dto = dto - (drag == DRAG_ALL || drag == DRAG_NODE_2D ? drag_from - drag_point_from : Vector2(0, 0));
@@ -1765,25 +1766,25 @@ void CanvasItemEditor::_viewport_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_event;
- const InputEventKey &k = p_event.key;
+ if (k.is_valid()) {
- if (k.pressed && drag == DRAG_NONE) {
+ if (k->is_pressed() && drag == DRAG_NONE) {
KeyMoveMODE move_mode = MOVE_VIEW_BASE;
- if (k.mod.alt) move_mode = MOVE_LOCAL_BASE;
- if (k.mod.control || k.mod.meta) move_mode = MOVE_LOCAL_WITH_ROT;
-
- if (k.scancode == KEY_UP)
- _key_move(Vector2(0, -1), k.mod.shift, move_mode);
- else if (k.scancode == KEY_DOWN)
- _key_move(Vector2(0, 1), k.mod.shift, move_mode);
- else if (k.scancode == KEY_LEFT)
- _key_move(Vector2(-1, 0), k.mod.shift, move_mode);
- else if (k.scancode == KEY_RIGHT)
- _key_move(Vector2(1, 0), k.mod.shift, move_mode);
- else if (k.scancode == KEY_ESCAPE) {
+ if (k->get_alt()) move_mode = MOVE_LOCAL_BASE;
+ if (k->get_control() || k->get_metakey()) move_mode = MOVE_LOCAL_WITH_ROT;
+
+ if (k->get_scancode() == KEY_UP)
+ _key_move(Vector2(0, -1), k->get_shift(), move_mode);
+ else if (k->get_scancode() == KEY_DOWN)
+ _key_move(Vector2(0, 1), k->get_shift(), move_mode);
+ else if (k->get_scancode() == KEY_LEFT)
+ _key_move(Vector2(-1, 0), k->get_shift(), move_mode);
+ else if (k->get_scancode() == KEY_RIGHT)
+ _key_move(Vector2(1, 0), k->get_shift(), move_mode);
+ else if (k->get_scancode() == KEY_ESCAPE) {
editor_selection->clear();
viewport->update();
} else
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 7f09b92f4c..22fa5b5db8 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -322,7 +322,7 @@ class CanvasItemEditor : public VBoxContainer {
void _clear_canvas_items();
void _visibility_changed(ObjectID p_canvas_item);
void _key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE p_move_mode);
- void _list_select(const InputEventMouseButton &b);
+ void _list_select(const Ref<InputEventMouseButton> &b);
DragType _find_drag_type(const Transform2D &p_xform, const Rect2 &p_local_rect, const Point2 &p_click, Vector2 &r_point);
void _prepare_drag(const Point2 &p_click_pos);
@@ -352,9 +352,9 @@ class CanvasItemEditor : public VBoxContainer {
int get_item_count();
void _keying_changed();
- void _unhandled_key_input(const InputEvent &p_ev);
+ void _unhandled_key_input(const Ref<InputEvent> &p_ev);
- void _viewport_gui_input(const InputEvent &p_event);
+ void _viewport_gui_input(const Ref<InputEvent> &p_event);
void _viewport_draw();
void _focus_selection(int p_op);
diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.cpp b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
index ae426ba29e..b7cfcaae02 100644
--- a/editor/plugins/collision_polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_2d_editor_plugin.cpp
@@ -94,213 +94,208 @@ void CollisionPolygon2DEditor::_wip_close() {
edited_point = -1;
}
-bool CollisionPolygon2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool CollisionPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- const InputEventMouseButton &mb = p_event.mouse_button;
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Vector<Vector2> poly = node->get_polygon();
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+ //first check if a point is to be added (segment split)
+ real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- Vector<Vector2> poly = node->get_polygon();
+ switch (mode) {
- //first check if a point is to be added (segment split)
- real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
+ case MODE_CREATE: {
- switch (mode) {
+ if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
- case MODE_CREATE: {
+ if (!wip_active) {
- if (mb.button_index == BUTTON_LEFT && mb.pressed) {
+ wip.clear();
+ wip.push_back(cpoint);
+ wip_active = true;
+ edited_point_pos = cpoint;
+ canvas_item_editor->get_viewport_control()->update();
+ edited_point = 1;
+ return true;
+ } else {
- if (!wip_active) {
+ if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
+ //wip closed
+ _wip_close();
- wip.clear();
- wip.push_back(cpoint);
- wip_active = true;
- edited_point_pos = cpoint;
- canvas_item_editor->get_viewport_control()->update();
- edited_point = 1;
return true;
} else {
- if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
- //wip closed
- _wip_close();
-
- return true;
- } else {
-
- wip.push_back(cpoint);
- edited_point = wip.size();
- canvas_item_editor->get_viewport_control()->update();
- return true;
+ wip.push_back(cpoint);
+ edited_point = wip.size();
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
- //add wip point
- }
+ //add wip point
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) {
- _wip_close();
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) {
+ _wip_close();
+ }
- } break;
-
- case MODE_EDIT: {
+ } break;
- if (mb.button_index == BUTTON_LEFT) {
- if (mb.pressed) {
+ case MODE_EDIT: {
- if (mb.mod.control) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_pressed()) {
- if (poly.size() < 3) {
+ if (mb->get_control()) {
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_undo_method(node, "set_polygon", poly);
- poly.push_back(cpoint);
- undo_redo->add_do_method(node, "set_polygon", poly);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- }
-
- //search edges
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
-
- Vector2 points[2] = { xform.xform(poly[i]),
- xform.xform(poly[(i + 1) % poly.size()]) };
-
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
- if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
- continue; //not valid to reuse point
-
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
- }
-
- if (closest_idx >= 0) {
+ if (poly.size() < 3) {
- pre_move_edit = poly;
- poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
- edited_point = closest_idx + 1;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- node->set_polygon(poly);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
- } else {
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_undo_method(node, "set_polygon", poly);
+ poly.push_back(cpoint);
+ undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
- //look for points to move
+ //search edges
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
+ Vector2 points[2] = { xform.xform(poly[i]),
+ xform.xform(poly[(i + 1) % poly.size()]) };
- Vector2 cp = xform.xform(poly[i]);
+ Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
+ if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
+ continue; //not valid to reuse point
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
}
+ }
- if (closest_idx >= 0) {
+ if (closest_idx >= 0) {
- pre_move_edit = poly;
- edited_point = closest_idx;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
+ pre_move_edit = poly;
+ poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
+ edited_point = closest_idx + 1;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ node->set_polygon(poly);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
} else {
- if (edited_point != -1) {
+ //look for points to move
- //apply
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
- poly[edited_point] = edited_point_pos;
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_do_method(node, "set_polygon", poly);
- undo_redo->add_undo_method(node, "set_polygon", pre_move_edit);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ Vector2 cp = xform.xform(poly[i]);
- edited_point = -1;
- return true;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
}
- }
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) {
-
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
- Vector2 cp = xform.xform(poly[i]);
+ if (closest_idx >= 0) {
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
+ pre_move_edit = poly;
+ edited_point = closest_idx;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
}
+ } else {
+
+ if (edited_point != -1) {
- if (closest_idx >= 0) {
+ //apply
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node, "set_polygon", poly);
- poly.remove(closest_idx);
+ ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
+ poly[edited_point] = edited_point_pos;
+ undo_redo->create_action(TTR("Edit Poly"));
undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_undo_method(node, "set_polygon", pre_move_edit);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->commit_action();
+
+ edited_point = -1;
return true;
}
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) {
- } break;
- }
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- } break;
- case InputEvent::MOUSE_MOTION: {
+ Vector2 cp = xform.xform(poly[i]);
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
+ }
- if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) {
+ if (closest_idx >= 0) {
- Vector2 gpoint = Point2(mm.x, mm.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+ undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
+ undo_redo->add_undo_method(node, "set_polygon", poly);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
+ }
- canvas_item_editor->get_viewport_control()->update();
- }
+ } break;
+ }
+ }
- } break;
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) {
+
+ Vector2 gpoint = mm->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
}
return false;
diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h
index babe653581..382c0d6c37 100644
--- a/editor/plugins/collision_polygon_2d_editor_plugin.h
+++ b/editor/plugins/collision_polygon_2d_editor_plugin.h
@@ -80,7 +80,7 @@ protected:
static void _bind_methods();
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_collision_polygon);
CollisionPolygon2DEditor(EditorNode *p_editor);
};
@@ -93,7 +93,7 @@ class CollisionPolygon2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "CollisionPolygon2D"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp
index fdb1bf984e..c89e6f59a4 100644
--- a/editor/plugins/collision_polygon_editor_plugin.cpp
+++ b/editor/plugins/collision_polygon_editor_plugin.cpp
@@ -131,7 +131,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
- Vector2 gpoint=Point2(mb.x,mb.y);
+ Vector2 gpoint=Point2(mb->get_pos().x,mb->get_pos().y);
Vector3 ray_from = p_camera->project_ray_origin(gpoint);
Vector3 ray_dir = p_camera->project_ray_normal(gpoint);
@@ -156,7 +156,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
case MODE_CREATE: {
- if (mb.button_index==BUTTON_LEFT && mb.pressed) {
+ if (mb->get_button_index()==BUTTON_LEFT && mb->is_pressed()) {
if (!wip_active) {
@@ -186,7 +186,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
//add wip point
}
}
- } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) {
+ } else if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && wip_active) {
_wip_close();
}
@@ -196,10 +196,10 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
case MODE_EDIT: {
- if (mb.button_index==BUTTON_LEFT) {
- if (mb.pressed) {
+ if (mb->get_button_index()==BUTTON_LEFT) {
+ if (mb->is_pressed()) {
- if (mb.mod.control) {
+ if (mb->get_control()) {
if (poly.size() < 3) {
@@ -297,7 +297,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
return true;
}
}
- } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) {
+ } if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && edited_point==-1) {
@@ -344,7 +344,7 @@ bool CollisionPolygonEditor::forward_spatial_gui_input(Camera* p_camera,const In
const InputEventMouseMotion &mm=p_event.mouse_motion;
- if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) {
+ if (edited_point!=-1 && (wip_active || mm->get_button_mask()&BUTTON_MASK_LEFT)) {
Vector2 gpoint = Point2(mm.x,mm.y);
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp
index 70cc81efb0..e2184c6158 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.cpp
+++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp
@@ -302,7 +302,7 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) {
undo_redo->commit_action();
}
-bool CollisionShape2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool CollisionShape2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node) {
return false;
@@ -316,68 +316,66 @@ bool CollisionShape2DEditor::forward_gui_input(const InputEvent &p_event) {
return false;
}
- switch (p_event.type) {
- case InputEvent::MOUSE_BUTTON: {
- const InputEventMouseButton &mb = p_event.mouse_button;
+ Ref<InputEventMouseButton> mb = p_event;
- Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ if (mb.is_valid()) {
- Point2 gpoint(mb.x, mb.y);
+ Transform2D gt = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- if (mb.button_index == BUTTON_LEFT) {
- if (mb.pressed) {
- for (int i = 0; i < handles.size(); i++) {
- if (gt.xform(handles[i]).distance_to(gpoint) < 8) {
- edit_handle = i;
+ Point2 gpoint(mb->get_pos().x, mb->get_pos().y);
- break;
- }
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_pressed()) {
+ for (int i = 0; i < handles.size(); i++) {
+ if (gt.xform(handles[i]).distance_to(gpoint) < 8) {
+ edit_handle = i;
+
+ break;
}
+ }
- if (edit_handle == -1) {
- pressed = false;
+ if (edit_handle == -1) {
+ pressed = false;
- return false;
- }
+ return false;
+ }
- original = get_handle_value(edit_handle);
- pressed = true;
+ original = get_handle_value(edit_handle);
+ pressed = true;
- return true;
+ return true;
- } else {
- if (pressed) {
- commit_handle(edit_handle, original);
+ } else {
+ if (pressed) {
+ commit_handle(edit_handle, original);
- edit_handle = -1;
- pressed = false;
+ edit_handle = -1;
+ pressed = false;
- return true;
- }
+ return true;
}
}
+ }
- return false;
-
- } break;
+ return false;
+ }
- case InputEvent::MOUSE_MOTION: {
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_event;
- if (edit_handle == -1 || !pressed) {
- return false;
- }
+ if (mm.is_valid()) {
- Point2 gpoint = Point2(mm.x, mm.y);
- Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+ if (edit_handle == -1 || !pressed) {
+ return false;
+ }
- set_handle(edit_handle, cpoint);
+ Point2 gpoint = mm->get_pos();
+ Point2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
- return true;
+ set_handle(edit_handle, cpoint);
- } break;
+ return true;
}
return false;
diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h
index bbd94516a8..09aefc65c0 100644
--- a/editor/plugins/collision_shape_2d_editor_plugin.h
+++ b/editor/plugins/collision_shape_2d_editor_plugin.h
@@ -74,7 +74,7 @@ protected:
static void _bind_methods();
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_node);
CollisionShape2DEditor(EditorNode *p_editor);
@@ -87,7 +87,7 @@ class CollisionShape2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_shape_2d_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_shape_2d_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "CollisionShape2D"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp
index f3ad5c0fd1..6dd94863a1 100644
--- a/editor/plugins/curve_editor_plugin.cpp
+++ b/editor/plugins/curve_editor_plugin.cpp
@@ -33,9 +33,10 @@
#include "os/keyboard.h"
#include "spatial_editor_plugin.h"
-void CurveTextureEdit::_gui_input(const InputEvent &p_event) {
+void CurveTextureEdit::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode == KEY_DELETE && grabbed != -1) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -44,7 +45,9 @@ void CurveTextureEdit::_gui_input(const InputEvent &p_event) {
accept_event();
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
update();
Ref<Font> font = get_font("font", "Label");
@@ -54,7 +57,7 @@ void CurveTextureEdit::_gui_input(const InputEvent &p_event) {
Vector2 size = get_size();
size.y -= font_h;
- Point2 p = Vector2(p_event.mouse_button.x, p_event.mouse_button.y) / size;
+ Point2 p = Vector2(mb->get_pos().x, mb->get_pos().y) / size;
p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min;
grabbed = -1;
grabbing = true;
@@ -90,7 +93,7 @@ void CurveTextureEdit::_gui_input(const InputEvent &p_event) {
emit_signal("curve_changed");
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && !p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
if (grabbing) {
grabbing = false;
@@ -99,14 +102,16 @@ void CurveTextureEdit::_gui_input(const InputEvent &p_event) {
update();
}
- if (p_event.type == InputEvent::MOUSE_MOTION && grabbing && grabbed != -1) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid() && grabbing && grabbed != -1) {
Ref<Font> font = get_font("font", "Label");
int font_h = font->get_height();
Vector2 size = get_size();
size.y -= font_h;
- Point2 p = Vector2(p_event.mouse_motion.x, p_event.mouse_motion.y) / size;
+ Point2 p = mm->get_pos() / size;
p.y = CLAMP(1.0 - p.y, 0, 1) * (max - min) + min;
p.x = CLAMP(p.x, 0.0, 1.0);
diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h
index ebe05539aa..4e75ba407c 100644
--- a/editor/plugins/curve_editor_plugin.h
+++ b/editor/plugins/curve_editor_plugin.h
@@ -54,7 +54,7 @@ class CurveTextureEdit : public Control {
void _plot_curve(const Vector2 &p_a, const Vector2 &p_b, const Vector2 &p_c, const Vector2 &p_d);
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/plugins/gradient_texture_editor_plugin.cpp b/editor/plugins/gradient_texture_editor_plugin.cpp
index 005633a10e..40f7de478d 100644
--- a/editor/plugins/gradient_texture_editor_plugin.cpp
+++ b/editor/plugins/gradient_texture_editor_plugin.cpp
@@ -77,9 +77,11 @@ void GradientTextureEdit::_show_color_picker() {
GradientTextureEdit::~GradientTextureEdit() {
}
-void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
+void GradientTextureEdit::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode == KEY_DELETE && grabbed != -1) {
+ Ref<InputEventKey> k = p_event;
+
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -89,16 +91,17 @@ void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
accept_event();
}
+ Ref<InputEventMouseButton> mb = p_event;
//Show color picker on double click.
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.doubleclick && p_event.mouse_button.pressed) {
- grabbed = _get_point_from_pos(p_event.mouse_button.x);
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) {
+ grabbed = _get_point_from_pos(mb->get_pos().x);
_show_color_picker();
accept_event();
}
//Delete point on right click
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 2 && p_event.mouse_button.pressed) {
- grabbed = _get_point_from_pos(p_event.mouse_button.x);
+ if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
+ grabbed = _get_point_from_pos(mb->get_pos().x);
if (grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -110,9 +113,9 @@ void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
}
//Hold alt key to duplicate selected color
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed && p_event.key.mod.alt) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) {
- int x = p_event.mouse_button.x;
+ int x = mb->get_pos().x;
grabbed = _get_point_from_pos(x);
if (grabbed != -1) {
@@ -134,10 +137,10 @@ void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
update();
- int x = p_event.mouse_button.x;
+ int x = mb->get_pos().x;
int total_w = get_size().width - get_size().height - 3;
//Check if color selector was clicked.
@@ -202,7 +205,7 @@ void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
emit_signal("ramp_changed");
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && !p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
if (grabbing) {
grabbing = false;
@@ -211,15 +214,17 @@ void GradientTextureEdit::_gui_input(const InputEvent &p_event) {
update();
}
- if (p_event.type == InputEvent::MOUSE_MOTION && grabbing) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid() && grabbing) {
int total_w = get_size().width - get_size().height - 3;
- int x = p_event.mouse_motion.x;
+ int x = mm->get_pos().x;
float newofs = CLAMP(x / float(total_w), 0, 1);
//Snap to nearest point if holding shift
- if (p_event.key.mod.shift) {
+ if (mm->get_shift()) {
float snap_treshhold = 0.03;
float smallest_ofs = snap_treshhold;
bool founded = false;
diff --git a/editor/plugins/gradient_texture_editor_plugin.h b/editor/plugins/gradient_texture_editor_plugin.h
index cb2f6b4061..842d586541 100644
--- a/editor/plugins/gradient_texture_editor_plugin.h
+++ b/editor/plugins/gradient_texture_editor_plugin.h
@@ -53,7 +53,7 @@ class GradientTextureEdit : public Control {
void _show_color_picker();
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.cpp b/editor/plugins/light_occluder_2d_editor_plugin.cpp
index 73b615d817..9c9e010b47 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.cpp
+++ b/editor/plugins/light_occluder_2d_editor_plugin.cpp
@@ -98,225 +98,223 @@ void LightOccluder2DEditor::_wip_close(bool p_closed) {
edited_point = -1;
}
-bool LightOccluder2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool LightOccluder2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
if (node->get_occluder_polygon().is_null()) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
create_poly->set_text("No OccluderPolygon2D resource on this node.\nCreate and assign one?");
create_poly->popup_centered_minsize();
}
- return (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1);
+ return (mb.is_valid() && mb->get_button_index() == 1);
}
- switch (p_event.type) {
- case InputEvent::MOUSE_BUTTON: {
+ Ref<InputEventMouseButton> mb = p_event;
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid()) {
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
- Vector<Vector2> poly = Variant(node->get_occluder_polygon()->get_polygon());
+ Vector<Vector2> poly = Variant(node->get_occluder_polygon()->get_polygon());
- //first check if a point is to be added (segment split)
- real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
+ //first check if a point is to be added (segment split)
+ real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- switch (mode) {
+ switch (mode) {
- case MODE_CREATE: {
+ case MODE_CREATE: {
- if (mb.button_index == BUTTON_LEFT && mb.pressed) {
+ if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
- if (!wip_active) {
+ if (!wip_active) {
- wip.clear();
- wip.push_back(cpoint);
- wip_active = true;
- edited_point_pos = cpoint;
- canvas_item_editor->get_viewport_control()->update();
- edited_point = 1;
- return true;
- } else {
+ wip.clear();
+ wip.push_back(cpoint);
+ wip_active = true;
+ edited_point_pos = cpoint;
+ canvas_item_editor->get_viewport_control()->update();
+ edited_point = 1;
+ return true;
+ } else {
- if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
- //wip closed
- _wip_close(true);
+ if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
+ //wip closed
+ _wip_close(true);
- return true;
- } else if (wip.size() > 1 && xform.xform(wip[wip.size() - 1]).distance_to(gpoint) < grab_treshold) {
- //wip closed
- _wip_close(false);
- return true;
+ return true;
+ } else if (wip.size() > 1 && xform.xform(wip[wip.size() - 1]).distance_to(gpoint) < grab_treshold) {
+ //wip closed
+ _wip_close(false);
+ return true;
- } else {
+ } else {
- wip.push_back(cpoint);
- edited_point = wip.size();
- canvas_item_editor->get_viewport_control()->update();
- return true;
+ wip.push_back(cpoint);
+ edited_point = wip.size();
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
- //add wip point
- }
+ //add wip point
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) {
- _wip_close(true);
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) {
+ _wip_close(true);
+ }
- } break;
-
- case MODE_EDIT: {
-
- if (mb.button_index == BUTTON_LEFT) {
- if (mb.pressed) {
-
- if (mb.mod.control) {
+ } break;
- if (poly.size() < 3) {
+ case MODE_EDIT: {
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
- poly.push_back(cpoint);
- undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- }
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_pressed()) {
- //search edges
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
-
- Vector2 points[2] = { xform.xform(poly[i]),
- xform.xform(poly[(i + 1) % poly.size()]) };
-
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
- if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
- continue; //not valid to reuse point
-
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
- }
+ if (mb->get_control()) {
- if (closest_idx >= 0) {
+ if (poly.size() < 3) {
- pre_move_edit = poly;
- poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
- edited_point = closest_idx + 1;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- node->get_occluder_polygon()->set_polygon(Variant(poly));
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
- } else {
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
+ poly.push_back(cpoint);
+ undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
- //look for points to move
+ //search edges
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
+ Vector2 points[2] = { xform.xform(poly[i]),
+ xform.xform(poly[(i + 1) % poly.size()]) };
- Vector2 cp = xform.xform(poly[i]);
+ Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
+ if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
+ continue; //not valid to reuse point
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
}
+ }
- if (closest_idx >= 0) {
+ if (closest_idx >= 0) {
- pre_move_edit = poly;
- edited_point = closest_idx;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
+ pre_move_edit = poly;
+ poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
+ edited_point = closest_idx + 1;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ node->get_occluder_polygon()->set_polygon(Variant(poly));
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
} else {
- if (edited_point != -1) {
+ //look for points to move
- //apply
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
- poly[edited_point] = edited_point_pos;
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
- undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", pre_move_edit);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ Vector2 cp = xform.xform(poly[i]);
- edited_point = -1;
- return true;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
}
- }
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) {
-
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
- Vector2 cp = xform.xform(poly[i]);
+ if (closest_idx >= 0) {
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
+ pre_move_edit = poly;
+ edited_point = closest_idx;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
}
+ } else {
+
+ if (edited_point != -1) {
- if (closest_idx >= 0) {
+ //apply
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
- poly.remove(closest_idx);
+ ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
+ poly[edited_point] = edited_point_pos;
+ undo_redo->create_action(TTR("Edit Poly"));
undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
+ undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", pre_move_edit);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->commit_action();
+
+ edited_point = -1;
return true;
}
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) {
- } break;
- }
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- } break;
- case InputEvent::MOUSE_MOTION: {
+ Vector2 cp = xform.xform(poly[i]);
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
+ }
- if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) {
+ if (closest_idx >= 0) {
- Vector2 gpoint = Point2(mm.x, mm.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+ undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
+ undo_redo->add_undo_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node->get_occluder_polygon().ptr(), "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
+ }
- canvas_item_editor->get_viewport_control()->update();
- }
+ } break;
+ }
+ }
- } break;
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) {
+
+ Vector2 gpoint = mm->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
}
return false;
diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h
index 8e0817e61e..d6579fc94c 100644
--- a/editor/plugins/light_occluder_2d_editor_plugin.h
+++ b/editor/plugins/light_occluder_2d_editor_plugin.h
@@ -84,7 +84,7 @@ protected:
public:
Vector2 snap_point(const Vector2 &p_point) const;
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_collision_polygon);
LightOccluder2DEditor(EditorNode *p_editor);
};
@@ -97,7 +97,7 @@ class LightOccluder2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "LightOccluder2D"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/line_2d_editor_plugin.cpp b/editor/plugins/line_2d_editor_plugin.cpp
index 4df0d2605a..3497af3602 100644
--- a/editor/plugins/line_2d_editor_plugin.cpp
+++ b/editor/plugins/line_2d_editor_plugin.cpp
@@ -75,7 +75,7 @@ int Line2DEditor::get_point_index_at(Vector2 gpos) {
return -1;
}
-bool Line2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool Line2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
@@ -83,75 +83,74 @@ bool Line2DEditor::forward_gui_input(const InputEvent &p_event) {
if (!node->is_visible())
return false;
- switch (p_event.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- const InputEventMouseButton &mb = p_event.mouse_button;
-
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = mouse_to_local_pos(gpoint, mb.mod.alt);
-
- if (mb.pressed && _dragging == false) {
- int i = get_point_index_at(gpoint);
- if (i != -1) {
- if (mb.button_index == BUTTON_LEFT && !mb.mod.shift && mode == MODE_EDIT) {
- _dragging = true;
- action_point = i;
- moving_from = node->get_point_pos(i);
- moving_screen_from = gpoint;
- } else if ((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) {
- undo_redo->create_action(TTR("Remove Point from Line2D"));
- undo_redo->add_do_method(node, "remove_point", i);
- undo_redo->add_undo_method(node, "add_point", node->get_point_pos(i), i);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- }
- return true;
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid()) {
+
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = mouse_to_local_pos(gpoint, mb->get_alt());
+
+ if (mb->is_pressed() && _dragging == false) {
+ int i = get_point_index_at(gpoint);
+ if (i != -1) {
+ if (mb->get_button_index() == BUTTON_LEFT && !mb->get_shift() && mode == MODE_EDIT) {
+ _dragging = true;
+ action_point = i;
+ moving_from = node->get_point_pos(i);
+ moving_screen_from = gpoint;
+ } else if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) {
+ undo_redo->create_action(TTR("Remove Point from Line2D"));
+ undo_redo->add_do_method(node, "remove_point", i);
+ undo_redo->add_undo_method(node, "add_point", node->get_point_pos(i), i);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
}
+ return true;
}
+ }
- if (mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) {
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && ((mb->get_command() && mode == MODE_EDIT) || mode == MODE_CREATE)) {
- undo_redo->create_action(TTR("Add Point to Line2D"));
- undo_redo->add_do_method(node, "add_point", cpoint);
- undo_redo->add_undo_method(node, "remove_point", node->get_point_count());
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ undo_redo->create_action(TTR("Add Point to Line2D"));
+ undo_redo->add_do_method(node, "add_point", cpoint);
+ undo_redo->add_undo_method(node, "remove_point", node->get_point_count());
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
- _dragging = true;
- action_point = node->get_point_count() - 1;
- moving_from = node->get_point_pos(action_point);
- moving_screen_from = gpoint;
+ _dragging = true;
+ action_point = node->get_point_count() - 1;
+ moving_from = node->get_point_pos(action_point);
+ moving_screen_from = gpoint;
- canvas_item_editor->get_viewport_control()->update();
+ canvas_item_editor->get_viewport_control()->update();
- return true;
- }
+ return true;
+ }
- if (!mb.pressed && mb.button_index == BUTTON_LEFT && _dragging) {
- undo_redo->create_action(TTR("Move Point in Line2D"));
- undo_redo->add_do_method(node, "set_point_pos", action_point, cpoint);
- undo_redo->add_undo_method(node, "set_point_pos", action_point, moving_from);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- _dragging = false;
- return true;
- }
- } break;
-
- case InputEvent::MOUSE_MOTION: {
- if (_dragging) {
- const InputEventMouseMotion &mm = p_event.mouse_motion;
- Vector2 cpoint = mouse_to_local_pos(Vector2(mm.x, mm.y), mm.mod.alt);
- node->set_point_pos(action_point, cpoint);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
- } break;
+ if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && _dragging) {
+ undo_redo->create_action(TTR("Move Point in Line2D"));
+ undo_redo->add_do_method(node, "set_point_pos", action_point, cpoint);
+ undo_redo->add_undo_method(node, "set_point_pos", action_point, moving_from);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ _dragging = false;
+ return true;
+ }
+ }
+
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ if (_dragging) {
+ Vector2 cpoint = mouse_to_local_pos(mm->get_pos(), mm->get_alt());
+ node->set_point_pos(action_point, cpoint);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
+ }
}
return false;
diff --git a/editor/plugins/line_2d_editor_plugin.h b/editor/plugins/line_2d_editor_plugin.h
index 7477f7eee5..3a1f841556 100644
--- a/editor/plugins/line_2d_editor_plugin.h
+++ b/editor/plugins/line_2d_editor_plugin.h
@@ -43,7 +43,7 @@ class Line2DEditor : public HBoxContainer {
GDCLASS(Line2DEditor, HBoxContainer)
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_line2d);
Line2DEditor(EditorNode *p_editor);
@@ -95,7 +95,7 @@ class Line2DEditorPlugin : public EditorPlugin {
public:
virtual bool forward_canvas_gui_input(
const Transform2D &p_canvas_xform,
- const InputEvent &p_event) {
+ const Ref<InputEvent> &p_event) {
return line2d_editor->forward_gui_input(p_event);
}
diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp
index 61da860cab..f377d3a7cc 100644
--- a/editor/plugins/mesh_editor_plugin.cpp
+++ b/editor/plugins/mesh_editor_plugin.cpp
@@ -33,10 +33,10 @@
void MeshEditor::_gui_input(InputEvent p_event) {
- if (p_event.type==InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) {
+ if (p_event.type==InputEvent::MOUSE_MOTION && p_event->get_button_mask()&BUTTON_MASK_LEFT) {
- rot_x-=p_event.mouse_motion.relative_y*0.01;
- rot_y-=p_event.mouse_motion.relative_x*0.01;
+ rot_x-=p_event->get_relative().y*0.01;
+ rot_y-=p_event->get_relative().x*0.01;
if (rot_x<-Math_PI/2)
rot_x=-Math_PI/2;
else if (rot_x>Math_PI/2) {
diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp
index be8c46f379..a7fc1d5adb 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.cpp
+++ b/editor/plugins/navigation_polygon_editor_plugin.cpp
@@ -112,263 +112,262 @@ void NavigationPolygonEditor::_wip_close() {
edited_point = -1;
}
-bool NavigationPolygonEditor::forward_gui_input(const InputEvent &p_event) {
+bool NavigationPolygonEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
if (node->get_navigation_polygon().is_null()) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
+
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
create_nav->set_text("No NavigationPolygon resource on this node.\nCreate and assign one?");
create_nav->popup_centered_minsize();
}
- return (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1);
+ return (mb.is_valid() && mb->get_button_index() == 1);
}
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_event.mouse_button;
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+ //first check if a point is to be added (segment split)
+ real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- //first check if a point is to be added (segment split)
- real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
+ switch (mode) {
- switch (mode) {
+ case MODE_CREATE: {
- case MODE_CREATE: {
+ if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
- if (mb.button_index == BUTTON_LEFT && mb.pressed) {
+ if (!wip_active) {
- if (!wip_active) {
+ wip.clear();
+ wip.push_back(cpoint);
+ wip_active = true;
+ edited_point_pos = cpoint;
+ edited_outline = -1;
+ canvas_item_editor->get_viewport_control()->update();
+ edited_point = 1;
+ return true;
+ } else {
+
+ if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
+ //wip closed
+ _wip_close();
- wip.clear();
- wip.push_back(cpoint);
- wip_active = true;
- edited_point_pos = cpoint;
- edited_outline = -1;
- canvas_item_editor->get_viewport_control()->update();
- edited_point = 1;
return true;
} else {
- if (wip.size() > 1 && xform.xform(wip[0]).distance_to(gpoint) < grab_treshold) {
- //wip closed
- _wip_close();
-
- return true;
- } else {
-
- wip.push_back(cpoint);
- edited_point = wip.size();
- canvas_item_editor->get_viewport_control()->update();
- return true;
+ wip.push_back(cpoint);
+ edited_point = wip.size();
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
- //add wip point
- }
+ //add wip point
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) {
- _wip_close();
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) {
+ _wip_close();
+ }
- } break;
+ } break;
- case MODE_EDIT: {
+ case MODE_EDIT: {
- if (mb.button_index == BUTTON_LEFT) {
- if (mb.pressed) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_pressed()) {
- if (mb.mod.control) {
+ if (mb->get_control()) {
- //search edges
- int closest_outline = -1;
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
+ //search edges
+ int closest_outline = -1;
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
- for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
+ for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
- PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
+ PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
- int pc = points.size();
- PoolVector<Vector2>::Read poly = points.read();
+ int pc = points.size();
+ PoolVector<Vector2>::Read poly = points.read();
- for (int i = 0; i < pc; i++) {
+ for (int i = 0; i < pc; i++) {
- Vector2 points[2] = { xform.xform(poly[i]),
- xform.xform(poly[(i + 1) % pc]) };
+ Vector2 points[2] = { xform.xform(poly[i]),
+ xform.xform(poly[(i + 1) % pc]) };
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
- if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
- continue; //not valid to reuse point
+ Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
+ if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
+ continue; //not valid to reuse point
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_outline = j;
- closest_pos = cp;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_outline = j;
+ closest_pos = cp;
+ closest_idx = i;
}
}
+ }
- if (closest_idx >= 0) {
-
- pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline);
- PoolVector<Point2> poly = pre_move_edit;
- poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
- edited_point = closest_idx + 1;
- edited_outline = closest_outline;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- node->get_navigation_polygon()->set_outline(closest_outline, poly);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
- } else {
+ if (closest_idx >= 0) {
+
+ pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline);
+ PoolVector<Point2> poly = pre_move_edit;
+ poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos));
+ edited_point = closest_idx + 1;
+ edited_outline = closest_outline;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ node->get_navigation_polygon()->set_outline(closest_outline, poly);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
+ }
+ } else {
- //look for points to move
- int closest_outline = -1;
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
+ //look for points to move
+ int closest_outline = -1;
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
- for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
+ for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
- PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
+ PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
- int pc = points.size();
- PoolVector<Vector2>::Read poly = points.read();
+ int pc = points.size();
+ PoolVector<Vector2>::Read poly = points.read();
- for (int i = 0; i < pc; i++) {
+ for (int i = 0; i < pc; i++) {
- Vector2 cp = xform.xform(poly[i]);
+ Vector2 cp = xform.xform(poly[i]);
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_outline = j;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_outline = j;
+ closest_idx = i;
}
}
+ }
- if (closest_idx >= 0) {
+ if (closest_idx >= 0) {
- pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline);
- edited_point = closest_idx;
- edited_outline = closest_outline;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
+ pre_move_edit = node->get_navigation_polygon()->get_outline(closest_outline);
+ edited_point = closest_idx;
+ edited_outline = closest_outline;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
- } else {
+ }
+ } else {
- if (edited_point != -1) {
+ if (edited_point != -1) {
- //apply
+ //apply
- PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(edited_outline);
- ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
- poly.set(edited_point, edited_point_pos);
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, poly);
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, pre_move_edit);
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(edited_outline);
+ ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
+ poly.set(edited_point, edited_point_pos);
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, poly);
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", edited_outline, pre_move_edit);
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
- edited_point = -1;
- return true;
- }
+ edited_point = -1;
+ return true;
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) {
+ }
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) {
- int closest_outline = -1;
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
+ int closest_outline = -1;
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
- for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
+ for (int j = 0; j < node->get_navigation_polygon()->get_outline_count(); j++) {
- PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
+ PoolVector<Vector2> points = node->get_navigation_polygon()->get_outline(j);
- int pc = points.size();
- PoolVector<Vector2>::Read poly = points.read();
+ int pc = points.size();
+ PoolVector<Vector2>::Read poly = points.read();
- for (int i = 0; i < pc; i++) {
+ for (int i = 0; i < pc; i++) {
- Vector2 cp = xform.xform(poly[i]);
+ Vector2 cp = xform.xform(poly[i]);
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_outline = j;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_outline = j;
+ closest_idx = i;
}
}
+ }
- if (closest_idx >= 0) {
-
- PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(closest_outline);
-
- if (poly.size() > 3) {
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly);
- poly.remove(closest_idx);
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly);
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- } else {
-
- undo_redo->create_action(TTR("Remove Poly And Point"));
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "add_outline_at_index", poly, closest_outline);
- poly.remove(closest_idx);
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "remove_outline", closest_outline);
- undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- }
- return true;
+ if (closest_idx >= 0) {
+
+ PoolVector<Vector2> poly = node->get_navigation_polygon()->get_outline(closest_outline);
+
+ if (poly.size() > 3) {
+ undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "set_outline", closest_outline, poly);
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ } else {
+
+ undo_redo->create_action(TTR("Remove Poly And Point"));
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "add_outline_at_index", poly, closest_outline);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "remove_outline", closest_outline);
+ undo_redo->add_do_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_undo_method(node->get_navigation_polygon().ptr(), "make_polygons_from_outlines");
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
}
+ return true;
}
+ }
- } break;
- }
-
- } break;
- case InputEvent::MOUSE_MOTION: {
+ } break;
+ }
+ }
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_event;
- if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) {
+ if (mm.is_valid()) {
- Vector2 gpoint = Point2(mm.x, mm.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+ if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) {
- canvas_item_editor->get_viewport_control()->update();
- }
+ Vector2 gpoint = mm->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
- } break;
+ canvas_item_editor->get_viewport_control()->update();
+ }
}
return false;
diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h
index 6de77b5ef3..62a83983fd 100644
--- a/editor/plugins/navigation_polygon_editor_plugin.h
+++ b/editor/plugins/navigation_polygon_editor_plugin.h
@@ -85,7 +85,7 @@ protected:
static void _bind_methods();
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_collision_polygon);
NavigationPolygonEditor(EditorNode *p_editor);
};
@@ -98,7 +98,7 @@ class NavigationPolygonEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "NavigationPolygonInstance"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp
index 045084d2ec..38a2a0c462 100644
--- a/editor/plugins/path_2d_editor_plugin.cpp
+++ b/editor/plugins/path_2d_editor_plugin.cpp
@@ -58,7 +58,7 @@ void Path2DEditor::_node_removed(Node *p_node) {
}
}
-bool Path2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node)
return false;
@@ -69,279 +69,299 @@ bool Path2DEditor::forward_gui_input(const InputEvent &p_event) {
if (!node->get_curve().is_valid())
return false;
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_event.mouse_button;
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
-
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = !mb.mod.alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
-
- //first check if a point is to be added (segment split)
- real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = !mb->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
+ //first check if a point is to be added (segment split)
+ real_t grab_threshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- // Test move point!!
+ // Test move point!!
- if (mb.pressed && action == ACTION_NONE) {
+ if (mb->is_pressed() && action == ACTION_NONE) {
- Ref<Curve2D> curve = node->get_curve();
+ Ref<Curve2D> curve = node->get_curve();
- for (int i = 0; i < curve->get_point_count(); i++) {
+ for (int i = 0; i < curve->get_point_count(); i++) {
- bool pointunder = false;
+ bool pointunder = false;
- real_t dist_to_p = gpoint.distance_to(xform.xform(curve->get_point_pos(i)));
- real_t dist_to_p_out = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)));
- real_t dist_to_p_in = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)));
+ real_t dist_to_p = gpoint.distance_to(xform.xform(curve->get_point_pos(i)));
+ real_t dist_to_p_out = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_out(i)));
+ real_t dist_to_p_in = gpoint.distance_to(xform.xform(curve->get_point_pos(i) + curve->get_point_in(i)));
- if (mb.button_index == BUTTON_LEFT && !mb.mod.shift && mode == MODE_EDIT) {
- if (dist_to_p < grab_threshold) {
+ if (mb->get_button_index() == BUTTON_LEFT && !mb->get_shift() && mode == MODE_EDIT) {
+ if (dist_to_p < grab_threshold) {
- action = ACTION_MOVING_POINT;
- action_point = i;
- moving_from = curve->get_point_pos(i);
- moving_screen_from = gpoint;
- return true;
- }
+ action = ACTION_MOVING_POINT;
+ action_point = i;
+ moving_from = curve->get_point_pos(i);
+ moving_screen_from = gpoint;
+ return true;
}
+ }
- if ((mb.button_index == BUTTON_RIGHT && mode == MODE_EDIT) || (mb.button_index == BUTTON_LEFT && mode == MODE_DELETE)) {
- if (dist_to_p < grab_threshold) {
+ if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) {
+ if (dist_to_p < grab_threshold) {
- undo_redo->create_action(TTR("Remove Point from Curve"));
- undo_redo->add_do_method(curve.ptr(), "remove_point", i);
- undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- } else if (dist_to_p_out < grab_threshold) {
+ undo_redo->create_action(TTR("Remove Point from Curve"));
+ undo_redo->add_do_method(curve.ptr(), "remove_point", i);
+ undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ } else if (dist_to_p_out < grab_threshold) {
- undo_redo->create_action(TTR("Remove Out-Control from Curve"));
- undo_redo->add_do_method(curve.ptr(), "set_point_out", i, Vector2());
- undo_redo->add_undo_method(curve.ptr(), "set_point_out", i, curve->get_point_out(i));
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- } else if (dist_to_p_in < grab_threshold) {
+ undo_redo->create_action(TTR("Remove Out-Control from Curve"));
+ undo_redo->add_do_method(curve.ptr(), "set_point_out", i, Vector2());
+ undo_redo->add_undo_method(curve.ptr(), "set_point_out", i, curve->get_point_out(i));
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ } else if (dist_to_p_in < grab_threshold) {
- undo_redo->create_action(TTR("Remove In-Control from Curve"));
- undo_redo->add_do_method(curve.ptr(), "set_point_in", i, Vector2());
- undo_redo->add_undo_method(curve.ptr(), "set_point_in", i, curve->get_point_in(i));
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- }
+ undo_redo->create_action(TTR("Remove In-Control from Curve"));
+ undo_redo->add_do_method(curve.ptr(), "set_point_in", i, Vector2());
+ undo_redo->add_undo_method(curve.ptr(), "set_point_in", i, curve->get_point_in(i));
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
}
+ }
- if (dist_to_p < grab_threshold)
- pointunder = true;
+ if (dist_to_p < grab_threshold)
+ pointunder = true;
- if (mb.button_index == BUTTON_LEFT && i < (curve->get_point_count() - 1)) {
- if (dist_to_p_out < grab_threshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) {
+ if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) {
+ if (dist_to_p_out < grab_threshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) {
- action = ACTION_MOVING_OUT;
- action_point = i;
- moving_from = curve->get_point_out(i);
- moving_screen_from = gpoint;
- return true;
- }
- }
-
- if (mb.button_index == BUTTON_LEFT && i > 0) {
- if (dist_to_p_in < grab_threshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) {
-
- action = ACTION_MOVING_IN;
- action_point = i;
- moving_from = curve->get_point_in(i);
- moving_screen_from = gpoint;
- return true;
- }
- }
+ action_point = i;
+ moving_from = curve->get_point_pos(i);
+ moving_screen_from = gpoint;
+ return true;
+ } else if ((mb->get_button_index() == BUTTON_RIGHT && mode == MODE_EDIT) || (mb->get_button_index() == BUTTON_LEFT && mode == MODE_DELETE)) {
- if (pointunder)
+ undo_redo->create_action(TTR("Remove Point from Curve"));
+ undo_redo->add_do_method(curve.ptr(), "remove_point", i);
+ undo_redo->add_undo_method(curve.ptr(), "add_point", curve->get_point_pos(i), curve->get_point_in(i), curve->get_point_out(i), i);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
return true;
+ } else
+ pointunder = true;
+ }
+
+ if (pointunder)
+ return true;
+ }
+#if 0
+I think i broke this, was this not suposed to go somewhere?
+ if (mb->get_button_index() == BUTTON_LEFT && i < (curve->get_point_count() - 1)) {
+ Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_out(i));
+ if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) {
+ action = ACTION_MOVING_OUT;
+ action_point = i;
+ moving_from = curve->get_point_out(i);
+ moving_screen_from = gpoint;
+ return true;
}
}
- // Test add point in empty space!
+ if (mb->get_button_index() == BUTTON_LEFT && i > 0) {
+ Point2 p = xform.xform(curve->get_point_pos(i) + curve->get_point_in(i));
+ if (gpoint.distance_to(p) < grab_treshold && (mode == MODE_EDIT || mode == MODE_EDIT_CURVE)) {
- if (mb.pressed && mb.button_index == BUTTON_LEFT && ((mb.mod.command && mode == MODE_EDIT) || mode == MODE_CREATE)) {
+ action = ACTION_MOVING_IN;
+ action_point = i;
+ moving_from = curve->get_point_in(i);
+ moving_screen_from = gpoint;
+ return true;
+ }
+ }
- Ref<Curve2D> curve = node->get_curve();
+ if (pointunder)
+ return true;
+#endif
+ }
- undo_redo->create_action(TTR("Add Point to Curve"));
- undo_redo->add_do_method(curve.ptr(), "add_point", cpoint);
- undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count());
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ // Test add point in empty space!
- action = ACTION_MOVING_POINT;
- action_point = curve->get_point_count() - 1;
- moving_from = curve->get_point_pos(action_point);
- moving_screen_from = gpoint;
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && ((mb->get_command() && mode == MODE_EDIT) || mode == MODE_CREATE)) {
- canvas_item_editor->get_viewport_control()->update();
+ Ref<Curve2D> curve = node->get_curve();
- return true;
- }
+ undo_redo->create_action(TTR("Add Point to Curve"));
+ undo_redo->add_do_method(curve.ptr(), "add_point", cpoint);
+ undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count());
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
- if (!mb.pressed && mb.button_index == BUTTON_LEFT && action != ACTION_NONE) {
+ action = ACTION_MOVING_POINT;
+ action_point = curve->get_point_count() - 1;
+ moving_from = curve->get_point_pos(action_point);
+ moving_screen_from = gpoint;
- Ref<Curve2D> curve = node->get_curve();
+ canvas_item_editor->get_viewport_control()->update();
- Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
- switch (action) {
+ return true;
+ }
- case ACTION_MOVING_POINT: {
+ if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT && action != ACTION_NONE) {
- undo_redo->create_action(TTR("Move Point in Curve"));
- undo_redo->add_do_method(curve.ptr(), "set_point_pos", action_point, cpoint);
- undo_redo->add_undo_method(curve.ptr(), "set_point_pos", action_point, moving_from);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ Ref<Curve2D> curve = node->get_curve();
- } break;
- case ACTION_MOVING_IN: {
+ Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
+ switch (action) {
- undo_redo->create_action(TTR("Move In-Control in Curve"));
- undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, new_pos);
- undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, moving_from);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ case ACTION_MOVING_POINT: {
- } break;
- case ACTION_MOVING_OUT: {
+ undo_redo->create_action(TTR("Move Point in Curve"));
+ undo_redo->add_do_method(curve.ptr(), "set_point_pos", action_point, cpoint);
+ undo_redo->add_undo_method(curve.ptr(), "set_point_pos", action_point, moving_from);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
- undo_redo->create_action(TTR("Move Out-Control in Curve"));
- undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, new_pos);
- undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, moving_from);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ } break;
+ case ACTION_MOVING_IN: {
- } break;
- }
+ undo_redo->create_action(TTR("Move In-Control in Curve"));
+ undo_redo->add_do_method(curve.ptr(), "set_point_in", action_point, new_pos);
+ undo_redo->add_undo_method(curve.ptr(), "set_point_in", action_point, moving_from);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
- action = ACTION_NONE;
+ } break;
+ case ACTION_MOVING_OUT: {
- return true;
+ undo_redo->create_action(TTR("Move Out-Control in Curve"));
+ undo_redo->add_do_method(curve.ptr(), "set_point_out", action_point, new_pos);
+ undo_redo->add_undo_method(curve.ptr(), "set_point_out", action_point, moving_from);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+
+ } break;
}
-#if 0
- switch(mode) {
+ action = ACTION_NONE;
+ return true;
+ }
- case MODE_CREATE: {
+#if 0
+ switch(mode) {
- if (mb.button_index==BUTTON_LEFT && mb.pressed) {
+ case MODE_CREATE: {
- if (!wip_active) {
+ if (mb->get_button_index()==BUTTON_LEFT && mb->is_pressed()) {
- wip.clear();
- wip.push_back( canvas_item_editor->snap_point(cpoint) );
- wip_active=true;
- edited_point_pos=canvas_item_editor->snap_point(cpoint);
- canvas_item_editor->update();
- edited_point=1;
- return true;
- } else {
+ if (!wip_active) {
+
+ wip.clear();
+ wip.push_back( canvas_item_editor->snap_point(cpoint) );
+ wip_active=true;
+ edited_point_pos=canvas_item_editor->snap_point(cpoint);
+ canvas_item_editor->update();
+ edited_point=1;
+ return true;
+ } else {
if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_threshold) {
//wip closed
_wip_close();
+ if (wip.size()>1 && xform.xform(wip[0]).distance_to(gpoint)<grab_treshold) {
+ //wip closed
+ _wip_close();
- return true;
- } else {
- wip.push_back( canvas_item_editor->snap_point(cpoint) );
- edited_point=wip.size();
- canvas_item_editor->update();
- return true;
+ return true;
+ } else {
- //add wip point
- }
+ wip.push_back( canvas_item_editor->snap_point(cpoint) );
+ edited_point=wip.size();
+ canvas_item_editor->update();
+ return true;
+
+ //add wip point
}
- } else if (mb.button_index==BUTTON_RIGHT && mb.pressed && wip_active) {
- _wip_close();
}
+ } else if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && wip_active) {
+ _wip_close();
+ }
- } break;
-
- case MODE_EDIT: {
+ } break;
- if (mb.button_index==BUTTON_LEFT) {
- if (mb.pressed) {
+ case MODE_EDIT: {
- if (mb.mod.control) {
+ if (mb->get_button_index()==BUTTON_LEFT) {
+ if (mb->is_pressed()) {
+ if (mb->get_control()) {
- if (poly.size() < 3) {
-
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_undo_method(node,"set_polygon",poly);
- poly.push_back(cpoint);
- undo_redo->add_do_method(node,"set_polygon",poly);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->commit_action();
- return true;
- }
- //search edges
- int closest_idx=-1;
- Vector2 closest_pos;
- real_t closest_dist=1e10;
- for(int i=0;i<poly.size();i++) {
+ if (poly.size() < 3) {
- Vector2 points[2] ={ xform.xform(poly[i]),
- xform.xform(poly[(i+1)%poly.size()]) };
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_undo_method(node,"set_polygon",poly);
+ poly.push_back(cpoint);
+ undo_redo->add_do_method(node,"set_polygon",poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->commit_action();
+ return true;
+ }
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points);
- if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2)
- continue; //not valid to reuse point
+ //search edges
+ int closest_idx=-1;
+ Vector2 closest_pos;
+ real_t closest_dist=1e10;
+ for(int i=0;i<poly.size();i++) {
- real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
closest_dist=d;
closest_pos=cp;
closest_idx=i;
}
+ Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint,points);
+ if (cp.distance_squared_to(points[0])<CMP_EPSILON2 || cp.distance_squared_to(points[1])<CMP_EPSILON2)
+ continue; //not valid to reuse point
+ real_t d = cp.distance_to(gpoint);
+ if (d<closest_dist && d<grab_treshold) {
+ closest_dist=d;
+ closest_pos=cp;
+ closest_idx=i;
}
- if (closest_idx>=0) {
-
- pre_move_edit=poly;
- poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)));
- edited_point=closest_idx+1;
- edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos));
- node->set_polygon(poly);
- canvas_item_editor->update();
- return true;
- }
- } else {
- //look for points to move
+ }
- int closest_idx=-1;
- Vector2 closest_pos;
- real_t closest_dist=1e10;
- for(int i=0;i<poly.size();i++) {
+ if (closest_idx>=0) {
- Vector2 cp =xform.xform(poly[i]);
+ pre_move_edit=poly;
+ poly.insert(closest_idx+1,canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos)));
+ edited_point=closest_idx+1;
+ edited_point_pos=canvas_item_editor->snap_point(xform.affine_inverse().xform(closest_pos));
+ node->set_polygon(poly);
+ canvas_item_editor->update();
+ return true;
+ }
+ } else {
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
@@ -350,46 +370,51 @@ bool Path2DEditor::forward_gui_input(const InputEvent &p_event) {
closest_idx=i;
}
- }
+ int closest_idx=-1;
+ Vector2 closest_pos;
+ real_t closest_dist=1e10;
+ for(int i=0;i<poly.size();i++) {
- if (closest_idx>=0) {
+ Vector2 cp =xform.xform(poly[i]);
- pre_move_edit=poly;
- edited_point=closest_idx;
- edited_point_pos=xform.affine_inverse().xform(closest_pos);
- canvas_item_editor->update();
- return true;
+ real_t d = cp.distance_to(gpoint);
+ if (d<closest_dist && d<grab_treshold) {
+ closest_dist=d;
+ closest_pos=cp;
+ closest_idx=i;
}
- }
- } else {
- if (edited_point!=-1) {
+ }
- //apply
+ if (closest_idx>=0) {
- ERR_FAIL_INDEX_V(edited_point,poly.size(),false);
- poly[edited_point]=edited_point_pos;
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_do_method(node,"set_polygon",poly);
- undo_redo->add_undo_method(node,"set_polygon",pre_move_edit);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->commit_action();
-
- edited_point=-1;
+ pre_move_edit=poly;
+ edited_point=closest_idx;
+ edited_point_pos=xform.affine_inverse().xform(closest_pos);
+ canvas_item_editor->update();
return true;
}
}
- } if (mb.button_index==BUTTON_RIGHT && mb.pressed && edited_point==-1) {
+ } else {
+ if (edited_point!=-1) {
+ //apply
- int closest_idx=-1;
- Vector2 closest_pos;
- real_t closest_dist=1e10;
- for(int i=0;i<poly.size();i++) {
+ ERR_FAIL_INDEX_V(edited_point,poly.size(),false);
+ poly[edited_point]=edited_point_pos;
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_do_method(node,"set_polygon",poly);
+ undo_redo->add_undo_method(node,"set_polygon",pre_move_edit);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->commit_action();
- Vector2 cp =xform.xform(poly[i]);
+ edited_point=-1;
+ return true;
+ }
+ }
+ } if (mb->get_button_index()==BUTTON_RIGHT && mb->is_pressed() && edited_point==-1) {
real_t d = cp.distance_to(gpoint);
if (d<closest_dist && d<grab_threshold) {
@@ -398,79 +423,93 @@ bool Path2DEditor::forward_gui_input(const InputEvent &p_event) {
closest_idx=i;
}
+ int closest_idx=-1;
+ Vector2 closest_pos;
+ real_t closest_dist=1e10;
+ for(int i=0;i<poly.size();i++) {
+
+ Vector2 cp =xform.xform(poly[i]);
+
+ real_t d = cp.distance_to(gpoint);
+ if (d<closest_dist && d<grab_treshold) {
+ closest_dist=d;
+ closest_pos=cp;
+ closest_idx=i;
}
- if (closest_idx>=0) {
+ }
+ if (closest_idx>=0) {
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node,"set_polygon",poly);
- poly.remove(closest_idx);
- undo_redo->add_do_method(node,"set_polygon",poly);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
- undo_redo->commit_action();
- return true;
- }
+ undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
+ undo_redo->add_undo_method(node,"set_polygon",poly);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node,"set_polygon",poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(),"update");
+ undo_redo->commit_action();
+ return true;
}
+ }
- } break;
- }
+
+ } break;
+ }
#endif
- } break;
- case InputEvent::MOUSE_MOTION: {
+ }
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_event;
- if (action != ACTION_NONE) {
+ if (mm.is_valid()) {
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Vector2 gpoint = Point2(mm.x, mm.y);
- Vector2 cpoint = !mm.mod.alt ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
+ if (action != ACTION_NONE) {
- Ref<Curve2D> curve = node->get_curve();
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Vector2 gpoint = mm->get_pos();
+ Vector2 cpoint = !mm->get_alt() ? canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint)) : node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint)));
- Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
+ Ref<Curve2D> curve = node->get_curve();
- switch (action) {
+ Vector2 new_pos = moving_from + xform.affine_inverse().basis_xform(gpoint - moving_screen_from);
- case ACTION_MOVING_POINT: {
+ switch (action) {
- curve->set_point_pos(action_point, cpoint);
- } break;
- case ACTION_MOVING_IN: {
+ case ACTION_MOVING_POINT: {
- curve->set_point_in(action_point, new_pos);
+ curve->set_point_pos(action_point, cpoint);
+ } break;
+ case ACTION_MOVING_IN: {
- } break;
- case ACTION_MOVING_OUT: {
+ curve->set_point_in(action_point, new_pos);
- curve->set_point_out(action_point, new_pos);
+ } break;
+ case ACTION_MOVING_OUT: {
- } break;
- }
+ curve->set_point_out(action_point, new_pos);
- canvas_item_editor->get_viewport_control()->update();
- return true;
+ } break;
}
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
+ }
+
#if 0
- if (edited_point!=-1 && (wip_active || mm.button_mask&BUTTON_MASK_LEFT)) {
+ if (edited_point!=-1 && (wip_active || mm->get_button_mask()&BUTTON_MASK_LEFT)) {
- Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Matrix32 xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Vector2 gpoint = Point2(mm.x,mm.y);
- edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint));
- canvas_item_editor->update();
+ Vector2 gpoint = Point2(mm.x,mm.y);
+ edited_point_pos = canvas_item_editor->snap_point(xform.affine_inverse().xform(gpoint));
+ canvas_item_editor->update();
- }
+ }
#endif
- } break;
}
return false;
diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h
index 67c6f3c8cb..70911444ad 100644
--- a/editor/plugins/path_2d_editor_plugin.h
+++ b/editor/plugins/path_2d_editor_plugin.h
@@ -95,7 +95,7 @@ protected:
static void _bind_methods();
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_path2d);
Path2DEditor(EditorNode *p_editor);
};
@@ -108,7 +108,7 @@ class Path2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return path2d_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return path2d_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "Path2D"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp
index 9e18a5c4c5..12b6dce798 100644
--- a/editor/plugins/path_editor_plugin.cpp
+++ b/editor/plugins/path_editor_plugin.cpp
@@ -303,9 +303,9 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
if (p_event.type==InputEvent::MOUSE_BUTTON) {
const InputEventMouseButton &mb=p_event.mouse_button;
- Point2 mbpos(mb.x,mb.y);
+ Point2 mbpos(mb->get_pos().x,mb->get_pos().y);
- if (mb.pressed && mb.button_index==BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb.mod.control))) {
+ if (mb->is_pressed() && mb->get_button_index()==BUTTON_LEFT && (curve_create->is_pressed() || (curve_edit->is_pressed() && mb->get_control()))) {
//click into curve, break it down
Vector3Array v3a = c->tesselate();
int idx=0;
@@ -405,7 +405,7 @@ bool PathEditorPlugin::forward_spatial_gui_input(Camera* p_camera,const InputEve
//add new at pos
}
- } else if (mb.pressed && ((mb.button_index==BUTTON_LEFT && curve_del->is_pressed()) || (mb.button_index==BUTTON_RIGHT && curve_edit->is_pressed()))) {
+ } else if (mb->is_pressed() && ((mb->get_button_index()==BUTTON_LEFT && curve_del->is_pressed()) || (mb->get_button_index()==BUTTON_RIGHT && curve_edit->is_pressed()))) {
for(int i=0;i<c->get_point_count();i++) {
real_t dist_to_p = p_camera->unproject_position(gt.xform(c->get_point_pos(i))).distance_to(mbpos);
diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp
index 896a26c8e8..c2edc608ab 100644
--- a/editor/plugins/polygon_2d_editor_plugin.cpp
+++ b/editor/plugins/polygon_2d_editor_plugin.cpp
@@ -201,213 +201,209 @@ void Polygon2DEditor::_wip_close() {
edited_point = -1;
}
-bool Polygon2DEditor::forward_gui_input(const InputEvent &p_event) {
+bool Polygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (node == NULL)
return false;
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_event.mouse_button;
+ Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
- Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform();
+ Vector2 gpoint = mb->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
- Vector2 gpoint = Point2(mb.x, mb.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- cpoint = node->get_global_transform().affine_inverse().xform(cpoint);
+ Vector<Vector2> poly = Variant(node->get_polygon());
- Vector<Vector2> poly = Variant(node->get_polygon());
+ //first check if a point is to be added (segment split)
+ real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
- //first check if a point is to be added (segment split)
- real_t grab_treshold = EDITOR_DEF("editors/poly_editor/point_grab_radius", 8);
+ switch (mode) {
- switch (mode) {
+ case MODE_CREATE: {
- case MODE_CREATE: {
+ if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
- if (mb.button_index == BUTTON_LEFT && mb.pressed) {
+ if (!wip_active) {
- if (!wip_active) {
+ wip.clear();
+ wip.push_back(cpoint - node->get_offset());
+ wip_active = true;
+ edited_point_pos = cpoint;
+ canvas_item_editor->get_viewport_control()->update();
+ edited_point = 1;
+ return true;
+ } else {
+
+ if (wip.size() > 1 && xform.xform(wip[0] + node->get_offset()).distance_to(gpoint) < grab_treshold) {
+ //wip closed
+ _wip_close();
- wip.clear();
- wip.push_back(cpoint - node->get_offset());
- wip_active = true;
- edited_point_pos = cpoint;
- canvas_item_editor->get_viewport_control()->update();
- edited_point = 1;
return true;
} else {
- if (wip.size() > 1 && xform.xform(wip[0] + node->get_offset()).distance_to(gpoint) < grab_treshold) {
- //wip closed
- _wip_close();
-
- return true;
- } else {
-
- wip.push_back(cpoint - node->get_offset());
- edited_point = wip.size();
- canvas_item_editor->get_viewport_control()->update();
- return true;
+ wip.push_back(cpoint - node->get_offset());
+ edited_point = wip.size();
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
- //add wip point
- }
+ //add wip point
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && wip_active) {
- _wip_close();
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && wip_active) {
+ _wip_close();
+ }
- } break;
-
- case MODE_EDIT: {
-
- if (mb.button_index == BUTTON_LEFT) {
- if (mb.pressed) {
-
- if (mb.mod.control) {
+ } break;
- if (poly.size() < 3) {
+ case MODE_EDIT: {
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_undo_method(node, "set_polygon", poly);
- poly.push_back(cpoint);
- undo_redo->add_do_method(node, "set_polygon", poly);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
- return true;
- }
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ if (mb->is_pressed()) {
- //search edges
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
-
- Vector2 points[2] = { xform.xform(poly[i] + node->get_offset()),
- xform.xform(poly[(i + 1) % poly.size()] + node->get_offset()) };
-
- Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
- if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
- continue; //not valid to reuse point
-
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
- }
+ if (mb->get_control()) {
- if (closest_idx >= 0) {
+ if (poly.size() < 3) {
- pre_move_edit = poly;
- poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos) - node->get_offset());
- edited_point = closest_idx + 1;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- node->set_polygon(Variant(poly));
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
- } else {
+ undo_redo->create_action(TTR("Edit Poly"));
+ undo_redo->add_undo_method(node, "set_polygon", poly);
+ poly.push_back(cpoint);
+ undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
- //look for points to move
+ //search edges
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
+ Vector2 points[2] = { xform.xform(poly[i] + node->get_offset()),
+ xform.xform(poly[(i + 1) % poly.size()] + node->get_offset()) };
- Vector2 cp = xform.xform(poly[i] + node->get_offset());
+ Vector2 cp = Geometry::get_closest_point_to_segment_2d(gpoint, points);
+ if (cp.distance_squared_to(points[0]) < CMP_EPSILON2 || cp.distance_squared_to(points[1]) < CMP_EPSILON2)
+ continue; //not valid to reuse point
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
- }
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
}
+ }
- if (closest_idx >= 0) {
+ if (closest_idx >= 0) {
- pre_move_edit = poly;
- edited_point = closest_idx;
- edited_point_pos = xform.affine_inverse().xform(closest_pos);
- canvas_item_editor->get_viewport_control()->update();
- return true;
- }
+ pre_move_edit = poly;
+ poly.insert(closest_idx + 1, xform.affine_inverse().xform(closest_pos) - node->get_offset());
+ edited_point = closest_idx + 1;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ node->set_polygon(Variant(poly));
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
} else {
- if (edited_point != -1) {
+ //look for points to move
- //apply
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
- poly[edited_point] = edited_point_pos - node->get_offset();
- undo_redo->create_action(TTR("Edit Poly"));
- undo_redo->add_do_method(node, "set_polygon", poly);
- undo_redo->add_undo_method(node, "set_polygon", pre_move_edit);
- undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
- undo_redo->commit_action();
+ Vector2 cp = xform.xform(poly[i] + node->get_offset());
- edited_point = -1;
- return true;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
}
- }
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed && edited_point == -1) {
- int closest_idx = -1;
- Vector2 closest_pos;
- real_t closest_dist = 1e10;
- for (int i = 0; i < poly.size(); i++) {
+ if (closest_idx >= 0) {
- Vector2 cp = xform.xform(poly[i] + node->get_offset());
-
- real_t d = cp.distance_to(gpoint);
- if (d < closest_dist && d < grab_treshold) {
- closest_dist = d;
- closest_pos = cp;
- closest_idx = i;
+ pre_move_edit = poly;
+ edited_point = closest_idx;
+ edited_point_pos = xform.affine_inverse().xform(closest_pos);
+ canvas_item_editor->get_viewport_control()->update();
+ return true;
}
}
+ } else {
+
+ if (edited_point != -1) {
- if (closest_idx >= 0) {
+ //apply
- undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
- undo_redo->add_undo_method(node, "set_polygon", poly);
- poly.remove(closest_idx);
+ ERR_FAIL_INDEX_V(edited_point, poly.size(), false);
+ poly[edited_point] = edited_point_pos - node->get_offset();
+ undo_redo->create_action(TTR("Edit Poly"));
undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_undo_method(node, "set_polygon", pre_move_edit);
undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
undo_redo->commit_action();
+
+ edited_point = -1;
return true;
}
}
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed() && edited_point == -1) {
- } break;
- }
+ int closest_idx = -1;
+ Vector2 closest_pos;
+ real_t closest_dist = 1e10;
+ for (int i = 0; i < poly.size(); i++) {
- } break;
- case InputEvent::MOUSE_MOTION: {
+ Vector2 cp = xform.xform(poly[i] + node->get_offset());
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ real_t d = cp.distance_to(gpoint);
+ if (d < closest_dist && d < grab_treshold) {
+ closest_dist = d;
+ closest_pos = cp;
+ closest_idx = i;
+ }
+ }
- if (edited_point != -1 && (wip_active || mm.button_mask & BUTTON_MASK_LEFT)) {
+ if (closest_idx >= 0) {
- Vector2 gpoint = Point2(mm.x, mm.y);
- Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
- cpoint = canvas_item_editor->snap_point(cpoint);
- edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+ undo_redo->create_action(TTR("Edit Poly (Remove Point)"));
+ undo_redo->add_undo_method(node, "set_polygon", poly);
+ poly.remove(closest_idx);
+ undo_redo->add_do_method(node, "set_polygon", poly);
+ undo_redo->add_do_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->add_undo_method(canvas_item_editor->get_viewport_control(), "update");
+ undo_redo->commit_action();
+ return true;
+ }
+ }
- canvas_item_editor->get_viewport_control()->update();
- }
+ } break;
+ }
+ }
- } break;
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ if (edited_point != -1 && (wip_active || mm->get_button_mask() & BUTTON_MASK_LEFT)) {
+
+ Vector2 gpoint = mm->get_pos();
+ Vector2 cpoint = canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint);
+ cpoint = canvas_item_editor->snap_point(cpoint);
+ edited_point_pos = node->get_global_transform().affine_inverse().xform(cpoint);
+
+ canvas_item_editor->get_viewport_control()->update();
+ }
}
return false;
@@ -455,31 +451,31 @@ void Polygon2DEditor::_uv_mode(int p_mode) {
}
}
-void Polygon2DEditor::_uv_input(const InputEvent &p_input) {
+void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
Transform2D mtx;
mtx.elements[2] = -uv_draw_ofs;
mtx.scale_basis(Vector2(uv_draw_zoom, uv_draw_zoom));
- if (p_input.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_input;
- const InputEventMouseButton &mb = p_input.mouse_button;
+ if (mb.is_valid()) {
- if (mb.button_index == BUTTON_LEFT) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
- uv_drag_from = Vector2(mb.x, mb.y);
+ uv_drag_from = Vector2(mb->get_pos().x, mb->get_pos().y);
uv_drag = true;
uv_prev = node->get_uv();
uv_move_current = uv_mode;
if (uv_move_current == UV_MODE_EDIT_POINT) {
- if (mb.mod.shift && mb.mod.command)
+ if (mb->get_shift() && mb->get_command())
uv_move_current = UV_MODE_SCALE;
- else if (mb.mod.shift)
+ else if (mb->get_shift())
uv_move_current = UV_MODE_MOVE;
- else if (mb.mod.command)
+ else if (mb->get_command())
uv_move_current = UV_MODE_ROTATE;
}
@@ -489,7 +485,7 @@ void Polygon2DEditor::_uv_input(const InputEvent &p_input) {
for (int i = 0; i < uv_prev.size(); i++) {
Vector2 tuv = mtx.xform(uv_prev[i]);
- if (tuv.distance_to(Vector2(mb.x, mb.y)) < 8) {
+ if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) {
uv_drag_from = tuv;
uv_drag_index = i;
}
@@ -511,7 +507,7 @@ void Polygon2DEditor::_uv_input(const InputEvent &p_input) {
uv_drag = false;
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed) {
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
if (uv_drag) {
@@ -520,27 +516,28 @@ void Polygon2DEditor::_uv_input(const InputEvent &p_input) {
uv_edit_draw->update();
}
- } else if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
+ } else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
- uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb.factor)));
- } else if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
+ uv_zoom->set_value(uv_zoom->get_value() / (1 - (0.1 * mb->get_factor())));
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
- uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb.factor)));
+ uv_zoom->set_value(uv_zoom->get_value() * (1 - (0.1 * mb->get_factor())));
}
+ }
- } else if (p_input.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_input;
- const InputEventMouseMotion &mm = p_input.mouse_motion;
+ if (mm.is_valid()) {
- if (mm.button_mask & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
+ if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
- Vector2 drag(mm.relative_x, mm.relative_y);
+ Vector2 drag(mm->get_relative().x, mm->get_relative().y);
uv_hscroll->set_value(uv_hscroll->get_value() - drag.x);
uv_vscroll->set_value(uv_vscroll->get_value() - drag.y);
} else if (uv_drag) {
- Vector2 uv_drag_to = snap_point(Vector2(mm.x, mm.y));
+ Vector2 uv_drag_to = mm->get_pos();
Vector2 drag = mtx.affine_inverse().xform(uv_drag_to) - mtx.affine_inverse().xform(uv_drag_from);
switch (uv_move_current) {
diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h
index 00926bf2d1..0901cc9082 100644
--- a/editor/plugins/polygon_2d_editor_plugin.h
+++ b/editor/plugins/polygon_2d_editor_plugin.h
@@ -113,7 +113,7 @@ class Polygon2DEditor : public HBoxContainer {
Vector2 snap_step;
void _uv_scroll_changed(float);
- void _uv_input(const InputEvent &p_input);
+ void _uv_input(const Ref<InputEvent> &p_input);
void _uv_draw();
void _uv_mode(int p_mode);
void _wip_close();
@@ -135,7 +135,7 @@ protected:
Vector2 snap_point(Vector2 p_target) const;
public:
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_collision_polygon);
Polygon2DEditor(EditorNode *p_editor);
};
@@ -148,7 +148,7 @@ class Polygon2DEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return collision_polygon_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "Polygon2D"; }
bool has_main_screen() const { return false; }
diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp
index 3b8d655af7..ea7a84d2f4 100644
--- a/editor/plugins/resource_preloader_editor_plugin.cpp
+++ b/editor/plugins/resource_preloader_editor_plugin.cpp
@@ -33,7 +33,7 @@
#include "global_config.h"
#include "io/resource_loader.h"
-void ResourcePreloaderEditor::_gui_input(InputEvent p_event) {
+void ResourcePreloaderEditor::_gui_input(Ref<InputEvent> p_event) {
}
void ResourcePreloaderEditor::_notification(int p_what) {
diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h
index fad3ba93f1..1f54620ba4 100644
--- a/editor/plugins/resource_preloader_editor_plugin.h
+++ b/editor/plugins/resource_preloader_editor_plugin.h
@@ -70,7 +70,7 @@ class ResourcePreloaderEditor : public PanelContainer {
protected:
void _notification(int p_what);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
static void _bind_methods();
public:
diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp
index 4582108210..d369064050 100644
--- a/editor/plugins/script_editor_plugin.cpp
+++ b/editor/plugins/script_editor_plugin.cpp
@@ -164,14 +164,16 @@ void ScriptEditorQuickOpen::_text_changed(const String &p_newtext) {
_update_search();
}
-void ScriptEditorQuickOpen::_sbox_input(const InputEvent &p_ie) {
+void ScriptEditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP ||
- p_ie.key.scancode == KEY_DOWN ||
- p_ie.key.scancode == KEY_PAGEUP ||
- p_ie.key.scancode == KEY_PAGEDOWN)) {
+ Ref<InputEventKey> k = p_ie;
- search_options->call("_gui_input", p_ie);
+ if (k.is_valid() && (k->get_scancode() == KEY_UP ||
+ k->get_scancode() == KEY_DOWN ||
+ k->get_scancode() == KEY_PAGEUP ||
+ k->get_scancode() == KEY_PAGEDOWN)) {
+
+ search_options->call("_gui_input", k);
search_box->accept_event();
}
}
@@ -1778,8 +1780,8 @@ void ScriptEditor::_script_split_dragged(float) {
_save_layout();
}
-void ScriptEditor::_unhandled_input(const InputEvent &p_event) {
- if (p_event.key.pressed || !is_visible_in_tree()) return;
+void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) {
+ if (p_event->is_pressed() || !is_visible_in_tree()) return;
if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) {
int next_tab = script_list->get_current() + 1;
next_tab %= script_list->get_item_count();
diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h
index 983847ddaf..fb2f108277 100644
--- a/editor/plugins/script_editor_plugin.h
+++ b/editor/plugins/script_editor_plugin.h
@@ -54,7 +54,7 @@ class ScriptEditorQuickOpen : public ConfirmationDialog {
void _update_search();
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
Vector<String> functions;
void _confirmed();
@@ -288,7 +288,7 @@ class ScriptEditor : public VBoxContainer {
void _script_split_dragged(float);
- void _unhandled_input(const InputEvent &p_event);
+ void _unhandled_input(const Ref<InputEvent> &p_event);
void _help_search(String p_text);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 3bb1c7852b..2d3a14e525 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -124,7 +124,6 @@ void ScriptTextEditor::_load_theme_settings() {
text_edit->add_keyword_color("Transform", basetype_color);
text_edit->add_keyword_color("Color", basetype_color);
text_edit->add_keyword_color("Image", basetype_color);
- text_edit->add_keyword_color("InputEvent", basetype_color);
text_edit->add_keyword_color("Rect2", basetype_color);
text_edit->add_keyword_color("NodePath", basetype_color);
@@ -1227,15 +1226,18 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
}
}
-void ScriptTextEditor::_text_edit_gui_input(const InputEvent &ev) {
- if (ev.type == InputEvent::MOUSE_BUTTON) {
- InputEventMouseButton mb = ev.mouse_button;
- if (mb.button_index == BUTTON_RIGHT && !mb.pressed) {
+void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> mb = ev;
+
+ if (mb.is_valid()) {
+
+ if (mb->get_button_index() == BUTTON_RIGHT && !mb->is_pressed()) {
int col, row;
TextEdit *tx = code_editor->get_text_edit();
- tx->_get_mouse_pos(Point2i(mb.global_x, mb.global_y) - tx->get_global_position(), row, col);
- Vector2 mpos = Vector2(mb.global_x, mb.global_y) - tx->get_global_position();
+ tx->_get_mouse_pos(mb->get_global_pos() - tx->get_global_position(), row, col);
+ Vector2 mpos = mb->get_global_pos() - tx->get_global_position();
bool have_selection = (tx->get_selection_text().length() > 0);
bool have_color = (tx->get_word_at_pos(mpos) == "Color");
if (have_color) {
diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h
index 77bce59f2e..fdae03949c 100644
--- a/editor/plugins/script_text_editor.h
+++ b/editor/plugins/script_text_editor.h
@@ -106,7 +106,7 @@ protected:
void _edit_option(int p_op);
void _make_context_menu(bool p_selection, bool p_color);
- void _text_edit_gui_input(const InputEvent &ev);
+ void _text_edit_gui_input(const Ref<InputEvent> &ev);
void _color_changed(const Color &p_color);
void _goto_line(int p_line) { goto_line(p_line); }
diff --git a/editor/plugins/shader_graph_editor_plugin.cpp b/editor/plugins/shader_graph_editor_plugin.cpp
index 0fd28a0b59..9c65ef667a 100644
--- a/editor/plugins/shader_graph_editor_plugin.cpp
+++ b/editor/plugins/shader_graph_editor_plugin.cpp
@@ -40,7 +40,7 @@
void GraphColorRampEdit::_gui_input(const InputEvent& p_event) {
- if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) {
+ if (p_event.type==InputEvent::KEY && p_event->is_pressed() && p_event->get_scancode()==KEY_DELETE && grabbed!=-1) {
points.remove(grabbed);
grabbed=-1;
@@ -49,10 +49,10 @@ void GraphColorRampEdit::_gui_input(const InputEvent& p_event) {
accept_event();
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==1 && p_event->is_pressed()) {
update();
- int x = p_event.mouse_button.x;
+ int x = p_event->get_pos().x;
int total_w = get_size().width-get_size().height-3;
if (x>total_w+3) {
@@ -132,7 +132,7 @@ void GraphColorRampEdit::_gui_input(const InputEvent& p_event) {
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) {
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==1 && !p_event->is_pressed()) {
if (grabbing) {
grabbing=false;
@@ -319,7 +319,7 @@ GraphColorRampEdit::GraphColorRampEdit(){
void GraphCurveMapEdit::_gui_input(const InputEvent& p_event) {
- if (p_event.type==InputEvent::KEY && p_event.key.pressed && p_event.key.scancode==KEY_DELETE && grabbed!=-1) {
+ if (p_event.type==InputEvent::KEY && p_event->is_pressed() && p_event->get_scancode()==KEY_DELETE && grabbed!=-1) {
points.remove(grabbed);
grabbed=-1;
@@ -328,10 +328,10 @@ void GraphCurveMapEdit::_gui_input(const InputEvent& p_event) {
accept_event();
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && p_event.mouse_button.pressed) {
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==1 && p_event->is_pressed()) {
update();
- Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size();
+ Point2 p = Vector2(p_event->get_pos().x,p_event->get_pos().y)/get_size();
p.y=1.0-p.y;
grabbed=-1;
grabbing=true;
@@ -371,7 +371,7 @@ void GraphCurveMapEdit::_gui_input(const InputEvent& p_event) {
}
- if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==1 && !p_event.mouse_button.pressed) {
+ if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==1 && !p_event->is_pressed()) {
if (grabbing) {
grabbing=false;
@@ -382,7 +382,7 @@ void GraphCurveMapEdit::_gui_input(const InputEvent& p_event) {
if (p_event.type==InputEvent::MOUSE_MOTION && grabbing && grabbed != -1) {
- Point2 p = Vector2(p_event.mouse_button.x,p_event.mouse_button.y)/get_size();
+ Point2 p = Vector2(p_event->get_pos().x,p_event->get_pos().y)/get_size();
p.y=1.0-p.y;
p.x = CLAMP(p.x,0.0,1.0);
diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp
index 91900465a5..c4595b477e 100644
--- a/editor/plugins/spatial_editor_plugin.cpp
+++ b/editor/plugins/spatial_editor_plugin.cpp
@@ -634,9 +634,9 @@ void SpatialEditorViewport::_smouseenter() {
surface->grab_focus();
}
-void SpatialEditorViewport::_list_select(InputEventMouseButton b) {
+void SpatialEditorViewport::_list_select(Ref<InputEventMouseButton> b) {
- _find_items_at_pos(Vector2(b.x, b.y), clicked_includes_current, selection_results, b.mod.shift);
+ _find_items_at_pos(b->get_pos(), clicked_includes_current, selection_results, b->get_shift());
Node *scene = editor->get_edited_scene();
@@ -649,7 +649,7 @@ void SpatialEditorViewport::_list_select(InputEventMouseButton b) {
}
}
- clicked_wants_append = b.mod.shift;
+ clicked_wants_append = b->get_shift();
if (selection_results.size() == 1) {
@@ -684,13 +684,13 @@ void SpatialEditorViewport::_list_select(InputEventMouseButton b) {
selection_menu->set_item_tooltip(i, String(spat->get_name()) + "\nType: " + spat->get_class() + "\nPath: " + node_path);
}
- selection_menu->set_global_position(Vector2(b.global_x, b.global_y));
+ selection_menu->set_global_position(b->get_global_pos());
selection_menu->popup();
selection_menu->call_deferred("grab_click_focus");
selection_menu->set_invalidate_click_until_motion();
}
}
-void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
+void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) {
if (previewing)
return; //do NONE
@@ -707,800 +707,802 @@ void SpatialEditorViewport::_sinput(const InputEvent &p_event) {
}
}
- switch (p_event.type) {
- case InputEvent::MOUSE_BUTTON: {
+ Ref<InputEventMouseButton> b = p_event;
- const InputEventMouseButton &b = p_event.mouse_button;
+ if (b.is_valid()) {
- switch (b.button_index) {
+ switch (b->get_button_index()) {
- case BUTTON_WHEEL_UP: {
- scale_cursor_distance(is_freelook_active() ? ZOOM_MULTIPLIER : 1.0 / ZOOM_MULTIPLIER);
- } break;
+ case BUTTON_WHEEL_UP: {
+ scale_cursor_distance(is_freelook_active() ? ZOOM_MULTIPLIER : 1.0 / ZOOM_MULTIPLIER);
+ } break;
- case BUTTON_WHEEL_DOWN: {
- scale_cursor_distance(is_freelook_active() ? 1.0 / ZOOM_MULTIPLIER : ZOOM_MULTIPLIER);
- } break;
+ case BUTTON_WHEEL_DOWN: {
+ scale_cursor_distance(is_freelook_active() ? 1.0 / ZOOM_MULTIPLIER : ZOOM_MULTIPLIER);
+ } break;
- case BUTTON_RIGHT: {
+ case BUTTON_RIGHT: {
- NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
+ NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
- if (b.pressed && _edit.gizmo.is_valid()) {
- //restore
- _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, true);
- _edit.gizmo = Ref<SpatialEditorGizmo>();
- }
+ if (b->is_pressed() && _edit.gizmo.is_valid()) {
+ //restore
+ _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, true);
+ _edit.gizmo = Ref<SpatialEditorGizmo>();
+ }
- if (_edit.mode == TRANSFORM_NONE && b.pressed) {
+ if (_edit.mode == TRANSFORM_NONE && b->is_pressed()) {
- if (b.mod.alt) {
+ if (b->get_alt()) {
- if (nav_scheme == NAVIGATION_MAYA)
- break;
+ if (nav_scheme == NAVIGATION_MAYA)
+ break;
- _list_select(b);
- return;
- }
+ _list_select(b);
+ return;
}
+ }
- if (_edit.mode != TRANSFORM_NONE && b.pressed) {
- //cancel motion
- _edit.mode = TRANSFORM_NONE;
- //_validate_selection();
+ if (_edit.mode != TRANSFORM_NONE && b->is_pressed()) {
+ //cancel motion
+ _edit.mode = TRANSFORM_NONE;
+ //_validate_selection();
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp)
- continue;
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp)
+ continue;
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
- if (!se)
- continue;
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
+ if (!se)
+ continue;
- sp->set_global_transform(se->original);
- }
- surface->update();
- //VisualServer::get_singleton()->poly_clear(indicators);
- set_message(TTR("Transform Aborted."), 3);
+ sp->set_global_transform(se->original);
}
+ surface->update();
+ //VisualServer::get_singleton()->poly_clear(indicators);
+ set_message(TTR("Transform Aborted."), 3);
+ }
- freelook_active = b.pressed;
+ freelook_active = b->is_pressed();
- } break;
- case BUTTON_MIDDLE: {
+ } break;
+ case BUTTON_MIDDLE: {
- if (b.pressed && _edit.mode != TRANSFORM_NONE) {
+ if (b->is_pressed() && _edit.mode != TRANSFORM_NONE) {
- switch (_edit.plane) {
+ switch (_edit.plane) {
- case TRANSFORM_VIEW: {
+ case TRANSFORM_VIEW: {
- _edit.plane = TRANSFORM_X_AXIS;
- set_message(TTR("X-Axis Transform."), 2);
- name = "";
- _update_name();
- } break;
- case TRANSFORM_X_AXIS: {
+ _edit.plane = TRANSFORM_X_AXIS;
+ set_message(TTR("X-Axis Transform."), 2);
+ name = "";
+ _update_name();
+ } break;
+ case TRANSFORM_X_AXIS: {
- _edit.plane = TRANSFORM_Y_AXIS;
- set_message(TTR("Y-Axis Transform."), 2);
+ _edit.plane = TRANSFORM_Y_AXIS;
+ set_message(TTR("Y-Axis Transform."), 2);
- } break;
- case TRANSFORM_Y_AXIS: {
+ } break;
+ case TRANSFORM_Y_AXIS: {
- _edit.plane = TRANSFORM_Z_AXIS;
- set_message(TTR("Z-Axis Transform."), 2);
+ _edit.plane = TRANSFORM_Z_AXIS;
+ set_message(TTR("Z-Axis Transform."), 2);
- } break;
- case TRANSFORM_Z_AXIS: {
+ } break;
+ case TRANSFORM_Z_AXIS: {
- _edit.plane = TRANSFORM_VIEW;
- set_message(TTR("View Plane Transform."), 2);
+ _edit.plane = TRANSFORM_VIEW;
+ set_message(TTR("View Plane Transform."), 2);
- } break;
- }
+ } break;
}
- } break;
- case BUTTON_LEFT: {
+ }
+ } break;
+ case BUTTON_LEFT: {
- if (b.pressed) {
+ if (b->is_pressed()) {
- NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
- if ((nav_scheme == NAVIGATION_MAYA || nav_scheme == NAVIGATION_MODO) && b.mod.alt) {
- break;
- }
+ NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
+ if ((nav_scheme == NAVIGATION_MAYA || nav_scheme == NAVIGATION_MODO) && b->get_alt()) {
+ break;
+ }
- if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_LIST_SELECT) {
- _list_select(b);
- break;
- }
+ if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_LIST_SELECT) {
+ _list_select(b);
+ break;
+ }
- _edit.mouse_pos = Point2(b.x, b.y);
- _edit.snap = false;
- _edit.mode = TRANSFORM_NONE;
+ _edit.mouse_pos = b->get_pos();
+ _edit.snap = false;
+ _edit.mode = TRANSFORM_NONE;
- //gizmo has priority over everything
+ //gizmo has priority over everything
- bool can_select_gizmos = true;
+ bool can_select_gizmos = true;
- {
- int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
- can_select_gizmos = view_menu->get_popup()->is_item_checked(idx);
- }
+ {
+ int idx = view_menu->get_popup()->get_item_index(VIEW_GIZMOS);
+ can_select_gizmos = view_menu->get_popup()->is_item_checked(idx);
+ }
- if (can_select_gizmos && spatial_editor->get_selected()) {
+ if (can_select_gizmos && spatial_editor->get_selected()) {
- Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
- if (seg.is_valid()) {
- int handle = -1;
- Vector3 point;
- Vector3 normal;
- bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b.mod.shift);
- if (inters && handle != -1) {
+ Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
+ if (seg.is_valid()) {
+ int handle = -1;
+ Vector3 point;
+ Vector3 normal;
+ bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, b->get_shift());
+ if (inters && handle != -1) {
- _edit.gizmo = seg;
- _edit.gizmo_handle = handle;
- //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
- _edit.gizmo_initial_value = seg->get_handle_value(handle);
- break;
- }
+ _edit.gizmo = seg;
+ _edit.gizmo_handle = handle;
+ //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
+ _edit.gizmo_initial_value = seg->get_handle_value(handle);
+ break;
}
}
+ }
- if (_gizmo_select(_edit.mouse_pos))
- break;
+ if (_gizmo_select(_edit.mouse_pos))
+ break;
- clicked = 0;
- clicked_includes_current = false;
+ clicked = 0;
+ clicked_includes_current = false;
- if ((spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT && b.mod.control) || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) {
+ if ((spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT && b->get_control()) || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE) {
- /* HANDLE ROTATION */
- if (get_selected_count() == 0)
- break; //bye
- //handle rotate
- _edit.mode = TRANSFORM_ROTATE;
- _compute_edit(Point2(b.x, b.y));
- break;
- }
+ /* HANDLE ROTATION */
+ if (get_selected_count() == 0)
+ break; //bye
+ //handle rotate
+ _edit.mode = TRANSFORM_ROTATE;
+ _compute_edit(b->get_pos());
+ break;
+ }
- if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE) {
+ if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_MOVE) {
- if (get_selected_count() == 0)
- break; //bye
- //handle rotate
- _edit.mode = TRANSFORM_TRANSLATE;
- _compute_edit(Point2(b.x, b.y));
- break;
- }
+ if (get_selected_count() == 0)
+ break; //bye
+ //handle rotate
+ _edit.mode = TRANSFORM_TRANSLATE;
+ _compute_edit(b->get_pos());
+ break;
+ }
- if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE) {
+ if (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE) {
- if (get_selected_count() == 0)
- break; //bye
- //handle rotate
- _edit.mode = TRANSFORM_SCALE;
- _compute_edit(Point2(b.x, b.y));
- break;
- }
+ if (get_selected_count() == 0)
+ break; //bye
+ //handle rotate
+ _edit.mode = TRANSFORM_SCALE;
+ _compute_edit(b->get_pos());
+ break;
+ }
- // todo scale
+ // todo scale
- int gizmo_handle = -1;
+ int gizmo_handle = -1;
- clicked = _select_ray(Vector2(b.x, b.y), b.mod.shift, clicked_includes_current, &gizmo_handle, b.mod.shift);
+ clicked = _select_ray(b->get_pos(), b->get_shift(), clicked_includes_current, &gizmo_handle, b->get_shift());
- //clicking is always deferred to either move or release
+ //clicking is always deferred to either move or release
- clicked_wants_append = b.mod.shift;
+ clicked_wants_append = b->get_shift();
- if (!clicked) {
+ if (!clicked) {
- if (!clicked_wants_append)
- _clear_selected();
+ if (!clicked_wants_append)
+ _clear_selected();
- //default to regionselect
- cursor.region_select = true;
- cursor.region_begin = Point2(b.x, b.y);
- cursor.region_end = Point2(b.x, b.y);
- }
+ //default to regionselect
+ cursor.region_select = true;
+ cursor.region_begin = b->get_pos();
+ cursor.region_end = b->get_pos();
+ }
- if (clicked && gizmo_handle >= 0) {
+ if (clicked && gizmo_handle >= 0) {
- Object *obj = ObjectDB::get_instance(clicked);
- if (obj) {
+ Object *obj = ObjectDB::get_instance(clicked);
+ if (obj) {
- Spatial *spa = obj->cast_to<Spatial>();
- if (spa) {
+ Spatial *spa = obj->cast_to<Spatial>();
+ if (spa) {
- Ref<SpatialEditorGizmo> seg = spa->get_gizmo();
- if (seg.is_valid()) {
+ Ref<SpatialEditorGizmo> seg = spa->get_gizmo();
+ if (seg.is_valid()) {
- _edit.gizmo = seg;
- _edit.gizmo_handle = gizmo_handle;
- //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
- _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
- //print_line("GIZMO: "+itos(gizmo_handle)+" FROMPOS: "+_edit.orig_gizmo_pos);
- break;
- }
+ _edit.gizmo = seg;
+ _edit.gizmo_handle = gizmo_handle;
+ //_edit.gizmo_initial_pos=seg->get_handle_pos(gizmo_handle);
+ _edit.gizmo_initial_value = seg->get_handle_value(gizmo_handle);
+ //print_line("GIZMO: "+itos(gizmo_handle)+" FROMPOS: "+_edit.orig_gizmo_pos);
+ break;
}
}
- //_compute_edit(Point2(b.x,b.y)); //in case a motion happens..
}
+ //_compute_edit(Point2(b.x,b.y)); //in case a motion happens..
+ }
- surface->update();
- } else {
+ surface->update();
+ } else {
- if (_edit.gizmo.is_valid()) {
+ if (_edit.gizmo.is_valid()) {
- _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false);
- _edit.gizmo = Ref<SpatialEditorGizmo>();
- break;
- }
- if (clicked) {
- _select_clicked(clicked_wants_append, true);
- //clickd processing was deferred
- clicked = 0;
- }
+ _edit.gizmo->commit_handle(_edit.gizmo_handle, _edit.gizmo_initial_value, false);
+ _edit.gizmo = Ref<SpatialEditorGizmo>();
+ break;
+ }
+ if (clicked) {
+ _select_clicked(clicked_wants_append, true);
+ //clickd processing was deferred
+ clicked = 0;
+ }
- if (cursor.region_select) {
- _select_region();
- cursor.region_select = false;
- surface->update();
- }
+ if (cursor.region_select) {
+ _select_region();
+ cursor.region_select = false;
+ surface->update();
+ }
- if (_edit.mode != TRANSFORM_NONE) {
+ if (_edit.mode != TRANSFORM_NONE) {
- static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" };
- undo_redo->create_action(_transform_name[_edit.mode]);
+ static const char *_transform_name[4] = { "None", "Rotate", "Translate", "Scale" };
+ undo_redo->create_action(_transform_name[_edit.mode]);
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp)
- continue;
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp)
+ continue;
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
- if (!se)
- continue;
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
+ if (!se)
+ continue;
- undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_transform());
- undo_redo->add_undo_method(sp, "set_global_transform", se->original);
- }
- undo_redo->commit_action();
- _edit.mode = TRANSFORM_NONE;
- //VisualServer::get_singleton()->poly_clear(indicators);
- set_message("");
+ undo_redo->add_do_method(sp, "set_global_transform", sp->get_global_transform());
+ undo_redo->add_undo_method(sp, "set_global_transform", se->original);
}
-
- surface->update();
+ undo_redo->commit_action();
+ _edit.mode = TRANSFORM_NONE;
+ //VisualServer::get_singleton()->poly_clear(indicators);
+ set_message("");
}
- } break;
- }
- } break;
- case InputEvent::MOUSE_MOTION: {
- const InputEventMouseMotion &m = p_event.mouse_motion;
- _edit.mouse_pos = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y);
+ surface->update();
+ }
- if (spatial_editor->get_selected()) {
+ } break;
+ }
+ }
- Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
- if (seg.is_valid()) {
+ Ref<InputEventMouseMotion> m = p_event;
- int selected_handle = -1;
+ if (m.is_valid()) {
- int handle = -1;
- Vector3 point;
- Vector3 normal;
- bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false);
- if (inters && handle != -1) {
+ _edit.mouse_pos = m->get_pos();
- selected_handle = handle;
- }
+ if (spatial_editor->get_selected()) {
- if (selected_handle != spatial_editor->get_over_gizmo_handle()) {
- spatial_editor->set_over_gizmo_handle(selected_handle);
- spatial_editor->get_selected()->update_gizmo();
- if (selected_handle != -1)
- spatial_editor->select_gizmo_highlight_axis(-1);
- }
- }
- }
+ Ref<SpatialEditorGizmo> seg = spatial_editor->get_selected()->get_gizmo();
+ if (seg.is_valid()) {
+
+ int selected_handle = -1;
+
+ int handle = -1;
+ Vector3 point;
+ Vector3 normal;
+ bool inters = seg->intersect_ray(camera, _edit.mouse_pos, point, normal, &handle, false);
+ if (inters && handle != -1) {
- if (spatial_editor->get_over_gizmo_handle() == -1 && !(m.button_mask & 1) && !_edit.gizmo.is_valid()) {
+ selected_handle = handle;
+ }
- _gizmo_select(_edit.mouse_pos, true);
+ if (selected_handle != spatial_editor->get_over_gizmo_handle()) {
+ spatial_editor->set_over_gizmo_handle(selected_handle);
+ spatial_editor->get_selected()->update_gizmo();
+ if (selected_handle != -1)
+ spatial_editor->select_gizmo_highlight_axis(-1);
+ }
}
+ }
- NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
- NavigationMode nav_mode = NAVIGATION_NONE;
+ if (spatial_editor->get_over_gizmo_handle() == -1 && !(m->get_button_mask() & 1) && !_edit.gizmo.is_valid()) {
- if (_edit.gizmo.is_valid()) {
+ _gizmo_select(_edit.mouse_pos, true);
+ }
- _edit.gizmo->set_handle(_edit.gizmo_handle, camera, Vector2(m.x, m.y));
- Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle);
- String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle);
- set_message(n + ": " + String(v));
+ NavigationScheme nav_scheme = (NavigationScheme)EditorSettings::get_singleton()->get("editors/3d/navigation_scheme").operator int();
+ NavigationMode nav_mode = NAVIGATION_NONE;
- } else if (m.button_mask & BUTTON_MASK_LEFT) {
+ if (_edit.gizmo.is_valid()) {
- if (nav_scheme == NAVIGATION_MAYA && m.mod.alt) {
- nav_mode = NAVIGATION_ORBIT;
- } else if (nav_scheme == NAVIGATION_MODO && m.mod.alt && m.mod.shift) {
- nav_mode = NAVIGATION_PAN;
- } else if (nav_scheme == NAVIGATION_MODO && m.mod.alt && m.mod.control) {
- nav_mode = NAVIGATION_ZOOM;
- } else if (nav_scheme == NAVIGATION_MODO && m.mod.alt) {
- nav_mode = NAVIGATION_ORBIT;
- } else {
- if (clicked) {
+ _edit.gizmo->set_handle(_edit.gizmo_handle, camera, m->get_pos());
+ Variant v = _edit.gizmo->get_handle_value(_edit.gizmo_handle);
+ String n = _edit.gizmo->get_handle_name(_edit.gizmo_handle);
+ set_message(n + ": " + String(v));
- if (!clicked_includes_current) {
+ } else if (m->get_button_mask() & BUTTON_MASK_LEFT) {
- _select_clicked(clicked_wants_append, true);
- //clickd processing was deferred
- }
+ if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) {
+ nav_mode = NAVIGATION_ORBIT;
+ } else if (nav_scheme == NAVIGATION_MODO && m->get_alt() && m->get_shift()) {
+ nav_mode = NAVIGATION_PAN;
+ } else if (nav_scheme == NAVIGATION_MODO && m->get_alt() && m->get_control()) {
+ nav_mode = NAVIGATION_ZOOM;
+ } else if (nav_scheme == NAVIGATION_MODO && m->get_alt()) {
+ nav_mode = NAVIGATION_ORBIT;
+ } else {
+ if (clicked) {
- _compute_edit(_edit.mouse_pos);
- clicked = 0;
+ if (!clicked_includes_current) {
- _edit.mode = TRANSFORM_TRANSLATE;
+ _select_clicked(clicked_wants_append, true);
+ //clickd processing was deferred
}
- if (cursor.region_select && nav_mode == NAVIGATION_NONE) {
+ _compute_edit(_edit.mouse_pos);
+ clicked = 0;
- cursor.region_end = Point2(m.x, m.y);
- surface->update();
- return;
- }
+ _edit.mode = TRANSFORM_TRANSLATE;
+ }
- if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE)
- break;
+ if (cursor.region_select && nav_mode == NAVIGATION_NONE) {
- Vector3 ray_pos = _get_ray_pos(Vector2(m.x, m.y));
- Vector3 ray = _get_ray(Vector2(m.x, m.y));
+ cursor.region_end = m->get_pos();
+ surface->update();
+ return;
+ }
- switch (_edit.mode) {
+ if (_edit.mode == TRANSFORM_NONE && nav_mode == NAVIGATION_NONE)
+ return;
- case TRANSFORM_SCALE: {
+ Vector3 ray_pos = _get_ray_pos(m->get_pos());
+ Vector3 ray = _get_ray(m->get_pos());
- Plane plane = Plane(_edit.center, _get_camera_normal());
+ switch (_edit.mode) {
- Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
- break;
+ case TRANSFORM_SCALE: {
- Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
- break;
+ Plane plane = Plane(_edit.center, _get_camera_normal());
- float center_click_dist = click.distance_to(_edit.center);
- float center_inters_dist = intersection.distance_to(_edit.center);
- if (center_click_dist == 0)
- break;
+ Vector3 intersection;
+ if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ break;
- float scale = (center_inters_dist / center_click_dist) * 100.0;
+ Vector3 click;
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ break;
- if (_edit.snap || spatial_editor->is_snap_enabled()) {
+ float center_click_dist = click.distance_to(_edit.center);
+ float center_inters_dist = intersection.distance_to(_edit.center);
+ if (center_click_dist == 0)
+ break;
- scale = Math::stepify(scale, spatial_editor->get_scale_snap());
- }
+ float scale = (center_inters_dist / center_click_dist) * 100.0;
- set_message(vformat(TTR("Scaling to %s%%."), String::num(scale, 1)));
- scale /= 100.0;
+ if (_edit.snap || spatial_editor->is_snap_enabled()) {
- Transform r;
- r.basis.scale(Vector3(scale, scale, scale));
+ scale = Math::stepify(scale, spatial_editor->get_scale_snap());
+ }
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ set_message(vformat(TTR("Scaling to %s%%."), String::num(scale, 1)));
+ scale /= 100.0;
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ Transform r;
+ r.basis.scale(Vector3(scale, scale, scale));
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp)
- continue;
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
- if (!se)
- continue;
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Transform original = se->original;
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp)
+ continue;
- Transform base = Transform(Basis(), _edit.center);
- Transform t = base * (r * (base.inverse() * original));
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
+ if (!se)
+ continue;
- sp->set_global_transform(t);
- }
+ Transform original = se->original;
- surface->update();
+ Transform base = Transform(Basis(), _edit.center);
+ Transform t = base * (r * (base.inverse() * original));
- } break;
+ sp->set_global_transform(t);
+ }
- case TRANSFORM_TRANSLATE: {
+ surface->update();
- Vector3 motion_mask;
- Plane plane;
+ } break;
- switch (_edit.plane) {
- case TRANSFORM_VIEW:
- motion_mask = Vector3(0, 0, 0);
- plane = Plane(_edit.center, _get_camera_normal());
- break;
- case TRANSFORM_X_AXIS:
- motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0);
- plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
- break;
- case TRANSFORM_Y_AXIS:
- motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(1);
- plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
- break;
- case TRANSFORM_Z_AXIS:
- motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2);
- plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
- break;
- }
+ case TRANSFORM_TRANSLATE: {
- Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
- break;
+ Vector3 motion_mask;
+ Plane plane;
- Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ switch (_edit.plane) {
+ case TRANSFORM_VIEW:
+ motion_mask = Vector3(0, 0, 0);
+ plane = Plane(_edit.center, _get_camera_normal());
+ break;
+ case TRANSFORM_X_AXIS:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0);
+ plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
+ break;
+ case TRANSFORM_Y_AXIS:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(1);
+ plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
break;
+ case TRANSFORM_Z_AXIS:
+ motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2);
+ plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized());
+ break;
+ }
- //_validate_selection();
- Vector3 motion = intersection - click;
- if (motion_mask != Vector3()) {
- motion = motion_mask.dot(motion) * motion_mask;
- }
+ Vector3 intersection;
+ if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ break;
- float snap = 0;
+ Vector3 click;
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ break;
- if (_edit.snap || spatial_editor->is_snap_enabled()) {
+ //_validate_selection();
+ Vector3 motion = intersection - click;
+ if (motion_mask != Vector3()) {
+ motion = motion_mask.dot(motion) * motion_mask;
+ }
- snap = spatial_editor->get_translate_snap();
- motion.snap(snap);
- }
+ float snap = 0;
- //set_message("Translating: "+motion);
+ if (_edit.snap || spatial_editor->is_snap_enabled()) {
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ snap = spatial_editor->get_translate_snap();
+ motion.snap(snap);
+ }
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ //set_message("Translating: "+motion);
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp) {
- continue;
- }
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
- if (!se) {
- continue;
- }
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Transform t = se->original;
- t.origin += motion;
- sp->set_global_transform(t);
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp) {
+ continue;
}
- } break;
- case TRANSFORM_ROTATE: {
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
+ if (!se) {
+ continue;
+ }
- Plane plane;
+ Transform t = se->original;
+ t.origin += motion;
+ sp->set_global_transform(t);
+ }
+ } break;
- switch (_edit.plane) {
- case TRANSFORM_VIEW:
- plane = Plane(_edit.center, _get_camera_normal());
- break;
- case TRANSFORM_X_AXIS:
- plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0));
- break;
- case TRANSFORM_Y_AXIS:
- plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1));
- break;
- case TRANSFORM_Z_AXIS:
- plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2));
- break;
- }
+ case TRANSFORM_ROTATE: {
- Vector3 intersection;
- if (!plane.intersects_ray(ray_pos, ray, &intersection))
- break;
+ Plane plane;
- Vector3 click;
- if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ switch (_edit.plane) {
+ case TRANSFORM_VIEW:
+ plane = Plane(_edit.center, _get_camera_normal());
+ break;
+ case TRANSFORM_X_AXIS:
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0));
break;
+ case TRANSFORM_Y_AXIS:
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1));
+ break;
+ case TRANSFORM_Z_AXIS:
+ plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2));
+ break;
+ }
+
+ Vector3 intersection;
+ if (!plane.intersects_ray(ray_pos, ray, &intersection))
+ break;
- Vector3 y_axis = (click - _edit.center).normalized();
- Vector3 x_axis = plane.normal.cross(y_axis).normalized();
+ Vector3 click;
+ if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click))
+ break;
- float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center));
- if (_edit.snap || spatial_editor->is_snap_enabled()) {
+ Vector3 y_axis = (click - _edit.center).normalized();
+ Vector3 x_axis = plane.normal.cross(y_axis).normalized();
- float snap = spatial_editor->get_rotate_snap();
+ float angle = Math::atan2(x_axis.dot(intersection - _edit.center), y_axis.dot(intersection - _edit.center));
+ if (_edit.snap || spatial_editor->is_snap_enabled()) {
- if (snap) {
- angle = Math::rad2deg(angle) + snap * 0.5; //else it wont reach +180
- angle -= Math::fmod(angle, snap);
- set_message(vformat(TTR("Rotating %s degrees."), rtos(angle)));
- angle = Math::deg2rad(angle);
- } else
- set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle))));
+ float snap = spatial_editor->get_rotate_snap();
- } else {
+ if (snap) {
+ angle = Math::rad2deg(angle) + snap * 0.5; //else it wont reach +180
+ angle -= Math::fmod(angle, snap);
+ set_message(vformat(TTR("Rotating %s degrees."), rtos(angle)));
+ angle = Math::deg2rad(angle);
+ } else
set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle))));
- }
- Transform r;
- r.basis.rotate(plane.normal, angle);
+ } else {
+ set_message(vformat(TTR("Rotating %s degrees."), rtos(Math::rad2deg(angle))));
+ }
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ Transform r;
+ r.basis.rotate(plane.normal, angle);
+
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp)
- continue;
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp)
+ continue;
- SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
- if (!se)
- continue;
+ SpatialEditorSelectedItem *se = editor_selection->get_node_editor_data<SpatialEditorSelectedItem>(sp);
+ if (!se)
+ continue;
- Transform original = se->original;
+ Transform original = se->original;
- Transform base = Transform(Basis(), _edit.center);
- Transform t = base * r * base.inverse() * original;
+ Transform base = Transform(Basis(), _edit.center);
+ Transform t = base * r * base.inverse() * original;
- sp->set_global_transform(t);
- }
+ sp->set_global_transform(t);
+ }
- surface->update();
- /*
- VisualServer::get_singleton()->poly_clear(indicators);
-
- Vector<Vector3> points;
- Vector<Vector3> empty;
- Vector<Color> colors;
- points.push_back(intersection);
- points.push_back(_edit.original.origin);
- colors.push_back( Color(255,155,100) );
- colors.push_back( Color(255,155,100) );
- VisualServer::get_singleton()->poly_add_primitive(indicators,points,empty,colors,empty);
- */
- } break;
- default: {}
- }
+ surface->update();
+ /*
+ VisualServer::get_singleton()->poly_clear(indicators);
+
+ Vector<Vector3> points;
+ Vector<Vector3> empty;
+ Vector<Color> colors;
+ points.push_back(intersection);
+ points.push_back(_edit.original.origin);
+ colors.push_back( Color(255,155,100) );
+ colors.push_back( Color(255,155,100) );
+ VisualServer::get_singleton()->poly_add_primitive(indicators,points,empty,colors,empty);
+ */
+ } break;
+ default: {}
}
+ }
- } else if (m.button_mask & BUTTON_MASK_RIGHT) {
+ } else if (m->get_button_mask() & BUTTON_MASK_RIGHT) {
- if (nav_scheme == NAVIGATION_MAYA && m.mod.alt) {
- nav_mode = NAVIGATION_ZOOM;
- } else {
- nav_mode = NAVIGATION_LOOK;
- }
+ if (nav_scheme == NAVIGATION_MAYA && m->get_alt()) {
+ nav_mode = NAVIGATION_ZOOM;
+ } else {
+ nav_mode = NAVIGATION_LOOK;
+ }
- } else if (m.button_mask & BUTTON_MASK_MIDDLE) {
-
- if (nav_scheme == NAVIGATION_GODOT) {
-
- int mod = 0;
- if (m.mod.shift)
- mod = KEY_SHIFT;
- if (m.mod.alt)
- mod = KEY_ALT;
- if (m.mod.control)
- mod = KEY_CONTROL;
- if (m.mod.meta)
- mod = KEY_META;
-
- if (mod == _get_key_modifier("editors/3d/pan_modifier"))
- nav_mode = NAVIGATION_PAN;
- else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
- nav_mode = NAVIGATION_ZOOM;
- else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
- nav_mode = NAVIGATION_ORBIT;
-
- } else if (nav_scheme == NAVIGATION_MAYA) {
- if (m.mod.alt)
- nav_mode = NAVIGATION_PAN;
- }
+ } else if (m->get_button_mask() & BUTTON_MASK_MIDDLE) {
+
+ if (nav_scheme == NAVIGATION_GODOT) {
- } else if (EditorSettings::get_singleton()->get("editors/3d/emulate_3_button_mouse")) {
- // Handle trackpad (no external mouse) use case
int mod = 0;
- if (m.mod.shift)
+ if (m->get_shift())
mod = KEY_SHIFT;
- if (m.mod.alt)
+ if (m->get_alt())
mod = KEY_ALT;
- if (m.mod.control)
+ if (m->get_control())
mod = KEY_CONTROL;
- if (m.mod.meta)
+ if (m->get_metakey())
mod = KEY_META;
- if (mod) {
- if (mod == _get_key_modifier("editors/3d/pan_modifier"))
- nav_mode = NAVIGATION_PAN;
- else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
- nav_mode = NAVIGATION_ZOOM;
- else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
- nav_mode = NAVIGATION_ORBIT;
- }
+ if (mod == _get_key_modifier("editors/3d/pan_modifier"))
+ nav_mode = NAVIGATION_PAN;
+ else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
+ nav_mode = NAVIGATION_ZOOM;
+ else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
+ nav_mode = NAVIGATION_ORBIT;
+
+ } else if (nav_scheme == NAVIGATION_MAYA) {
+ if (m->get_alt())
+ nav_mode = NAVIGATION_PAN;
}
- switch (nav_mode) {
- case NAVIGATION_PAN: {
+ } else if (EditorSettings::get_singleton()->get("editors/3d/emulate_3_button_mouse")) {
+ // Handle trackpad (no external mouse) use case
+ int mod = 0;
+ if (m->get_shift())
+ mod = KEY_SHIFT;
+ if (m->get_alt())
+ mod = KEY_ALT;
+ if (m->get_control())
+ mod = KEY_CONTROL;
+ if (m->get_metakey())
+ mod = KEY_META;
+
+ if (mod) {
+ if (mod == _get_key_modifier("editors/3d/pan_modifier"))
+ nav_mode = NAVIGATION_PAN;
+ else if (mod == _get_key_modifier("editors/3d/zoom_modifier"))
+ nav_mode = NAVIGATION_ZOOM;
+ else if (mod == _get_key_modifier("editors/3d/orbit_modifier"))
+ nav_mode = NAVIGATION_ORBIT;
+ }
+ }
- real_t pan_speed = 1 / 150.0;
- int pan_speed_modifier = 10;
- if (nav_scheme == NAVIGATION_MAYA && m.mod.shift)
- pan_speed *= pan_speed_modifier;
+ switch (nav_mode) {
+ case NAVIGATION_PAN: {
- Point2i relative = _get_warped_mouse_motion(m);
+ real_t pan_speed = 1 / 150.0;
+ int pan_speed_modifier = 10;
+ if (nav_scheme == NAVIGATION_MAYA && m->get_shift())
+ pan_speed *= pan_speed_modifier;
- Transform camera_transform;
-
- camera_transform.translate(cursor.pos);
- camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot);
- camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot);
- Vector3 translation(-relative.x * pan_speed, relative.y * pan_speed, 0);
- translation *= cursor.distance / DISTANCE_DEFAULT;
- camera_transform.translate(translation);
- cursor.pos = camera_transform.origin;
-
- } break;
-
- case NAVIGATION_ZOOM: {
- real_t zoom_speed = 1 / 80.0;
- int zoom_speed_modifier = 10;
- if (nav_scheme == NAVIGATION_MAYA && m.mod.shift)
- zoom_speed *= zoom_speed_modifier;
-
- NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/zoom_style").operator int();
- if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) {
- if (m.relative_x > 0)
- scale_cursor_distance(1 - m.relative_x * zoom_speed);
- else if (m.relative_x < 0)
- scale_cursor_distance(1.0 / (1 + m.relative_x * zoom_speed));
- } else {
- if (m.relative_y > 0)
- scale_cursor_distance(1 + m.relative_y * zoom_speed);
- else if (m.relative_y < 0)
- scale_cursor_distance(1.0 / (1 - m.relative_y * zoom_speed));
- }
+ Point2i relative = _get_warped_mouse_motion(m);
+
+ Transform camera_transform;
+
+ camera_transform.translate(cursor.pos);
+ camera_transform.basis.rotate(Vector3(1, 0, 0), -cursor.x_rot);
+ camera_transform.basis.rotate(Vector3(0, 1, 0), -cursor.y_rot);
+ Vector3 translation(-relative.x * pan_speed, relative.y * pan_speed, 0);
+ translation *= cursor.distance / DISTANCE_DEFAULT;
+ camera_transform.translate(translation);
+ cursor.pos = camera_transform.origin;
+
+ } break;
+
+ case NAVIGATION_ZOOM: {
+ real_t zoom_speed = 1 / 80.0;
+ int zoom_speed_modifier = 10;
+ if (nav_scheme == NAVIGATION_MAYA && m->get_shift())
+ zoom_speed *= zoom_speed_modifier;
+
+ NavigationZoomStyle zoom_style = (NavigationZoomStyle)EditorSettings::get_singleton()->get("editors/3d/zoom_style").operator int();
+ if (zoom_style == NAVIGATION_ZOOM_HORIZONTAL) {
+ if (m->get_relative().x > 0)
+ scale_cursor_distance(1 - m->get_relative().x * zoom_speed);
+ else if (m->get_relative().x < 0)
+ scale_cursor_distance(1.0 / (1 + m->get_relative().x * zoom_speed));
+ } else {
+ if (m->get_relative().y > 0)
+ scale_cursor_distance(1 + m->get_relative().y * zoom_speed);
+ else if (m->get_relative().y < 0)
+ scale_cursor_distance(1.0 / (1 - m->get_relative().y * zoom_speed));
+ }
+
+ } break;
- } break;
+ case NAVIGATION_ORBIT: {
+ Point2i relative = _get_warped_mouse_motion(m);
+ cursor.x_rot += relative.y / 80.0;
+ cursor.y_rot += relative.x / 80.0;
+ if (cursor.x_rot > Math_PI / 2.0)
+ cursor.x_rot = Math_PI / 2.0;
+ if (cursor.x_rot < -Math_PI / 2.0)
+ cursor.x_rot = -Math_PI / 2.0;
+ name = "";
+ _update_name();
+ } break;
- case NAVIGATION_ORBIT: {
+ case NAVIGATION_LOOK: {
+ // Freelook only works properly in perspective.
+ // It technically works too in ortho, but it's awful for a user due to fov being near zero
+ if (!orthogonal) {
Point2i relative = _get_warped_mouse_motion(m);
- cursor.x_rot += relative.y / 80.0;
- cursor.y_rot += relative.x / 80.0;
+ cursor.x_rot += relative.y / 120.0;
+ cursor.y_rot += relative.x / 120.0;
if (cursor.x_rot > Math_PI / 2.0)
cursor.x_rot = Math_PI / 2.0;
if (cursor.x_rot < -Math_PI / 2.0)
cursor.x_rot = -Math_PI / 2.0;
+
+ // Look is like Orbit, except the cursor translates, not the camera
+ Transform camera_transform = to_camera_transform(cursor);
+ Vector3 pos = camera_transform.xform(Vector3(0, 0, 0));
+ Vector3 diff = camera->get_translation() - pos;
+ cursor.pos += diff;
+
name = "";
_update_name();
- } break;
-
- case NAVIGATION_LOOK: {
- // Freelook only works properly in perspective.
- // It technically works too in ortho, but it's awful for a user due to fov being near zero
- if (!orthogonal) {
- Point2i relative = _get_warped_mouse_motion(m);
- cursor.x_rot += relative.y / 120.0;
- cursor.y_rot += relative.x / 120.0;
- if (cursor.x_rot > Math_PI / 2.0)
- cursor.x_rot = Math_PI / 2.0;
- if (cursor.x_rot < -Math_PI / 2.0)
- cursor.x_rot = -Math_PI / 2.0;
-
- // Look is like Orbit, except the cursor translates, not the camera
- Transform camera_transform = to_camera_transform(cursor);
- Vector3 pos = camera_transform.xform(Vector3(0, 0, 0));
- Vector3 diff = camera->get_translation() - pos;
- cursor.pos += diff;
-
- name = "";
- _update_name();
- }
+ }
- } break;
+ } break;
- default: {}
- }
- } break;
- case InputEvent::KEY: {
- const InputEventKey &k = p_event.key;
- if (!k.pressed)
- break;
+ default: {}
+ }
+ }
- if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
- if (_edit.mode != TRANSFORM_NONE) {
- _edit.snap = true;
- }
- }
- if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) {
- cursor.y_rot = 0;
- cursor.x_rot = -Math_PI / 2.0;
- set_message(TTR("Bottom View."), 2);
- name = TTR("Bottom");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/top_view", p_event)) {
- cursor.y_rot = 0;
- cursor.x_rot = Math_PI / 2.0;
- set_message(TTR("Top View."), 2);
- name = TTR("Top");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/rear_view", p_event)) {
- cursor.x_rot = 0;
- cursor.y_rot = Math_PI;
- set_message(TTR("Rear View."), 2);
- name = TTR("Rear");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/front_view", p_event)) {
- cursor.x_rot = 0;
- cursor.y_rot = 0;
- set_message(TTR("Front View."), 2);
- name = TTR("Front");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/left_view", p_event)) {
- cursor.x_rot = 0;
- cursor.y_rot = Math_PI / 2.0;
- set_message(TTR("Left View."), 2);
- name = TTR("Left");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/right_view", p_event)) {
- cursor.x_rot = 0;
- cursor.y_rot = -Math_PI / 2.0;
- set_message(TTR("Right View."), 2);
- name = TTR("Right");
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) {
- _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
- _update_name();
- }
- if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) {
- if (!get_selected_count() || _edit.mode != TRANSFORM_NONE)
- break;
+ Ref<InputEventKey> k = p_event;
- if (!AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) {
- set_message(TTR("Keying is disabled (no key inserted)."));
- break;
- }
+ if (k.is_valid()) {
+ if (!k->is_pressed())
+ return;
+
+ if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) {
+ if (_edit.mode != TRANSFORM_NONE) {
+ _edit.snap = true;
+ }
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/bottom_view", p_event)) {
+ cursor.y_rot = 0;
+ cursor.x_rot = -Math_PI / 2.0;
+ set_message(TTR("Bottom View."), 2);
+ name = TTR("Bottom");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/top_view", p_event)) {
+ cursor.y_rot = 0;
+ cursor.x_rot = Math_PI / 2.0;
+ set_message(TTR("Top View."), 2);
+ name = TTR("Top");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/rear_view", p_event)) {
+ cursor.x_rot = 0;
+ cursor.y_rot = Math_PI;
+ set_message(TTR("Rear View."), 2);
+ name = TTR("Rear");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/front_view", p_event)) {
+ cursor.x_rot = 0;
+ cursor.y_rot = 0;
+ set_message(TTR("Front View."), 2);
+ name = TTR("Front");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/left_view", p_event)) {
+ cursor.x_rot = 0;
+ cursor.y_rot = Math_PI / 2.0;
+ set_message(TTR("Left View."), 2);
+ name = TTR("Left");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/right_view", p_event)) {
+ cursor.x_rot = 0;
+ cursor.y_rot = -Math_PI / 2.0;
+ set_message(TTR("Right View."), 2);
+ name = TTR("Right");
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/switch_perspective_orthogonal", p_event)) {
+ _menu_option(orthogonal ? VIEW_PERSPECTIVE : VIEW_ORTHOGONAL);
+ _update_name();
+ }
+ if (ED_IS_SHORTCUT("spatial_editor/insert_anim_key", p_event)) {
+ if (!get_selected_count() || _edit.mode != TRANSFORM_NONE)
+ return;
- List<Node *> &selection = editor_selection->get_selected_node_list();
+ if (!AnimationPlayerEditor::singleton->get_key_editor()->has_keying()) {
+ set_message(TTR("Keying is disabled (no key inserted)."));
+ return;
+ }
- for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
+ List<Node *> &selection = editor_selection->get_selected_node_list();
- Spatial *sp = E->get()->cast_to<Spatial>();
- if (!sp)
- continue;
+ for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
- emit_signal("transform_key_request", sp, "", sp->get_transform());
- }
+ Spatial *sp = E->get()->cast_to<Spatial>();
+ if (!sp)
+ continue;
- set_message(TTR("Animation Key Inserted."));
+ emit_signal("transform_key_request", sp, "", sp->get_transform());
}
- if (k.scancode == KEY_SPACE) {
- if (!k.pressed) emit_signal("toggle_maximize_view", this);
- }
+ set_message(TTR("Animation Key Inserted."));
+ }
- } break;
+ if (k->get_scancode() == KEY_SPACE) {
+ if (!k->is_pressed()) emit_signal("toggle_maximize_view", this);
+ }
}
}
@@ -1526,12 +1528,12 @@ void SpatialEditorViewport::scale_cursor_distance(real_t scale) {
surface->update();
}
-Point2i SpatialEditorViewport::_get_warped_mouse_motion(const InputEventMouseMotion &p_ev_mouse_motion) const {
+Point2i SpatialEditorViewport::_get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const {
Point2i relative;
if (bool(EditorSettings::get_singleton()->get("editors/3d/warped_mouse_panning"))) {
relative = Input::get_singleton()->warp_mouse_motion(p_ev_mouse_motion, surface->get_global_rect());
} else {
- relative = Point2i(p_ev_mouse_motion.relative_x, p_ev_mouse_motion.relative_y);
+ relative = p_ev_mouse_motion->get_relative();
}
return relative;
}
@@ -1545,13 +1547,13 @@ void SpatialEditorViewport::_update_freelook(real_t delta) {
Vector3 right = camera->get_transform().basis.xform(Vector3(1, 0, 0));
Vector3 up = camera->get_transform().basis.xform(Vector3(0, 1, 0));
- int key_left = ED_SHORTCUT("spatial_editor/freelook_left", TTR("Freelook Left"), KEY_A)->get_shortcut().key.scancode;
- int key_right = ED_SHORTCUT("spatial_editor/freelook_right", TTR("Freelook Right"), KEY_D)->get_shortcut().key.scancode;
- int key_forward = ED_SHORTCUT("spatial_editor/freelook_forward", TTR("Freelook Forward"), KEY_W)->get_shortcut().key.scancode;
- int key_backwards = ED_SHORTCUT("spatial_editor/freelook_backwards", TTR("Freelook Backwards"), KEY_S)->get_shortcut().key.scancode;
- int key_up = ED_SHORTCUT("spatial_editor/freelook_up", TTR("Freelook Up"), KEY_Q)->get_shortcut().key.scancode;
- int key_down = ED_SHORTCUT("spatial_editor/freelook_down", TTR("Freelook Down"), KEY_E)->get_shortcut().key.scancode;
- int key_speed_modifier = ED_SHORTCUT("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), KEY_SHIFT)->get_shortcut().key.scancode;
+ int key_left = ED_SHORTCUT("spatial_editor/freelook_left", TTR("Freelook Left"), KEY_A)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_right = ED_SHORTCUT("spatial_editor/freelook_right", TTR("Freelook Right"), KEY_D)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_forward = ED_SHORTCUT("spatial_editor/freelook_forward", TTR("Freelook Forward"), KEY_W)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_backwards = ED_SHORTCUT("spatial_editor/freelook_backwards", TTR("Freelook Backwards"), KEY_S)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_up = ED_SHORTCUT("spatial_editor/freelook_up", TTR("Freelook Up"), KEY_Q)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_down = ED_SHORTCUT("spatial_editor/freelook_down", TTR("Freelook Down"), KEY_E)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
+ int key_speed_modifier = ED_SHORTCUT("spatial_editor/freelook_speed_modifier", TTR("Freelook Speed Modifier"), KEY_SHIFT)->get_shortcut()->cast_to<InputEventKey>()->get_scancode();
Vector3 velocity;
bool pressed = false;
@@ -3274,7 +3276,7 @@ bool SpatialEditor::is_any_freelook_active() const {
return false;
}
-void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
+void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) {
if (!is_visible_in_tree() || get_viewport()->gui_has_modal_stack())
return;
@@ -3294,43 +3296,39 @@ void SpatialEditor::_unhandled_key_input(InputEvent p_event) {
}
#endif
- switch (p_event.type) {
-
- case InputEvent::KEY: {
+ Ref<InputEventKey> k = p_event;
- // Note: need to check is_echo because first person movement keys might still be held
- if (!is_any_freelook_active() && !p_event.is_echo()) {
+ if (k.is_valid()) {
- const InputEventKey &k = p_event.key;
+ // Note: need to check is_echo because first person movement keys might still be held
+ if (!is_any_freelook_active() && !p_event->is_echo()) {
- if (!k.pressed)
- break;
+ if (!k->is_pressed())
+ return;
- if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event))
- _menu_item_pressed(MENU_TOOL_SELECT);
+ if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event))
+ _menu_item_pressed(MENU_TOOL_SELECT);
- else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event))
- _menu_item_pressed(MENU_TOOL_MOVE);
+ else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event))
+ _menu_item_pressed(MENU_TOOL_MOVE);
- else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event))
- _menu_item_pressed(MENU_TOOL_ROTATE);
+ else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event))
+ _menu_item_pressed(MENU_TOOL_ROTATE);
- else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event))
- _menu_item_pressed(MENU_TOOL_SCALE);
+ else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event))
+ _menu_item_pressed(MENU_TOOL_SCALE);
- else if (ED_IS_SHORTCUT("spatial_editor/display_wireframe", p_event)) {
- if (k.mod.shift || k.mod.control || k.mod.command)
- break;
+ else if (ED_IS_SHORTCUT("spatial_editor/display_wireframe", p_event)) {
+ if (k->get_shift() || k->get_control() || k->get_command())
+ return;
- if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) {
- _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL);
- } else {
- _menu_item_pressed(MENU_VIEW_DISPLAY_WIREFRAME);
- }
+ if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(MENU_VIEW_DISPLAY_WIREFRAME))) {
+ _menu_item_pressed(MENU_VIEW_DISPLAY_NORMAL);
+ } else {
+ _menu_item_pressed(MENU_VIEW_DISPLAY_WIREFRAME);
}
}
-
- } break;
+ }
}
}
void SpatialEditor::_notification(int p_what) {
@@ -3547,12 +3545,13 @@ void SpatialEditor::_update_default_light_angle() {
}
}
-void SpatialEditor::_default_light_angle_input(const InputEvent &p_event) {
+void SpatialEditor::_default_light_angle_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & (0x1 | 0x2 | 0x4)) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid() && mm->get_button_mask() & (0x1 | 0x2 | 0x4)) {
- settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - p_event.mouse_motion.relative_x * 0.01, Math_PI * 2.0);
- settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - p_event.mouse_motion.relative_y * 0.01, Math_PI * 2.0);
+ settings_default_light_rot_y = Math::fposmod(settings_default_light_rot_y - mm->get_relative().x * 0.01, Math_PI * 2.0);
+ settings_default_light_rot_x = Math::fposmod(settings_default_light_rot_x - mm->get_relative().y * 0.01, Math_PI * 2.0);
_update_default_light_angle();
}
}
diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h
index 0f07ec4c66..1f76d9bfb8 100644
--- a/editor/plugins/spatial_editor_plugin.h
+++ b/editor/plugins/spatial_editor_plugin.h
@@ -236,7 +236,7 @@ private:
void _draw();
void _smouseenter();
- void _sinput(const InputEvent &p_ie);
+ void _sinput(const Ref<InputEvent> &p_ie);
void _update_freelook(real_t delta);
SpatialEditor *spatial_editor;
@@ -249,8 +249,8 @@ private:
void _finish_gizmo_instances();
void _selection_result_pressed(int);
void _selection_menu_hide();
- void _list_select(InputEventMouseButton b);
- Point2i _get_warped_mouse_motion(const InputEventMouseMotion &p_ev_mouse_motion) const;
+ void _list_select(Ref<InputEventMouseButton> b);
+ Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const;
protected:
void _notification(int p_what);
@@ -464,14 +464,14 @@ private:
void _update_ambient_light_color(const Color &p_color);
void _update_default_light_angle();
- void _default_light_angle_input(const InputEvent &p_event);
+ void _default_light_angle_input(const Ref<InputEvent> &p_event);
bool is_any_freelook_active() const;
protected:
void _notification(int p_what);
//void _gui_input(InputEvent p_event);
- void _unhandled_key_input(InputEvent p_event);
+ void _unhandled_key_input(Ref<InputEvent> p_event);
static void _bind_methods();
diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp
index c7c77fa960..d06c065f4f 100644
--- a/editor/plugins/sprite_frames_editor_plugin.cpp
+++ b/editor/plugins/sprite_frames_editor_plugin.cpp
@@ -34,7 +34,7 @@
#include "io/resource_loader.h"
#include "scene/3d/sprite_3d.h"
-void SpriteFramesEditor::_gui_input(InputEvent p_event) {
+void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) {
}
void SpriteFramesEditor::_notification(int p_what) {
diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h
index 3778e4ca55..c9081c599a 100644
--- a/editor/plugins/sprite_frames_editor_plugin.h
+++ b/editor/plugins/sprite_frames_editor_plugin.h
@@ -100,7 +100,7 @@ class SpriteFramesEditor : public PanelContainer {
protected:
void _notification(int p_what);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
static void _bind_methods();
public:
diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp
index 62977d86ea..3b705aae24 100644
--- a/editor/plugins/texture_editor_plugin.cpp
+++ b/editor/plugins/texture_editor_plugin.cpp
@@ -33,7 +33,7 @@
#include "global_config.h"
#include "io/resource_loader.h"
-void TextureEditor::_gui_input(InputEvent p_event) {
+void TextureEditor::_gui_input(Ref<InputEvent> p_event) {
}
void TextureEditor::_notification(int p_what) {
diff --git a/editor/plugins/texture_editor_plugin.h b/editor/plugins/texture_editor_plugin.h
index 8750ce4d5e..9382983538 100644
--- a/editor/plugins/texture_editor_plugin.h
+++ b/editor/plugins/texture_editor_plugin.h
@@ -42,7 +42,7 @@ class TextureEditor : public Control {
protected:
void _notification(int p_what);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
static void _bind_methods();
public:
diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp
index 89995edf05..799bfbf358 100644
--- a/editor/plugins/texture_region_editor_plugin.cpp
+++ b/editor/plugins/texture_region_editor_plugin.cpp
@@ -202,7 +202,7 @@ void TextureRegionEditor::_region_draw() {
}
}
-void TextureRegionEditor::_region_input(const InputEvent &p_input) {
+void TextureRegionEditor::_region_input(const Ref<InputEvent> &p_input) {
Transform2D mtx;
mtx.elements[2] = -draw_ofs;
mtx.scale_basis(Vector2(draw_zoom, draw_zoom));
@@ -218,13 +218,12 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
mtx.xform(rect.pos + Vector2(0, rect.size.y / 2)) + Vector2(-4, 0)
};
- if (p_input.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb;
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_input.mouse_button;
+ if (mb->get_button_index() == BUTTON_LEFT) {
- if (mb.button_index == BUTTON_LEFT) {
-
- if (mb.pressed) {
+ if (mb->is_pressed()) {
if (node_patch9 || obj_styleBox.is_valid()) {
edited_margin = -1;
float margins[4];
@@ -245,26 +244,26 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
mtx.basis_xform(rect.pos + Vector2(margins[2], 0)) - draw_ofs,
mtx.basis_xform(rect.pos + rect.size - Vector2(margins[3], 0)) - draw_ofs
};
- if (Math::abs(mb.y - pos[0].y) < 8) {
+ if (Math::abs(mb->get_pos().y - pos[0].y) < 8) {
edited_margin = 0;
prev_margin = margins[0];
- } else if (Math::abs(mb.y - pos[1].y) < 8) {
+ } else if (Math::abs(mb->get_pos().y - pos[1].y) < 8) {
edited_margin = 1;
prev_margin = margins[1];
- } else if (Math::abs(mb.x - pos[2].x) < 8) {
+ } else if (Math::abs(mb->get_pos().x - pos[2].x) < 8) {
edited_margin = 2;
prev_margin = margins[2];
- } else if (Math::abs(mb.x - pos[3].x) < 8) {
+ } else if (Math::abs(mb->get_pos().x - pos[3].x) < 8) {
edited_margin = 3;
prev_margin = margins[3];
}
if (edited_margin >= 0) {
- drag_from = Vector2(mb.x, mb.y);
+ drag_from = Vector2(mb->get_pos().x, mb->get_pos().y);
drag = true;
}
}
if (edited_margin < 0 && snap_mode == SNAP_AUTOSLICE) {
- Vector2 point = mtx.affine_inverse().xform(Vector2(mb.x, mb.y));
+ Vector2 point = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y));
for (List<Rect2>::Element *E = autoslice_cache.front(); E; E = E->next()) {
if (E->get().has_point(point)) {
rect = E->get();
@@ -302,7 +301,7 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
}
}
} else if (edited_margin < 0) {
- drag_from = mtx.affine_inverse().xform(Vector2(mb.x, mb.y));
+ drag_from = mtx.affine_inverse().xform(Vector2(mb->get_pos().x, mb->get_pos().y));
if (snap_mode == SNAP_PIXEL)
drag_from = drag_from.snapped(Vector2(1, 1));
else if (snap_mode == SNAP_GRID)
@@ -319,7 +318,7 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
for (int i = 0; i < 8; i++) {
Vector2 tuv = endpoints[i];
- if (tuv.distance_to(Vector2(mb.x, mb.y)) < 8) {
+ if (tuv.distance_to(Vector2(mb->get_pos().x, mb->get_pos().y)) < 8) {
drag_index = i;
}
}
@@ -369,7 +368,7 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
creating = false;
}
- } else if (mb.button_index == BUTTON_RIGHT && mb.pressed) {
+ } else if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) {
if (drag) {
drag = false;
@@ -387,18 +386,20 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
drag_index = -1;
}
}
- } else if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
+ } else if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
_zoom_in();
- } else if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
_zoom_out();
}
- } else if (p_input.type == InputEvent::MOUSE_MOTION) {
+ }
+
+ Ref<InputEventMouseMotion> mm = p_input;
- const InputEventMouseMotion &mm = p_input.mouse_motion;
+ if (mm.is_valid()) {
- if (mm.button_mask & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
+ if (mm->get_button_mask() & BUTTON_MASK_MIDDLE || Input::get_singleton()->is_key_pressed(KEY_SPACE)) {
- Vector2 draged(mm.relative_x, mm.relative_y);
+ Vector2 draged(mm->get_relative().x, mm->get_relative().y);
hscroll->set_value(hscroll->get_value() - draged.x);
vscroll->set_value(vscroll->get_value() - draged.y);
@@ -407,13 +408,13 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
if (edited_margin >= 0) {
float new_margin;
if (edited_margin == 0)
- new_margin = prev_margin + (mm.y - drag_from.y) / draw_zoom;
+ new_margin = prev_margin + (mm->get_pos().y - drag_from.y) / draw_zoom;
else if (edited_margin == 1)
- new_margin = prev_margin - (mm.y - drag_from.y) / draw_zoom;
+ new_margin = prev_margin - (mm->get_pos().y - drag_from.y) / draw_zoom;
else if (edited_margin == 2)
- new_margin = prev_margin + (mm.x - drag_from.x) / draw_zoom;
+ new_margin = prev_margin + (mm->get_pos().x - drag_from.x) / draw_zoom;
else if (edited_margin == 3)
- new_margin = prev_margin - (mm.x - drag_from.x) / draw_zoom;
+ new_margin = prev_margin - (mm->get_pos().x - drag_from.x) / draw_zoom;
if (new_margin < 0)
new_margin = 0;
static Margin m[4] = { MARGIN_TOP, MARGIN_BOTTOM, MARGIN_LEFT, MARGIN_RIGHT };
@@ -422,7 +423,7 @@ void TextureRegionEditor::_region_input(const InputEvent &p_input) {
if (obj_styleBox.is_valid())
obj_styleBox->set_margin_size(m[edited_margin], new_margin);
} else {
- Vector2 new_pos = mtx.affine_inverse().xform(Vector2(mm.x, mm.y));
+ Vector2 new_pos = mtx.affine_inverse().xform(mm->get_pos());
if (snap_mode == SNAP_PIXEL)
new_pos = new_pos.snapped(Vector2(1, 1));
else if (snap_mode == SNAP_GRID)
diff --git a/editor/plugins/texture_region_editor_plugin.h b/editor/plugins/texture_region_editor_plugin.h
index 093e2f7d01..cb0b9fc372 100644
--- a/editor/plugins/texture_region_editor_plugin.h
+++ b/editor/plugins/texture_region_editor_plugin.h
@@ -122,7 +122,7 @@ protected:
public:
void _edit_region();
void _region_draw();
- void _region_input(const InputEvent &p_input);
+ void _region_input(const Ref<InputEvent> &p_input);
void _scroll_changed(float);
void edit(Object *p_obj);
diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp
index 9f99a9b978..9f7a41b8b6 100644
--- a/editor/plugins/tile_map_editor_plugin.cpp
+++ b/editor/plugins/tile_map_editor_plugin.cpp
@@ -179,14 +179,16 @@ void TileMapEditor::_text_changed(const String &p_text) {
_update_palette();
}
-void TileMapEditor::_sbox_input(const InputEvent &p_ie) {
+void TileMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY && (p_ie.key.scancode == KEY_UP ||
- p_ie.key.scancode == KEY_DOWN ||
- p_ie.key.scancode == KEY_PAGEUP ||
- p_ie.key.scancode == KEY_PAGEDOWN)) {
+ Ref<InputEventKey> k = p_ie;
- palette->call("_gui_input", p_ie);
+ if (k.is_valid() && (k->get_scancode() == KEY_UP ||
+ k->get_scancode() == KEY_DOWN ||
+ k->get_scancode() == KEY_PAGEUP ||
+ k->get_scancode() == KEY_PAGEDOWN)) {
+
+ palette->call("_gui_input", k);
search_box->accept_event();
}
}
@@ -622,7 +624,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) {
return points;
}
-bool TileMapEditor::forward_gui_input(const InputEvent &p_event) {
+bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree())
return false;
@@ -630,464 +632,459 @@ bool TileMapEditor::forward_gui_input(const InputEvent &p_event) {
Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform();
Transform2D xform_inv = xform.affine_inverse();
- switch (p_event.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- const InputEventMouseButton &mb = p_event.mouse_button;
-
- if (mb.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
- if (mb.pressed) {
+ if (mb.is_valid()) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
- return false; //drag
+ if (mb->is_pressed()) {
- if (tool == TOOL_NONE) {
+ if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
+ return false; //drag
- if (mb.mod.shift) {
+ if (tool == TOOL_NONE) {
- if (mb.mod.control)
- tool = TOOL_RECTANGLE_PAINT;
- else
- tool = TOOL_LINE_PAINT;
+ if (mb->get_shift()) {
- selection_active = false;
- rectangle_begin = over_tile;
+ if (mb->get_control())
+ tool = TOOL_RECTANGLE_PAINT;
+ else
+ tool = TOOL_LINE_PAINT;
- return true;
- }
+ selection_active = false;
+ rectangle_begin = over_tile;
- if (mb.mod.control) {
+ return true;
+ }
- tool = TOOL_PICKING;
- _pick_tile(over_tile);
+ if (mb->get_control()) {
- return true;
- }
+ tool = TOOL_PICKING;
+ _pick_tile(over_tile);
- tool = TOOL_PAINTING;
+ return true;
}
- if (tool == TOOL_PAINTING) {
-
- int id = get_selected_tile();
+ tool = TOOL_PAINTING;
+ }
- if (id != TileMap::INVALID_CELL) {
+ if (tool == TOOL_PAINTING) {
- tool = TOOL_PAINTING;
+ int id = get_selected_tile();
- paint_undo.clear();
- paint_undo[over_tile] = _get_op_from_cell(over_tile);
+ if (id != TileMap::INVALID_CELL) {
- _set_cell(over_tile, id, flip_h, flip_v, transpose);
- }
- } else if (tool == TOOL_PICKING) {
+ tool = TOOL_PAINTING;
- _pick_tile(over_tile);
- } else if (tool == TOOL_SELECTING) {
+ paint_undo.clear();
+ paint_undo[over_tile] = _get_op_from_cell(over_tile);
- selection_active = true;
- rectangle_begin = over_tile;
+ _set_cell(over_tile, id, flip_h, flip_v, transpose);
}
+ } else if (tool == TOOL_PICKING) {
- return true;
+ _pick_tile(over_tile);
+ } else if (tool == TOOL_SELECTING) {
- } else {
+ selection_active = true;
+ rectangle_begin = over_tile;
+ }
+
+ return true;
- if (tool != TOOL_NONE) {
+ } else {
- if (tool == TOOL_PAINTING) {
+ if (tool != TOOL_NONE) {
- int id = get_selected_tile();
+ if (tool == TOOL_PAINTING) {
- if (id != TileMap::INVALID_CELL && paint_undo.size()) {
+ int id = get_selected_tile();
- undo_redo->create_action(TTR("Paint TileMap"));
- for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+ if (id != TileMap::INVALID_CELL && paint_undo.size()) {
- Point2 p = E->key();
- undo_redo->add_do_method(node, "set_cellv", p, id, flip_h, flip_v, transpose);
- undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr);
- }
- undo_redo->commit_action();
+ undo_redo->create_action(TTR("Paint TileMap"));
+ for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
- paint_undo.clear();
+ Point2 p = E->key();
+ undo_redo->add_do_method(node, "set_cellv", p, id, flip_h, flip_v, transpose);
+ undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr);
}
- } else if (tool == TOOL_LINE_PAINT) {
-
- int id = get_selected_tile();
+ undo_redo->commit_action();
- if (id != TileMap::INVALID_CELL) {
+ paint_undo.clear();
+ }
+ } else if (tool == TOOL_LINE_PAINT) {
- undo_redo->create_action("Line Draw");
- for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+ int id = get_selected_tile();
- _set_cell(E->key(), id, flip_h, flip_v, transpose, true);
- }
- undo_redo->commit_action();
+ if (id != TileMap::INVALID_CELL) {
- paint_undo.clear();
+ undo_redo->create_action("Line Draw");
+ for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
- canvas_item_editor->update();
+ _set_cell(E->key(), id, flip_h, flip_v, transpose, true);
}
- } else if (tool == TOOL_RECTANGLE_PAINT) {
-
- int id = get_selected_tile();
-
- if (id != TileMap::INVALID_CELL) {
+ undo_redo->commit_action();
- undo_redo->create_action("Rectangle Paint");
- for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) {
- for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) {
+ paint_undo.clear();
- _set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true);
- }
- }
- undo_redo->commit_action();
+ canvas_item_editor->update();
+ }
+ } else if (tool == TOOL_RECTANGLE_PAINT) {
- canvas_item_editor->update();
- }
- } else if (tool == TOOL_DUPLICATING) {
+ int id = get_selected_tile();
- Point2 ofs = over_tile - rectangle.pos;
+ if (id != TileMap::INVALID_CELL) {
- undo_redo->create_action(TTR("Duplicate"));
- for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) {
+ undo_redo->create_action("Rectangle Paint");
+ for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) {
+ for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) {
- _set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose, true);
+ _set_cell(Point2i(j, i), id, flip_h, flip_v, transpose, true);
+ }
}
undo_redo->commit_action();
- copydata.clear();
-
canvas_item_editor->update();
+ }
+ } else if (tool == TOOL_DUPLICATING) {
- } else if (tool == TOOL_SELECTING) {
+ Point2 ofs = over_tile - rectangle.pos;
- canvas_item_editor->update();
+ undo_redo->create_action(TTR("Duplicate"));
+ for (List<TileData>::Element *E = copydata.front(); E; E = E->next()) {
- } else if (tool == TOOL_BUCKET) {
+ _set_cell(E->get().pos + ofs, E->get().cell, E->get().flip_h, E->get().flip_v, E->get().transpose, true);
+ }
+ undo_redo->commit_action();
- Dictionary pop;
- pop["id"] = node->get_cell(over_tile.x, over_tile.y);
- pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y);
- pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y);
- pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y);
+ copydata.clear();
+
+ canvas_item_editor->update();
- PoolVector<Vector2> points = _bucket_fill(over_tile);
+ } else if (tool == TOOL_SELECTING) {
- if (points.size() == 0)
- return false;
+ canvas_item_editor->update();
- Dictionary op;
- op["id"] = get_selected_tile();
- op["flip_h"] = flip_h;
- op["flip_v"] = flip_v;
- op["transpose"] = transpose;
+ } else if (tool == TOOL_BUCKET) {
- undo_redo->create_action("Bucket Fill");
+ Dictionary pop;
+ pop["id"] = node->get_cell(over_tile.x, over_tile.y);
+ pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y);
+ pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y);
+ pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y);
- undo_redo->add_do_method(this, "_fill_points", points, op);
- undo_redo->add_undo_method(this, "_fill_points", points, pop);
+ PoolVector<Vector2> points = _bucket_fill(over_tile);
- undo_redo->commit_action();
- }
+ if (points.size() == 0)
+ return false;
- tool = TOOL_NONE;
+ Dictionary op;
+ op["id"] = get_selected_tile();
+ op["flip_h"] = flip_h;
+ op["flip_v"] = flip_v;
+ op["transpose"] = transpose;
- return true;
+ undo_redo->create_action("Bucket Fill");
+
+ undo_redo->add_do_method(this, "_fill_points", points, op);
+ undo_redo->add_undo_method(this, "_fill_points", points, pop);
+
+ undo_redo->commit_action();
}
- }
- } else if (mb.button_index == BUTTON_RIGHT) {
- if (mb.pressed) {
+ tool = TOOL_NONE;
- if (tool == TOOL_SELECTING || selection_active) {
+ return true;
+ }
+ }
+ } else if (mb->get_button_index() == BUTTON_RIGHT) {
- tool = TOOL_NONE;
- selection_active = false;
+ if (mb->is_pressed()) {
- canvas_item_editor->update();
+ if (tool == TOOL_SELECTING || selection_active) {
- return true;
- }
+ tool = TOOL_NONE;
+ selection_active = false;
- if (tool == TOOL_DUPLICATING) {
+ canvas_item_editor->update();
- tool = TOOL_NONE;
- copydata.clear();
+ return true;
+ }
- canvas_item_editor->update();
+ if (tool == TOOL_DUPLICATING) {
- return true;
- }
+ tool = TOOL_NONE;
+ copydata.clear();
- if (tool == TOOL_NONE) {
+ canvas_item_editor->update();
- paint_undo.clear();
+ return true;
+ }
- Point2 local = node->world_to_map(xform_inv.xform(Point2(mb.x, mb.y)));
+ if (tool == TOOL_NONE) {
- if (mb.mod.shift) {
+ paint_undo.clear();
- if (mb.mod.control)
- tool = TOOL_RECTANGLE_ERASE;
- else
- tool = TOOL_LINE_ERASE;
+ Point2 local = node->world_to_map(xform_inv.xform(mb->get_pos()));
- selection_active = false;
- rectangle_begin = local;
- } else {
+ if (mb->get_shift()) {
- tool = TOOL_ERASING;
+ if (mb->get_control())
+ tool = TOOL_RECTANGLE_ERASE;
+ else
+ tool = TOOL_LINE_ERASE;
- paint_undo[local] = _get_op_from_cell(local);
- _set_cell(local, TileMap::INVALID_CELL);
- }
+ selection_active = false;
+ rectangle_begin = local;
+ } else {
- return true;
+ tool = TOOL_ERASING;
+
+ paint_undo[local] = _get_op_from_cell(local);
+ _set_cell(local, TileMap::INVALID_CELL);
}
- } else {
- if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
+ return true;
+ }
- if (paint_undo.size()) {
- undo_redo->create_action(TTR("Erase TileMap"));
- for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+ } else {
+ if (tool == TOOL_ERASING || tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
- Point2 p = E->key();
- undo_redo->add_do_method(node, "set_cellv", p, TileMap::INVALID_CELL, false, false, false);
- undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr);
- }
+ if (paint_undo.size()) {
+ undo_redo->create_action(TTR("Erase TileMap"));
+ for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
- undo_redo->commit_action();
- paint_undo.clear();
+ Point2 p = E->key();
+ undo_redo->add_do_method(node, "set_cellv", p, TileMap::INVALID_CELL, false, false, false);
+ undo_redo->add_undo_method(node, "set_cellv", p, E->get().idx, E->get().xf, E->get().yf, E->get().tr);
}
- if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
- canvas_item_editor->update();
- }
+ undo_redo->commit_action();
+ paint_undo.clear();
+ }
- tool = TOOL_NONE;
+ if (tool == TOOL_RECTANGLE_ERASE || tool == TOOL_LINE_ERASE) {
+ canvas_item_editor->update();
+ }
- return true;
+ tool = TOOL_NONE;
- } else if (tool == TOOL_BUCKET) {
+ return true;
- Dictionary pop;
- pop["id"] = node->get_cell(over_tile.x, over_tile.y);
- pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y);
- pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y);
- pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y);
+ } else if (tool == TOOL_BUCKET) {
- PoolVector<Vector2> points = _bucket_fill(over_tile, true);
+ Dictionary pop;
+ pop["id"] = node->get_cell(over_tile.x, over_tile.y);
+ pop["flip_h"] = node->is_cell_x_flipped(over_tile.x, over_tile.y);
+ pop["flip_v"] = node->is_cell_y_flipped(over_tile.x, over_tile.y);
+ pop["transpose"] = node->is_cell_transposed(over_tile.x, over_tile.y);
- if (points.size() == 0)
- return false;
+ PoolVector<Vector2> points = _bucket_fill(over_tile, true);
- undo_redo->create_action("Bucket Fill");
+ if (points.size() == 0)
+ return false;
- undo_redo->add_do_method(this, "_erase_points", points);
- undo_redo->add_undo_method(this, "_fill_points", points, pop);
+ undo_redo->create_action("Bucket Fill");
- undo_redo->commit_action();
- }
+ undo_redo->add_do_method(this, "_erase_points", points);
+ undo_redo->add_undo_method(this, "_fill_points", points, pop);
+
+ undo_redo->commit_action();
}
}
- } break;
- case InputEvent::MOUSE_MOTION: {
+ }
+ }
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_event;
- Point2i new_over_tile = node->world_to_map(xform_inv.xform(Point2(mm.x, mm.y)));
+ if (mm.is_valid()) {
- if (new_over_tile != over_tile) {
+ Point2i new_over_tile = node->world_to_map(xform_inv.xform(mm->get_pos()));
- over_tile = new_over_tile;
- canvas_item_editor->update();
- }
+ if (new_over_tile != over_tile) {
- int tile_under = node->get_cell(over_tile.x, over_tile.y);
- String tile_name = "none";
+ over_tile = new_over_tile;
+ canvas_item_editor->update();
+ }
- if (node->get_tileset()->has_tile(tile_under))
- tile_name = node->get_tileset()->tile_get_name(tile_under);
- tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]");
+ int tile_under = node->get_cell(over_tile.x, over_tile.y);
+ String tile_name = "none";
- if (tool == TOOL_PAINTING) {
+ if (node->get_tileset()->has_tile(tile_under))
+ tile_name = node->get_tileset()->tile_get_name(tile_under);
+ tile_info->set_text(String::num(over_tile.x) + ", " + String::num(over_tile.y) + " [" + tile_name + "]");
- int id = get_selected_tile();
- if (id != TileMap::INVALID_CELL) {
+ if (tool == TOOL_PAINTING) {
- if (!paint_undo.has(over_tile)) {
- paint_undo[over_tile] = _get_op_from_cell(over_tile);
- }
-
- _set_cell(over_tile, id, flip_h, flip_v, transpose);
+ int id = get_selected_tile();
+ if (id != TileMap::INVALID_CELL) {
- return true;
+ if (!paint_undo.has(over_tile)) {
+ paint_undo[over_tile] = _get_op_from_cell(over_tile);
}
- }
- if (tool == TOOL_SELECTING) {
-
- _select(rectangle_begin, over_tile);
+ _set_cell(over_tile, id, flip_h, flip_v, transpose);
return true;
}
+ }
- if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) {
+ if (tool == TOOL_SELECTING) {
- int id = get_selected_tile();
- bool erasing = (tool == TOOL_LINE_ERASE);
+ _select(rectangle_begin, over_tile);
- if (erasing && paint_undo.size()) {
+ return true;
+ }
- for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+ if (tool == TOOL_LINE_PAINT || tool == TOOL_LINE_ERASE) {
- _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr);
- }
- }
+ int id = get_selected_tile();
+ bool erasing = (tool == TOOL_LINE_ERASE);
- paint_undo.clear();
+ if (erasing && paint_undo.size()) {
+
+ for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+
+ _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr);
+ }
+ }
- if (id != TileMap::INVALID_CELL) {
+ paint_undo.clear();
- Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y);
+ if (id != TileMap::INVALID_CELL) {
- for (int i = 0; i < points.size(); i++) {
+ Vector<Point2i> points = line(rectangle_begin.x, over_tile.x, rectangle_begin.y, over_tile.y);
- paint_undo[points[i]] = _get_op_from_cell(points[i]);
+ for (int i = 0; i < points.size(); i++) {
- if (erasing)
- _set_cell(points[i], TileMap::INVALID_CELL);
- }
+ paint_undo[points[i]] = _get_op_from_cell(points[i]);
- canvas_item_editor->update();
+ if (erasing)
+ _set_cell(points[i], TileMap::INVALID_CELL);
}
- return true;
+ canvas_item_editor->update();
}
- if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) {
- _select(rectangle_begin, over_tile);
+ return true;
+ }
+ if (tool == TOOL_RECTANGLE_PAINT || tool == TOOL_RECTANGLE_ERASE) {
- if (tool == TOOL_RECTANGLE_ERASE) {
+ _select(rectangle_begin, over_tile);
- if (paint_undo.size()) {
+ if (tool == TOOL_RECTANGLE_ERASE) {
- for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+ if (paint_undo.size()) {
- _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr);
- }
+ for (Map<Point2i, CellOp>::Element *E = paint_undo.front(); E; E = E->next()) {
+
+ _set_cell(E->key(), E->get().idx, E->get().xf, E->get().yf, E->get().tr);
}
+ }
- paint_undo.clear();
+ paint_undo.clear();
- for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) {
- for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) {
+ for (int i = rectangle.pos.y; i <= rectangle.pos.y + rectangle.size.y; i++) {
+ for (int j = rectangle.pos.x; j <= rectangle.pos.x + rectangle.size.x; j++) {
- Point2i tile = Point2i(j, i);
- paint_undo[tile] = _get_op_from_cell(tile);
+ Point2i tile = Point2i(j, i);
+ paint_undo[tile] = _get_op_from_cell(tile);
- _set_cell(tile, TileMap::INVALID_CELL);
- }
+ _set_cell(tile, TileMap::INVALID_CELL);
}
}
-
- return true;
}
- if (tool == TOOL_ERASING) {
-
- if (!paint_undo.has(over_tile)) {
- paint_undo[over_tile] = _get_op_from_cell(over_tile);
- }
- _set_cell(over_tile, TileMap::INVALID_CELL);
+ return true;
+ }
+ if (tool == TOOL_ERASING) {
- return true;
+ if (!paint_undo.has(over_tile)) {
+ paint_undo[over_tile] = _get_op_from_cell(over_tile);
}
- if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
- _pick_tile(over_tile);
+ _set_cell(over_tile, TileMap::INVALID_CELL);
- return true;
- }
- } break;
- case InputEvent::KEY: {
+ return true;
+ }
+ if (tool == TOOL_PICKING && Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT)) {
- const InputEventKey &k = p_event.key;
+ _pick_tile(over_tile);
- if (!k.pressed)
- break;
+ return true;
+ }
+ }
- if (k.scancode == KEY_ESCAPE) {
+ Ref<InputEventKey> k = p_event;
- if (tool == TOOL_DUPLICATING)
- copydata.clear();
- else if (tool == TOOL_SELECTING || selection_active)
- selection_active = false;
+ if (k.is_valid() && k->is_pressed()) {
- tool = TOOL_NONE;
+ if (k->get_scancode() == KEY_ESCAPE) {
- canvas_item_editor->update();
+ if (tool == TOOL_DUPLICATING)
+ copydata.clear();
+ else if (tool == TOOL_SELECTING || selection_active)
+ selection_active = false;
- return true;
- }
+ tool = TOOL_NONE;
- if (tool != TOOL_NONE || !mouse_over)
- return false;
+ canvas_item_editor->update();
- if (ED_IS_SHORTCUT("tile_map_editor/erase_selection", p_event)) {
- _menu_option(OPTION_ERASE_SELECTION);
+ return true;
+ }
- return true;
- }
- if (ED_IS_SHORTCUT("tile_map_editor/select", p_event)) {
- tool = TOOL_SELECTING;
- selection_active = false;
+ if (tool != TOOL_NONE || !mouse_over)
+ return false;
- canvas_item_editor->update();
+ if (ED_IS_SHORTCUT("tile_map_editor/erase_selection", p_event)) {
+ _menu_option(OPTION_ERASE_SELECTION);
- return true;
- }
- if (ED_IS_SHORTCUT("tile_map_editor/duplicate_selection", p_event)) {
- _update_copydata();
+ return true;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/select", p_event)) {
+ tool = TOOL_SELECTING;
+ selection_active = false;
- if (selection_active) {
- tool = TOOL_DUPLICATING;
+ canvas_item_editor->update();
- canvas_item_editor->update();
+ return true;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/duplicate_selection", p_event)) {
+ _update_copydata();
- return true;
- }
- }
- if (ED_IS_SHORTCUT("tile_map_editor/find_tile", p_event)) {
- search_box->select_all();
- search_box->grab_focus();
+ if (selection_active) {
+ tool = TOOL_DUPLICATING;
- return true;
- }
- if (ED_IS_SHORTCUT("tile_map_editor/mirror_x", p_event)) {
- flip_h = !flip_h;
- mirror_x->set_pressed(flip_h);
- canvas_item_editor->update();
- return true;
- }
- if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) {
- flip_v = !flip_v;
- mirror_y->set_pressed(flip_v);
- canvas_item_editor->update();
- return true;
- }
- if (ED_IS_SHORTCUT("tile_map_editor/transpose", p_event)) {
- transpose = !transpose;
- transp->set_pressed(transpose);
canvas_item_editor->update();
+
return true;
}
- } break;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/find_tile", p_event)) {
+ search_box->select_all();
+ search_box->grab_focus();
+
+ return true;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/mirror_x", p_event)) {
+ flip_h = !flip_h;
+ mirror_x->set_pressed(flip_h);
+ canvas_item_editor->update();
+ return true;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/mirror_y", p_event)) {
+ flip_v = !flip_v;
+ mirror_y->set_pressed(flip_v);
+ canvas_item_editor->update();
+ return true;
+ }
+ if (ED_IS_SHORTCUT("tile_map_editor/transpose", p_event)) {
+ transpose = !transpose;
+ transp->set_pressed(transpose);
+ canvas_item_editor->update();
+ return true;
+ }
}
return false;
diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h
index 3eedb6c941..981d5c66a1 100644
--- a/editor/plugins/tile_map_editor_plugin.h
+++ b/editor/plugins/tile_map_editor_plugin.h
@@ -158,7 +158,7 @@ class TileMapEditor : public VBoxContainer {
void _text_entered(const String &p_text);
void _text_changed(const String &p_text);
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _update_palette();
void _canvas_draw();
void _menu_option(int p_option);
@@ -179,7 +179,7 @@ protected:
public:
HBoxContainer *get_toolbar() const { return toolbar; }
- bool forward_gui_input(const InputEvent &p_event);
+ bool forward_gui_input(const Ref<InputEvent> &p_event);
void edit(Node *p_tile_map);
TileMapEditor(EditorNode *p_editor);
@@ -193,7 +193,7 @@ class TileMapEditorPlugin : public EditorPlugin {
TileMapEditor *tile_map_editor;
public:
- virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const InputEvent &p_event) { return tile_map_editor->forward_gui_input(p_event); }
+ virtual bool forward_canvas_gui_input(const Transform2D &p_canvas_xform, const Ref<InputEvent> &p_event) { return tile_map_editor->forward_gui_input(p_event); }
virtual String get_name() const { return "TileMap"; }
bool has_main_screen() const { return false; }
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp
index 2d3b3a2200..50b518afba 100644
--- a/editor/project_manager.cpp
+++ b/editor/project_manager.cpp
@@ -503,14 +503,16 @@ void ProjectManager::_update_project_buttons() {
run_btn->set_disabled(!has_runnable_scene);
}
-void ProjectManager::_panel_input(const InputEvent &p_ev, Node *p_hb) {
+void ProjectManager::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) {
- if (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_ev;
+
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
String clicked = p_hb->get_meta("name");
String clicked_main_scene = p_hb->get_meta("main_scene");
- if (p_ev.key.mod.shift && selected_list.size() > 0 && last_clicked != "" && clicked != last_clicked) {
+ if (mb->get_shift() && selected_list.size() > 0 && last_clicked != "" && clicked != last_clicked) {
int clicked_id = -1;
int last_clicked_id = -1;
@@ -527,7 +529,7 @@ void ProjectManager::_panel_input(const InputEvent &p_ev, Node *p_hb) {
for (int i = 0; i < scroll_childs->get_child_count(); ++i) {
HBoxContainer *hb = scroll_childs->get_child(i)->cast_to<HBoxContainer>();
if (!hb) continue;
- if (i != clicked_id && (i < min || i > max) && !p_ev.key.mod.control) {
+ if (i != clicked_id && (i < min || i > max) && !mb->get_control()) {
selected_list.erase(hb->get_meta("name"));
} else if (i >= min && i <= max) {
selected_list.insert(hb->get_meta("name"), hb->get_meta("main_scene"));
@@ -535,14 +537,14 @@ void ProjectManager::_panel_input(const InputEvent &p_ev, Node *p_hb) {
}
}
- } else if (selected_list.has(clicked) && p_ev.key.mod.control) {
+ } else if (selected_list.has(clicked) && mb->get_control()) {
selected_list.erase(clicked);
} else {
last_clicked = clicked;
- if (p_ev.key.mod.control || selected_list.size() == 0) {
+ if (mb->get_control() || selected_list.size() == 0) {
selected_list.insert(clicked, clicked_main_scene);
} else {
selected_list.clear();
@@ -552,23 +554,23 @@ void ProjectManager::_panel_input(const InputEvent &p_ev, Node *p_hb) {
_update_project_buttons();
- if (p_ev.mouse_button.doubleclick)
+ if (mb->is_doubleclick())
_open_project(); //open if doubleclicked
}
}
-void ProjectManager::_unhandled_input(const InputEvent &p_ev) {
+void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) {
- if (p_ev.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_ev;
- const InputEventKey &k = p_ev.key;
+ if (k.is_valid()) {
- if (!k.pressed)
+ if (!k->is_pressed())
return;
bool scancode_handled = true;
- switch (k.scancode) {
+ switch (k->get_scancode()) {
case KEY_RETURN: {
@@ -606,7 +608,7 @@ void ProjectManager::_unhandled_input(const InputEvent &p_ev) {
} break;
case KEY_UP: {
- if (k.mod.shift)
+ if (k->get_shift())
break;
if (selected_list.size()) {
@@ -645,7 +647,7 @@ void ProjectManager::_unhandled_input(const InputEvent &p_ev) {
}
case KEY_DOWN: {
- if (k.mod.shift)
+ if (k->get_shift())
break;
bool found = selected_list.empty();
@@ -679,7 +681,7 @@ void ProjectManager::_unhandled_input(const InputEvent &p_ev) {
} break;
case KEY_F: {
- if (k.mod.command)
+ if (k->get_command())
this->project_filter->search_box->grab_focus();
else
scancode_handled = false;
diff --git a/editor/project_manager.h b/editor/project_manager.h
index 5be28ce2f0..27886132c5 100644
--- a/editor/project_manager.h
+++ b/editor/project_manager.h
@@ -91,8 +91,8 @@ class ProjectManager : public Control {
void _install_project(const String &p_zip_path, const String &p_title);
void _panel_draw(Node *p_hb);
- void _panel_input(const InputEvent &p_ev, Node *p_hb);
- void _unhandled_input(const InputEvent &p_ev);
+ void _panel_input(const Ref<InputEvent> &p_ev, Node *p_hb);
+ void _unhandled_input(const Ref<InputEvent> &p_ev);
void _favorite_pressed(Node *p_hb);
void _files_dropped(PoolStringArray p_files, int p_screen);
void _scan_multiple_folders(PoolStringArray p_files);
diff --git a/editor/project_settings.cpp b/editor/project_settings.cpp
index c9a6d4df66..1c4ca3cb58 100644
--- a/editor/project_settings.cpp
+++ b/editor/project_settings.cpp
@@ -83,10 +83,10 @@ void ProjectSettings::_notification(int p_what) {
translation_list->connect("button_pressed", this, "_translation_delete");
_update_actions();
- popup_add->add_icon_item(get_icon("Keyboard", "EditorIcons"), TTR("Key "), InputEvent::KEY); //"Key " - because the word 'key' has already been used as a key animation
- popup_add->add_icon_item(get_icon("JoyButton", "EditorIcons"), TTR("Joy Button"), InputEvent::JOYPAD_BUTTON);
- popup_add->add_icon_item(get_icon("JoyAxis", "EditorIcons"), TTR("Joy Axis"), InputEvent::JOYPAD_MOTION);
- popup_add->add_icon_item(get_icon("Mouse", "EditorIcons"), TTR("Mouse Button"), InputEvent::MOUSE_BUTTON);
+ popup_add->add_icon_item(get_icon("Keyboard", "EditorIcons"), TTR("Key "), INPUT_KEY); //"Key " - because the word 'key' has already been used as a key animation
+ popup_add->add_icon_item(get_icon("JoyButton", "EditorIcons"), TTR("Joy Button"), INPUT_JOY_BUTTON);
+ popup_add->add_icon_item(get_icon("JoyAxis", "EditorIcons"), TTR("Joy Axis"), INPUT_JOY_MOTION);
+ popup_add->add_icon_item(get_icon("Mouse", "EditorIcons"), TTR("Mouse Button"), INPUT_MOUSE_BUTTON);
List<String> tfn;
ResourceLoader::get_recognized_extensions_for_type("Translation", &tfn);
@@ -178,54 +178,74 @@ void ProjectSettings::_action_edited() {
void ProjectSettings::_device_input_add() {
- InputEvent ie;
+ Ref<InputEvent> ie;
String name = add_at;
Variant old_val = GlobalConfig::get_singleton()->get(name);
Array arr = old_val;
- ie.device = device_id->get_value();
-
- ie.type = add_type;
+ // ie.device = device_id->get_value();
+ // ie.type = add_type;
switch (add_type) {
- case InputEvent::MOUSE_BUTTON: {
+ case INPUT_MOUSE_BUTTON: {
- ie.mouse_button.button_index = device_index->get_selected() + 1;
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+ mb->set_button_index(device_index->get_selected() + 1);
+ mb->set_device(device_id->get_value());
for (int i = 0; i < arr.size(); i++) {
- InputEvent aie = arr[i];
- if (aie.device == ie.device && aie.type == InputEvent::MOUSE_BUTTON && aie.mouse_button.button_index == ie.mouse_button.button_index) {
+ Ref<InputEventMouseButton> aie = arr[i];
+ if (aie.is_null())
+ continue;
+ if (aie->get_device() == mb->get_device() && aie->get_button_index() == mb->get_button_index()) {
return;
}
}
+ ie = mb;
+
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case INPUT_JOY_MOTION: {
- ie.joy_motion.axis = device_index->get_selected() >> 1;
- ie.joy_motion.axis_value = device_index->get_selected() & 1 ? 1 : -1;
+ Ref<InputEventJoypadMotion> jm;
+ jm.instance();
+ jm->set_axis(device_index->get_selected() >> 1);
+ jm->set_axis_value(device_index->get_selected() & 1 ? 1 : -1);
+ jm->set_device(device_id->get_value());
for (int i = 0; i < arr.size(); i++) {
- InputEvent aie = arr[i];
- if (aie.device == ie.device && aie.type == InputEvent::JOYPAD_MOTION && aie.joy_motion.axis == ie.joy_motion.axis && aie.joy_motion.axis_value == ie.joy_motion.axis_value) {
+ Ref<InputEventJoypadMotion> aie = arr[i];
+ if (aie.is_null())
+ continue;
+ if (aie->get_device() == jm->get_device() && aie->get_axis() == jm->get_axis() && aie->get_axis_value() == jm->get_axis_value()) {
return;
}
}
+ ie = jm;
+
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case INPUT_JOY_BUTTON: {
- ie.joy_button.button_index = device_index->get_selected();
+ Ref<InputEventJoypadButton> jb;
+ jb.instance();
+
+ jb->set_button_index(device_index->get_selected());
+ jb->set_device(device_id->get_value());
for (int i = 0; i < arr.size(); i++) {
- InputEvent aie = arr[i];
- if (aie.device == ie.device && aie.type == InputEvent::JOYPAD_BUTTON && aie.joy_button.button_index == ie.joy_button.button_index) {
+ Ref<InputEventJoypadButton> aie = arr[i];
+ if (aie.is_null())
+ continue;
+ if (aie->get_device() == jb->get_device() && aie->get_button_index() == jb->get_button_index()) {
return;
}
}
+ ie = jb;
} break;
default: {}
@@ -247,13 +267,17 @@ void ProjectSettings::_device_input_add() {
void ProjectSettings::_press_a_key_confirm() {
- if (last_wait_for_key.type != InputEvent::KEY)
+ if (last_wait_for_key.is_null())
return;
- InputEvent ie;
- ie.type = InputEvent::KEY;
- ie.key.scancode = last_wait_for_key.key.scancode;
- ie.key.mod = last_wait_for_key.key.mod;
+ Ref<InputEventKey> ie;
+ ie.instance();
+ ie->set_scancode(last_wait_for_key->get_scancode());
+ ie->set_shift(last_wait_for_key->get_shift());
+ ie->set_alt(last_wait_for_key->get_alt());
+ ie->set_control(last_wait_for_key->get_control());
+ ie->set_metakey(last_wait_for_key->get_metakey());
+
String name = add_at;
Variant old_val = GlobalConfig::get_singleton()->get(name);
@@ -261,8 +285,10 @@ void ProjectSettings::_press_a_key_confirm() {
for (int i = 0; i < arr.size(); i++) {
- InputEvent aie = arr[i];
- if (aie.type == InputEvent::KEY && aie.key.scancode == ie.key.scancode && aie.key.mod == ie.key.mod) {
+ Ref<InputEventKey> aie = arr[i];
+ if (aie.is_null())
+ continue;
+ if (aie->get_scancode_with_modifiers() == ie->get_scancode_with_modifiers()) {
return;
}
}
@@ -281,7 +307,7 @@ void ProjectSettings::_press_a_key_confirm() {
_show_last_added(ie, name);
}
-void ProjectSettings::_show_last_added(const InputEvent &p_event, const String &p_name) {
+void ProjectSettings::_show_last_added(const Ref<InputEvent> &p_event, const String &p_name) {
TreeItem *r = input_editor->get_root();
String name = p_name;
@@ -314,19 +340,21 @@ void ProjectSettings::_show_last_added(const InputEvent &p_event, const String &
if (found) input_editor->ensure_cursor_is_visible();
}
-void ProjectSettings::_wait_for_key(const InputEvent &p_event) {
+void ProjectSettings::_wait_for_key(const Ref<InputEvent> &p_event) {
+
+ Ref<InputEventKey> k = p_event;
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode != 0) {
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() != 0) {
last_wait_for_key = p_event;
- String str = keycode_get_string(p_event.key.scancode).capitalize();
- if (p_event.key.mod.meta)
+ String str = keycode_get_string(k->get_scancode()).capitalize();
+ if (k->get_metakey())
str = TTR("Meta+") + str;
- if (p_event.key.mod.shift)
+ if (k->get_shift())
str = TTR("Shift+") + str;
- if (p_event.key.mod.alt)
+ if (k->get_alt())
str = TTR("Alt+") + str;
- if (p_event.key.mod.control)
+ if (k->get_control())
str = TTR("Control+") + str;
press_a_key_label->set_text(str);
@@ -336,18 +364,18 @@ void ProjectSettings::_wait_for_key(const InputEvent &p_event) {
void ProjectSettings::_add_item(int p_item) {
- add_type = InputEvent::Type(p_item);
+ add_type = InputType(p_item);
switch (add_type) {
- case InputEvent::KEY: {
+ case INPUT_KEY: {
press_a_key_label->set_text(TTR("Press a Key.."));
- last_wait_for_key = InputEvent();
+ last_wait_for_key = Ref<InputEvent>();
press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
press_a_key->grab_focus();
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case INPUT_MOUSE_BUTTON: {
device_id->set_value(0);
device_index_label->set_text(TTR("Mouse Button Index:"));
@@ -363,7 +391,7 @@ void ProjectSettings::_add_item(int p_item) {
device_index->add_item(TTR("Button 9"));
device_input->popup_centered_minsize(Size2(350, 95));
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case INPUT_JOY_MOTION: {
device_id->set_value(0);
device_index_label->set_text(TTR("Joypad Axis Index:"));
@@ -376,7 +404,7 @@ void ProjectSettings::_add_item(int p_item) {
device_input->popup_centered_minsize(Size2(350, 95));
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case INPUT_JOY_BUTTON: {
device_id->set_value(0);
device_index_label->set_text(TTR("Joypad Button Index:"));
@@ -496,65 +524,70 @@ void ProjectSettings::_update_actions() {
for (int i = 0; i < actions.size(); i++) {
- if (actions[i].get_type() != Variant::INPUT_EVENT)
+ Ref<InputEvent> ie = actions[i];
+ if (ie.is_null())
continue;
- InputEvent ie = actions[i];
TreeItem *action = input_editor->create_item(item);
- switch (ie.type) {
-
- case InputEvent::KEY: {
-
- String str = keycode_get_string(ie.key.scancode).capitalize();
- if (ie.key.mod.meta)
- str = TTR("Meta+") + str;
- if (ie.key.mod.shift)
- str = TTR("Shift+") + str;
- if (ie.key.mod.alt)
- str = TTR("Alt+") + str;
- if (ie.key.mod.control)
- str = TTR("Control+") + str;
-
- action->set_text(0, str);
- action->set_icon(0, get_icon("Keyboard", "EditorIcons"));
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- String str = TTR("Device") + " " + itos(ie.device) + ", " + TTR("Button") + " " + itos(ie.joy_button.button_index);
- if (ie.joy_button.button_index >= 0 && ie.joy_button.button_index < JOY_BUTTON_MAX)
- str += String() + " (" + _button_names[ie.joy_button.button_index] + ").";
- else
- str += ".";
-
- action->set_text(0, str);
- action->set_icon(0, get_icon("JoyButton", "EditorIcons"));
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- String str = TTR("Device") + " " + itos(ie.device) + ", ";
- switch (ie.mouse_button.button_index) {
- case BUTTON_LEFT: str += TTR("Left Button."); break;
- case BUTTON_RIGHT: str += TTR("Right Button."); break;
- case BUTTON_MIDDLE: str += TTR("Middle Button."); break;
- case BUTTON_WHEEL_UP: str += TTR("Wheel Up."); break;
- case BUTTON_WHEEL_DOWN: str += TTR("Wheel Down."); break;
- default: str += TTR("Button") + " " + itos(ie.mouse_button.button_index) + ".";
- }
-
- action->set_text(0, str);
- action->set_icon(0, get_icon("Mouse", "EditorIcons"));
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- int ax = ie.joy_motion.axis;
- int n = 2 * ax + (ie.joy_motion.axis_value < 0 ? 0 : 1);
- String desc = _axis_names[n];
- String str = TTR("Device") + " " + itos(ie.device) + ", " + TTR("Axis") + " " + itos(ax) + " " + (ie.joy_motion.axis_value < 0 ? "-" : "+") + desc + ".";
- action->set_text(0, str);
- action->set_icon(0, get_icon("JoyAxis", "EditorIcons"));
- } break;
+ Ref<InputEventKey> k = ie;
+ if (k.is_valid()) {
+
+ String str = keycode_get_string(k->get_scancode()).capitalize();
+ if (k->get_metakey())
+ str = TTR("Meta+") + str;
+ if (k->get_shift())
+ str = TTR("Shift+") + str;
+ if (k->get_alt())
+ str = TTR("Alt+") + str;
+ if (k->get_control())
+ str = TTR("Control+") + str;
+
+ action->set_text(0, str);
+ action->set_icon(0, get_icon("Keyboard", "EditorIcons"));
+ }
+
+ Ref<InputEventJoypadButton> jb = ie;
+
+ if (jb.is_valid()) {
+
+ String str = TTR("Device") + " " + itos(jb->get_device()) + ", " + TTR("Button") + " " + itos(jb->get_button_index());
+ if (jb->get_button_index() >= 0 && jb->get_button_index() < JOY_BUTTON_MAX)
+ str += String() + " (" + _button_names[jb->get_button_index()] + ").";
+ else
+ str += ".";
+
+ action->set_text(0, str);
+ action->set_icon(0, get_icon("JoyButton", "EditorIcons"));
+ }
+
+ Ref<InputEventMouseButton> mb = ie;
+
+ if (mb.is_valid()) {
+ String str = TTR("Device") + " " + itos(mb->get_device()) + ", ";
+ switch (mb->get_button_index()) {
+ case BUTTON_LEFT: str += TTR("Left Button."); break;
+ case BUTTON_RIGHT: str += TTR("Right Button."); break;
+ case BUTTON_MIDDLE: str += TTR("Middle Button."); break;
+ case BUTTON_WHEEL_UP: str += TTR("Wheel Up."); break;
+ case BUTTON_WHEEL_DOWN: str += TTR("Wheel Down."); break;
+ default: str += TTR("Button") + " " + itos(mb->get_button_index()) + ".";
+ }
+
+ action->set_text(0, str);
+ action->set_icon(0, get_icon("Mouse", "EditorIcons"));
+ }
+
+ Ref<InputEventJoypadMotion> jm = ie;
+
+ if (jm.is_valid()) {
+
+ int ax = jm->get_axis();
+ int n = 2 * ax + (jm->get_axis_value() < 0 ? 0 : 1);
+ String desc = _axis_names[n];
+ String str = TTR("Device") + " " + itos(jm->get_device()) + ", " + TTR("Axis") + " " + itos(ax) + " " + (jm->get_axis_value() < 0 ? "-" : "+") + desc + ".";
+ action->set_text(0, str);
+ action->set_icon(0, get_icon("JoyAxis", "EditorIcons"));
}
action->add_button(0, get_icon("Remove", "EditorIcons"), 2, false, TTR("Remove"));
action->set_metadata(0, i);
diff --git a/editor/project_settings.h b/editor/project_settings.h
index a5a9e04250..47fb45cf8e 100644
--- a/editor/project_settings.h
+++ b/editor/project_settings.h
@@ -43,10 +43,17 @@
class ProjectSettings : public AcceptDialog {
GDCLASS(ProjectSettings, AcceptDialog);
+ enum InputType {
+ INPUT_KEY,
+ INPUT_JOY_BUTTON,
+ INPUT_JOY_MOTION,
+ INPUT_MOUSE_BUTTON
+ };
+
TabContainer *tab_container;
Timer *timer;
- InputEvent::Type add_type;
+ InputType add_type;
String add_at;
EditorData *data;
@@ -77,7 +84,7 @@ class ProjectSettings : public AcceptDialog {
bool setting;
bool updating_translations;
- InputEvent last_wait_for_key;
+ Ref<InputEventKey> last_wait_for_key;
EditorFileDialog *translation_file_open;
Tree *translation_list;
@@ -108,9 +115,9 @@ class ProjectSettings : public AcceptDialog {
void _action_selected();
void _action_edited();
void _action_button_pressed(Object *p_obj, int p_column, int p_id);
- void _wait_for_key(const InputEvent &p_event);
+ void _wait_for_key(const Ref<InputEvent> &p_event);
void _press_a_key_confirm();
- void _show_last_added(const InputEvent &p_event, const String &p_name);
+ void _show_last_added(const Ref<InputEvent> &p_event, const String &p_name);
void _settings_prop_edited(const String &p_name);
void _settings_changed();
diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp
index 2cc7acd260..1c8a1c0ee0 100644
--- a/editor/property_editor.cpp
+++ b/editor/property_editor.cpp
@@ -609,12 +609,9 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
type = Variant::Type(Variant::Type(i));
}
}
- InputEvent::Type iet = InputEvent::NONE;
- if (hint_text.find(".") != -1) {
- iet = InputEvent::Type(int(hint_text.get_slice(".", 1).to_int()));
- }
+
if (type)
- property_select->select_property_from_basic_type(type, iet, v);
+ property_select->select_property_from_basic_type(type, v);
updating = false;
return false;
@@ -979,9 +976,6 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant::
return false;
} break;
- case Variant::INPUT_EVENT: {
-
- } break;
case Variant::DICTIONARY: {
} break;
@@ -1401,11 +1395,13 @@ void CustomPropertyEditor::_scroll_modified(double p_value) {
*/
}
-void CustomPropertyEditor::_drag_easing(const InputEvent &p_ev) {
+void CustomPropertyEditor::_drag_easing(const Ref<InputEvent> &p_ev) {
+
+ Ref<InputEventMouseMotion> mm = p_ev;
- if (p_ev.type == InputEvent::MOUSE_MOTION && p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
- float rel = p_ev.mouse_motion.relative_x;
+ float rel = mm->get_relative().x;
if (rel == 0)
return;
@@ -1434,8 +1430,8 @@ void CustomPropertyEditor::_drag_easing(const InputEvent &p_ev) {
//emit_signal("variant_changed");
emit_signal("variant_changed");
}
- if (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index == BUTTON_LEFT) {
- }
+ // if (p_ev.type == Ref<InputEvent>::MOUSE_BUTTON && p_ev->get_button_index() == BUTTON_LEFT) {
+ // }
}
void CustomPropertyEditor::_draw_easing() {
@@ -1715,9 +1711,6 @@ void CustomPropertyEditor::_modified(String p_string) {
v = NodePath(value_editor[0]->get_text());
emit_signal("variant_changed");
} break;
- case Variant::INPUT_EVENT: {
-
- } break;
case Variant::DICTIONARY: {
} break;
@@ -3862,9 +3855,6 @@ void PropertyEditor::_item_edited() {
} break;
- case Variant::INPUT_EVENT: {
-
- } break;
case Variant::DICTIONARY: {
} break;
diff --git a/editor/property_editor.h b/editor/property_editor.h
index b88ba38e19..c02c301acf 100644
--- a/editor/property_editor.h
+++ b/editor/property_editor.h
@@ -134,7 +134,7 @@ class CustomPropertyEditor : public Popup {
void _draw_easing();
void _menu_option(int p_which);
- void _drag_easing(const InputEvent &p_ev);
+ void _drag_easing(const Ref<InputEvent> &p_ev);
void _node_path_selected(NodePath p_path);
void show_value_editors(int p_amount);
diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp
index 752965c806..47e5994e3f 100644
--- a/editor/property_selector.cpp
+++ b/editor/property_selector.cpp
@@ -37,17 +37,19 @@ void PropertySelector::_text_changed(const String &p_newtext) {
_update_search();
}
-void PropertySelector::_sbox_input(const InputEvent &p_ie) {
+void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_ie;
- switch (p_ie.key.scancode) {
+ if (k.is_valid()) {
+
+ switch (k->get_scancode()) {
case KEY_UP:
case KEY_DOWN:
case KEY_PAGEUP:
case KEY_PAGEDOWN: {
- search_options->call("_gui_input", p_ie);
+ search_options->call("_gui_input", k);
search_box->accept_event();
TreeItem *root = search_options->get_root();
@@ -89,14 +91,8 @@ void PropertySelector::_update_search() {
instance->get_property_list(&props, true);
} else if (type != Variant::NIL) {
Variant v;
- if (type == Variant::INPUT_EVENT) {
- InputEvent ie;
- ie.type = event_type;
- v = ie;
- } else {
- Variant::CallError ce;
- v = Variant::construct(type, NULL, 0, ce);
- }
+ Variant::CallError ce;
+ v = Variant::construct(type, NULL, 0, ce);
v.get_property_list(&props);
} else {
@@ -139,7 +135,6 @@ void PropertySelector::_update_search() {
Control::get_icon("MiniPath", "EditorIcons"),
Control::get_icon("MiniRid", "EditorIcons"),
Control::get_icon("MiniObject", "EditorIcons"),
- Control::get_icon("MiniInput", "EditorIcons"),
Control::get_icon("MiniDictionary", "EditorIcons"),
Control::get_icon("MiniArray", "EditorIcons"),
Control::get_icon("MiniRawArray", "EditorIcons"),
@@ -325,22 +320,7 @@ void PropertySelector::_item_selected() {
String name = item->get_metadata(0);
String class_type;
- if (properties && type == Variant::INPUT_EVENT) {
-
- switch (event_type) {
- case InputEvent::NONE: class_type = "InputEvent"; break;
- case InputEvent::KEY: class_type = "InputEventKey"; break;
- case InputEvent::MOUSE_MOTION: class_type = "InputEventMouseMotion"; break;
- case InputEvent::MOUSE_BUTTON: class_type = "InputEventMouseButton"; break;
- case InputEvent::JOYPAD_MOTION: class_type = "InputEventJoypadMotion"; break;
- case InputEvent::JOYPAD_BUTTON: class_type = "InputEventJoypadButton"; break;
- case InputEvent::SCREEN_TOUCH: class_type = "InputEventScreenTouch"; break;
- case InputEvent::SCREEN_DRAG: class_type = "InputEventScreenDrag"; break;
- case InputEvent::ACTION: class_type = "InputEventAction"; break;
- default: {}
- }
-
- } else if (type) {
+ if (type) {
class_type = Variant::get_type_name(type);
} else {
@@ -514,13 +494,12 @@ void PropertySelector::select_property_from_script(const Ref<Script> &p_script,
search_box->grab_focus();
_update_search();
}
-void PropertySelector::select_property_from_basic_type(Variant::Type p_type, InputEvent::Type p_event_type, const String &p_current) {
+void PropertySelector::select_property_from_basic_type(Variant::Type p_type, const String &p_current) {
ERR_FAIL_COND(p_type == Variant::NIL);
base_type = "";
selected = p_current;
type = p_type;
- event_type = p_event_type;
script = 0;
properties = true;
instance = NULL;
diff --git a/editor/property_selector.h b/editor/property_selector.h
index 6dc2592176..def791a3fd 100644
--- a/editor/property_selector.h
+++ b/editor/property_selector.h
@@ -42,7 +42,7 @@ class PropertySelector : public ConfirmationDialog {
void _update_search();
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _confirmed();
void _text_changed(const String &p_newtext);
@@ -52,7 +52,6 @@ class PropertySelector : public ConfirmationDialog {
bool properties;
String selected;
Variant::Type type;
- InputEvent::Type event_type;
String base_type;
ObjectID script;
Object *instance;
@@ -71,7 +70,7 @@ public:
void select_property_from_base_type(const String &p_base, const String &p_current = "");
void select_property_from_script(const Ref<Script> &p_script, const String &p_current = "");
- void select_property_from_basic_type(Variant::Type p_type, InputEvent::Type p_event_type, const String &p_current = "");
+ void select_property_from_basic_type(Variant::Type p_type, const String &p_current = "");
void select_property_from_instance(Object *p_instance, const String &p_current = "");
PropertySelector();
diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp
index 7fce485f3a..7fb9666afb 100644
--- a/editor/quick_open.cpp
+++ b/editor/quick_open.cpp
@@ -77,17 +77,18 @@ void EditorQuickOpen::_text_changed(const String &p_newtext) {
_update_search();
}
-void EditorQuickOpen::_sbox_input(const InputEvent &p_ie) {
+void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) {
- if (p_ie.type == InputEvent::KEY) {
+ Ref<InputEventKey> k = p_ie;
+ if (k.is_valid()) {
- switch (p_ie.key.scancode) {
+ switch (k->get_scancode()) {
case KEY_UP:
case KEY_DOWN:
case KEY_PAGEUP:
case KEY_PAGEDOWN: {
- search_options->call("_gui_input", p_ie);
+ search_options->call("_gui_input", k);
search_box->accept_event();
TreeItem *root = search_options->get_root();
diff --git a/editor/quick_open.h b/editor/quick_open.h
index 0e5766033f..44f8c025e6 100644
--- a/editor/quick_open.h
+++ b/editor/quick_open.h
@@ -47,7 +47,7 @@ class EditorQuickOpen : public ConfirmationDialog {
void _update_search();
- void _sbox_input(const InputEvent &p_ie);
+ void _sbox_input(const Ref<InputEvent> &p_ie);
void _parse_fs(EditorFileSystemDirectory *efsd, Vector<Pair<String, Ref<Texture> > > &list);
float _path_cmp(String search, String path) const;
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 7916b6b63c..0f05cc79ff 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -52,19 +52,21 @@ void SceneTreeDock::_nodes_drag_begin() {
}
}
-void SceneTreeDock::_input(InputEvent p_event) {
+void SceneTreeDock::_input(Ref<InputEvent> p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
restore_script_editor_on_drag = false; //lost chance
}
}
-void SceneTreeDock::_unhandled_key_input(InputEvent p_event) {
+void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) {
if (get_viewport()->get_modal_stack_top())
return; //ignore because of modal window
- if (!p_event.key.pressed || p_event.key.echo)
+ if (!p_event->is_pressed() || p_event->is_echo())
return;
if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) {
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index de6b81d44a..f190025dd6 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -133,8 +133,8 @@ class SceneTreeDock : public VBoxContainer {
void _node_prerenamed(Node *p_node, const String &p_new_name);
void _nodes_drag_begin();
- void _input(InputEvent p_event);
- void _unhandled_key_input(InputEvent p_event);
+ void _input(Ref<InputEvent> p_event);
+ void _unhandled_key_input(Ref<InputEvent> p_event);
void _import_subscene();
diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp
index 16ab431321..563de78415 100644
--- a/editor/settings_config_dialog.cpp
+++ b/editor/settings_config_dialog.cpp
@@ -148,7 +148,7 @@ void EditorSettingsDialog::_update_shortcuts() {
if (!sc->has_meta("original"))
continue;
- InputEvent original = sc->get_meta("original");
+ Ref<InputEvent> original = sc->get_meta("original");
String section_name = E->get().get_slice("/", 0);
@@ -170,7 +170,7 @@ void EditorSettingsDialog::_update_shortcuts() {
item->set_text(0, sc->get_name());
item->set_text(1, sc->get_as_text());
- if (!sc->is_shortcut(original) && !(sc->get_shortcut().type == InputEvent::NONE && original.type == InputEvent::NONE)) {
+ if (!sc->is_shortcut(original) && !(sc->get_shortcut().is_null() && original.is_null())) {
item->add_button(1, get_icon("Reload", "EditorIcons"), 2);
}
item->add_button(1, get_icon("Edit", "EditorIcons"), 0);
@@ -199,7 +199,7 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
if (p_idx == 0) {
press_a_key_label->set_text(TTR("Press a Key.."));
- last_wait_for_key = InputEvent();
+ last_wait_for_key = Ref<InputEventKey>();
press_a_key->popup_centered(Size2(250, 80) * EDSCALE);
press_a_key->grab_focus();
press_a_key->get_ok()->set_focus_mode(FOCUS_NONE);
@@ -212,7 +212,7 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
ur->create_action("Erase Shortcut");
- ur->add_do_method(sc.ptr(), "set_shortcut", InputEvent());
+ ur->add_do_method(sc.ptr(), "set_shortcut", Ref<InputEvent>());
ur->add_undo_method(sc.ptr(), "set_shortcut", sc->get_shortcut());
ur->add_do_method(this, "_update_shortcuts");
ur->add_undo_method(this, "_update_shortcuts");
@@ -223,7 +223,7 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
if (!sc.is_valid())
return; //pointless, there is nothing
- InputEvent original = sc->get_meta("original");
+ Ref<InputEvent> original = sc->get_meta("original");
UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo();
ur->create_action("Restore Shortcut");
@@ -237,19 +237,21 @@ void EditorSettingsDialog::_shortcut_button_pressed(Object *p_item, int p_column
}
}
-void EditorSettingsDialog::_wait_for_key(const InputEvent &p_event) {
+void EditorSettingsDialog::_wait_for_key(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode != 0) {
+ Ref<InputEventKey> k = p_event;
- last_wait_for_key = p_event;
- String str = keycode_get_string(p_event.key.scancode).capitalize();
- if (p_event.key.mod.meta)
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() != 0) {
+
+ last_wait_for_key = k;
+ String str = keycode_get_string(k->get_scancode()).capitalize();
+ if (k->get_metakey())
str = TTR("Meta+") + str;
- if (p_event.key.mod.shift)
+ if (k->get_shift())
str = TTR("Shift+") + str;
- if (p_event.key.mod.alt)
+ if (k->get_alt())
str = TTR("Alt+") + str;
- if (p_event.key.mod.control)
+ if (k->get_control())
str = TTR("Control+") + str;
press_a_key_label->set_text(str);
@@ -259,13 +261,16 @@ void EditorSettingsDialog::_wait_for_key(const InputEvent &p_event) {
void EditorSettingsDialog::_press_a_key_confirm() {
- if (last_wait_for_key.type != InputEvent::KEY)
+ if (last_wait_for_key.is_null())
return;
- InputEvent ie;
- ie.type = InputEvent::KEY;
- ie.key.scancode = last_wait_for_key.key.scancode;
- ie.key.mod = last_wait_for_key.key.mod;
+ Ref<InputEventKey> ie;
+ ie.instance();
+ ie->set_scancode(last_wait_for_key->get_scancode());
+ ie->set_shift(last_wait_for_key->get_shift());
+ ie->set_control(last_wait_for_key->get_control());
+ ie->set_alt(last_wait_for_key->get_alt());
+ ie->set_metakey(last_wait_for_key->get_metakey());
Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(shortcut_configured);
diff --git a/editor/settings_config_dialog.h b/editor/settings_config_dialog.h
index 7b6e8862dc..cda191ac36 100644
--- a/editor/settings_config_dialog.h
+++ b/editor/settings_config_dialog.h
@@ -54,7 +54,7 @@ class EditorSettingsDialog : public AcceptDialog {
ConfirmationDialog *press_a_key;
Label *press_a_key_label;
- InputEvent last_wait_for_key;
+ Ref<InputEventKey> last_wait_for_key;
String shortcut_configured;
String shortcut_filter;
@@ -68,7 +68,7 @@ class EditorSettingsDialog : public AcceptDialog {
void _notification(int p_what);
void _press_a_key_confirm();
- void _wait_for_key(const InputEvent &p_event);
+ void _wait_for_key(const Ref<InputEvent> &p_event);
void _clear_shortcut_search_box();
void _clear_search_box();
diff --git a/main/input_default.cpp b/main/input_default.cpp
index 8f0b8464eb..2cce62ab51 100644
--- a/main/input_default.cpp
+++ b/main/input_default.cpp
@@ -115,19 +115,19 @@ bool InputDefault::is_action_pressed(const StringName &p_action) const {
case InputEvent::KEY: {
const InputEventKey &iek=E->get().key;
- if ((keys_pressed.has(iek.scancode)))
+ if ((keys_pressed.has(iek->get_scancode())))
return true;
} break;
case InputEvent::MOUSE_BUTTON: {
const InputEventMouseButton &iemb=E->get().mouse_button;
- if(mouse_button_mask&(1<<iemb.button_index))
+ if(mouse_button_mask&(1<<iemb->get_button_index()))
return true;
} break;
case InputEvent::JOYPAD_BUTTON: {
const InputEventJoypadButton &iejb=E->get().joy_button;
- int c = _combine_device(iejb.button_index,device);
+ int c = _combine_device(iejb->get_button_index(),device);
if (joy_buttons_pressed.has(c))
return true;
} break;
@@ -297,94 +297,86 @@ Vector3 InputDefault::get_gyroscope() const {
return gyroscope;
}
-void InputDefault::parse_input_event(const InputEvent &p_event) {
+void InputDefault::parse_input_event(const Ref<InputEvent> &p_event) {
_THREAD_SAFE_METHOD_
- switch (p_event.type) {
-
- case InputEvent::KEY: {
-
- if (p_event.key.echo)
- break;
- if (p_event.key.scancode == 0)
- break;
-
- //print_line(p_event);
-
- if (p_event.key.pressed)
- keys_pressed.insert(p_event.key.scancode);
- else
- keys_pressed.erase(p_event.key.scancode);
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- if (p_event.mouse_button.doubleclick)
- break;
-
- if (p_event.mouse_button.pressed)
- mouse_button_mask |= (1 << p_event.mouse_button.button_index);
- else
- mouse_button_mask &= ~(1 << p_event.mouse_button.button_index);
-
- if (main_loop && emulate_touch && p_event.mouse_button.button_index == 1) {
- InputEventScreenTouch touch_event;
- touch_event.index = 0;
- touch_event.pressed = p_event.mouse_button.pressed;
- touch_event.x = p_event.mouse_button.x;
- touch_event.y = p_event.mouse_button.y;
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch = touch_event;
- main_loop->input_event(ev);
- }
- Point2 pos = Point2(p_event.mouse_button.global_x, p_event.mouse_button.global_y);
- if (mouse_pos != pos) {
- set_mouse_position(pos);
- }
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- if (main_loop && emulate_touch && p_event.mouse_motion.button_mask & 1) {
- InputEventScreenDrag drag_event;
- drag_event.index = 0;
- drag_event.x = p_event.mouse_motion.x;
- drag_event.y = p_event.mouse_motion.y;
- drag_event.relative_x = p_event.mouse_motion.relative_x;
- drag_event.relative_y = p_event.mouse_motion.relative_y;
- drag_event.speed_x = p_event.mouse_motion.speed_x;
- drag_event.speed_y = p_event.mouse_motion.speed_y;
-
- InputEvent ev;
- ev.type = InputEvent::SCREEN_DRAG;
- ev.screen_drag = drag_event;
-
- main_loop->input_event(ev);
- }
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && k->is_echo() && k->get_scancode() != 0) {
+
+ //print_line(p_event);
+
+ if (k->is_pressed())
+ keys_pressed.insert(k->get_scancode());
+ else
+ keys_pressed.erase(k->get_scancode());
+ }
+
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && !mb->is_doubleclick()) {
+
+ if (mb->is_pressed())
+ mouse_button_mask |= (1 << mb->get_button_index());
+ else
+ mouse_button_mask &= ~(1 << mb->get_button_index());
+
+ if (main_loop && emulate_touch && mb->get_button_index() == 1) {
+ Ref<InputEventScreenTouch> touch_event;
+ touch_event.instance();
+ touch_event->set_pressed(mb->is_pressed());
+ touch_event->set_pos(mb->get_pos());
+ main_loop->input_event(touch_event);
+ }
+
+ Point2 pos = mb->get_global_pos();
+ if (mouse_pos != pos) {
+ set_mouse_position(pos);
+ }
+ }
+
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
+
+ if (main_loop && emulate_touch && mm->get_button_mask() & 1) {
+ Ref<InputEventScreenDrag> drag_event;
+ drag_event.instance();
- } break;
- case InputEvent::JOYPAD_BUTTON: {
+ drag_event->set_pos(mm->get_pos());
+ drag_event->set_relative(mm->get_relative());
+ drag_event->set_speed(mm->get_speed());
+
+ main_loop->input_event(drag_event);
+ }
+ }
+
+ Ref<InputEventJoypadButton> jb = p_event;
+
+ if (jb.is_valid()) {
+
+ int c = _combine_device(jb->get_button_index(), jb->get_device());
+
+ if (jb->is_pressed())
+ joy_buttons_pressed.insert(c);
+ else
+ joy_buttons_pressed.erase(c);
+ }
- int c = _combine_device(p_event.joy_button.button_index, p_event.device);
+ Ref<InputEventJoypadMotion> jm = p_event;
- if (p_event.joy_button.pressed)
- joy_buttons_pressed.insert(c);
- else
- joy_buttons_pressed.erase(c);
- } break;
- case InputEvent::JOYPAD_MOTION: {
- set_joy_axis(p_event.device, p_event.joy_motion.axis, p_event.joy_motion.axis_value);
- } break;
+ if (jm.is_valid()) {
+ set_joy_axis(jm->get_device(), jm->get_axis(), jm->get_axis_value());
}
- if (!p_event.is_echo()) {
+ if (p_event->is_echo()) {
for (const Map<StringName, InputMap::Action>::Element *E = InputMap::get_singleton()->get_action_map().front(); E; E = E->next()) {
- if (InputMap::get_singleton()->event_is_action(p_event, E->key()) && is_action_pressed(E->key()) != p_event.is_pressed()) {
+ if (InputMap::get_singleton()->event_is_action(p_event, E->key()) && is_action_pressed(E->key()) != p_event->is_pressed()) {
Action action;
action.fixed_frame = Engine::get_singleton()->get_fixed_frames();
action.idle_frame = Engine::get_singleton()->get_idle_frames();
- action.pressed = p_event.is_pressed();
+ action.pressed = p_event->is_pressed();
action_state[E->key()] = action;
}
}
@@ -484,7 +476,7 @@ void InputDefault::warp_mouse_pos(const Vector2 &p_to) {
OS::get_singleton()->warp_mouse_pos(p_to);
}
-Point2i InputDefault::warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect) {
+Point2i InputDefault::warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect) {
// The relative distance reported for the next event after a warp is in the boundaries of the
// size of the rect on that axis, but it may be greater, in which case there's not problem as fmod()
@@ -495,13 +487,13 @@ Point2i InputDefault::warp_mouse_motion(const InputEventMouseMotion &p_motion, c
// detect the warp: if the relative distance is greater than the half of the size of the relevant rect
// (checked per each axis), it will be considered as the consequence of a former pointer warp.
- const Point2i rel_sgn(p_motion.relative_x >= 0.0f ? 1 : -1, p_motion.relative_y >= 0.0 ? 1 : -1);
+ const Point2i rel_sgn(p_motion->get_relative().x >= 0.0f ? 1 : -1, p_motion->get_relative().y >= 0.0 ? 1 : -1);
const Size2i warp_margin = p_rect.size * 0.5f;
const Point2i rel_warped(
- Math::fmod(p_motion.relative_x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x,
- Math::fmod(p_motion.relative_y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y);
+ Math::fmod(p_motion->get_relative().x + rel_sgn.x * warp_margin.x, p_rect.size.x) - rel_sgn.x * warp_margin.x,
+ Math::fmod(p_motion->get_relative().y + rel_sgn.y * warp_margin.y, p_rect.size.y) - rel_sgn.y * warp_margin.y);
- const Point2i pos_local = Point2i(p_motion.global_x, p_motion.global_y) - p_rect.pos;
+ const Point2i pos_local = p_motion->get_global_pos() - p_rect.pos;
const Point2i pos_warped(Math::fposmod(pos_local.x, p_rect.size.x), Math::fposmod(pos_local.y, p_rect.size.y));
if (pos_warped != pos_local) {
OS::get_singleton()->warp_mouse_pos(pos_warped + p_rect.pos);
@@ -1020,22 +1012,22 @@ void InputDefault::joy_hat(int p_device, int p_val) {
void InputDefault::_button_event(int p_device, int p_index, bool p_pressed) {
- InputEvent ievent;
- ievent.type = InputEvent::JOYPAD_BUTTON;
- ievent.device = p_device;
- ievent.joy_button.button_index = p_index;
- ievent.joy_button.pressed = p_pressed;
+ Ref<InputEventJoypadButton> ievent;
+ ievent.instance();
+ ievent->set_device(p_device);
+ ievent->set_button_index(p_index);
+ ievent->set_pressed(p_pressed);
parse_input_event(ievent);
};
void InputDefault::_axis_event(int p_device, int p_axis, float p_value) {
- InputEvent ievent;
- ievent.type = InputEvent::JOYPAD_MOTION;
- ievent.device = p_device;
- ievent.joy_motion.axis = p_axis;
- ievent.joy_motion.axis_value = p_value;
+ Ref<InputEventJoypadMotion> ievent;
+ ievent.instance();
+ ievent->set_device(p_device);
+ ievent->set_axis(p_axis);
+ ievent->set_axis_value(p_value);
parse_input_event(ievent);
};
diff --git a/main/input_default.h b/main/input_default.h
index 55b7555ef9..35e841a488 100644
--- a/main/input_default.h
+++ b/main/input_default.h
@@ -201,9 +201,9 @@ public:
virtual int get_mouse_button_mask() const;
virtual void warp_mouse_pos(const Vector2 &p_to);
- virtual Point2i warp_mouse_motion(const InputEventMouseMotion &p_motion, const Rect2 &p_rect);
+ virtual Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect);
- virtual void parse_input_event(const InputEvent &p_event);
+ virtual void parse_input_event(const Ref<InputEvent> &p_event);
void set_gravity(const Vector3 &p_gravity);
void set_accelerometer(const Vector3 &p_accel);
diff --git a/main/tests/test_image.cpp b/main/tests/test_image.cpp
index c2c742e75d..0b120f87d5 100644
--- a/main/tests/test_image.cpp
+++ b/main/tests/test_image.cpp
@@ -41,7 +41,7 @@ class TestMainLoop : public MainLoop {
bool quit;
public:
- virtual void input_event(const InputEvent &p_event) {
+ virtual void input_event(const Ref<InputEvent> &p_event) {
}
virtual void init() {
diff --git a/main/tests/test_physics.cpp b/main/tests/test_physics.cpp
index d32756937a..5a233e818e 100644
--- a/main/tests/test_physics.cpp
+++ b/main/tests/test_physics.cpp
@@ -263,18 +263,19 @@ protected:
}
public:
- virtual void input_event(const InputEvent &p_event) {
+ virtual void input_event(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 4) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid() && mm->get_button_mask() & 4) {
- ofs_y -= p_event.mouse_motion.relative_y / 200.0;
- ofs_x += p_event.mouse_motion.relative_x / 200.0;
+ ofs_y -= mm->get_relative().y / 200.0;
+ ofs_x += mm->get_relative().x / 200.0;
}
- if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_motion.button_mask & 1) {
+ if (mm.is_valid() && mm->get_button_mask() & 1) {
- float y = -p_event.mouse_motion.relative_y / 20.0;
- float x = p_event.mouse_motion.relative_x / 20.0;
+ float y = -mm->get_relative().y / 20.0;
+ float x = mm->get_relative().x / 20.0;
if (mover.is_valid()) {
@@ -285,19 +286,6 @@ public:
ps->body_set_state(mover, PhysicsServer::BODY_STATE_TRANSFORM, t);
}
}
-
- if (p_event.type == InputEvent::JOYPAD_MOTION) {
-
- if (p_event.joy_motion.axis == 0) {
-
- joy_direction.x = p_event.joy_motion.axis_value;
- };
-
- if (p_event.joy_motion.axis == 1) {
-
- joy_direction.y = p_event.joy_motion.axis_value;
- };
- };
}
virtual void request_quit() {
diff --git a/main/tests/test_physics_2d.cpp b/main/tests/test_physics_2d.cpp
index d8a00a589a..5f57275503 100644
--- a/main/tests/test_physics_2d.cpp
+++ b/main/tests/test_physics_2d.cpp
@@ -208,35 +208,36 @@ class TestPhysics2DMainLoop : public MainLoop {
}
protected:
- void input_event(const InputEvent &p_event) {
+ void input_event(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_event;
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid()) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
- Point2 p(mb.x, mb.y);
+ Point2 p(mb->get_pos().x, mb->get_pos().y);
- if (mb.button_index == 1) {
+ if (mb->get_button_index() == 1) {
ray_to = p;
_do_ray_query();
- } else if (mb.button_index == 2) {
+ } else if (mb->get_button_index() == 2) {
ray_from = p;
_do_ray_query();
}
}
}
- if (p_event.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_event;
- Point2 p(mm.x, mm.y);
+ if (mm.is_valid()) {
- if (mm.button_mask & BUTTON_MASK_LEFT) {
+ Point2 p = mm->get_pos();
+
+ if (mm->get_button_mask() & BUTTON_MASK_LEFT) {
ray_to = p;
_do_ray_query();
- } else if (mm.button_mask & BUTTON_MASK_RIGHT) {
+ } else if (mm->get_button_mask() & BUTTON_MASK_RIGHT) {
ray_from = p;
_do_ray_query();
}
diff --git a/main/tests/test_render.cpp b/main/tests/test_render.cpp
index 89bd5db60f..74f7453d1b 100644
--- a/main/tests/test_render.cpp
+++ b/main/tests/test_render.cpp
@@ -64,9 +64,9 @@ class TestMainLoop : public MainLoop {
protected:
public:
- virtual void input_event(const InputEvent &p_event) {
+ virtual void input_event(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed)
+ if (p_event->is_pressed())
quit = true;
}
diff --git a/modules/gdscript/gd_editor.cpp b/modules/gdscript/gd_editor.cpp
index 7d5ba08d6c..eea5b15236 100644
--- a/modules/gdscript/gd_editor.cpp
+++ b/modules/gdscript/gd_editor.cpp
@@ -1321,7 +1321,7 @@ static void _find_identifiers(GDCompletionContext &context, int p_line, bool p_o
static const char *_type_names[Variant::VARIANT_MAX] = {
"null", "bool", "int", "float", "String", "Vector2", "Rect2", "Vector3", "Transform2D", "Plane", "Quat", "AABB", "Basis", "Transform",
- "Color", "NodePath", "RID", "Object", "InputEvent", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray",
+ "Color", "NodePath", "RID", "Object", "Dictionary", "Array", "RawArray", "IntArray", "FloatArray", "StringArray",
"Vector2Array", "Vector3Array", "ColorArray"
};
@@ -1425,22 +1425,7 @@ void get_directory_contents(EditorFileSystemDirectory *p_dir, Set<String> &r_lis
static void _find_type_arguments(GDCompletionContext &context, const GDParser::Node *p_node, int p_line, const StringName &p_method, const GDCompletionIdentifier &id, int p_argidx, Set<String> &result, String &arghint) {
//print_line("find type arguments?");
- if (id.type == Variant::INPUT_EVENT && String(p_method) == "is_action" && p_argidx == 0) {
-
- List<PropertyInfo> pinfo;
- GlobalConfig::get_singleton()->get_property_list(&pinfo);
-
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- const PropertyInfo &pi = E->get();
-
- if (!pi.name.begins_with("input/"))
- continue;
-
- String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
- result.insert("\"" + name + "\"");
- }
-
- } else if (id.type == Variant::OBJECT && id.obj_type != StringName()) {
+ if (id.type == Variant::OBJECT && id.obj_type != StringName()) {
MethodBind *m = ClassDB::get_method(id.obj_type, p_method);
if (!m) {
@@ -2266,54 +2251,8 @@ Error GDScriptLanguage::complete_code(const String &p_code, const String &p_base
}
} else {
- if (t.type == Variant::INPUT_EVENT) {
-
- //this is hardcoded otherwise it's not obvious
- Set<String> exclude;
-
- for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
-
- InputEvent ie;
- ie.type = InputEvent::Type(i);
- static const char *evnames[] = {
- "# Common",
- "# Key",
- "# MouseMotion",
- "# MouseButton",
- "# JoypadMotion",
- "# JoypadButton",
- "# ScreenTouch",
- "# ScreenDrag",
- "# Action"
- };
-
- r_options->push_back(evnames[i]);
-
- Variant v = ie;
-
- if (i == 0) {
- List<MethodInfo> mi;
- v.get_method_list(&mi);
- for (List<MethodInfo>::Element *E = mi.front(); E; E = E->next()) {
- r_options->push_back(E->get().name + "(");
- }
- }
-
- List<PropertyInfo> pi;
- v.get_property_list(&pi);
-
- for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
-
- if (i == 0)
- exclude.insert(E->get().name);
- else if (exclude.has(E->get().name))
- continue;
-
- r_options->push_back(E->get().name);
- }
- }
- return OK;
- } else {
+ //check InputEvent hint
+ {
if (t.value.get_type() == Variant::NIL) {
Variant::CallError ce;
t.value = Variant::construct(t.type, NULL, 0, ce);
diff --git a/modules/gdscript/gd_tokenizer.cpp b/modules/gdscript/gd_tokenizer.cpp
index c26ba03a64..5e1a48ae86 100644
--- a/modules/gdscript/gd_tokenizer.cpp
+++ b/modules/gdscript/gd_tokenizer.cpp
@@ -802,7 +802,6 @@ void GDTokenizerText::_advance() {
{ Variant::COLOR, "Color" },
{ Variant::_RID, "RID" },
{ Variant::OBJECT, "Object" },
- { Variant::INPUT_EVENT, "InputEvent" },
{ Variant::NODE_PATH, "NodePath" },
{ Variant::DICTIONARY, "Dictionary" },
{ Variant::ARRAY, "Array" },
diff --git a/modules/gridmap/grid_map_editor_plugin.cpp b/modules/gridmap/grid_map_editor_plugin.cpp
index d8993710a4..e567e08c79 100644
--- a/modules/gridmap/grid_map_editor_plugin.cpp
+++ b/modules/gridmap/grid_map_editor_plugin.cpp
@@ -508,146 +508,150 @@ void GridMapEditor::_duplicate_paste() {
}
}
-bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) {
+bool GridMapEditor::forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) {
if (!node) {
return false;
}
if (edit_mode->get_selected() == 0) { // regular click
- switch (p_event.type) {
- case InputEvent::MOUSE_BUTTON: {
- if (p_event.mouse_button.button_index == BUTTON_WHEEL_UP && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) {
- if (p_event.mouse_button.pressed)
- floor->set_value(floor->get_value() + p_event.mouse_button.factor);
+ Ref<InputEventMouseButton> mb = p_event;
- return true; //eaten
- } else if (p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && (p_event.mouse_button.mod.command || p_event.mouse_button.mod.shift)) {
- if (p_event.mouse_button.pressed)
- floor->set_value(floor->get_value() - p_event.mouse_button.factor);
- return true;
- }
+ if (mb.is_valid()) {
- if (p_event.mouse_button.pressed) {
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && (mb->get_command() || mb->get_shift())) {
+ if (mb->is_pressed())
+ floor->set_value(floor->get_value() + mb->get_factor());
- if (p_event.mouse_button.button_index == BUTTON_LEFT) {
+ return true; //eaten
+ } else if (mb->get_button_index() == BUTTON_WHEEL_DOWN && (mb->get_command() || mb->get_shift())) {
+ if (mb->is_pressed())
+ floor->set_value(floor->get_value() - mb->get_factor());
+ return true;
+ }
- if (input_action == INPUT_DUPLICATE) {
+ if (mb->is_pressed()) {
- //paste
- _duplicate_paste();
- input_action = INPUT_NONE;
- _update_duplicate_indicator();
- } else if (p_event.mouse_button.mod.shift) {
- input_action = INPUT_SELECT;
- } else if (p_event.mouse_button.mod.command)
- input_action = INPUT_COPY;
- else {
- input_action = INPUT_PAINT;
- set_items.clear();
- }
- } else if (p_event.mouse_button.button_index == BUTTON_RIGHT)
- if (input_action == INPUT_DUPLICATE) {
-
- input_action = INPUT_NONE;
- _update_duplicate_indicator();
- } else {
- input_action = INPUT_ERASE;
- set_items.clear();
- }
- else
- return false;
+ if (mb->get_button_index() == BUTTON_LEFT) {
- return do_input_action(p_camera, Point2(p_event.mouse_button.x, p_event.mouse_button.y), true);
- } else {
+ if (input_action == INPUT_DUPLICATE) {
- if (
- (p_event.mouse_button.button_index == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
- (p_event.mouse_button.button_index == BUTTON_LEFT && input_action == INPUT_PAINT)) {
+ //paste
+ _duplicate_paste();
+ input_action = INPUT_NONE;
+ _update_duplicate_indicator();
+ } else if (mb->get_shift()) {
+ input_action = INPUT_SELECT;
+ } else if (mb->get_command())
+ input_action = INPUT_COPY;
+ else {
+ input_action = INPUT_PAINT;
+ set_items.clear();
+ }
+ } else if (mb->get_button_index() == BUTTON_RIGHT)
+ if (input_action == INPUT_DUPLICATE) {
- if (set_items.size()) {
- undo_redo->create_action("GridMap Paint");
- for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
+ input_action = INPUT_NONE;
+ _update_duplicate_indicator();
+ } else {
+ input_action = INPUT_ERASE;
+ set_items.clear();
+ }
+ else
+ return false;
+
+ return do_input_action(p_camera, Point2(mb->get_pos().x, mb->get_pos().y), true);
+ } else {
- const SetItem &si = E->get();
- undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
- }
- for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
+ if (
+ (mb->get_button_index() == BUTTON_RIGHT && input_action == INPUT_ERASE) ||
+ (mb->get_button_index() == BUTTON_LEFT && input_action == INPUT_PAINT)) {
- const SetItem &si = E->get();
- undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
- }
+ if (set_items.size()) {
+ undo_redo->create_action("GridMap Paint");
+ for (List<SetItem>::Element *E = set_items.front(); E; E = E->next()) {
- undo_redo->commit_action();
+ const SetItem &si = E->get();
+ undo_redo->add_do_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.new_value, si.new_orientation);
}
- set_items.clear();
- input_action = INPUT_NONE;
- return true;
- }
+ for (List<SetItem>::Element *E = set_items.back(); E; E = E->prev()) {
- if (p_event.mouse_button.button_index == BUTTON_LEFT && input_action != INPUT_NONE) {
+ const SetItem &si = E->get();
+ undo_redo->add_undo_method(node, "set_cell_item", si.pos.x, si.pos.y, si.pos.z, si.old_value, si.old_orientation);
+ }
- set_items.clear();
- input_action = INPUT_NONE;
- return true;
- }
- if (p_event.mouse_button.button_index == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) {
- input_action = INPUT_NONE;
- return true;
+ undo_redo->commit_action();
}
+ set_items.clear();
+ input_action = INPUT_NONE;
+ return true;
+ }
+
+ if (mb->get_button_index() == BUTTON_LEFT && input_action != INPUT_NONE) {
+
+ set_items.clear();
+ input_action = INPUT_NONE;
+ return true;
+ }
+ if (mb->get_button_index() == BUTTON_RIGHT && (input_action == INPUT_ERASE || input_action == INPUT_DUPLICATE)) {
+ input_action = INPUT_NONE;
+ return true;
}
- } break;
- case InputEvent::MOUSE_MOTION: {
+ }
+ }
+
+ Ref<InputEventMouseMotion> mm = p_event;
- return do_input_action(p_camera, Point2(p_event.mouse_motion.x, p_event.mouse_motion.y), false);
- } break;
+ if (mm.is_valid()) {
+
+ return do_input_action(p_camera, mm->get_pos(), false);
}
} else if (edit_mode->get_selected() == 1) {
//area mode, select an area
- switch (p_event.type) {
- case InputEvent::MOUSE_BUTTON: {
+ Ref<InputEventMouseButton> mb = p_event;
- if (p_event.mouse_button.button_index == BUTTON_LEFT && p_event.mouse_button.pressed) {
+ if (mb.is_valid()) {
- Point2 point = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y);
+ if (mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
- Camera *camera = p_camera;
- Vector3 from = camera->project_ray_origin(point);
- Vector3 normal = camera->project_ray_normal(point);
- Transform local_xform = node->get_global_transform().affine_inverse();
- from = local_xform.xform(from);
- normal = local_xform.basis.xform(normal).normalized();
+ Point2 point = mb->get_pos();
- List<int> areas;
- node->get_area_list(&areas);
+ Camera *camera = p_camera;
+ Vector3 from = camera->project_ray_origin(point);
+ Vector3 normal = camera->project_ray_normal(point);
+ Transform local_xform = node->get_global_transform().affine_inverse();
+ from = local_xform.xform(from);
+ normal = local_xform.basis.xform(normal).normalized();
- float min_d = 1e10;
- int min_area = -1;
+ List<int> areas;
+ node->get_area_list(&areas);
- for (List<int>::Element *E = areas.front(); E; E = E->next()) {
+ float min_d = 1e10;
+ int min_area = -1;
- int area = E->get();
- Rect3 aabb = node->area_get_bounds(area);
- aabb.pos *= node->get_cell_size();
- aabb.size *= node->get_cell_size();
+ for (List<int>::Element *E = areas.front(); E; E = E->next()) {
- Vector3 rclip, rnormal;
- if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal))
- continue;
+ int area = E->get();
+ Rect3 aabb = node->area_get_bounds(area);
+ aabb.pos *= node->get_cell_size();
+ aabb.size *= node->get_cell_size();
- float d = normal.dot(rclip);
- if (d < min_d) {
- min_d = d;
- min_area = area;
- }
- }
+ Vector3 rclip, rnormal;
+ if (!aabb.intersects_segment(from, from + normal * 10000, &rclip, &rnormal))
+ continue;
- selected_area = min_area;
- update_areas();
+ float d = normal.dot(rclip);
+ if (d < min_d) {
+ min_d = d;
+ min_area = area;
+ }
}
- } break;
+
+ selected_area = min_area;
+ update_areas();
+ }
}
}
diff --git a/modules/gridmap/grid_map_editor_plugin.h b/modules/gridmap/grid_map_editor_plugin.h
index d928e6afac..1572f4fbe5 100644
--- a/modules/gridmap/grid_map_editor_plugin.h
+++ b/modules/gridmap/grid_map_editor_plugin.h
@@ -220,7 +220,7 @@ protected:
static void _bind_methods();
public:
- bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event);
+ bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
void edit(GridMap *p_gridmap);
GridMapEditor() {}
@@ -236,7 +236,7 @@ class GridMapEditorPlugin : public EditorPlugin {
EditorNode *editor;
public:
- virtual bool forward_spatial_input_event(Camera *p_camera, const InputEvent &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); }
+ virtual bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event) { return gridmap_editor->forward_spatial_input_event(p_camera, p_event); }
virtual String get_name() const { return "GridMap"; }
bool has_main_screen() const { return false; }
virtual void edit(Object *p_node);
diff --git a/modules/visual_script/register_types.cpp b/modules/visual_script/register_types.cpp
index 4006ad3428..c0467a901b 100644
--- a/modules/visual_script/register_types.cpp
+++ b/modules/visual_script/register_types.cpp
@@ -88,7 +88,7 @@ void register_visual_script_types() {
ClassDB::register_class<VisualScriptWhile>();
ClassDB::register_class<VisualScriptIterator>();
ClassDB::register_class<VisualScriptSequence>();
- ClassDB::register_class<VisualScriptInputFilter>();
+ //ClassDB::register_class<VisualScriptInputFilter>();
ClassDB::register_class<VisualScriptSwitch>();
ClassDB::register_class<VisualScriptYield>();
diff --git a/modules/visual_script/visual_script.h b/modules/visual_script/visual_script.h
index 273a819611..72843099c7 100644
--- a/modules/visual_script/visual_script.h
+++ b/modules/visual_script/visual_script.h
@@ -89,13 +89,11 @@ public:
struct TypeGuess {
Variant::Type type;
- InputEvent::Type ev_type;
StringName GDCLASS;
Ref<Script> script;
TypeGuess() {
type = Variant::NIL;
- ev_type = InputEvent::NONE;
}
};
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp
index 9c77a2ce5e..5839bc9243 100644
--- a/modules/visual_script/visual_script_editor.cpp
+++ b/modules/visual_script/visual_script_editor.cpp
@@ -349,7 +349,6 @@ static Color _color_from_type(Variant::Type p_type) {
case Variant::NODE_PATH: color = Color::html("6993ec"); break;
case Variant::_RID: color = Color::html("69ec9a"); break;
case Variant::OBJECT: color = Color::html("79f3e8"); break;
- case Variant::INPUT_EVENT: color = Color::html("adf18f"); break;
case Variant::DICTIONARY: color = Color::html("77edb1"); break;
case Variant::ARRAY: color = Color::html("e0e0e0"); break;
@@ -453,7 +452,6 @@ void VisualScriptEditor::_update_graph(int p_only_id) {
Control::get_icon("MiniPath", "EditorIcons"),
Control::get_icon("MiniRid", "EditorIcons"),
Control::get_icon("MiniObject", "EditorIcons"),
- Control::get_icon("MiniInput", "EditorIcons"),
Control::get_icon("MiniDictionary", "EditorIcons"),
Control::get_icon("MiniArray", "EditorIcons"),
Control::get_icon("MiniRawArray", "EditorIcons"),
@@ -736,7 +734,6 @@ void VisualScriptEditor::_update_members() {
Control::get_icon("MiniPath", "EditorIcons"),
Control::get_icon("MiniRid", "EditorIcons"),
Control::get_icon("MiniObject", "EditorIcons"),
- Control::get_icon("MiniInput", "EditorIcons"),
Control::get_icon("MiniDictionary", "EditorIcons"),
Control::get_icon("MiniArray", "EditorIcons"),
Control::get_icon("MiniRawArray", "EditorIcons"),
@@ -1419,9 +1416,11 @@ void VisualScriptEditor::_on_nodes_duplicate() {
}
}
-void VisualScriptEditor::_input(const InputEvent &p_event) {
+void VisualScriptEditor::_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
revert_on_drag = String(); //so we can still drag functions
}
}
@@ -2640,7 +2639,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
} else {
n->set_call_mode(VisualScriptPropertySet::CALL_MODE_BASIC_TYPE);
n->set_basic_type(tg.type);
- new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type);
+ new_connect_node_select->select_property_from_basic_type(tg.type);
}
} break;
case CREATE_GET: {
@@ -2670,7 +2669,7 @@ void VisualScriptEditor::_port_action_menu(int p_option) {
} else {
n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_BASIC_TYPE);
n->set_basic_type(tg.type);
- new_connect_node_select->select_property_from_basic_type(tg.type, tg.ev_type);
+ new_connect_node_select->select_property_from_basic_type(tg.type);
}
} break;
diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h
index 1fd97cc1bc..bb832431a0 100644
--- a/modules/visual_script/visual_script_editor.h
+++ b/modules/visual_script/visual_script_editor.h
@@ -196,7 +196,7 @@ class VisualScriptEditor : public ScriptEditorBase {
String revert_on_drag;
- void _input(const InputEvent &p_event);
+ void _input(const Ref<InputEvent> &p_event);
void _on_nodes_delete();
void _on_nodes_duplicate();
diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp
index 2deb6064d3..07d69db207 100644
--- a/modules/visual_script/visual_script_flow_control.cpp
+++ b/modules/visual_script/visual_script_flow_control.cpp
@@ -734,6 +734,7 @@ VisualScriptSwitch::VisualScriptSwitch() {
////////////////EVENT ACTION FILTER///////////
//////////////////////////////////////////
+#if 0
int VisualScriptInputFilter::get_output_sequence_port_count() const {
return filters.size();
@@ -758,86 +759,86 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const
String text;
switch (filters[p_port].type) {
- case InputEvent::NONE: {
+ case Ref<InputEvent>::NONE: {
text = "None";
} break;
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
InputEventKey k = filters[p_port].key;
- if (k.scancode == 0 && k.unicode == 0) {
+ if (k->get_scancode() == 0 && k.unicode == 0) {
text = "No Key";
} else {
- if (k.scancode != 0) {
- text = "KeyCode: " + keycode_get_string(k.scancode);
+ if (k->get_scancode() != 0) {
+ text = "KeyCode: " + keycode_get_string(k->get_scancode());
} else if (k.unicode != 0) {
text = "Uniode: " + String::chr(k.unicode);
}
- if (k.pressed)
+ if (k->is_pressed())
text += ", Pressed";
else
text += ", Released";
if (k.echo)
text += ", Echo";
- if (k.mod.alt)
+ if (k->get_alt())
text = "Alt+" + text;
- if (k.mod.shift)
+ if (k->get_shift())
text = "Shift+" + text;
- if (k.mod.control)
+ if (k->get_control())
text = "Ctrl+" + text;
- if (k.mod.meta)
+ if (k->get_metakey())
text = "Meta+" + text;
}
} break;
- case InputEvent::MOUSE_MOTION: {
+ case Ref<InputEvent>::MOUSE_MOTION: {
InputEventMouseMotion mm = filters[p_port].mouse_motion;
text = "Mouse Motion";
String b = "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight";
for (int i = 0; i < 7; i++) {
- if (mm.button_mask & (1 << i)) {
+ if (mm->get_button_mask() & (1 << i)) {
text = b.get_slice(",", i) + "+" + text;
}
}
- if (mm.mod.alt)
+ if (mm->get_alt())
text = "Alt+" + text;
- if (mm.mod.shift)
+ if (mm->get_shift())
text = "Shift+" + text;
- if (mm.mod.control)
+ if (mm->get_control())
text = "Ctrl+" + text;
- if (mm.mod.meta)
+ if (mm->get_metakey())
text = "Meta+" + text;
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
InputEventMouseButton mb = filters[p_port].mouse_button;
String b = "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight";
- text = b.get_slice(",", mb.button_index) + " Mouse Button";
+ text = b.get_slice(",", mb->get_button_index()) + " Mouse Button";
- if (mb.pressed)
+ if (mb->is_pressed())
text += ", Pressed";
else
text += ", Released";
if (mb.doubleclick)
text += ", DblClick";
- if (mb.mod.alt)
+ if (mb->get_alt())
text = "Alt+" + text;
- if (mb.mod.shift)
+ if (mb->get_shift())
text = "Shift+" + text;
- if (mb.mod.control)
+ if (mb->get_control())
text = "Ctrl+" + text;
- if (mb.mod.meta)
+ if (mb->get_metakey())
text = "Meta+" + text;
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
InputEventJoypadMotion jm = filters[p_port].joy_motion;
@@ -848,29 +849,29 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const
text += " < " + rtos(-jm.axis_value);
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
InputEventJoypadButton jb = filters[p_port].joy_button;
- text = "JoyButton " + itos(jb.button_index);
- if (jb.pressed)
+ text = "JoyButton " + itos(jb->get_button_index());
+ if (jb->is_pressed())
text += ", Pressed";
else
text += ", Released";
} break;
- case InputEvent::SCREEN_TOUCH: {
+ case Ref<InputEvent>::SCREEN_TOUCH: {
InputEventScreenTouch sd = filters[p_port].screen_touch;
text = "Touch Finger " + itos(sd.index);
- if (sd.pressed)
+ if (sd->is_pressed())
text += ", Pressed";
else
text += ", Released";
} break;
- case InputEvent::SCREEN_DRAG: {
+ case Ref<InputEvent>::SCREEN_DRAG: {
InputEventScreenDrag sd = filters[p_port].screen_drag;
text = "Drag Finger " + itos(sd.index);
} break;
- case InputEvent::ACTION: {
+ case Ref<InputEvent>::ACTION: {
List<PropertyInfo> pinfo;
GlobalConfig::get_singleton()->get_property_list(&pinfo);
@@ -890,7 +891,7 @@ String VisualScriptInputFilter::get_output_sequence_port_text(int p_port) const
index++;
}
- if (filters[p_port].action.pressed)
+ if (filters[p_port].action->is_pressed())
text += ", Pressed";
else
text += ", Released";
@@ -939,20 +940,20 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
String what = String(p_name).get_slice("/", 1);
if (what == "type") {
- filters[idx] = InputEvent();
- filters[idx].type = InputEvent::Type(int(p_value));
- if (filters[idx].type == InputEvent::JOYPAD_MOTION) {
+ filters[idx] = Ref<InputEvent>();
+ filters[idx].type = Ref<InputEvent>::Type(int(p_value));
+ if (filters[idx].type == Ref<InputEvent>::JOYPAD_MOTION) {
filters[idx].joy_motion.axis_value = 0.5; //for treshold
- } else if (filters[idx].type == InputEvent::KEY) {
- filters[idx].key.pressed = true; //put these as true to make it more user friendly
- } else if (filters[idx].type == InputEvent::MOUSE_BUTTON) {
- filters[idx].mouse_button.pressed = true;
- } else if (filters[idx].type == InputEvent::JOYPAD_BUTTON) {
- filters[idx].joy_button.pressed = true;
- } else if (filters[idx].type == InputEvent::SCREEN_TOUCH) {
- filters[idx].screen_touch.pressed = true;
- } else if (filters[idx].type == InputEvent::ACTION) {
- filters[idx].action.pressed = true;
+ } else if (filters[idx].type == Ref<InputEvent>::KEY) {
+ filters[idx]->is_pressed() = true; //put these as true to make it more user friendly
+ } else if (filters[idx].type == Ref<InputEvent>::MOUSE_BUTTON) {
+ filters[idx]->is_pressed() = true;
+ } else if (filters[idx].type == Ref<InputEvent>::JOYPAD_BUTTON) {
+ filters[idx].joy_button->is_pressed() = true;
+ } else if (filters[idx].type == Ref<InputEvent>::SCREEN_TOUCH) {
+ filters[idx].screen_touch->is_pressed() = true;
+ } else if (filters[idx].type == Ref<InputEvent>::ACTION) {
+ filters[idx].action->is_pressed() = true;
}
_change_notify();
ports_changed_notify();
@@ -967,14 +968,14 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
switch (filters[idx].type) {
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
if (what == "scancode") {
String sc = p_value;
if (sc == String()) {
- filters[idx].key.scancode = 0;
+ filters[idx]->get_scancode() = 0;
} else {
- filters[idx].key.scancode = find_keycode(p_value);
+ filters[idx]->get_scancode() = find_keycode(p_value);
}
} else if (what == "unicode") {
@@ -989,22 +990,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
} else if (what == "pressed") {
- filters[idx].key.pressed = p_value;
+ filters[idx]->is_pressed() = p_value;
} else if (what == "echo") {
- filters[idx].key.echo = p_value;
+ filters[idx]->is_echo() = p_value;
} else if (what == "mod_alt") {
- filters[idx].key.mod.alt = p_value;
+ filters[idx]->get_alt() = p_value;
} else if (what == "mod_shift") {
- filters[idx].key.mod.shift = p_value;
+ filters[idx]->get_shift() = p_value;
} else if (what == "mod_ctrl") {
- filters[idx].key.mod.control = p_value;
+ filters[idx]->get_control() = p_value;
} else if (what == "mod_meta") {
- filters[idx].key.mod.meta = p_value;
+ filters[idx]->get_metakey() = p_value;
} else {
return false;
}
@@ -1012,22 +1013,22 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
return true;
} break;
- case InputEvent::MOUSE_MOTION: {
+ case Ref<InputEvent>::MOUSE_MOTION: {
if (what == "button_mask") {
- filters[idx].mouse_motion.button_mask = p_value;
+ filters[idx]->get_button_mask() = p_value;
} else if (what == "mod_alt") {
- filters[idx].mouse_motion.mod.alt = p_value;
+ filters[idx].mouse_motion->get_alt() = p_value;
} else if (what == "mod_shift") {
- filters[idx].mouse_motion.mod.shift = p_value;
+ filters[idx].mouse_motion->get_shift() = p_value;
} else if (what == "mod_ctrl") {
- filters[idx].mouse_motion.mod.control = p_value;
+ filters[idx].mouse_motion->get_control() = p_value;
} else if (what == "mod_meta") {
- filters[idx].mouse_motion.mod.meta = p_value;
+ filters[idx].mouse_motion->get_metakey() = p_value;
} else {
return false;
}
@@ -1036,26 +1037,26 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
return true;
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
if (what == "button_index") {
- filters[idx].mouse_button.button_index = p_value;
+ filters[idx]->get_button_index() = p_value;
} else if (what == "pressed") {
- filters[idx].mouse_button.pressed = p_value;
+ filters[idx]->is_pressed() = p_value;
} else if (what == "doubleclicked") {
filters[idx].mouse_button.doubleclick = p_value;
} else if (what == "mod_alt") {
- filters[idx].mouse_button.mod.alt = p_value;
+ filters[idx].mouse_button->get_alt() = p_value;
} else if (what == "mod_shift") {
- filters[idx].mouse_button.mod.shift = p_value;
+ filters[idx].mouse_button->get_shift() = p_value;
} else if (what == "mod_ctrl") {
- filters[idx].mouse_button.mod.control = p_value;
+ filters[idx].mouse_button->get_control() = p_value;
} else if (what == "mod_meta") {
- filters[idx].mouse_button.mod.meta = p_value;
+ filters[idx].mouse_button->get_metakey() = p_value;
} else {
return false;
}
@@ -1063,7 +1064,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
return true;
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
if (what == "axis") {
filters[idx].joy_motion.axis = int(p_value) << 1 | filters[idx].joy_motion.axis;
@@ -1078,12 +1079,12 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
return true;
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
if (what == "button_index") {
- filters[idx].joy_button.button_index = p_value;
+ filters[idx].joy_button->get_button_index() = p_value;
} else if (what == "pressed") {
- filters[idx].joy_button.pressed = p_value;
+ filters[idx].joy_button->is_pressed() = p_value;
} else {
return false;
}
@@ -1091,19 +1092,19 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
return true;
} break;
- case InputEvent::SCREEN_TOUCH: {
+ case Ref<InputEvent>::SCREEN_TOUCH: {
if (what == "finger_index") {
filters[idx].screen_touch.index = p_value;
} else if (what == "pressed") {
- filters[idx].screen_touch.pressed = p_value;
+ filters[idx].screen_touch->is_pressed() = p_value;
} else {
return false;
}
ports_changed_notify();
return true;
} break;
- case InputEvent::SCREEN_DRAG: {
+ case Ref<InputEvent>::SCREEN_DRAG: {
if (what == "finger_index") {
filters[idx].screen_drag.index = p_value;
} else {
@@ -1112,7 +1113,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
ports_changed_notify();
return true;
} break;
- case InputEvent::ACTION: {
+ case Ref<InputEvent>::ACTION: {
if (what == "action_name") {
@@ -1144,7 +1145,7 @@ bool VisualScriptInputFilter::_set(const StringName &p_name, const Variant &p_va
} else if (what == "pressed") {
- filters[idx].action.pressed = p_value;
+ filters[idx].action->is_pressed() = p_value;
ports_changed_notify();
return true;
}
@@ -1181,14 +1182,14 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
switch (filters[idx].type) {
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
if (what == "scancode") {
- if (filters[idx].key.scancode == 0)
+ if (filters[idx]->get_scancode() == 0)
r_ret = String();
else {
- r_ret = keycode_get_string(filters[idx].key.scancode);
+ r_ret = keycode_get_string(filters[idx]->get_scancode());
}
} else if (what == "unicode") {
@@ -1202,44 +1203,44 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
} else if (what == "pressed") {
- r_ret = filters[idx].key.pressed;
+ r_ret = filters[idx]->is_pressed();
} else if (what == "echo") {
- r_ret = filters[idx].key.echo;
+ r_ret = filters[idx]->is_echo();
} else if (what == "mod_alt") {
- r_ret = filters[idx].key.mod.alt;
+ r_ret = filters[idx]->get_alt();
} else if (what == "mod_shift") {
- r_ret = filters[idx].key.mod.shift;
+ r_ret = filters[idx]->get_shift();
} else if (what == "mod_ctrl") {
- r_ret = filters[idx].key.mod.control;
+ r_ret = filters[idx]->get_control();
} else if (what == "mod_meta") {
- r_ret = filters[idx].key.mod.meta;
+ r_ret = filters[idx]->get_metakey();
} else {
return false;
}
return true;
} break;
- case InputEvent::MOUSE_MOTION: {
+ case Ref<InputEvent>::MOUSE_MOTION: {
if (what == "button_mask") {
- r_ret = filters[idx].mouse_motion.button_mask;
+ r_ret = filters[idx]->get_button_mask();
} else if (what == "mod_alt") {
- r_ret = filters[idx].mouse_motion.mod.alt;
+ r_ret = filters[idx].mouse_motion->get_alt();
} else if (what == "mod_shift") {
- r_ret = filters[idx].mouse_motion.mod.shift;
+ r_ret = filters[idx].mouse_motion->get_shift();
} else if (what == "mod_ctrl") {
- r_ret = filters[idx].mouse_motion.mod.control;
+ r_ret = filters[idx].mouse_motion->get_control();
} else if (what == "mod_meta") {
- r_ret = filters[idx].mouse_motion.mod.meta;
+ r_ret = filters[idx].mouse_motion->get_metakey();
} else {
return false;
}
@@ -1247,33 +1248,33 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
return true;
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
if (what == "button_index") {
- r_ret = filters[idx].mouse_button.button_index;
+ r_ret = filters[idx]->get_button_index();
} else if (what == "pressed") {
- r_ret = filters[idx].mouse_button.pressed;
+ r_ret = filters[idx]->is_pressed();
} else if (what == "doubleclicked") {
r_ret = filters[idx].mouse_button.doubleclick;
} else if (what == "mod_alt") {
- r_ret = filters[idx].mouse_button.mod.alt;
+ r_ret = filters[idx].mouse_button->get_alt();
} else if (what == "mod_shift") {
- r_ret = filters[idx].mouse_button.mod.shift;
+ r_ret = filters[idx].mouse_button->get_shift();
} else if (what == "mod_ctrl") {
- r_ret = filters[idx].mouse_button.mod.control;
+ r_ret = filters[idx].mouse_button->get_control();
} else if (what == "mod_meta") {
- r_ret = filters[idx].mouse_button.mod.meta;
+ r_ret = filters[idx].mouse_button->get_metakey();
} else {
return false;
}
return true;
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
if (what == "axis_index") {
r_ret = filters[idx].joy_motion.axis >> 1;
@@ -1287,30 +1288,30 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
return true;
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
if (what == "button_index") {
- r_ret = filters[idx].joy_button.button_index;
+ r_ret = filters[idx].joy_button->get_button_index();
} else if (what == "pressed") {
- r_ret = filters[idx].joy_button.pressed;
+ r_ret = filters[idx].joy_button->is_pressed();
} else {
return false;
}
return true;
} break;
- case InputEvent::SCREEN_TOUCH: {
+ case Ref<InputEvent>::SCREEN_TOUCH: {
if (what == "finger_index") {
r_ret = filters[idx].screen_touch.index;
} else if (what == "pressed") {
- r_ret = filters[idx].screen_touch.pressed;
+ r_ret = filters[idx].screen_touch->is_pressed();
} else {
return false;
}
return true;
} break;
- case InputEvent::SCREEN_DRAG: {
+ case Ref<InputEvent>::SCREEN_DRAG: {
if (what == "finger_index") {
r_ret = filters[idx].screen_drag.index;
} else {
@@ -1318,7 +1319,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
}
return true;
} break;
- case InputEvent::ACTION: {
+ case Ref<InputEvent>::ACTION: {
if (what == "action_name") {
@@ -1344,7 +1345,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
} else if (what == "pressed") {
- r_ret = filters[idx].action.pressed;
+ r_ret = filters[idx].action->is_pressed();
return true;
}
@@ -1354,7 +1355,7 @@ bool VisualScriptInputFilter::_get(const StringName &p_name, Variant &r_ret) con
return false;
}
-static const char *event_type_names[InputEvent::TYPE_MAX] = {
+static const char *event_type_names[Ref<InputEvent>::TYPE_MAX] = {
"None",
"Key",
"MouseMotion",
@@ -1371,7 +1372,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
p_list->push_back(PropertyInfo(Variant::INT, "filter_count", PROPERTY_HINT_RANGE, "0,64"));
String et;
- for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
+ for (int i = 0; i < Ref<InputEvent>::TYPE_MAX; i++) {
if (i > 0)
et += ",";
@@ -1388,10 +1389,10 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
p_list->push_back(PropertyInfo(Variant::INT, base + "device"));
switch (filters[i].type) {
- case InputEvent::NONE: {
+ case Ref<InputEvent>::NONE: {
} break;
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
if (kc == String()) {
int kcc = keycode_get_count();
kc = "None";
@@ -1410,7 +1411,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
- case InputEvent::MOUSE_MOTION: {
+ case Ref<InputEvent>::MOUSE_MOTION: {
p_list->push_back(PropertyInfo(Variant::INT, base + "button_mask", PROPERTY_HINT_FLAGS, "Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_alt"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_shift"));
@@ -1418,7 +1419,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
p_list->push_back(PropertyInfo(Variant::INT, base + "button_index", PROPERTY_HINT_ENUM, "Any,Left,Right,Middle,WheelUp,WheelDown,WheelLeft,WheelRight"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "doubleclicked"));
@@ -1428,26 +1429,26 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
p_list->push_back(PropertyInfo(Variant::BOOL, base + "mod_meta"));
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
p_list->push_back(PropertyInfo(Variant::INT, base + "axis_index"));
p_list->push_back(PropertyInfo(Variant::INT, base + "mode", PROPERTY_HINT_ENUM, "Min,Max"));
p_list->push_back(PropertyInfo(Variant::REAL, base + "treshold", PROPERTY_HINT_RANGE, "0,1,0.01"));
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
p_list->push_back(PropertyInfo(Variant::INT, base + "button_index"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
} break;
- case InputEvent::SCREEN_TOUCH: {
+ case Ref<InputEvent>::SCREEN_TOUCH: {
p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index"));
p_list->push_back(PropertyInfo(Variant::BOOL, base + "pressed"));
} break;
- case InputEvent::SCREEN_DRAG: {
+ case Ref<InputEvent>::SCREEN_DRAG: {
p_list->push_back(PropertyInfo(Variant::INT, base + "finger_index"));
} break;
- case InputEvent::ACTION: {
+ case Ref<InputEvent>::ACTION: {
if (actions == String()) {
@@ -1485,7 +1486,7 @@ void VisualScriptInputFilter::_get_property_list(List<PropertyInfo> *p_list) con
class VisualScriptNodeInstanceInputFilter : public VisualScriptNodeInstance {
public:
VisualScriptInstance *instance;
- Vector<InputEvent> filters;
+ Vector<Ref<InputEvent>> filters;
//virtual int get_working_memory_size() const { return 0; }
//virtual bool is_output_port_unsequenced(int p_idx) const { return false; }
@@ -1499,11 +1500,11 @@ public:
return 0;
}
- InputEvent event = *p_inputs[0];
+ Ref<InputEvent> event = *p_inputs[0];
for (int i = 0; i < filters.size(); i++) {
- const InputEvent &ie = filters[i];
+ const Ref<InputEvent> &ie = filters[i];
if (ie.type != event.type)
continue;
@@ -1511,25 +1512,25 @@ public:
switch (ie.type) {
- case InputEvent::NONE: {
+ case Ref<InputEvent>::NONE: {
match = true;
} break;
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
InputEventKey k = ie.key;
InputEventKey k2 = event.key;
- if (k.scancode == 0 && k.unicode == 0 && k2.scancode == 0 && k2.unicode == 0) {
+ if (k->get_scancode() == 0 && k.unicode == 0 && k2->get_scancode() == 0 && k2.unicode == 0) {
match = true;
} else {
- if ((k.scancode != 0 && k.scancode == k2.scancode) || (k.unicode != 0 && k.unicode == k2.unicode)) {
+ if ((k->get_scancode() != 0 && k->get_scancode() == k2->get_scancode()) || (k.unicode != 0 && k.unicode == k2.unicode)) {
//key valid
if (
- k.pressed == k2.pressed &&
+ k->is_pressed() == k2->is_pressed() &&
k.echo == k2.echo &&
k.mod == k2.mod) {
match = true;
@@ -1538,30 +1539,30 @@ public:
}
} break;
- case InputEvent::MOUSE_MOTION: {
+ case Ref<InputEvent>::MOUSE_MOTION: {
InputEventMouseMotion mm = ie.mouse_motion;
InputEventMouseMotion mm2 = event.mouse_motion;
- if (mm.button_mask == mm2.button_mask &&
+ if (mm->get_button_mask() == mm2->get_button_mask() &&
mm.mod == mm2.mod) {
match = true;
}
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
InputEventMouseButton mb = ie.mouse_button;
InputEventMouseButton mb2 = event.mouse_button;
- if (mb.button_index == mb2.button_index &&
- mb.pressed == mb2.pressed &&
+ if (mb->get_button_index() == mb2->get_button_index() &&
+ mb->is_pressed() == mb2->is_pressed() &&
mb.doubleclick == mb2.doubleclick &&
mb.mod == mb2.mod) {
match = true;
}
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
InputEventJoypadMotion jm = ie.joy_motion;
InputEventJoypadMotion jm2 = event.joy_motion;
@@ -1584,26 +1585,26 @@ public:
}
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
InputEventJoypadButton jb = ie.joy_button;
InputEventJoypadButton jb2 = event.joy_button;
- if (jb.button_index == jb2.button_index &&
- jb.pressed == jb2.pressed) {
+ if (jb->get_button_index() == jb2->get_button_index() &&
+ jb->is_pressed() == jb2->is_pressed()) {
match = true;
}
} break;
- case InputEvent::SCREEN_TOUCH: {
+ case Ref<InputEvent>::SCREEN_TOUCH: {
InputEventScreenTouch st = ie.screen_touch;
InputEventScreenTouch st2 = event.screen_touch;
if (st.index == st2.index &&
- st.pressed == st2.pressed) {
+ st->is_pressed() == st2->is_pressed()) {
match = true;
}
} break;
- case InputEvent::SCREEN_DRAG: {
+ case Ref<InputEvent>::SCREEN_DRAG: {
InputEventScreenDrag sd = ie.screen_drag;
InputEventScreenDrag sd2 = event.screen_drag;
@@ -1611,13 +1612,13 @@ public:
match = true;
}
} break;
- case InputEvent::ACTION: {
+ case Ref<InputEvent>::ACTION: {
InputEventAction ia = ie.action;
InputEventAction ia2 = event.action;
if (ia.action == ia2.action &&
- ia.pressed == ia2.pressed) {
+ ia->is_pressed() == ia2->is_pressed()) {
match = true;
}
} break;
@@ -1643,7 +1644,7 @@ VisualScriptNodeInstance *VisualScriptInputFilter::instance(VisualScriptInstance
VisualScriptInputFilter::VisualScriptInputFilter() {
}
-
+#endif
//////////////////////////////////////////
////////////////TYPE CAST///////////
//////////////////////////////////////////
@@ -1832,6 +1833,6 @@ void register_visual_script_flow_control_nodes() {
VisualScriptLanguage::singleton->add_register_func("flow_control/iterator", create_node_generic<VisualScriptIterator>);
VisualScriptLanguage::singleton->add_register_func("flow_control/sequence", create_node_generic<VisualScriptSequence>);
VisualScriptLanguage::singleton->add_register_func("flow_control/switch", create_node_generic<VisualScriptSwitch>);
- VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>);
+ //VisualScriptLanguage::singleton->add_register_func("flow_control/input_filter", create_node_generic<VisualScriptInputFilter>);
VisualScriptLanguage::singleton->add_register_func("flow_control/type_cast", create_node_generic<VisualScriptTypeCast>);
}
diff --git a/modules/visual_script/visual_script_flow_control.h b/modules/visual_script/visual_script_flow_control.h
index e3936da9e5..314804602e 100644
--- a/modules/visual_script/visual_script_flow_control.h
+++ b/modules/visual_script/visual_script_flow_control.h
@@ -228,11 +228,12 @@ public:
VisualScriptSwitch();
};
+#if 0
class VisualScriptInputFilter : public VisualScriptNode {
GDCLASS(VisualScriptInputFilter, VisualScriptNode)
- Vector<InputEvent> filters;
+ Vector<Ref<InputEvent>> filters;
protected:
bool _set(const StringName &p_name, const Variant &p_value);
@@ -259,7 +260,7 @@ public:
VisualScriptInputFilter();
};
-
+#endif
class VisualScriptTypeCast : public VisualScriptNode {
GDCLASS(VisualScriptTypeCast, VisualScriptNode)
diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp
index 84224dfcbe..b466e64aec 100644
--- a/modules/visual_script/visual_script_func_nodes.cpp
+++ b/modules/visual_script/visual_script_func_nodes.cpp
@@ -943,18 +943,6 @@ static Ref<VisualScriptNode> create_function_call_node(const String &p_name) {
////////////////SET//////////////////////
//////////////////////////////////////////
-static const char *event_type_names[InputEvent::TYPE_MAX] = {
- "None",
- "Key",
- "MouseMotion",
- "MouseButton",
- "JoypadMotion",
- "JoypadButton",
- "ScreenTouch",
- "ScreenDrag",
- "Action"
-};
-
int VisualScriptPropertySet::get_output_sequence_port_count() const {
return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0;
@@ -1119,24 +1107,6 @@ Variant::Type VisualScriptPropertySet::get_basic_type() const {
return basic_type;
}
-void VisualScriptPropertySet::set_event_type(InputEvent::Type p_type) {
-
- if (event_type == p_type)
- return;
- event_type = p_type;
- if (call_mode == CALL_MODE_BASIC_TYPE) {
- _update_cache();
- }
- _change_notify();
- _update_base_type();
- ports_changed_notify();
-}
-
-InputEvent::Type VisualScriptPropertySet::get_event_type() const {
-
- return event_type;
-}
-
void VisualScriptPropertySet::set_base_type(const StringName &p_type) {
if (base_type == p_type)
@@ -1182,14 +1152,8 @@ void VisualScriptPropertySet::_update_cache() {
//not super efficient..
Variant v;
- if (basic_type == Variant::INPUT_EVENT) {
- InputEvent ev;
- ev.type = event_type;
- v = ev;
- } else {
- Variant::CallError ce;
- v = Variant::construct(basic_type, NULL, 0, ce);
- }
+ Variant::CallError ce;
+ v = Variant::construct(basic_type, NULL, 0, ce);
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
@@ -1341,12 +1305,6 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const {
}
}
- if (property.name == "property/event_type") {
- if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) {
- property.usage = 0;
- }
- }
-
if (property.name == "property/node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
property.usage = 0;
@@ -1418,9 +1376,6 @@ void VisualScriptPropertySet::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertySet::_set_type_cache);
ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertySet::_get_type_cache);
- ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertySet::set_event_type);
- ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertySet::get_event_type);
-
ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertySet::set_property);
ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertySet::get_property);
@@ -1438,14 +1393,6 @@ void VisualScriptPropertySet::_bind_methods() {
bt += Variant::get_type_name(Variant::Type(i));
}
- String et;
- for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
- if (i > 0)
- et += ",";
-
- et += event_type_names[i];
- }
-
List<String> script_extensions;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
@@ -1463,7 +1410,6 @@ void VisualScriptPropertySet::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache");
ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property");
@@ -1574,7 +1520,6 @@ VisualScriptPropertySet::VisualScriptPropertySet() {
call_mode = CALL_MODE_SELF;
base_type = "Object";
basic_type = Variant::NIL;
- event_type = InputEvent::NONE;
}
template <VisualScriptPropertySet::CallMode cmode>
@@ -1764,14 +1709,8 @@ void VisualScriptPropertyGet::_update_cache() {
//not super efficient..
Variant v;
- if (basic_type == Variant::INPUT_EVENT) {
- InputEvent ev;
- ev.type = event_type;
- v = ev;
- } else {
- Variant::CallError ce;
- v = Variant::construct(basic_type, NULL, 0, ce);
- }
+ Variant::CallError ce;
+ v = Variant::construct(basic_type, NULL, 0, ce);
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
@@ -1919,24 +1858,6 @@ Variant::Type VisualScriptPropertyGet::get_basic_type() const {
return basic_type;
}
-void VisualScriptPropertyGet::set_event_type(InputEvent::Type p_type) {
-
- if (event_type == p_type)
- return;
- event_type = p_type;
- if (call_mode == CALL_MODE_BASIC_TYPE) {
- _update_cache();
- }
- _change_notify();
- _update_base_type();
- ports_changed_notify();
-}
-
-InputEvent::Type VisualScriptPropertyGet::get_event_type() const {
-
- return event_type;
-}
-
void VisualScriptPropertyGet::_set_type_cache(Variant::Type p_type) {
type_cache = p_type;
}
@@ -1965,11 +1886,6 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const {
property.usage = 0;
}
}
- if (property.name == "property/event_type") {
- if (call_mode != CALL_MODE_BASIC_TYPE || basic_type != Variant::INPUT_EVENT) {
- property.usage = 0;
- }
- }
if (property.name == "property/node_path") {
if (call_mode != CALL_MODE_NODE_PATH) {
@@ -2041,9 +1957,6 @@ void VisualScriptPropertyGet::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_type_cache", "type_cache"), &VisualScriptPropertyGet::_set_type_cache);
ClassDB::bind_method(D_METHOD("_get_type_cache"), &VisualScriptPropertyGet::_get_type_cache);
- ClassDB::bind_method(D_METHOD("set_event_type", "event_type"), &VisualScriptPropertyGet::set_event_type);
- ClassDB::bind_method(D_METHOD("get_event_type"), &VisualScriptPropertyGet::get_event_type);
-
ClassDB::bind_method(D_METHOD("set_property", "property"), &VisualScriptPropertyGet::set_property);
ClassDB::bind_method(D_METHOD("get_property"), &VisualScriptPropertyGet::get_property);
@@ -2061,14 +1974,6 @@ void VisualScriptPropertyGet::_bind_methods() {
bt += Variant::get_type_name(Variant::Type(i));
}
- String et;
- for (int i = 0; i < InputEvent::TYPE_MAX; i++) {
- if (i > 0)
- et += ",";
-
- et += event_type_names[i];
- }
-
List<String> script_extensions;
for (int i = 0; i < ScriptServer::get_language_count(); i++) {
ScriptServer::get_language(i)->get_recognized_extensions(&script_extensions);
@@ -2086,7 +1991,6 @@ void VisualScriptPropertyGet::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/base_script", PROPERTY_HINT_FILE, script_ext_hint), "set_base_script", "get_base_script");
ADD_PROPERTY(PropertyInfo(Variant::INT, "property/type_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_type_cache", "_get_type_cache");
ADD_PROPERTY(PropertyInfo(Variant::INT, "property/basic_type", PROPERTY_HINT_ENUM, bt), "set_basic_type", "get_basic_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "property/event_type", PROPERTY_HINT_ENUM, et), "set_event_type", "get_event_type");
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "property/node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_base_path", "get_base_path");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "property/property"), "set_property", "get_property");
@@ -2184,7 +2088,6 @@ VisualScriptPropertyGet::VisualScriptPropertyGet() {
call_mode = CALL_MODE_SELF;
base_type = "Object";
basic_type = Variant::NIL;
- event_type = InputEvent::NONE;
type_cache = Variant::NIL;
}
diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h
index b56a3c2bcc..3b284952c5 100644
--- a/modules/visual_script/visual_script_func_nodes.h
+++ b/modules/visual_script/visual_script_func_nodes.h
@@ -155,7 +155,6 @@ private:
String base_script;
NodePath base_path;
StringName property;
- InputEvent::Type event_type;
Node *_get_base_node() const;
StringName _get_base_type() const;
@@ -197,9 +196,6 @@ public:
void set_basic_type(Variant::Type p_type);
Variant::Type get_basic_type() const;
- void set_event_type(InputEvent::Type p_type);
- InputEvent::Type get_event_type() const;
-
void set_property(const StringName &p_type);
StringName get_property() const;
@@ -238,7 +234,6 @@ private:
String base_script;
NodePath base_path;
StringName property;
- InputEvent::Type event_type;
void _update_base_type();
Node *_get_base_node() const;
@@ -279,9 +274,6 @@ public:
void set_basic_type(Variant::Type p_type);
Variant::Type get_basic_type() const;
- void set_event_type(InputEvent::Type p_type);
- InputEvent::Type get_event_type() const;
-
void set_property(const StringName &p_type);
StringName get_property() const;
diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp
index 08f4191d3d..8ea3b8098d 100644
--- a/modules/visual_script/visual_script_nodes.cpp
+++ b/modules/visual_script/visual_script_nodes.cpp
@@ -3460,14 +3460,8 @@ void VisualScriptDeconstruct::_update_elements() {
elements.clear();
Variant v;
- if (type == Variant::INPUT_EVENT) {
- InputEvent ie;
- ie.type = input_type;
- v = ie;
- } else {
- Variant::CallError ce;
- v = Variant::construct(type, NULL, 0, ce);
- }
+ Variant::CallError ce;
+ v = Variant::construct(type, NULL, 0, ce);
List<PropertyInfo> pinfo;
v.get_property_list(&pinfo);
@@ -3497,21 +3491,6 @@ Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const {
return type;
}
-void VisualScriptDeconstruct::set_deconstruct_input_type(InputEvent::Type p_input_type) {
-
- if (input_type == p_input_type)
- return;
-
- input_type = p_input_type;
- _update_elements();
- ports_changed_notify();
-}
-
-InputEvent::Type VisualScriptDeconstruct::get_deconstruct_input_type() const {
-
- return input_type;
-}
-
void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) {
ERR_FAIL_COND(p_elements.size() % 2 == 1);
@@ -3570,12 +3549,6 @@ VisualScriptNodeInstance *VisualScriptDeconstruct::instance(VisualScriptInstance
}
void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const {
-
- if (property.name == "input_type") {
- if (type != Variant::INPUT_EVENT) {
- property.usage = 0;
- }
- }
}
void VisualScriptDeconstruct::_bind_methods() {
@@ -3583,9 +3556,6 @@ void VisualScriptDeconstruct::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type);
ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type);
- ClassDB::bind_method(D_METHOD("set_deconstruct_input_type", "input_type"), &VisualScriptDeconstruct::set_deconstruct_input_type);
- ClassDB::bind_method(D_METHOD("get_deconstruct_input_type"), &VisualScriptDeconstruct::get_deconstruct_input_type);
-
ClassDB::bind_method(D_METHOD("_set_elem_cache", "_cache"), &VisualScriptDeconstruct::_set_elem_cache);
ClassDB::bind_method(D_METHOD("_get_elem_cache"), &VisualScriptDeconstruct::_get_elem_cache);
@@ -3594,17 +3564,13 @@ void VisualScriptDeconstruct::_bind_methods() {
argt += "," + Variant::get_type_name(Variant::Type(i));
}
- String iet = "None,Key,MouseMotion,MouseButton,JoypadMotion,JoypadButton,ScreenTouch,ScreenDrag,Action";
-
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_deconstruct_type", "get_deconstruct_type");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "input_type", PROPERTY_HINT_ENUM, iet), "set_deconstruct_input_type", "get_deconstruct_input_type");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_elem_cache", "_get_elem_cache");
}
VisualScriptDeconstruct::VisualScriptDeconstruct() {
type = Variant::NIL;
- input_type = InputEvent::NONE;
}
void register_visual_script_nodes() {
diff --git a/modules/visual_script/visual_script_nodes.h b/modules/visual_script/visual_script_nodes.h
index c0933d1a78..402093fa80 100644
--- a/modules/visual_script/visual_script_nodes.h
+++ b/modules/visual_script/visual_script_nodes.h
@@ -923,7 +923,6 @@ class VisualScriptDeconstruct : public VisualScriptNode {
void _update_elements();
Variant::Type type;
- InputEvent::Type input_type;
void _set_elem_cache(const Array &p_elements);
Array _get_elem_cache() const;
@@ -952,9 +951,6 @@ public:
void set_deconstruct_type(Variant::Type p_type);
Variant::Type get_deconstruct_type() const;
- void set_deconstruct_input_type(InputEvent::Type p_input_type);
- InputEvent::Type get_deconstruct_input_type() const;
-
virtual VisualScriptNodeInstance *instance(VisualScriptInstance *p_instance);
VisualScriptDeconstruct();
diff --git a/platform/android/java_glue.cpp b/platform/android/java_glue.cpp
index 6882dad4f0..37f53a2478 100644
--- a/platform/android/java_glue.cpp
+++ b/platform/android/java_glue.cpp
@@ -610,7 +610,7 @@ struct JAndroidPointerEvent {
};
static List<JAndroidPointerEvent> pointer_events;
-static List<InputEvent> key_events;
+static List<Ref<InputEvent> > key_events;
static List<OS_Android::JoypadEvent> joy_events;
static bool initialized = false;
static Mutex *input_mutex = NULL;
@@ -1036,7 +1036,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_step(JNIEnv *env, job
while (key_events.size()) {
- InputEvent event = key_events.front()->get();
+ Ref<InputEvent> event = key_events.front()->get();
os_android->process_event(event);
key_events.pop_front();
@@ -1367,7 +1367,7 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joybutton(JNIEnv *env
jevent.device = p_device;
jevent.type = OS_Android::JOY_EVENT_BUTTON;
jevent.index = p_button;
- jevent.pressed = p_pressed;
+ jevent->is_pressed() = p_pressed;
input_mutex->lock();
joy_events.push_back(jevent);
@@ -1419,30 +1419,23 @@ JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_joyconnectionchanged(
JNIEXPORT void JNICALL Java_org_godotengine_godot_GodotLib_key(JNIEnv *env, jobject obj, jint p_scancode, jint p_unicode_char, jboolean p_pressed) {
- InputEvent ievent;
- ievent.type = InputEvent::KEY;
- ievent.device = 0;
+ Ref<InputEventKey> ievent;
int val = p_unicode_char;
int scancode = android_get_keysym(p_scancode);
- ievent.key.scancode = scancode;
- ievent.key.unicode = val;
- ievent.key.pressed = p_pressed;
+ ievent->set_scancode(scancode);
+ ievent->set_unicode(val);
+ ievent->set_pressed(p_pressed);
- print_line("Scancode: " + String::num(p_scancode) + ":" + String::num(ievent.key.scancode) + " Unicode: " + String::num(val));
-
- ievent.key.mod.shift = false;
- ievent.key.mod.alt = false;
- ievent.key.mod.control = false;
- ievent.key.echo = false;
+ print_line("Scancode: " + String::num(p_scancode) + ":" + String::num(ievent->get_scancode()) + " Unicode: " + String::num(val));
if (val == '\n') {
- ievent.key.scancode = KEY_ENTER;
+ ievent->set_scancode(KEY_ENTER);
} else if (val == 61448) {
- ievent.key.scancode = KEY_BACKSPACE;
- ievent.key.unicode = KEY_BACKSPACE;
+ ievent->set_scancode(KEY_BACKSPACE);
+ ievent->set_unicode(KEY_BACKSPACE);
} else if (val == 61453) {
- ievent.key.scancode = KEY_ENTER;
- ievent.key.unicode = KEY_ENTER;
+ ievent->set_scancode(KEY_ENTER);
+ ievent->set_unicode(KEY_ENTER);
} else if (p_scancode == 4) {
go_back_request = true;
diff --git a/platform/android/os_android.cpp b/platform/android/os_android.cpp
index 6772964c2f..1c721c645c 100644
--- a/platform/android/os_android.cpp
+++ b/platform/android/os_android.cpp
@@ -344,7 +344,7 @@ void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) {
switch (p_event.type) {
case JOY_EVENT_BUTTON:
- input->joy_button(p_event.device, p_event.index, p_event.pressed);
+ input->joy_button(p_event.device, p_event.index, p_event->is_pressed());
break;
case JOY_EVENT_AXIS:
InputDefault::JoyAxis value;
@@ -360,7 +360,7 @@ void OS_Android::process_joy_event(OS_Android::JoypadEvent p_event) {
}
}
-void OS_Android::process_event(InputEvent p_event) {
+void OS_Android::process_event(Ref<InputEvent> p_event) {
input->parse_input_event(p_event);
}
@@ -374,25 +374,24 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
if (touch.size()) {
//end all if exist
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
- ev.mouse_button.pressed = false;
- ev.mouse_button.x = touch[0].pos.x;
- ev.mouse_button.y = touch[0].pos.y;
- ev.mouse_button.global_x = touch[0].pos.x;
- ev.mouse_button.global_y = touch[0].pos.y;
- input->parse_input_event(ev);
+ {
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
+ ev->set_button_index(BUTTON_LEFT);
+ ev->set_button_mask(BUTTON_MASK_LEFT);
+ ev->set_pressed(false);
+ ev->set_pos(touch[0].pos);
+ ev->set_global_pos(touch[0].pos);
+ input->parse_input_event(ev);
+ }
for (int i = 0; i < touch.size(); i++) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = touch[i].id;
- ev.screen_touch.pressed = false;
- ev.screen_touch.x = touch[i].pos.x;
- ev.screen_touch.y = touch[i].pos.y;
+ Ref<InputEventScreenTouch> ev;
+ ev.instance();
+ ev->set_index(touch[i].id);
+ ev->set_pressed(false);
+ ev->set_pos(touch[i].pos);
input->parse_input_event(ev);
}
}
@@ -405,15 +404,14 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
{
//send mouse
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
- ev.mouse_button.pressed = true;
- ev.mouse_button.x = touch[0].pos.x;
- ev.mouse_button.y = touch[0].pos.y;
- ev.mouse_button.global_x = touch[0].pos.x;
- ev.mouse_button.global_y = touch[0].pos.y;
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
+ ev.type = Ref<InputEvent>::MOUSE_BUTTON;
+ ev->set_button_index(BUTTON_LEFT);
+ ev->set_button_mask(BUTTON_MASK_LEFT);
+ ev->set_pressed(true);
+ ev->set_pos(touch[0].pos);
+ ev->set_global_pos(touch[0].pos);
input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y));
last_mouse = touch[0].pos;
input->parse_input_event(ev);
@@ -422,12 +420,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
//send touch
for (int i = 0; i < touch.size(); i++) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = touch[i].id;
- ev.screen_touch.pressed = true;
- ev.screen_touch.x = touch[i].pos.x;
- ev.screen_touch.y = touch[i].pos.y;
+ Ref<InputEventScreenTouch> ev;
+ ev.instance();
+ ev->set_index(touch[i].id);
+ ev->set_pressed(true);
+ ev->set_pos(touch[i].pos.x);
input->parse_input_event(ev);
}
@@ -436,16 +433,13 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
if (p_points.size()) {
//send mouse, should look for point 0?
- InputEvent ev;
- ev.type = InputEvent::MOUSE_MOTION;
- ev.mouse_motion.button_mask = BUTTON_MASK_LEFT;
- ev.mouse_motion.x = p_points[0].pos.x;
- ev.mouse_motion.y = p_points[0].pos.y;
+ Ref<InputEventMouseMotion> ev;
+ ev.instance();
+ ev->set_button_mask(BUTTON_MASK_LEFT);
+ ev->set_pos(p_points[0].pos.x);
input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
- ev.mouse_motion.speed_x = input->get_last_mouse_speed().x;
- ev.mouse_motion.speed_y = input->get_last_mouse_speed().y;
- ev.mouse_motion.relative_x = p_points[0].pos.x - last_mouse.x;
- ev.mouse_motion.relative_y = p_points[0].pos.y - last_mouse.y;
+ ev->set_speed(input->get_last_mouse_speed());
+ ev->set_relative(p_points[0].pos - last_mouse);
last_mouse = p_points[0].pos;
input->parse_input_event(ev);
}
@@ -468,13 +462,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
if (touch[i].pos == p_points[idx].pos)
continue; //no move unncesearily
- InputEvent ev;
- ev.type = InputEvent::SCREEN_DRAG;
- ev.screen_drag.index = touch[i].id;
- ev.screen_drag.x = p_points[idx].pos.x;
- ev.screen_drag.y = p_points[idx].pos.y;
- ev.screen_drag.relative_x = p_points[idx].pos.x - touch[i].pos.x;
- ev.screen_drag.relative_y = p_points[idx].pos.y - touch[i].pos.y;
+ Ref<InputEventScreenDrag> ev;
+ ev.instance();
+ ev->set_index(touch[i].id);
+ ev->set_pos(p_points[idx].pos.x);
+ ev->set_relative(p_points[idx].pos - touch[i].pos);
input->parse_input_event(ev);
touch[i].pos = p_points[idx].pos;
}
@@ -484,26 +476,23 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
if (touch.size()) {
//end all if exist
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.button_mask = BUTTON_MASK_LEFT;
- ev.mouse_button.pressed = false;
- ev.mouse_button.x = touch[0].pos.x;
- ev.mouse_button.y = touch[0].pos.y;
- ev.mouse_button.global_x = touch[0].pos.x;
- ev.mouse_button.global_y = touch[0].pos.y;
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
+ ev->set_button_index(BUTTON_LEFT);
+ ev->set_button_mask(BUTTON_MASK_LEFT);
+ ev->set_pressed(false);
+ ev->set_pos(touch[0].pos.x);
+ ev->set_global_pos(touch[0].pos.x);
input->set_mouse_position(Point2(touch[0].pos.x, touch[0].pos.y));
input->parse_input_event(ev);
for (int i = 0; i < touch.size(); i++) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = touch[i].id;
- ev.screen_touch.pressed = false;
- ev.screen_touch.x = touch[i].pos.x;
- ev.screen_touch.y = touch[i].pos.y;
+ Ref<InputEventScreenTouch> ev;
+ ev.instance();
+ ev->set_index(touch[i].id);
+ ev->set_pressed(false);
+ ev->set_pos(touch[i].pos);
input->parse_input_event(ev);
}
touch.clear();
@@ -517,12 +506,12 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
TouchPos tp = p_points[p_pointer];
touch.push_back(tp);
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = tp.id;
- ev.screen_touch.pressed = true;
- ev.screen_touch.x = tp.pos.x;
- ev.screen_touch.y = tp.pos.y;
+ Ref<InputEventScreenTouch> ev;
+ ev.instance();
+
+ ev->set_index(tp.id);
+ ev->set_pressed(true);
+ ev->set_pos(tp.pos);
input->parse_input_event(ev);
} break;
@@ -531,12 +520,11 @@ void OS_Android::process_touch(int p_what, int p_pointer, const Vector<TouchPos>
for (int i = 0; i < touch.size(); i++) {
if (touch[i].id == p_pointer) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = touch[i].id;
- ev.screen_touch.pressed = false;
- ev.screen_touch.x = touch[i].pos.x;
- ev.screen_touch.y = touch[i].pos.y;
+ Ref<InputEventScreenTouch> ev;
+ ev.instance();
+ ev->set_index(touch[i].id);
+ ev->set_pressed(false);
+ ev->set_pos(touch[i].pos);
input->parse_input_event(ev);
touch.remove(i);
i--;
diff --git a/platform/android/os_android.h b/platform/android/os_android.h
index f1da2867f0..897c71a7df 100644
--- a/platform/android/os_android.h
+++ b/platform/android/os_android.h
@@ -231,7 +231,7 @@ public:
void process_gyroscope(const Vector3 &p_gyroscope);
void process_touch(int p_what, int p_pointer, const Vector<TouchPos> &p_points);
void process_joy_event(JoypadEvent p_event);
- void process_event(InputEvent p_event);
+ void process_event(Ref<InputEvent> p_event);
void init_video_mode(int p_video_width, int p_video_height);
virtual Error native_video_play(String p_path, float p_volume);
diff --git a/platform/haiku/haiku_direct_window.cpp b/platform/haiku/haiku_direct_window.cpp
index fb6d9afd85..4a9f8c780d 100644
--- a/platform/haiku/haiku_direct_window.cpp
+++ b/platform/haiku/haiku_direct_window.cpp
@@ -151,35 +151,35 @@ void HaikuDirectWindow::HandleMouseButton(BMessage *message) {
}
*/
- InputEvent mouse_event;
- mouse_event.type = InputEvent::MOUSE_BUTTON;
+ Ref<InputEvent> mouse_event;
+ mouse_event.type = Ref<InputEvent>::MOUSE_BUTTON;
mouse_event.device = 0;
mouse_event.mouse_button.mod = GetKeyModifierState(modifiers);
- mouse_event.mouse_button.button_mask = GetMouseButtonState(buttons);
- mouse_event.mouse_button.x = where.x;
- mouse_event.mouse_button.y = where.y;
+ mouse_event->get_button_mask() = GetMouseButtonState(buttons);
+ mouse_event->get_pos().x = where.x;
+ mouse_event->get_pos().y = where.y;
mouse_event.mouse_button.global_x = where.x;
mouse_event.mouse_button.global_y = where.y;
switch (button) {
default:
case B_PRIMARY_MOUSE_BUTTON:
- mouse_event.mouse_button.button_index = 1;
+ mouse_event->get_button_index() = 1;
break;
case B_SECONDARY_MOUSE_BUTTON:
- mouse_event.mouse_button.button_index = 2;
+ mouse_event->get_button_index() = 2;
break;
case B_TERTIARY_MOUSE_BUTTON:
- mouse_event.mouse_button.button_index = 3;
+ mouse_event->get_button_index() = 3;
break;
}
- mouse_event.mouse_button.pressed = (message->what == B_MOUSE_DOWN);
+ mouse_event->is_pressed() = (message->what == B_MOUSE_DOWN);
- if (message->what == B_MOUSE_DOWN && mouse_event.mouse_button.button_index == 1) {
+ if (message->what == B_MOUSE_DOWN && mouse_event->get_button_index() == 1) {
int32 clicks = message->FindInt32("clicks");
if (clicks > 1) {
@@ -207,12 +207,12 @@ void HaikuDirectWindow::HandleMouseMoved(BMessage *message) {
Point2i rel = pos - last_mouse_position;
- InputEvent motion_event;
- motion_event.type = InputEvent::MOUSE_MOTION;
+ Ref<InputEvent> motion_event;
+ motion_event.type = Ref<InputEvent>::MOUSE_MOTION;
motion_event.device = 0;
motion_event.mouse_motion.mod = GetKeyModifierState(modifiers);
- motion_event.mouse_motion.button_mask = GetMouseButtonState(buttons);
+ motion_event->get_button_mask() = GetMouseButtonState(buttons);
motion_event.mouse_motion.x = pos.x;
motion_event.mouse_motion.y = pos.y;
input->set_mouse_position(pos);
@@ -221,8 +221,8 @@ void HaikuDirectWindow::HandleMouseMoved(BMessage *message) {
motion_event.mouse_motion.speed_x = input->get_last_mouse_speed().x;
motion_event.mouse_motion.speed_y = input->get_last_mouse_speed().y;
- motion_event.mouse_motion.relative_x = rel.x;
- motion_event.mouse_motion.relative_y = rel.y;
+ motion_event->get_relative().x = rel.x;
+ motion_event->get_relative().y = rel.y;
last_mouse_position = pos;
@@ -235,22 +235,22 @@ void HaikuDirectWindow::HandleMouseWheelChanged(BMessage *message) {
return;
}
- InputEvent mouse_event;
- mouse_event.type = InputEvent::MOUSE_BUTTON;
+ Ref<InputEvent> mouse_event;
+ mouse_event.type = Ref<InputEvent>::MOUSE_BUTTON;
mouse_event.device = 0;
- mouse_event.mouse_button.button_index = wheel_delta_y < 0 ? 4 : 5;
+ mouse_event->get_button_index() = wheel_delta_y < 0 ? 4 : 5;
mouse_event.mouse_button.mod = GetKeyModifierState(last_key_modifier_state);
- mouse_event.mouse_button.button_mask = last_button_mask;
- mouse_event.mouse_button.x = last_mouse_position.x;
- mouse_event.mouse_button.y = last_mouse_position.y;
+ mouse_event->get_button_mask() = last_button_mask;
+ mouse_event->get_pos().x = last_mouse_position.x;
+ mouse_event->get_pos().y = last_mouse_position.y;
mouse_event.mouse_button.global_x = last_mouse_position.x;
mouse_event.mouse_button.global_y = last_mouse_position.y;
- mouse_event.mouse_button.pressed = true;
+ mouse_event->is_pressed() = true;
input->parse_input_event(mouse_event);
- mouse_event.mouse_button.pressed = false;
+ mouse_event->is_pressed() = false;
input->parse_input_event(mouse_event);
}
@@ -271,13 +271,13 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) {
return;
}
- InputEvent event;
- event.type = InputEvent::KEY;
+ Ref<InputEvent> event;
+ event.type = Ref<InputEvent>::KEY;
event.device = 0;
event.key.mod = GetKeyModifierState(modifiers);
- event.key.pressed = (message->what == B_KEY_DOWN);
- event.key.scancode = KeyMappingHaiku::get_keysym(raw_char, key);
- event.key.echo = message->HasInt32("be:key_repeat");
+ event->is_pressed() = (message->what == B_KEY_DOWN);
+ event->get_scancode() = KeyMappingHaiku::get_keysym(raw_char, key);
+ event->is_echo() = message->HasInt32("be:key_repeat");
event.key.unicode = 0;
const char *bytes = NULL;
@@ -286,9 +286,9 @@ void HaikuDirectWindow::HandleKeyboardEvent(BMessage *message) {
}
//make it consistent across platforms.
- if (event.key.scancode == KEY_BACKTAB) {
- event.key.scancode = KEY_TAB;
- event.key.mod.shift = true;
+ if (event->get_scancode() == KEY_BACKTAB) {
+ event->get_scancode() = KEY_TAB;
+ event->get_shift() = true;
}
input->parse_input_event(event);
@@ -308,13 +308,13 @@ void HaikuDirectWindow::HandleKeyboardModifierEvent(BMessage *message) {
int32 key = old_modifiers ^ modifiers;
- InputEvent event;
- event.type = InputEvent::KEY;
+ Ref<InputEvent> event;
+ event.type = Ref<InputEvent>::KEY;
event.device = 0;
event.key.mod = GetKeyModifierState(modifiers);
- event.key.pressed = ((modifiers & key) != 0);
- event.key.scancode = KeyMappingHaiku::get_modifier_keysym(key);
- event.key.echo = false;
+ event->is_pressed() = ((modifiers & key) != 0);
+ event->get_scancode() = KeyMappingHaiku::get_modifier_keysym(key);
+ event->is_echo() = false;
event.key.unicode = 0;
input->parse_input_event(event);
diff --git a/platform/iphone/os_iphone.cpp b/platform/iphone/os_iphone.cpp
index 0a9d776421..3e95d1a706 100644
--- a/platform/iphone/os_iphone.cpp
+++ b/platform/iphone/os_iphone.cpp
@@ -195,48 +195,45 @@ bool OSIPhone::iterate() {
void OSIPhone::key(uint32_t p_key, bool p_pressed) {
- InputEvent ev;
- ev.type = InputEvent::KEY;
- ev.key.echo = false;
- ev.key.pressed = p_pressed;
- ev.key.scancode = p_key;
- ev.key.unicode = p_key;
+ Ref<InputEventKey> ev;
+ ev.instance()
+ ev->set_echo(false);
+ ev->set_pressed(p_pressed);
+ ev->set_scancode(p_key);
+ ev->set_unicode(p_key);
queue_event(ev);
};
void OSIPhone::mouse_button(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick, bool p_use_as_mouse) {
if (!GLOBAL_DEF("debug/disable_touch", false)) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
- ev.screen_touch.index = p_idx;
- ev.screen_touch.pressed = p_pressed;
- ev.screen_touch.x = p_x;
- ev.screen_touch.y = p_y;
+ Ref<InputEventSreenTouch> ev;
+ ev.instance();
+
+ ev->set_index(p_idx);
+ ev->set_pressed(p_pressed);
+ ev->set_pos(Vector2(p_x, p_y));
queue_event(ev);
};
- mouse_list.pressed[p_idx] = p_pressed;
+ mouse_list->is_pressed()[p_idx] = p_pressed;
if (p_use_as_mouse) {
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.device = 0;
- ev.mouse_button.pointer_index = p_idx;
-
+ Ref<InputEventMouseButton> ev;
+ ev.instance();
// swaped it for tilted screen
- //ev.mouse_button.x = ev.mouse_button.global_x = video_mode.height - p_y;
- //ev.mouse_button.y = ev.mouse_button.global_y = p_x;
- ev.mouse_button.x = ev.mouse_button.global_x = p_x;
- ev.mouse_button.y = ev.mouse_button.global_y = p_y;
+ //ev->get_pos().x = ev.mouse_button.global_x = video_mode.height - p_y;
+ //ev->get_pos().y = ev.mouse_button.global_y = p_x;
+ ev->set_pos(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y));
+ ev->set_global_pos(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y));
- //mouse_list.pressed[p_idx] = p_pressed;
+ //mouse_list->is_pressed()[p_idx] = p_pressed;
- input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.doubleclick = p_doubleclick;
- ev.mouse_button.pressed = p_pressed;
+ input->set_mouse_position(ev->get_pos());
+ ev->set_button_index(BUTTON_LEFT);
+ ev->set_doubleclick(p_doubleclick);
+ ev->set_pressed(p_pressed);
queue_event(ev);
};
@@ -246,46 +243,31 @@ void OSIPhone::mouse_move(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_
if (!GLOBAL_DEF("debug/disable_touch", false)) {
- InputEvent ev;
- ev.type = InputEvent::SCREEN_DRAG;
- ev.screen_drag.index = p_idx;
- ev.screen_drag.x = p_x;
- ev.screen_drag.y = p_y;
- ev.screen_drag.relative_x = p_x - p_prev_x;
- ev.screen_drag.relative_y = p_y - p_prev_y;
+ Ref<InputEventScreenDrag> ev;
+ ev.instance();
+ ev->set_index(p_idx);
+ ev->set_pos(Vector2(p_x, p_y));
+ ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y));
queue_event(ev);
};
if (p_use_as_mouse) {
- InputEvent ev;
- ev.type = InputEvent::MOUSE_MOTION;
- ev.device = 0;
- ev.mouse_motion.pointer_index = p_idx;
-
- if (true) { // vertical
+ Ref<InputEventMouseMotion> ev;
+ ev.instance();
- ev.mouse_motion.x = ev.mouse_button.global_x = p_x;
- ev.mouse_motion.y = ev.mouse_button.global_y = p_y;
- ev.mouse_motion.relative_x = ev.mouse_motion.x - p_prev_x;
- ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_y;
-
- } else { // horizontal?
- ev.mouse_motion.x = ev.mouse_button.global_x = video_mode.height - p_y;
- ev.mouse_motion.y = ev.mouse_button.global_y = p_x;
- ev.mouse_motion.relative_x = ev.mouse_motion.x - (video_mode.height - p_prev_x);
- ev.mouse_motion.relative_y = ev.mouse_motion.y - p_prev_x;
- };
+ ev->set_pos(Vector2(p_x, p_y));
+ ev->set_global_pos(Vector2(p_x, p_y));
+ ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y));
- input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
- ev.mouse_motion.speed_x = input->get_last_mouse_speed().x;
- ev.mouse_motion.speed_y = input->get_last_mouse_speed().y;
- ev.mouse_motion.button_mask = 1; // pressed
+ input->set_mouse_position(ev->get_pos());
+ ev->set_speed(input->get_last_mouse_speed());
+ ev->set_button_mask(BUTTON_LEFT); // pressed
queue_event(ev);
};
};
-void OSIPhone::queue_event(const InputEvent &p_event) {
+void OSIPhone::queue_event(const Ref<InputEvent> &p_event) {
ERR_FAIL_INDEX(event_count, MAX_EVENTS);
@@ -296,7 +278,7 @@ void OSIPhone::touches_cancelled() {
for (int i = 0; i < MAX_MOUSE_COUNT; i++) {
- if (mouse_list.pressed[i]) {
+ if (mouse_list->is_pressed()[i]) {
// send a mouse_up outside the screen
mouse_button(i, -1, -1, false, false, false);
@@ -416,7 +398,7 @@ Point2 OSIPhone::get_mouse_position() const {
int OSIPhone::get_mouse_button_state() const {
- return mouse_list.pressed[0];
+ return mouse_list->is_pressed()[0];
};
void OSIPhone::set_window_title(const String &p_title){};
diff --git a/platform/iphone/os_iphone.h b/platform/iphone/os_iphone.h
index 209bf00788..0da7e6d081 100644
--- a/platform/iphone/os_iphone.h
+++ b/platform/iphone/os_iphone.h
@@ -118,9 +118,9 @@ private:
Vector3 last_accel;
- InputEvent event_queue[MAX_EVENTS];
+ Ref<InputEvent> event_queue[MAX_EVENTS];
int event_count;
- void queue_event(const InputEvent &p_event);
+ void queue_event(const Ref<InputEvent> &p_event);
String data_dir;
String unique_ID;
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp
index dda619a54d..ae00fb429e 100644
--- a/platform/javascript/os_javascript.cpp
+++ b/platform/javascript/os_javascript.cpp
@@ -151,26 +151,26 @@ static EM_BOOL _mousebutton_callback(int event_type, const EmscriptenMouseEvent
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_MOUSEDOWN && event_type != EMSCRIPTEN_EVENT_MOUSEUP, false);
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.pressed = event_type == EMSCRIPTEN_EVENT_MOUSEDOWN;
- ev.mouse_button.global_x = ev.mouse_button.x = mouse_event->canvasX;
- ev.mouse_button.global_y = ev.mouse_button.y = mouse_event->canvasY;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::MOUSE_BUTTON;
+ ev->is_pressed() = event_type == EMSCRIPTEN_EVENT_MOUSEDOWN;
+ ev.mouse_button.global_x = ev->get_pos().x = mouse_event->canvasX;
+ ev.mouse_button.global_y = ev->get_pos().y = mouse_event->canvasY;
ev.mouse_button.mod = dom2godot_mod(mouse_event);
switch (mouse_event->button) {
- case DOM_BUTTON_LEFT: ev.mouse_button.button_index = BUTTON_LEFT; break;
- case DOM_BUTTON_MIDDLE: ev.mouse_button.button_index = BUTTON_MIDDLE; break;
- case DOM_BUTTON_RIGHT: ev.mouse_button.button_index = BUTTON_RIGHT; break;
+ case DOM_BUTTON_LEFT: ev->get_button_index() = BUTTON_LEFT; break;
+ case DOM_BUTTON_MIDDLE: ev->get_button_index() = BUTTON_MIDDLE; break;
+ case DOM_BUTTON_RIGHT: ev->get_button_index() = BUTTON_RIGHT; break;
default: return false;
}
- ev.mouse_button.button_mask = _input->get_mouse_button_mask();
- if (ev.mouse_button.pressed)
- ev.mouse_button.button_mask |= 1 << ev.mouse_button.button_index;
+ ev->get_button_mask() = _input->get_mouse_button_mask();
+ if (ev->is_pressed())
+ ev->get_button_mask() |= 1 << ev->get_button_index();
else
- ev.mouse_button.button_mask &= ~(1 << ev.mouse_button.button_index);
- ev.mouse_button.button_mask >>= 1;
+ ev->get_button_mask() &= ~(1 << ev->get_button_index());
+ ev->get_button_mask() >>= 1;
_input->parse_input_event(ev);
return true;
@@ -180,16 +180,16 @@ static EM_BOOL _mousemove_callback(int event_type, const EmscriptenMouseEvent *m
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_MOUSEMOVE, false);
- InputEvent ev;
- ev.type = InputEvent::MOUSE_MOTION;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::MOUSE_MOTION;
ev.mouse_motion.mod = dom2godot_mod(mouse_event);
- ev.mouse_motion.button_mask = _input->get_mouse_button_mask() >> 1;
+ ev->get_button_mask() = _input->get_mouse_button_mask() >> 1;
ev.mouse_motion.global_x = ev.mouse_motion.x = mouse_event->canvasX;
ev.mouse_motion.global_y = ev.mouse_motion.y = mouse_event->canvasY;
- ev.mouse_motion.relative_x = _input->get_mouse_position().x - ev.mouse_motion.x;
- ev.mouse_motion.relative_y = _input->get_mouse_position().y - ev.mouse_motion.y;
+ ev->get_relative().x = _input->get_mouse_position().x - ev.mouse_motion.x;
+ ev->get_relative().y = _input->get_mouse_position().y - ev.mouse_motion.y;
_input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
ev.mouse_motion.speed_x = _input->get_last_mouse_speed().x;
@@ -203,31 +203,31 @@ static EM_BOOL _wheel_callback(int event_type, const EmscriptenWheelEvent *wheel
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_WHEEL, false);
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_mask = _input->get_mouse_button_mask() >> 1;
- ev.mouse_button.global_x = ev.mouse_button.x = _input->get_mouse_position().x;
- ev.mouse_button.global_y = ev.mouse_button.y = _input->get_mouse_position().y;
- ev.mouse_button.mod.shift = _input->is_key_pressed(KEY_SHIFT);
- ev.mouse_button.mod.alt = _input->is_key_pressed(KEY_ALT);
- ev.mouse_button.mod.control = _input->is_key_pressed(KEY_CONTROL);
- ev.mouse_button.mod.meta = _input->is_key_pressed(KEY_META);
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::MOUSE_BUTTON;
+ ev->get_button_mask() = _input->get_mouse_button_mask() >> 1;
+ ev.mouse_button.global_x = ev->get_pos().x = _input->get_mouse_position().x;
+ ev.mouse_button.global_y = ev->get_pos().y = _input->get_mouse_position().y;
+ ev.mouse_button->get_shift() = _input->is_key_pressed(KEY_SHIFT);
+ ev.mouse_button->get_alt() = _input->is_key_pressed(KEY_ALT);
+ ev.mouse_button->get_control() = _input->is_key_pressed(KEY_CONTROL);
+ ev.mouse_button->get_metakey() = _input->is_key_pressed(KEY_META);
if (wheel_event->deltaY < 0)
- ev.mouse_button.button_index = BUTTON_WHEEL_UP;
+ ev->get_button_index() = BUTTON_WHEEL_UP;
else if (wheel_event->deltaY > 0)
- ev.mouse_button.button_index = BUTTON_WHEEL_DOWN;
+ ev->get_button_index() = BUTTON_WHEEL_DOWN;
else if (wheel_event->deltaX > 0)
- ev.mouse_button.button_index = BUTTON_WHEEL_LEFT;
+ ev->get_button_index() = BUTTON_WHEEL_LEFT;
else if (wheel_event->deltaX < 0)
- ev.mouse_button.button_index = BUTTON_WHEEL_RIGHT;
+ ev->get_button_index() = BUTTON_WHEEL_RIGHT;
else
return false;
- ev.mouse_button.pressed = true;
+ ev->is_pressed() = true;
_input->parse_input_event(ev);
- ev.mouse_button.pressed = false;
+ ev->is_pressed() = false;
_input->parse_input_event(ev);
return true;
@@ -243,8 +243,8 @@ static EM_BOOL _touchpress_callback(int event_type, const EmscriptenTouchEvent *
event_type != EMSCRIPTEN_EVENT_TOUCHCANCEL,
false);
- InputEvent ev;
- ev.type = InputEvent::SCREEN_TOUCH;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::SCREEN_TOUCH;
int lowest_id_index = -1;
for (int i = 0; i < touch_event->numTouches; ++i) {
@@ -256,20 +256,20 @@ static EM_BOOL _touchpress_callback(int event_type, const EmscriptenTouchEvent *
ev.screen_touch.index = touch.identifier;
_prev_touches[i].x = ev.screen_touch.x = touch.canvasX;
_prev_touches[i].y = ev.screen_touch.y = touch.canvasY;
- ev.screen_touch.pressed = event_type == EMSCRIPTEN_EVENT_TOUCHSTART;
+ ev.screen_touch->is_pressed() = event_type == EMSCRIPTEN_EVENT_TOUCHSTART;
_input->parse_input_event(ev);
}
if (touch_event->touches[lowest_id_index].isChanged) {
- ev.type = InputEvent::MOUSE_BUTTON;
+ ev.type = Ref<InputEvent>::MOUSE_BUTTON;
ev.mouse_button.mod = dom2godot_mod(touch_event);
- ev.mouse_button.button_mask = _input->get_mouse_button_mask() >> 1;
- ev.mouse_button.global_x = ev.mouse_button.x = touch_event->touches[lowest_id_index].canvasX;
- ev.mouse_button.global_y = ev.mouse_button.y = touch_event->touches[lowest_id_index].canvasY;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.pressed = event_type == EMSCRIPTEN_EVENT_TOUCHSTART;
+ ev->get_button_mask() = _input->get_mouse_button_mask() >> 1;
+ ev.mouse_button.global_x = ev->get_pos().x = touch_event->touches[lowest_id_index].canvasX;
+ ev.mouse_button.global_y = ev->get_pos().y = touch_event->touches[lowest_id_index].canvasY;
+ ev->get_button_index() = BUTTON_LEFT;
+ ev->is_pressed() = event_type == EMSCRIPTEN_EVENT_TOUCHSTART;
_input->parse_input_event(ev);
}
@@ -280,8 +280,8 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_TOUCHMOVE, false);
- InputEvent ev;
- ev.type = InputEvent::SCREEN_DRAG;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::SCREEN_DRAG;
int lowest_id_index = -1;
for (int i = 0; i < touch_event->numTouches; ++i) {
@@ -304,13 +304,13 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t
if (touch_event->touches[lowest_id_index].isChanged) {
- ev.type = InputEvent::MOUSE_MOTION;
+ ev.type = Ref<InputEvent>::MOUSE_MOTION;
ev.mouse_motion.mod = dom2godot_mod(touch_event);
- ev.mouse_motion.button_mask = _input->get_mouse_button_mask() >> 1;
+ ev->get_button_mask() = _input->get_mouse_button_mask() >> 1;
ev.mouse_motion.global_x = ev.mouse_motion.x = touch_event->touches[lowest_id_index].canvasX;
ev.mouse_motion.global_y = ev.mouse_motion.y = touch_event->touches[lowest_id_index].canvasY;
- ev.mouse_motion.relative_x = _input->get_mouse_position().x - ev.mouse_motion.x;
- ev.mouse_motion.relative_y = _input->get_mouse_position().y - ev.mouse_motion.y;
+ ev->get_relative().x = _input->get_mouse_position().x - ev.mouse_motion.x;
+ ev->get_relative().y = _input->get_mouse_position().y - ev.mouse_motion.y;
_input->set_mouse_position(Point2(ev.mouse_motion.x, ev.mouse_motion.y));
ev.mouse_motion.speed_x = _input->get_last_mouse_speed().x;
@@ -321,13 +321,13 @@ static EM_BOOL _touchmove_callback(int event_type, const EmscriptenTouchEvent *t
return true;
}
-static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) {
+static Ref<InputEvent> _setup_key_event(const EmscriptenKeyboardEvent *emscripten_event) {
- InputEvent ev;
- ev.type = InputEvent::KEY;
- ev.key.echo = emscripten_event->repeat;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::KEY;
+ ev->is_echo() = emscripten_event->repeat;
ev.key.mod = dom2godot_mod(emscripten_event);
- ev.key.scancode = dom2godot_scancode(emscripten_event->keyCode);
+ ev->get_scancode() = dom2godot_scancode(emscripten_event->keyCode);
String unicode = String::utf8(emscripten_event->key);
// check if empty or multi-character (e.g. `CapsLock`)
@@ -342,15 +342,15 @@ static InputEvent _setup_key_event(const EmscriptenKeyboardEvent *emscripten_eve
return ev;
}
-static InputEvent deferred_key_event;
+static Ref<InputEvent> deferred_key_event;
static EM_BOOL _keydown_callback(int event_type, const EmscriptenKeyboardEvent *key_event, void *user_data) {
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYDOWN, false);
- InputEvent ev = _setup_key_event(key_event);
- ev.key.pressed = true;
- if (ev.key.unicode == 0 && keycode_has_unicode(ev.key.scancode)) {
+ Ref<InputEvent> ev = _setup_key_event(key_event);
+ ev->is_pressed() = true;
+ if (ev.key.unicode == 0 && keycode_has_unicode(ev->get_scancode())) {
// defer to keypress event for legacy unicode retrieval
deferred_key_event = ev;
return false; // do not suppress keypress event
@@ -372,10 +372,10 @@ static EM_BOOL _keyup_callback(int event_type, const EmscriptenKeyboardEvent *ke
ERR_FAIL_COND_V(event_type != EMSCRIPTEN_EVENT_KEYUP, false);
- InputEvent ev = _setup_key_event(key_event);
- ev.key.pressed = false;
+ Ref<InputEvent> ev = _setup_key_event(key_event);
+ ev->is_pressed() = false;
_input->parse_input_event(ev);
- return ev.key.scancode != KEY_UNKNOWN && ev.key.scancode != 0;
+ return ev->get_scancode() != KEY_UNKNOWN && ev->get_scancode() != 0;
}
static EM_BOOL joy_callback_func(int p_type, const EmscriptenGamepadEvent *p_event, void *p_user) {
diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h
index 2bc603d8d9..65269148ec 100644
--- a/platform/javascript/os_javascript.h
+++ b/platform/javascript/os_javascript.h
@@ -154,7 +154,7 @@ public:
virtual String get_resource_dir() const;
void process_accelerometer(const Vector3 &p_accelerometer);
- void push_input(const InputEvent &p_ev);
+ void push_input(const Ref<InputEvent> &p_ev);
virtual bool is_joy_known(int p_device);
virtual String get_joy_guid(int p_device) const;
diff --git a/platform/osx/os_osx.h b/platform/osx/os_osx.h
index ff02bf0794..3a37d663ad 100644
--- a/platform/osx/os_osx.h
+++ b/platform/osx/os_osx.h
@@ -165,7 +165,7 @@ public:
virtual void swap_buffers();
Error shell_open(String p_uri);
- void push_input(const InputEvent &p_event);
+ void push_input(const Ref<InputEvent> &p_event);
String get_locale() const;
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm
index d6647fc1d2..462a926674 100644
--- a/platform/osx/os_osx.mm
+++ b/platform/osx/os_osx.mm
@@ -288,15 +288,15 @@ static int button_mask = 0;
//print_line("mouse down:");
button_mask |= BUTTON_MASK_LEFT;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.pressed = true;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_LEFT;
+ ev->is_pressed() = true;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.doubleclick = [event clickCount] == 2;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
@@ -309,24 +309,24 @@ static int button_mask = 0;
- (void)mouseUp:(NSEvent *)event {
button_mask &= ~BUTTON_MASK_LEFT;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_LEFT;
- ev.mouse_button.pressed = false;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_LEFT;
+ ev->is_pressed() = false;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
}
- (void)mouseMoved:(NSEvent *)event {
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_MOTION;
- ev.mouse_motion.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
prev_mouse_x = mouse_x;
prev_mouse_y = mouse_y;
const NSRect contentRect = [OS_OSX::singleton->window_view frame];
@@ -337,8 +337,8 @@ static int button_mask = 0;
ev.mouse_motion.y = mouse_y;
ev.mouse_motion.global_x = mouse_x;
ev.mouse_motion.global_y = mouse_y;
- ev.mouse_motion.relative_x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
- ev.mouse_motion.relative_y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ ev->get_relative().x = [event deltaX] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
+ ev->get_relative().y = [event deltaY] * OS_OSX::singleton->_mouse_scale([[event window] backingScaleFactor]);
ev.mouse_motion.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->input->set_mouse_position(Point2(mouse_x, mouse_y));
@@ -348,15 +348,15 @@ static int button_mask = 0;
- (void)rightMouseDown:(NSEvent *)event {
button_mask |= BUTTON_MASK_RIGHT;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_RIGHT;
- ev.mouse_button.pressed = true;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_RIGHT;
+ ev->is_pressed() = true;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
}
@@ -368,15 +368,15 @@ static int button_mask = 0;
- (void)rightMouseUp:(NSEvent *)event {
button_mask &= ~BUTTON_MASK_RIGHT;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_RIGHT;
- ev.mouse_button.pressed = false;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_RIGHT;
+ ev->is_pressed() = false;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
}
@@ -387,15 +387,15 @@ static int button_mask = 0;
return;
button_mask |= BUTTON_MASK_MIDDLE;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_MIDDLE;
- ev.mouse_button.pressed = true;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_MIDDLE;
+ ev->is_pressed() = true;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
}
@@ -410,15 +410,15 @@ static int button_mask = 0;
return;
button_mask &= ~BUTTON_MASK_MIDDLE;
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = BUTTON_MIDDLE;
- ev.mouse_button.pressed = false;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ ev->get_button_index() = BUTTON_MIDDLE;
+ ev->is_pressed() = false;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
ev.mouse_button.mod = translateFlags([event modifierFlags]);
OS_OSX::singleton->push_input(ev);
}
@@ -610,21 +610,21 @@ static int translateKey(unsigned int key) {
}
- (void)keyDown:(NSEvent *)event {
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::KEY;
- ev.key.pressed = true;
+ ev->is_pressed() = true;
ev.key.mod = translateFlags([event modifierFlags]);
- ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
- ev.key.echo = [event isARepeat];
+ ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode]));
+ ev->is_echo() = [event isARepeat];
NSString *characters = [event characters];
NSUInteger i, length = [characters length];
- if (length > 0 && keycode_has_unicode(ev.key.scancode)) {
+ if (length > 0 && keycode_has_unicode(ev->get_scancode())) {
for (i = 0; i < length; i++) {
ev.key.unicode = [characters characterAtIndex:i];
OS_OSX::singleton->push_input(ev);
- ev.key.scancode = 0;
+ ev->get_scancode() = 0;
}
} else {
OS_OSX::singleton->push_input(ev);
@@ -632,7 +632,7 @@ static int translateKey(unsigned int key) {
}
- (void)flagsChanged:(NSEvent *)event {
- InputEvent ev;
+ Ref<InputEvent> ev;
int key = [event keyCode];
int mod = [event modifierFlags];
@@ -641,64 +641,64 @@ static int translateKey(unsigned int key) {
if (key == 0x36 || key == 0x37) {
if (mod & NSCommandKeyMask) {
mod &= ~NSCommandKeyMask;
- ev.key.pressed = true;
+ ev->is_pressed() = true;
} else {
- ev.key.pressed = false;
+ ev->is_pressed() = false;
}
} else if (key == 0x38 || key == 0x3c) {
if (mod & NSShiftKeyMask) {
mod &= ~NSShiftKeyMask;
- ev.key.pressed = true;
+ ev->is_pressed() = true;
} else {
- ev.key.pressed = false;
+ ev->is_pressed() = false;
}
} else if (key == 0x3a || key == 0x3d) {
if (mod & NSAlternateKeyMask) {
mod &= ~NSAlternateKeyMask;
- ev.key.pressed = true;
+ ev->is_pressed() = true;
} else {
- ev.key.pressed = false;
+ ev->is_pressed() = false;
}
} else if (key == 0x3b || key == 0x3e) {
if (mod & NSControlKeyMask) {
mod &= ~NSControlKeyMask;
- ev.key.pressed = true;
+ ev->is_pressed() = true;
} else {
- ev.key.pressed = false;
+ ev->is_pressed() = false;
}
} else {
return;
}
ev.key.mod = translateFlags(mod);
- ev.key.scancode = latin_keyboard_keycode_convert(translateKey(key));
+ ev->get_scancode() = latin_keyboard_keycode_convert(translateKey(key));
OS_OSX::singleton->push_input(ev);
}
- (void)keyUp:(NSEvent *)event {
- InputEvent ev;
+ Ref<InputEvent> ev;
ev.type = InputEvent::KEY;
- ev.key.pressed = false;
+ ev->is_pressed() = false;
ev.key.mod = translateFlags([event modifierFlags]);
- ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
+ ev->get_scancode() = latin_keyboard_keycode_convert(translateKey([event keyCode]));
OS_OSX::singleton->push_input(ev);
}
inline void sendScrollEvent(int button, double factor) {
- InputEvent ev;
- ev.type = InputEvent::MOUSE_BUTTON;
- ev.mouse_button.button_index = button;
- ev.mouse_button.factor = factor;
- ev.mouse_button.pressed = true;
- ev.mouse_button.x = mouse_x;
- ev.mouse_button.y = mouse_y;
+ Ref<InputEvent> ev;
+ ev.type = Ref<InputEvent>::MOUSE_BUTTON;
+ ev->get_button_index() = button;
+ ev.mouse_button->get_factor() = factor;
+ ev->is_pressed() = true;
+ ev->get_pos().x = mouse_x;
+ ev->get_pos().y = mouse_y;
ev.mouse_button.global_x = mouse_x;
ev.mouse_button.global_y = mouse_y;
- ev.mouse_button.button_mask = button_mask;
+ ev->get_button_mask() = button_mask;
OS_OSX::singleton->push_input(ev);
- ev.mouse_button.pressed = false;
+ ev->is_pressed() = false;
OS_OSX::singleton->push_input(ev);
}
@@ -1515,9 +1515,9 @@ void OS_OSX::process_events() {
autoreleasePool = [[NSAutoreleasePool alloc] init];
}
-void OS_OSX::push_input(const InputEvent &p_event) {
+void OS_OSX::push_input(const Ref<InputEvent> &p_event) {
- InputEvent ev = p_event;
+ Ref<InputEvent> ev = p_event;
input->parse_input_event(ev);
}
diff --git a/platform/uwp/app.cpp b/platform/uwp/app.cpp
index 2946aa1eae..7c8f09b27b 100644
--- a/platform/uwp/app.cpp
+++ b/platform/uwp/app.cpp
@@ -259,10 +259,10 @@ void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Cor
int but = _get_button(point);
if (_is_touch(point)) {
- InputEvent event;
+ Ref<InputEvent> event;
event.type = InputEvent::SCREEN_TOUCH;
event.device = 0;
- event.screen_touch.pressed = p_pressed;
+ event.screen_touch->is_pressed() = p_pressed;
event.screen_touch.x = pos.X;
event.screen_touch.y = pos.Y;
event.screen_touch.index = _get_finger(point->PointerId);
@@ -276,21 +276,21 @@ void App::pointer_event(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Cor
}; // fallthrought of sorts
- InputEvent event;
+ Ref<InputEvent> event;
event.type = InputEvent::MOUSE_BUTTON;
event.device = 0;
- event.mouse_button.pressed = p_pressed;
- event.mouse_button.button_index = but;
- event.mouse_button.x = pos.X;
- event.mouse_button.y = pos.Y;
+ event->is_pressed() = p_pressed;
+ event->get_button_index() = but;
+ event->get_pos().x = pos.X;
+ event->get_pos().y = pos.Y;
event.mouse_button.global_x = pos.X;
event.mouse_button.global_y = pos.Y;
if (p_is_wheel) {
if (point->Properties->MouseWheelDelta > 0) {
- event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP;
+ event->get_button_index() = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_UP;
} else if (point->Properties->MouseWheelDelta < 0) {
- event.mouse_button.button_index = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN;
+ event->get_button_index() = point->Properties->IsHorizontalMouseWheel ? BUTTON_WHEEL_LEFT : BUTTON_WHEEL_DOWN;
}
}
@@ -350,7 +350,7 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co
if (point->IsInContact && _is_touch(point)) {
InputEvent event;
- event.type = InputEvent::SCREEN_DRAG;
+ event.type = Ref<InputEvent>::SCREEN_DRAG;
event.device = 0;
event.screen_drag.x = pos.X;
event.screen_drag.y = pos.Y;
@@ -369,14 +369,14 @@ void App::OnPointerMoved(Windows::UI::Core::CoreWindow ^ sender, Windows::UI::Co
return;
InputEvent event;
- event.type = InputEvent::MOUSE_MOTION;
+ event.type = Ref<InputEvent>::MOUSE_MOTION;
event.device = 0;
event.mouse_motion.x = pos.X;
event.mouse_motion.y = pos.Y;
event.mouse_motion.global_x = pos.X;
event.mouse_motion.global_y = pos.Y;
- event.mouse_motion.relative_x = pos.X - last_touch_x[31];
- event.mouse_motion.relative_y = pos.Y - last_touch_y[31];
+ event->get_relative().x = pos.X - last_touch_x[31];
+ event->get_relative().y = pos.Y - last_touch_y[31];
last_mouse_pos = pos;
@@ -394,14 +394,14 @@ void App::OnMouseMoved(MouseDevice ^ mouse_device, MouseEventArgs ^ args) {
pos.Y = last_mouse_pos.Y + args->MouseDelta.Y;
InputEvent event;
- event.type = InputEvent::MOUSE_MOTION;
+ event.type = Ref<InputEvent>::MOUSE_MOTION;
event.device = 0;
event.mouse_motion.x = pos.X;
event.mouse_motion.y = pos.Y;
event.mouse_motion.global_x = pos.X;
event.mouse_motion.global_y = pos.Y;
- event.mouse_motion.relative_x = args->MouseDelta.X;
- event.mouse_motion.relative_y = args->MouseDelta.Y;
+ event->get_relative().x = args->MouseDelta.X;
+ event->get_relative().y = args->MouseDelta.Y;
last_mouse_pos = pos;
@@ -420,20 +420,20 @@ void App::key_event(Windows::UI::Core::CoreWindow ^ sender, bool p_pressed, Wind
mod.shift = sender->GetAsyncKeyState(VirtualKey::Shift) == CoreVirtualKeyStates::Down;
ke.mod_state = mod;
- ke.pressed = p_pressed;
+ ke->is_pressed() = p_pressed;
if (key_args != nullptr) {
ke.type = OSUWP::KeyEvent::MessageType::KEY_EVENT_MESSAGE;
ke.unicode = 0;
- ke.scancode = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey);
+ ke->get_scancode() = KeyMappingWindows::get_keysym((unsigned int)key_args->VirtualKey);
ke.echo = (!p_pressed && !key_args->KeyStatus.IsKeyReleased) || (p_pressed && key_args->KeyStatus.WasKeyDown);
} else {
ke.type = OSUWP::KeyEvent::MessageType::CHAR_EVENT_MESSAGE;
ke.unicode = char_args->KeyCode;
- ke.scancode = 0;
+ ke->get_scancode() = 0;
ke.echo = (!p_pressed && !char_args->KeyStatus.IsKeyReleased) || (p_pressed && char_args->KeyStatus.WasKeyDown);
}
diff --git a/platform/uwp/os_uwp.cpp b/platform/uwp/os_uwp.cpp
index c68b2ffa33..47f4b3f3c8 100644
--- a/platform/uwp/os_uwp.cpp
+++ b/platform/uwp/os_uwp.cpp
@@ -330,14 +330,14 @@ String OSUWP::get_clipboard() const {
return "";
};
-void OSUWP::input_event(InputEvent &p_event) {
+void OSUWP::input_event(Ref<InputEvent> &p_event) {
input->parse_input_event(p_event);
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index > 3) {
+ if (p_event.type == Ref<InputEvent>::MOUSE_BUTTON && p_event->is_pressed() && p_event->get_button_index() > 3) {
//send release for mouse wheel
- p_event.mouse_button.pressed = false;
+ p_event->is_pressed() = false;
input->parse_input_event(p_event);
}
};
@@ -663,14 +663,14 @@ void OSUWP::process_key_events() {
for (int i = 0; i < key_event_pos; i++) {
KeyEvent &kev = key_event_buffer[i];
- InputEvent iev;
+ Ref<InputEvent> iev;
- iev.type = InputEvent::KEY;
+ iev.type = Ref<InputEvent>::KEY;
iev.key.mod = kev.mod_state;
- iev.key.echo = kev.echo;
- iev.key.scancode = kev.scancode;
+ iev->is_echo() = kev.echo;
+ iev->get_scancode() = kev->get_scancode();
iev.key.unicode = kev.unicode;
- iev.key.pressed = kev.pressed;
+ iev->is_pressed() = kev->is_pressed();
input_event(iev);
}
diff --git a/platform/uwp/os_uwp.h b/platform/uwp/os_uwp.h
index 22602e4564..d2a51aad4c 100644
--- a/platform/uwp/os_uwp.h
+++ b/platform/uwp/os_uwp.h
@@ -257,7 +257,7 @@ public:
virtual bool get_swap_ok_cancel() { return true; }
- void input_event(InputEvent &p_event);
+ void input_event(Ref<InputEvent> &p_event);
virtual PowerState get_power_state();
virtual int get_power_seconds_left();
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index 42597f79c8..ba5db05dab 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -215,14 +215,11 @@ bool OS_Windows::can_draw() const {
void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) {
- InputEvent event;
- event.type = InputEvent::SCREEN_TOUCH;
- event.screen_touch.index = idx;
-
- event.screen_touch.pressed = p_pressed;
-
- event.screen_touch.x = p_x;
- event.screen_touch.y = p_y;
+ Ref<InputEventScreenTouch> event;
+ event.instance();
+ event->set_index(idx);
+ event->set_pressed(p_pressed);
+ event->set_pos(Vector2(p_x, p_y));
if (main_loop) {
input->parse_input_event(event);
@@ -231,12 +228,10 @@ void OS_Windows::_touch_event(bool p_pressed, int p_x, int p_y, int idx) {
void OS_Windows::_drag_event(int p_x, int p_y, int idx) {
- InputEvent event;
- event.type = InputEvent::SCREEN_DRAG;
- event.screen_drag.index = idx;
-
- event.screen_drag.x = p_x;
- event.screen_drag.y = p_y;
+ Ref<InputEventScreenDrag> event;
+ event.instance();
+ event->set_index(idx);
+ event->set_pos(Vector2(p_x, p_y));
if (main_loop)
input->parse_input_event(event);
@@ -367,22 +362,23 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
};
*/
- InputEvent event;
- event.type = InputEvent::MOUSE_MOTION;
- InputEventMouseMotion &mm = event.mouse_motion;
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
+
+ mm->set_control((wParam & MK_CONTROL) != 0);
+ mm->set_shift((wParam & MK_SHIFT) != 0);
+ mm->set_alt(alt_mem);
- mm.mod.control = (wParam & MK_CONTROL) != 0;
- mm.mod.shift = (wParam & MK_SHIFT) != 0;
- mm.mod.alt = alt_mem;
+ int bmask = 0;
+ bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
+ bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
+ bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
+ mm->set_button_mask(bmask);
- mm.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
- mm.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
- mm.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
- last_button_state = mm.button_mask;
- /*mm.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0;
- mm.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
- mm.x = GET_X_LPARAM(lParam);
- mm.y = GET_Y_LPARAM(lParam);
+ last_button_state = mm->get_button_mask();
+ /*mm->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0;
+ mm->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
+ mm->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
if (mouse_mode == MOUSE_MODE_CAPTURED) {
@@ -390,35 +386,33 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
old_x = c.x;
old_y = c.y;
- if (Point2i(mm.x, mm.y) == c) {
+ if (mm->get_pos() == c) {
center = c;
return 0;
}
- Point2i ncenter(mm.x, mm.y);
+ Point2i ncenter = mm->get_pos();
center = ncenter;
POINT pos = { (int)c.x, (int)c.y };
ClientToScreen(hWnd, &pos);
SetCursorPos(pos.x, pos.y);
}
- input->set_mouse_position(Point2(mm.x, mm.y));
- mm.speed_x = input->get_last_mouse_speed().x;
- mm.speed_y = input->get_last_mouse_speed().y;
+ input->set_mouse_position(mm->get_pos());
+ mm->set_speed(input->get_last_mouse_speed());
if (old_invalid) {
- old_x = mm.x;
- old_y = mm.y;
+ old_x = mm->get_pos().x;
+ old_y = mm->get_pos().y;
old_invalid = false;
}
- mm.relative_x = mm.x - old_x;
- mm.relative_y = mm.y - old_y;
- old_x = mm.x;
- old_y = mm.y;
+ mm->set_relative(Vector2(mm->get_pos() - Vector2(old_x, old_y)));
+ old_x = mm->get_pos().x;
+ old_y = mm->get_pos().y;
if (window_has_focus && main_loop)
- input->parse_input_event(event);
+ input->parse_input_event(mm);
} break;
case WM_LBUTTONDOWN:
@@ -447,114 +441,112 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
};
*/
- InputEvent event;
- event.type = InputEvent::MOUSE_BUTTON;
- InputEventMouseButton &mb = event.mouse_button;
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
switch (uMsg) {
case WM_LBUTTONDOWN: {
- mb.pressed = true;
- mb.button_index = 1;
+ mb->set_pressed(true);
+ mb->set_button_index(1);
} break;
case WM_LBUTTONUP: {
- mb.pressed = false;
- mb.button_index = 1;
+ mb->set_pressed(false);
+ mb->set_button_index(1);
} break;
case WM_MBUTTONDOWN: {
- mb.pressed = true;
- mb.button_index = 3;
+ mb->set_pressed(true);
+ mb->set_button_index(3);
} break;
case WM_MBUTTONUP: {
- mb.pressed = false;
- mb.button_index = 3;
+ mb->set_pressed(false);
+ mb->set_button_index(3);
} break;
case WM_RBUTTONDOWN: {
- mb.pressed = true;
- mb.button_index = 2;
+ mb->set_pressed(true);
+ mb->set_button_index(2);
} break;
case WM_RBUTTONUP: {
- mb.pressed = false;
- mb.button_index = 2;
+ mb->set_pressed(false);
+ mb->set_button_index(2);
} break;
case WM_LBUTTONDBLCLK: {
- mb.pressed = true;
- mb.button_index = 1;
- mb.doubleclick = true;
+ mb->set_pressed(true);
+ mb->set_button_index(1);
+ mb->set_doubleclick(true);
} break;
case WM_RBUTTONDBLCLK: {
- mb.pressed = true;
- mb.button_index = 2;
- mb.doubleclick = true;
+ mb->set_pressed(true);
+ mb->set_button_index(2);
+ mb->set_doubleclick(true);
} break;
case WM_MOUSEWHEEL: {
- mb.pressed = true;
+ mb->set_pressed(true);
int motion = (short)HIWORD(wParam);
if (!motion)
return 0;
if (motion > 0)
- mb.button_index = BUTTON_WHEEL_UP;
+ mb->set_button_index(BUTTON_WHEEL_UP);
else
- mb.button_index = BUTTON_WHEEL_DOWN;
+ mb->set_button_index(BUTTON_WHEEL_DOWN);
} break;
case WM_MOUSEHWHEEL: {
- mb.pressed = true;
+ mb->set_pressed(true);
int motion = (short)HIWORD(wParam);
if (!motion)
return 0;
if (motion < 0) {
- mb.button_index = BUTTON_WHEEL_LEFT;
- mb.factor = fabs((double)motion / (double)WHEEL_DELTA);
+ mb->set_button_index(BUTTON_WHEEL_LEFT);
+ mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA));
} else {
- mb.button_index = BUTTON_WHEEL_RIGHT;
- mb.factor = fabs((double)motion / (double)WHEEL_DELTA);
+ mb->set_button_index(BUTTON_WHEEL_RIGHT);
+ mb->set_factor(fabs((double)motion / (double)WHEEL_DELTA));
}
} break;
/*
case WM_XBUTTONDOWN: {
- mb.pressed=true;
- mb.button_index=(HIWORD(wParam)==XBUTTON1)?6:7;
+ mb->is_pressed()=true;
+ mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7;
} break;
case WM_XBUTTONUP:
- mb.pressed=true;
- mb.button_index=(HIWORD(wParam)==XBUTTON1)?6:7;
+ mb->is_pressed()=true;
+ mb->get_button_index()=(HIWORD(wParam)==XBUTTON1)?6:7;
} break;*/
default: { return 0; }
}
- mb.mod.control = (wParam & MK_CONTROL) != 0;
- mb.mod.shift = (wParam & MK_SHIFT) != 0;
- mb.mod.alt = alt_mem;
- //mb.mod.alt=(wParam&MK_MENU)!=0;
- mb.button_mask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
- mb.button_mask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
- mb.button_mask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
-
- last_button_state = mb.button_mask;
+ mb->set_control((wParam & MK_CONTROL) != 0);
+ mb->set_shift((wParam & MK_SHIFT) != 0);
+ mb->set_alt(alt_mem);
+ //mb->get_alt()=(wParam&MK_MENU)!=0;
+ int bmask = 0;
+ bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0;
+ bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0;
+ bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0;
+ mb->set_button_mask(bmask);
+
+ last_button_state = mb->get_button_mask();
/*
- mb.button_mask|=(wParam&MK_XBUTTON1)?(1<<5):0;
- mb.button_mask|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
- mb.x = GET_X_LPARAM(lParam);
- mb.y = GET_Y_LPARAM(lParam);
+ mb->get_button_mask()|=(wParam&MK_XBUTTON1)?(1<<5):0;
+ mb->get_button_mask()|=(wParam&MK_XBUTTON2)?(1<<6):0;*/
+ mb->set_pos(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
if (mouse_mode == MOUSE_MODE_CAPTURED) {
- mb.x = old_x;
- mb.y = old_y;
+ mb->set_pos(Vector2(old_x, old_y));
}
- mb.global_x = mb.x;
- mb.global_y = mb.y;
+ mb->set_global_pos(mb->get_pos());
if (uMsg != WM_MOUSEWHEEL) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
if (++pressrc > 0)
SetCapture(hWnd);
@@ -568,21 +560,21 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
} else if (mouse_mode != MOUSE_MODE_CAPTURED) {
// for reasons unknown to mankind, wheel comes in screen cordinates
POINT coords;
- coords.x = mb.x;
- coords.y = mb.y;
+ coords.x = mb->get_pos().x;
+ coords.y = mb->get_pos().y;
ScreenToClient(hWnd, &coords);
- mb.x = coords.x;
- mb.y = coords.y;
+ mb->set_pos(coords);
}
if (main_loop) {
- input->parse_input_event(event);
- if (mb.pressed && mb.button_index > 3) {
+ input->parse_input_event(mb);
+ if (mb->is_pressed() && mb->get_button_index() > 3) {
//send release for mouse wheel
- mb.pressed = false;
- input->parse_input_event(event);
+ Ref<InputEventMouseButton> mbd = mb->duplicate();
+ mbd->set_pressed(false);
+ input->parse_input_event(mbd);
}
}
}
@@ -638,10 +630,10 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
// Make sure we don't include modifiers for the modifier key itself.
KeyEvent ke;
- ke.mod_state.shift = (wParam != VK_SHIFT) ? shift_mem : false;
- ke.mod_state.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false;
- ke.mod_state.control = (wParam != VK_CONTROL) ? control_mem : false;
- ke.mod_state.meta = meta_mem;
+ ke.shift = (wParam != VK_SHIFT) ? shift_mem : false;
+ ke.alt = (!(wParam == VK_MENU && (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN))) ? alt_mem : false;
+ ke.control = (wParam != VK_CONTROL) ? control_mem : false;
+ ke.meta = meta_mem;
ke.uMsg = uMsg;
if (ke.uMsg == WM_SYSKEYDOWN)
@@ -777,23 +769,25 @@ void OS_Windows::process_key_events() {
case WM_CHAR: {
if ((i == 0 && ke.uMsg == WM_CHAR) || (i > 0 && key_event_buffer[i - 1].uMsg == WM_CHAR)) {
- InputEvent event;
- event.type = InputEvent::KEY;
- InputEventKey &k = event.key;
-
- k.mod = ke.mod_state;
- k.pressed = true;
- k.scancode = KeyMappingWindows::get_keysym(ke.wParam);
- k.unicode = ke.wParam;
- if (k.unicode && gr_mem) {
- k.mod.alt = false;
- k.mod.control = false;
+ Ref<InputEventKey> k;
+ k.instance();
+
+ k->set_shift(ke.shift);
+ k->set_alt(ke.alt);
+ k->set_control(ke.control);
+ k->set_metakey(ke.meta);
+ k->set_pressed(true);
+ k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
+ k->set_unicode(ke.wParam);
+ if (k->get_unicode() && gr_mem) {
+ k->set_alt(false);
+ k->set_control(false);
}
- if (k.unicode < 32)
- k.unicode = 0;
+ if (k->get_unicode() < 32)
+ k->set_unicode(0);
- input->parse_input_event(event);
+ input->parse_input_event(k);
}
//do nothing
@@ -801,27 +795,32 @@ void OS_Windows::process_key_events() {
case WM_KEYUP:
case WM_KEYDOWN: {
- InputEvent event;
- event.type = InputEvent::KEY;
- InputEventKey &k = event.key;
+ Ref<InputEventKey> k;
+ k.instance();
+
+ k->set_shift(ke.shift);
+ k->set_alt(ke.alt);
+ k->set_control(ke.control);
+ k->set_metakey(ke.meta);
- k.mod = ke.mod_state;
- k.pressed = (ke.uMsg == WM_KEYDOWN);
+ k->set_pressed(ke.uMsg == WM_KEYDOWN);
- k.scancode = KeyMappingWindows::get_keysym(ke.wParam);
- if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR)
- k.unicode = key_event_buffer[i + 1].wParam;
- if (k.unicode && gr_mem) {
- k.mod.alt = false;
- k.mod.control = false;
+ k->set_scancode(KeyMappingWindows::get_keysym(ke.wParam));
+
+ if (i + 1 < key_event_pos && key_event_buffer[i + 1].uMsg == WM_CHAR) {
+ k->set_unicode(key_event_buffer[i + 1].wParam);
+ }
+ if (k->get_unicode() && gr_mem) {
+ k->set_alt(false);
+ k->set_control(false);
}
- if (k.unicode < 32)
- k.unicode = 0;
+ if (k->get_unicode() < 32)
+ k->set_unicode(0);
- k.echo = (ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30)));
+ k->set_echo((ke.uMsg == WM_KEYDOWN && (ke.lParam & (1 << 30))));
- input->parse_input_event(event);
+ input->parse_input_event(k);
} break;
}
diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h
index 4dd05928df..bd5acde417 100644
--- a/platform/windows/os_windows.h
+++ b/platform/windows/os_windows.h
@@ -69,6 +69,7 @@ class OS_Windows : public OS {
struct KeyEvent {
InputModifierState mod_state;
+ bool alt, shift, ctrl, meta;
UINT uMsg;
WPARAM wParam;
LPARAM lParam;
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 59ac1fed96..8534185389 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -958,16 +958,12 @@ void OS_X11::request_attention() {
XSendEvent(x11_display, DefaultRootWindow(x11_display), False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
}
-InputModifierState OS_X11::get_key_modifier_state(unsigned int p_x11_state) {
+void OS_X11::get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state) {
- InputModifierState state;
-
- state.shift = (p_x11_state & ShiftMask);
- state.control = (p_x11_state & ControlMask);
- state.alt = (p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/); //altgr should not count as alt
- state.meta = (p_x11_state & Mod4Mask);
-
- return state;
+ state->set_shift((p_x11_state & ShiftMask));
+ state->set_control((p_x11_state & ControlMask));
+ state->set_alt((p_x11_state & Mod1Mask /*|| p_x11_state&Mod5Mask*/)); //altgr should not count as alt
+ state->set_metakey((p_x11_state & Mod4Mask));
}
unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) {
@@ -1099,7 +1095,10 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
//print_line("mod1: "+itos(xkeyevent->state&Mod1Mask)+" mod 5: "+itos(xkeyevent->state&Mod5Mask));
- InputModifierState state = get_key_modifier_state(xkeyevent->state);
+ Ref<InputEventKey> k;
+ k.instance();
+
+ get_key_modifier_state(xkeyevent->state, k);
/* Phase 6, determine echo character */
@@ -1142,40 +1141,36 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
/* Phase 7, send event to Window */
- InputEvent event;
- event.type = InputEvent::KEY;
- event.device = 0;
- event.key.mod = state;
- event.key.pressed = keypress;
+ k->set_pressed(keypress);
if (keycode >= 'a' && keycode <= 'z')
keycode -= 'a' - 'A';
- event.key.scancode = keycode;
- event.key.unicode = unicode;
- event.key.echo = p_echo;
+ k->set_scancode(keycode);
+ k->set_unicode(unicode);
+ k->set_echo(p_echo);
- if (event.key.scancode == KEY_BACKTAB) {
+ if (k->get_scancode() == KEY_BACKTAB) {
//make it consistent across platforms.
- event.key.scancode = KEY_TAB;
- event.key.mod.shift = true;
+ k->set_scancode(KEY_TAB);
+ k->set_shift(true);
}
//don't set mod state if modifier keys are released by themselves
//else event.is_action() will not work correctly here
- if (!event.key.pressed) {
- if (event.key.scancode == KEY_SHIFT)
- event.key.mod.shift = false;
- else if (event.key.scancode == KEY_CONTROL)
- event.key.mod.control = false;
- else if (event.key.scancode == KEY_ALT)
- event.key.mod.alt = false;
- else if (event.key.scancode == KEY_META)
- event.key.mod.meta = false;
+ if (!k->is_pressed()) {
+ if (k->get_scancode() == KEY_SHIFT)
+ k->set_shift(false);
+ else if (k->get_scancode() == KEY_CONTROL)
+ k->set_control(false);
+ else if (k->get_scancode() == KEY_ALT)
+ k->set_alt(false);
+ else if (k->get_scancode() == KEY_META)
+ k->set_metakey(false);
}
- //printf("key: %x\n",event.key.scancode);
- input->parse_input_event(event);
+ //printf("key: %x\n",k->get_scancode());
+ input->parse_input_event(k);
}
struct Property {
@@ -1332,22 +1327,20 @@ void OS_X11::process_xevents() {
event.xbutton.y = last_mouse_pos.y;
}
- InputEvent mouse_event;
- mouse_event.type = InputEvent::MOUSE_BUTTON;
- mouse_event.device = 0;
- mouse_event.mouse_button.mod = get_key_modifier_state(event.xbutton.state);
- mouse_event.mouse_button.button_mask = get_mouse_button_state(event.xbutton.state);
- mouse_event.mouse_button.x = event.xbutton.x;
- mouse_event.mouse_button.y = event.xbutton.y;
- mouse_event.mouse_button.global_x = event.xbutton.x;
- mouse_event.mouse_button.global_y = event.xbutton.y;
- mouse_event.mouse_button.button_index = event.xbutton.button;
- if (mouse_event.mouse_button.button_index == 2)
- mouse_event.mouse_button.button_index = 3;
- else if (mouse_event.mouse_button.button_index == 3)
- mouse_event.mouse_button.button_index = 2;
-
- mouse_event.mouse_button.pressed = (event.type == ButtonPress);
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+
+ get_key_modifier_state(event.xbutton.state, mb);
+ mb->set_button_mask(get_mouse_button_state(event.xbutton.state));
+ mb->set_pos(Vector2(event.xbutton.x, event.xbutton.y));
+ mb->set_global_pos(mb->get_pos());
+ mb->set_button_index(event.xbutton.button);
+ if (mb->get_button_index() == 2)
+ mb->set_button_index(3);
+ else if (mb->get_button_index() == 3)
+ mb->set_button_index(2);
+
+ mb->set_pressed((event.type == ButtonPress));
if (event.type == ButtonPress && event.xbutton.button == 1) {
@@ -1357,7 +1350,7 @@ void OS_X11::process_xevents() {
last_click_ms = 0;
last_click_pos = Point2(-100, -100);
- mouse_event.mouse_button.doubleclick = true;
+ mb->set_doubleclick(true);
} else {
last_click_ms += diff;
@@ -1365,7 +1358,7 @@ void OS_X11::process_xevents() {
}
}
- input->parse_input_event(mouse_event);
+ input->parse_input_event(mb);
} break;
case MotionNotify: {
@@ -1443,22 +1436,16 @@ void OS_X11::process_xevents() {
Point2i rel = pos - last_mouse_pos;
- InputEvent motion_event;
- motion_event.type = InputEvent::MOUSE_MOTION;
- motion_event.device = 0;
+ Ref<InputEventMouseMotion> mm;
+ mm.instance();
- motion_event.mouse_motion.mod = get_key_modifier_state(event.xmotion.state);
- motion_event.mouse_motion.button_mask = get_mouse_button_state(event.xmotion.state);
- motion_event.mouse_motion.x = pos.x;
- motion_event.mouse_motion.y = pos.y;
+ get_key_modifier_state(event.xmotion.state, mm);
+ mm->set_button_mask(get_mouse_button_state(event.xmotion.state));
+ mm->set_pos(pos);
+ mm->set_global_pos(pos);
input->set_mouse_position(pos);
- motion_event.mouse_motion.global_x = pos.x;
- motion_event.mouse_motion.global_y = pos.y;
- motion_event.mouse_motion.speed_x = input->get_last_mouse_speed().x;
- motion_event.mouse_motion.speed_y = input->get_last_mouse_speed().y;
-
- motion_event.mouse_motion.relative_x = rel.x;
- motion_event.mouse_motion.relative_y = rel.y;
+ mm->set_speed(input->get_last_mouse_speed());
+ mm->set_relative(rel);
last_mouse_pos = pos;
@@ -1467,7 +1454,7 @@ void OS_X11::process_xevents() {
// this is so that the relative motion doesn't get messed up
// after we regain focus.
if (window_has_focus || !mouse_mode_grab)
- input->parse_input_event(motion_event);
+ input->parse_input_event(mm);
} break;
case KeyPress:
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 7f01f9c617..d62186e5bd 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -121,7 +121,7 @@ class OS_X11 : public OS_Unix {
PhysicsServer *physics_server;
unsigned int get_mouse_button_state(unsigned int p_x11_state);
- InputModifierState get_key_modifier_state(unsigned int p_x11_state);
+ void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
Physics2DServer *physics_2d_server;
MouseMode mouse_mode;
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index f699c8f0e8..b2258ec94b 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -688,11 +688,11 @@ Vector2 CanvasItem::make_canvas_pos_local(const Vector2 &screen_point) const {
return local_matrix.xform(screen_point);
}
-InputEvent CanvasItem::make_input_local(const InputEvent &p_event) const {
+Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const {
ERR_FAIL_COND_V(!is_inside_tree(), p_event);
- return p_event.xform_by((get_canvas_transform() * get_global_transform()).affine_inverse());
+ return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse());
}
Vector2 CanvasItem::get_global_mouse_position() const {
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 72fe5b93da..bea4301326 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -209,7 +209,7 @@ public:
void set_use_parent_material(bool p_use_parent_material);
bool get_use_parent_material() const;
- InputEvent make_input_local(const InputEvent &pevent) const;
+ Ref<InputEvent> make_input_local(const Ref<InputEvent> &pevent) const;
Vector2 make_canvas_pos_local(const Vector2 &screen_point) const;
Vector2 get_global_mouse_position() const;
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index afbdfec45e..caf9cf201a 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -180,7 +180,7 @@ bool CollisionObject2D::is_pickable() const {
return pickable;
}
-void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape) {
+void CollisionObject2D::_input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape) {
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_viewport, p_input_event, p_shape);
@@ -231,9 +231,9 @@ void CollisionObject2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable);
ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
- ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index e3dc39feae..4d4611afd1 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -70,7 +70,7 @@ protected:
void _update_pickable();
friend class Viewport;
- void _input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape);
+ void _input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);
void _mouse_enter();
void _mouse_exit();
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index 7712108488..f503a66208 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -148,11 +148,6 @@ void TouchScreenButton::_notification(int p_what) {
if (!get_tree()->is_editor_hint())
set_process_input(is_visible_in_tree());
- if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
- action_id = InputMap::get_singleton()->get_action_id(action);
- } else {
- action_id = -1;
- }
} break;
case NOTIFICATION_EXIT_TREE: {
if (is_pressed())
@@ -184,11 +179,6 @@ bool TouchScreenButton::is_pressed() const {
void TouchScreenButton::set_action(const String &p_action) {
action = p_action;
- if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
- action_id = InputMap::get_singleton()->get_action_id(action);
- } else {
- action_id = -1;
- }
}
String TouchScreenButton::get_action() const {
@@ -196,26 +186,32 @@ String TouchScreenButton::get_action() const {
return action;
}
-void TouchScreenButton::_input(const InputEvent &p_event) {
+void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
if (!get_tree())
return;
- if (p_event.device != 0)
+ if (p_event->get_device() != 0)
return;
if (passby_press) {
- if (p_event.type == InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed == p_event.screen_touch.index) {
+ Ref<InputEventScreenTouch> st = p_event;
+ Ref<InputEventScreenTouch> sd = p_event;
+
+ if (st.is_valid() && !st->is_pressed() && finger_pressed == st->get_index()) {
_release();
}
- if ((p_event.type == InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed) || p_event.type == InputEvent::SCREEN_DRAG) {
+ if ((st.is_valid() && st->is_pressed()) || sd.is_valid()) {
+
+ int index = st.is_valid() ? st->get_index() : sd->get_index();
+ Vector2 coord = st.is_valid() ? st->get_pos() : sd->get_pos();
- if (finger_pressed == -1 || p_event.screen_touch.index == finger_pressed) {
+ if (finger_pressed == -1 || index == finger_pressed) {
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
+ coord = (get_global_transform_with_canvas()).affine_inverse().xform(coord);
bool touched = false;
if (bitmask.is_valid()) {
@@ -233,7 +229,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
if (touched) {
if (finger_pressed == -1) {
- _press(p_event.screen_touch.index);
+ _press(index);
}
} else {
if (finger_pressed != -1) {
@@ -245,9 +241,11 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
} else {
- if (p_event.type == InputEvent::SCREEN_TOUCH) {
+ Ref<InputEventScreenTouch> st = p_event;
- if (p_event.screen_touch.pressed) {
+ if (st.is_valid()) {
+
+ if (st->is_pressed()) {
if (!is_visible_in_tree())
return;
@@ -256,7 +254,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
if (!can_press)
return; //already fingering
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
+ Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(st->get_pos());
Rect2 item_rect = get_item_rect();
bool touched = false;
@@ -284,10 +282,10 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
}
if (touched) {
- _press(p_event.screen_touch.index);
+ _press(st->get_index());
}
} else {
- if (p_event.screen_touch.index == finger_pressed) {
+ if (st->get_index() == finger_pressed) {
_release();
}
}
@@ -299,15 +297,14 @@ void TouchScreenButton::_press(int p_finger_pressed) {
finger_pressed = p_finger_pressed;
- if (action_id != -1) {
+ if (action != StringName()) {
Input::get_singleton()->action_press(action);
- InputEvent ie;
- ie.type = InputEvent::ACTION;
- ie.ID = 0;
- ie.action.action = action_id;
- ie.action.pressed = true;
- get_tree()->input_event(ie);
+ Ref<InputEventAction> iea;
+ iea.instance();
+ iea->set_action(action);
+ iea->set_pressed(true);
+ get_tree()->input_event(iea);
}
emit_signal("pressed");
@@ -318,16 +315,16 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
finger_pressed = -1;
- if (action_id != -1) {
+ if (action != StringName()) {
Input::get_singleton()->action_release(action);
if (!p_exiting_tree) {
- InputEvent ie;
- ie.type = InputEvent::ACTION;
- ie.ID = 0;
- ie.action.action = action_id;
- ie.action.pressed = false;
- get_tree()->input_event(ie);
+
+ Ref<InputEventAction> iea;
+ iea.instance();
+ iea->set_action(action);
+ iea->set_pressed(false);
+ get_tree()->input_event(iea);
}
}
@@ -419,7 +416,6 @@ void TouchScreenButton::_bind_methods() {
TouchScreenButton::TouchScreenButton() {
finger_pressed = -1;
- action_id = -1;
passby_press = false;
visibility = VISIBILITY_ALWAYS;
shape_centered = true;
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index 0cfaf681dd..e44f556c31 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -58,11 +58,10 @@ private:
StringName action;
bool passby_press;
int finger_pressed;
- int action_id;
VisibilityMode visibility;
- void _input(const InputEvent &p_Event);
+ void _input(const Ref<InputEvent> &p_Event);
void _press(int p_finger_pressed);
void _release(bool p_exiting_tree = false);
diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp
index 4dc01975b8..1b27313d3b 100644
--- a/scene/3d/collision_object.cpp
+++ b/scene/3d/collision_object.cpp
@@ -172,7 +172,7 @@ void CollisionObject::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
-void CollisionObject::_input_event(Node *p_camera, const InputEvent &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) {
+void CollisionObject::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) {
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape);
@@ -235,9 +235,9 @@ void CollisionObject::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject::set_capture_input_on_drag);
ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject::get_capture_input_on_drag);
ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject::get_rid);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
- ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::VECTOR3, "click_pos"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object.h
index abe0b804bf..3822fb0d5a 100644
--- a/scene/3d/collision_object.h
+++ b/scene/3d/collision_object.h
@@ -70,7 +70,7 @@ protected:
void _get_property_list(List<PropertyInfo> *p_list) const;
static void _bind_methods();
friend class Viewport;
- virtual void _input_event(Node *p_camera, const InputEvent &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
+ virtual void _input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape);
virtual void _mouse_enter();
virtual void _mouse_exit();
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 839dcc3678..318db8458b 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -48,188 +48,185 @@ void BaseButton::_unpress_group() {
}
}
-void BaseButton::_gui_input(InputEvent p_event) {
+void BaseButton::_gui_input(Ref<InputEvent> p_event) {
if (status.disabled) // no interaction with disabled button
return;
- switch (p_event.type) {
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (b.is_valid()) {
+ if (status.disabled || b->get_button_index() != 1)
+ return;
- const InputEventMouseButton &b = p_event.mouse_button;
+ if (status.pressing_button)
+ return;
- if (status.disabled || b.button_index != 1)
- return;
+ if (action_mode == ACTION_MODE_BUTTON_PRESS) {
- if (status.pressing_button)
- break;
+ if (b->is_pressed()) {
- if (action_mode == ACTION_MODE_BUTTON_PRESS) {
-
- if (b.pressed) {
-
- emit_signal("button_down");
-
- if (!toggle_mode) { //mouse press attempt
+ emit_signal("button_down");
- status.press_attempt = true;
- status.pressing_inside = true;
+ if (!toggle_mode) { //mouse press attempt
- pressed();
- if (get_script_instance()) {
- Variant::CallError ce;
- get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
- }
+ status.press_attempt = true;
+ status.pressing_inside = true;
- emit_signal("pressed");
- _unpress_group();
+ pressed();
+ if (get_script_instance()) {
+ Variant::CallError ce;
+ get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
+ }
- } else {
+ emit_signal("pressed");
+ _unpress_group();
- status.pressed = !status.pressed;
- pressed();
- if (get_script_instance()) {
- Variant::CallError ce;
- get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
- }
- emit_signal("pressed");
- _unpress_group();
+ } else {
- toggled(status.pressed);
- emit_signal("toggled", status.pressed);
+ status.pressed = !status.pressed;
+ pressed();
+ if (get_script_instance()) {
+ Variant::CallError ce;
+ get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
}
+ emit_signal("pressed");
+ _unpress_group();
- } else {
+ toggled(status.pressed);
+ emit_signal("toggled", status.pressed);
+ }
+
+ } else {
- emit_signal("button_up");
+ emit_signal("button_up");
- /* this is pointless if (status.press_attempt && status.pressing_inside) {
- //released();
- emit_signal("released");
- }
-*/
- status.press_attempt = false;
+ /* this is pointless if (status.press_attempt && status.pressing_inside) {
+ //released();
+ emit_signal("released");
}
- update();
- break;
+*/
+ status.press_attempt = false;
}
+ update();
+ return;
+ }
- if (b.pressed) {
+ if (b->is_pressed()) {
- status.press_attempt = true;
- status.pressing_inside = true;
- emit_signal("button_down");
+ status.press_attempt = true;
+ status.pressing_inside = true;
+ emit_signal("button_down");
- } else {
+ } else {
- emit_signal("button_up");
+ emit_signal("button_up");
- if (status.press_attempt && status.pressing_inside) {
+ if (status.press_attempt && status.pressing_inside) {
- if (!toggle_mode) { //mouse press attempt
+ if (!toggle_mode) { //mouse press attempt
- pressed();
- if (get_script_instance()) {
- Variant::CallError ce;
- get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
- }
+ pressed();
+ if (get_script_instance()) {
+ Variant::CallError ce;
+ get_script_instance()->call(SceneStringNames::get_singleton()->_pressed, NULL, 0, ce);
+ }
- emit_signal("pressed");
+ emit_signal("pressed");
- } else {
+ } else {
- status.pressed = !status.pressed;
+ status.pressed = !status.pressed;
- pressed();
- emit_signal("pressed");
+ pressed();
+ emit_signal("pressed");
- toggled(status.pressed);
- emit_signal("toggled", status.pressed);
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
- }
+ toggled(status.pressed);
+ emit_signal("toggled", status.pressed);
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
}
-
- _unpress_group();
}
- status.press_attempt = false;
+ _unpress_group();
}
- update();
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- if (status.press_attempt && status.pressing_button == 0) {
- bool last_press_inside = status.pressing_inside;
- status.pressing_inside = has_point(Point2(p_event.mouse_motion.x, p_event.mouse_motion.y));
- if (last_press_inside != status.pressing_inside)
- update();
- }
- } break;
- case InputEvent::ACTION:
- case InputEvent::JOYPAD_BUTTON:
- case InputEvent::KEY: {
+ status.press_attempt = false;
+ }
- if (p_event.is_echo()) {
- break;
- }
+ update();
+ }
- if (status.disabled) {
- break;
- }
+ Ref<InputEventMouseMotion> mm = p_event;
- if (status.press_attempt && status.pressing_button == 0) {
- break;
- }
+ if (mm.is_valid()) {
+ if (status.press_attempt && status.pressing_button == 0) {
+ bool last_press_inside = status.pressing_inside;
+ status.pressing_inside = has_point(mm->get_pos());
+ if (last_press_inside != status.pressing_inside)
+ update();
+ }
+ }
- if (p_event.is_action("ui_accept")) {
+ if (!mm.is_valid() && !b.is_valid()) {
- if (p_event.is_pressed()) {
+ if (p_event->is_echo()) {
+ return;
+ }
- status.pressing_button++;
- status.press_attempt = true;
- status.pressing_inside = true;
- emit_signal("button_down");
+ if (status.disabled) {
+ return;
+ }
- } else if (status.press_attempt) {
+ if (status.press_attempt && status.pressing_button == 0) {
+ return;
+ }
- if (status.pressing_button)
- status.pressing_button--;
+ if (p_event->is_action("ui_accept")) {
- if (status.pressing_button)
- break;
+ if (p_event->is_pressed()) {
- status.press_attempt = false;
- status.pressing_inside = false;
+ status.pressing_button++;
+ status.press_attempt = true;
+ status.pressing_inside = true;
+ emit_signal("button_down");
- emit_signal("button_up");
+ } else if (status.press_attempt) {
- if (!toggle_mode) { //mouse press attempt
+ if (status.pressing_button)
+ status.pressing_button--;
- pressed();
- emit_signal("pressed");
- } else {
+ if (status.pressing_button)
+ return;
- status.pressed = !status.pressed;
+ status.press_attempt = false;
+ status.pressing_inside = false;
- pressed();
- emit_signal("pressed");
+ emit_signal("button_up");
- toggled(status.pressed);
- if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
- }
- emit_signal("toggled", status.pressed);
- }
+ if (!toggle_mode) { //mouse press attempt
- _unpress_group();
+ pressed();
+ emit_signal("pressed");
+ } else {
+
+ status.pressed = !status.pressed;
+
+ pressed();
+ emit_signal("pressed");
+
+ toggled(status.pressed);
+ if (get_script_instance()) {
+ get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, status.pressed);
+ }
+ emit_signal("toggled", status.pressed);
}
- accept_event();
- update();
+ _unpress_group();
}
+
+ accept_event();
+ update();
}
}
}
@@ -430,9 +427,9 @@ Ref<ShortCut> BaseButton::get_shortcut() const {
return shortcut;
}
-void BaseButton::_unhandled_input(InputEvent p_event) {
+void BaseButton::_unhandled_input(Ref<InputEvent> p_event) {
- if (!is_disabled() && is_visible_in_tree() && p_event.is_pressed() && !p_event.is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {
+ if (!is_disabled() && is_visible_in_tree() && p_event->is_pressed() && !p_event->is_echo() && shortcut.is_valid() && shortcut->is_shortcut(p_event)) {
if (get_viewport()->get_modal_stack_top() && !get_viewport()->get_modal_stack_top()->is_a_parent_of(this))
return; //ignore because of modal window
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 62b6633bfc..dfcf3b0f8a 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -73,8 +73,8 @@ protected:
virtual void pressed();
virtual void toggled(bool p_pressed);
static void _bind_methods();
- virtual void _gui_input(InputEvent p_event);
- virtual void _unhandled_input(InputEvent p_event);
+ virtual void _gui_input(Ref<InputEvent> p_event);
+ virtual void _unhandled_input(Ref<InputEvent> p_event);
void _notification(int p_what);
public:
diff --git a/scene/gui/button_array.cpp b/scene/gui/button_array.cpp
index eccf3ea64a..0d518059c8 100644
--- a/scene/gui/button_array.cpp
+++ b/scene/gui/button_array.cpp
@@ -287,12 +287,12 @@ void ButtonArray::_notification(int p_what) {
}
}
-void ButtonArray::_gui_input(const InputEvent &p_event) {
+void ButtonArray::_gui_input(const Ref<InputEvent> &p_event) {
if (
- ((orientation == HORIZONTAL && p_event.is_action("ui_left")) ||
- (orientation == VERTICAL && p_event.is_action("ui_up"))) &&
- p_event.is_pressed() && selected > 0) {
+ ((orientation == HORIZONTAL && p_event->is_action("ui_left")) ||
+ (orientation == VERTICAL && p_event->is_action("ui_up"))) &&
+ p_event->is_pressed() && selected > 0) {
set_selected(selected - 1);
accept_event();
emit_signal("button_selected", selected);
@@ -300,18 +300,20 @@ void ButtonArray::_gui_input(const InputEvent &p_event) {
}
if (
- ((orientation == HORIZONTAL && p_event.is_action("ui_right")) ||
- (orientation == VERTICAL && p_event.is_action("ui_down"))) &&
- p_event.is_pressed() && selected < (buttons.size() - 1)) {
+ ((orientation == HORIZONTAL && p_event->is_action("ui_right")) ||
+ (orientation == VERTICAL && p_event->is_action("ui_down"))) &&
+ p_event->is_pressed() && selected < (buttons.size() - 1)) {
set_selected(selected + 1);
accept_event();
emit_signal("button_selected", selected);
return;
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
- int ofs = orientation == HORIZONTAL ? p_event.mouse_button.x : p_event.mouse_button.y;
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ int ofs = orientation == HORIZONTAL ? mb->get_pos().x : mb->get_pos().y;
for (int i = 0; i < buttons.size(); i++) {
@@ -324,9 +326,11 @@ void ButtonArray::_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
- int ofs = orientation == HORIZONTAL ? p_event.mouse_motion.x : p_event.mouse_motion.y;
+ int ofs = orientation == HORIZONTAL ? mm->get_pos().x : mm->get_pos().y;
int new_hover = -1;
for (int i = 0; i < buttons.size(); i++) {
diff --git a/scene/gui/button_array.h b/scene/gui/button_array.h
index f2f7bea9c6..0ebf681cb6 100644
--- a/scene/gui/button_array.h
+++ b/scene/gui/button_array.h
@@ -76,7 +76,7 @@ protected:
static void _bind_methods();
public:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void set_align(Align p_align);
Align get_align() const;
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 264ee6297e..67d440ca67 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -297,13 +297,15 @@ void ColorPicker::_hsv_draw(int p_wich, Control *c) {
}
}
-void ColorPicker::_uv_input(const InputEvent &ev) {
- if (ev.type == InputEvent::MOUSE_BUTTON) {
- const InputEventMouseButton &bev = ev.mouse_button;
- if (bev.pressed && bev.button_index == BUTTON_LEFT) {
+void ColorPicker::_uv_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> bev = ev;
+
+ if (bev.is_valid()) {
+ if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
changing_color = true;
- float x = CLAMP((float)bev.x, 0, 256);
- float y = CLAMP((float)bev.y, 0, 256);
+ float x = CLAMP((float)bev->get_pos().x, 0, 256);
+ float y = CLAMP((float)bev->get_pos().y, 0, 256);
s = x / 256;
v = 1.0 - y / 256.0;
color.set_hsv(h, s, v, color.a);
@@ -314,12 +316,15 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
} else {
changing_color = false;
}
- } else if (ev.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouse &bev = ev.mouse_motion;
+ }
+
+ Ref<InputEventMouseMotion> mev = ev;
+
+ if (mev.is_valid()) {
if (!changing_color)
return;
- float x = CLAMP((float)bev.x, 0, 256);
- float y = CLAMP((float)bev.y, 0, 256);
+ float x = CLAMP((float)mev->get_pos().x, 0, 256);
+ float y = CLAMP((float)mev->get_pos().y, 0, 256);
s = x / 256;
v = 1.0 - y / 256.0;
color.set_hsv(h, s, v, color.a);
@@ -330,12 +335,15 @@ void ColorPicker::_uv_input(const InputEvent &ev) {
}
}
-void ColorPicker::_w_input(const InputEvent &ev) {
- if (ev.type == InputEvent::MOUSE_BUTTON) {
- const InputEventMouseButton &bev = ev.mouse_button;
- if (bev.pressed && bev.button_index == BUTTON_LEFT) {
+void ColorPicker::_w_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> bev = ev;
+
+ if (bev.is_valid()) {
+
+ if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
changing_color = true;
- h = 1 - ((float)bev.y) / 256.0;
+ h = 1 - ((float)bev->get_pos().y) / 256.0;
} else {
changing_color = false;
@@ -345,11 +353,15 @@ void ColorPicker::_w_input(const InputEvent &ev) {
set_pick_color(color);
_update_color();
emit_signal("color_changed", color);
- } else if (ev.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouse &bev = ev.mouse_motion;
+ }
+
+ Ref<InputEventMouseMotion> mev = ev;
+
+ if (mev.is_valid()) {
+
if (!changing_color)
return;
- float y = CLAMP((float)bev.y, 0, 256);
+ float y = CLAMP((float)bev->get_pos().y, 0, 256);
h = 1.0 - y / 256.0;
color.set_hsv(h, s, v, color.a);
last_hsv = color;
@@ -359,23 +371,30 @@ void ColorPicker::_w_input(const InputEvent &ev) {
}
}
-void ColorPicker::_preset_input(const InputEvent &ev) {
- if (ev.type == InputEvent::MOUSE_BUTTON) {
- const InputEventMouseButton &bev = ev.mouse_button;
- if (bev.pressed && bev.button_index == BUTTON_LEFT) {
- int index = bev.x / (preset->get_size().x / presets.size());
+void ColorPicker::_preset_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> bev = ev;
+
+ if (bev.is_valid()) {
+
+ if (bev->is_pressed() && bev->get_button_index() == BUTTON_LEFT) {
+ int index = bev->get_pos().x / (preset->get_size().x / presets.size());
set_pick_color(presets[index]);
- } else if (bev.pressed && bev.button_index == BUTTON_RIGHT) {
- int index = bev.x / (preset->get_size().x / presets.size());
+ } else if (bev->is_pressed() && bev->get_button_index() == BUTTON_RIGHT) {
+ int index = bev->get_pos().x / (preset->get_size().x / presets.size());
presets.erase(presets[index]);
_update_presets();
bt_add_preset->show();
}
_update_color();
emit_signal("color_changed", color);
- } else if (ev.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouse &mev = ev.mouse_motion;
- int index = mev.x * presets.size();
+ }
+
+ Ref<InputEventMouseMotion> mev = ev;
+
+ if (mev.is_valid()) {
+
+ int index = mev->get_pos().x * presets.size();
if (preset->get_size().x != 0) {
index /= preset->get_size().x;
}
@@ -387,17 +406,23 @@ void ColorPicker::_preset_input(const InputEvent &ev) {
}
}
-void ColorPicker::_screen_input(const InputEvent &ev) {
- if (ev.type == InputEvent::MOUSE_BUTTON) {
- const InputEventMouseButton &bev = ev.mouse_button;
- if (bev.button_index == BUTTON_LEFT && !bev.pressed) {
+void ColorPicker::_screen_input(const Ref<InputEvent> &ev) {
+
+ Ref<InputEventMouseButton> bev = ev;
+
+ if (bev.is_valid()) {
+
+ if (bev->get_button_index() == BUTTON_LEFT && !bev->is_pressed()) {
emit_signal("color_changed", color);
screen->hide();
}
- } else if (ev.type == InputEvent::MOUSE_MOTION) {
- const InputEventMouse &mev = ev.mouse_motion;
+ }
+
+ Ref<InputEventMouseMotion> mev = ev;
+
+ if (mev.is_valid()) {
Viewport *r = get_tree()->get_root();
- if (!r->get_visible_rect().has_point(Point2(mev.global_x, mev.global_y)))
+ if (!r->get_visible_rect().has_point(Point2(mev->get_global_pos().x, mev->get_global_pos().y)))
return;
Ref<Image> img = r->get_screen_capture();
if (!img.is_null()) {
@@ -406,7 +431,7 @@ void ColorPicker::_screen_input(const InputEvent &ev) {
}
if (last_capture.is_valid() && !last_capture->empty()) {
int pw = last_capture->get_format() == Image::FORMAT_RGBA8 ? 4 : 3;
- int ofs = (mev.global_y * last_capture->get_width() + mev.global_x) * pw;
+ int ofs = (mev->get_global_pos().y * last_capture->get_width() + mev->get_global_pos().x) * pw;
PoolVector<uint8_t>::Read r = last_capture->get_data().read();
diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h
index 437a491b54..ca47c3a5f4 100644
--- a/scene/gui/color_picker.h
+++ b/scene/gui/color_picker.h
@@ -82,10 +82,10 @@ private:
void _sample_draw();
void _hsv_draw(int p_wich, Control *c);
- void _uv_input(const InputEvent &p_input);
- void _w_input(const InputEvent &p_input);
- void _preset_input(const InputEvent &p_input);
- void _screen_input(const InputEvent &p_input);
+ void _uv_input(const Ref<InputEvent> &p_input);
+ void _w_input(const Ref<InputEvent> &p_input);
+ void _preset_input(const Ref<InputEvent> &p_input);
+ void _screen_input(const Ref<InputEvent> &p_input);
void _add_preset_pressed();
void _screen_pick_pressed();
diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp
index a0fd2dd33c..9270b97e02 100644
--- a/scene/gui/color_ramp_edit.cpp
+++ b/scene/gui/color_ramp_edit.cpp
@@ -71,9 +71,11 @@ void ColorRampEdit::_show_color_picker() {
ColorRampEdit::~ColorRampEdit() {
}
-void ColorRampEdit::_gui_input(const InputEvent &p_event) {
+void ColorRampEdit::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && p_event.key.pressed && p_event.key.scancode == KEY_DELETE && grabbed != -1) {
+ Ref<InputEventKey> k = p_event;
+
+ if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -83,16 +85,17 @@ void ColorRampEdit::_gui_input(const InputEvent &p_event) {
accept_event();
}
+ Ref<InputEventMouseButton> mb = p_event;
//Show color picker on double click.
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.doubleclick && p_event.mouse_button.pressed) {
- grabbed = _get_point_from_pos(p_event.mouse_button.x);
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_doubleclick() && mb->is_pressed()) {
+ grabbed = _get_point_from_pos(mb->get_pos().x);
_show_color_picker();
accept_event();
}
//Delete point on right click
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 2 && p_event.mouse_button.pressed) {
- grabbed = _get_point_from_pos(p_event.mouse_button.x);
+ if (mb.is_valid() && mb->get_button_index() == 2 && mb->is_pressed()) {
+ grabbed = _get_point_from_pos(mb->get_pos().x);
if (grabbed != -1) {
points.remove(grabbed);
grabbed = -1;
@@ -104,9 +107,9 @@ void ColorRampEdit::_gui_input(const InputEvent &p_event) {
}
//Hold alt key to duplicate selected color
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed && p_event.key.mod.alt) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed() && mb->get_alt()) {
- int x = p_event.mouse_button.x;
+ int x = mb->get_pos().x;
grabbed = _get_point_from_pos(x);
if (grabbed != -1) {
@@ -128,10 +131,10 @@ void ColorRampEdit::_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
update();
- int x = p_event.mouse_button.x;
+ int x = mb->get_pos().x;
int total_w = get_size().width - get_size().height - 3;
//Check if color selector was clicked.
@@ -196,7 +199,7 @@ void ColorRampEdit::_gui_input(const InputEvent &p_event) {
emit_signal("ramp_changed");
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == 1 && !p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
if (grabbing) {
grabbing = false;
@@ -205,15 +208,18 @@ void ColorRampEdit::_gui_input(const InputEvent &p_event) {
update();
}
- if (p_event.type == InputEvent::MOUSE_MOTION && grabbing) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid() && grabbing) {
int total_w = get_size().width - get_size().height - 3;
- int x = p_event.mouse_motion.x;
+ int x = mm->get_pos().x;
+
float newofs = CLAMP(x / float(total_w), 0, 1);
//Snap to nearest point if holding shift
- if (p_event.key.mod.shift) {
+ if (mm->get_shift()) {
float snap_treshhold = 0.03;
float smallest_ofs = snap_treshhold;
bool founded = false;
diff --git a/scene/gui/color_ramp_edit.h b/scene/gui/color_ramp_edit.h
index 38176d2e77..ede8954040 100644
--- a/scene/gui/color_ramp_edit.h
+++ b/scene/gui/color_ramp_edit.h
@@ -56,7 +56,7 @@ class ColorRampEdit : public Control {
void _show_color_picker();
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index e62a993651..1263dc91be 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2419,7 +2419,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("_font_changed"), &Control::_font_changed);
- BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::INPUT_EVENT, "event")));
+ BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
BIND_VMETHOD(MethodInfo(Variant::OBJECT, "get_drag_data", PropertyInfo(Variant::VECTOR2, "pos")));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "pos"), PropertyInfo(Variant::NIL, "data")));
@@ -2507,7 +2507,7 @@ void Control::_bind_methods() {
BIND_CONSTANT(MOUSE_FILTER_IGNORE);
ADD_SIGNAL(MethodInfo("resized"));
- ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::INPUT_EVENT, "ev")));
+ ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
ADD_SIGNAL(MethodInfo("focus_entered"));
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 053be515ac..627bc96fb1 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -105,29 +105,33 @@ bool WindowDialog::has_point(const Point2 &p_point) const {
return r.has_point(p_point);
}
-void WindowDialog::_gui_input(const InputEvent &p_event) {
+void WindowDialog::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
- if (p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) {
+
+ if (mb->is_pressed()) {
// Begin a possible dragging operation.
- drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y));
+ drag_type = _drag_hit_test(Point2(mb->get_pos().x, mb->get_pos().y));
if (drag_type != DRAG_NONE)
drag_offset = get_global_mouse_position() - get_position();
drag_offset_far = get_position() + get_size() - get_global_mouse_position();
- } else if (drag_type != DRAG_NONE && !p_event.mouse_button.pressed) {
+ } else if (drag_type != DRAG_NONE && !mb->is_pressed()) {
// End a dragging operation.
drag_type = DRAG_NONE;
}
}
- if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid()) {
if (drag_type == DRAG_NONE) {
// Update the cursor while moving along the borders.
CursorShape cursor = CURSOR_ARROW;
if (resizable) {
- int preview_drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y));
+ int preview_drag_type = _drag_hit_test(Point2(mm->get_pos().x, mm->get_pos().y));
switch (preview_drag_type) {
case DRAG_RESIZE_TOP:
case DRAG_RESIZE_BOTTOM:
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index 2365df3d79..9d8f113caa 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -60,7 +60,7 @@ class WindowDialog : public Popup {
Point2 drag_offset_far;
bool resizable;
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _closed();
int _drag_hit_test(const Point2 &pos) const;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 391b39443d..3527b834c7 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -61,21 +61,20 @@ void FileDialog::_notification(int p_what) {
}
}
-void FileDialog::_unhandled_input(const InputEvent &p_event) {
+void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::KEY && is_window_modal_on_top()) {
+ Ref<InputEventKey> k = p_event;
+ if (k.is_valid() && is_window_modal_on_top()) {
- const InputEventKey &k = p_event.key;
-
- if (k.pressed) {
+ if (k->is_pressed()) {
bool handled = true;
- switch (k.scancode) {
+ switch (k->get_scancode()) {
case KEY_H: {
- if (k.mod.command) {
+ if (k->get_command()) {
set_show_hidden_files(!show_hidden_files);
} else {
handled = false;
diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h
index 2afd0227c6..9873a677b2 100644
--- a/scene/gui/file_dialog.h
+++ b/scene/gui/file_dialog.h
@@ -115,7 +115,7 @@ private:
void _update_drives();
- void _unhandled_input(const InputEvent &p_event);
+ void _unhandled_input(const Ref<InputEvent> &p_event);
virtual void _post_popup();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index cfa09f538d..c52cdd9325 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -367,13 +367,14 @@ bool GraphEdit::_filter_input(const Point2 &p_point) {
return false;
}
-void GraphEdit::_top_layer_input(const InputEvent &p_ev) {
+void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) {
float grab_r_extend = 2.0;
- if (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index == BUTTON_LEFT && p_ev.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_ev;
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) {
Ref<Texture> port = get_icon("port", "GraphNode");
- Vector2 mpos(p_ev.mouse_button.x, p_ev.mouse_button.y);
+ Vector2 mpos(mb->get_pos().x, mb->get_pos().y);
float grab_r = port->get_width() * 0.5 * grab_r_extend;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -479,14 +480,15 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) {
}
}
- if (p_ev.type == InputEvent::MOUSE_MOTION && connecting) {
+ Ref<InputEventMouseMotion> mm = p_ev;
+ if (mm.is_valid() && connecting) {
- connecting_to = Vector2(p_ev.mouse_motion.x, p_ev.mouse_motion.y);
+ connecting_to = mm->get_pos();
connecting_target = false;
top_layer->update();
Ref<Texture> port = get_icon("port", "GraphNode");
- Vector2 mpos(p_ev.mouse_button.x, p_ev.mouse_button.y);
+ Vector2 mpos = mm->get_pos();
float grab_r = port->get_width() * 0.5 * grab_r_extend;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -526,7 +528,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) {
}
}
- if (p_ev.type == InputEvent::MOUSE_BUTTON && p_ev.mouse_button.button_index == BUTTON_LEFT && !p_ev.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
if (connecting && connecting_target) {
@@ -544,7 +546,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) {
} else if (!just_disconected) {
String from = connecting_from;
int from_slot = connecting_index;
- Vector2 ofs = Vector2(p_ev.mouse_button.x, p_ev.mouse_button.y);
+ Vector2 ofs = Vector2(mb->get_pos().x, mb->get_pos().y);
emit_signal("connection_to_empty", from, from_slot, ofs);
}
connecting = false;
@@ -739,18 +741,19 @@ void GraphEdit::set_selected(Node *p_child) {
}
}
-void GraphEdit::_gui_input(const InputEvent &p_ev) {
+void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
- if (p_ev.type == InputEvent::MOUSE_MOTION && (p_ev.mouse_motion.button_mask & BUTTON_MASK_MIDDLE || (p_ev.mouse_motion.button_mask & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
- h_scroll->set_value(h_scroll->get_value() - p_ev.mouse_motion.relative_x);
- v_scroll->set_value(v_scroll->get_value() - p_ev.mouse_motion.relative_y);
+ Ref<InputEventMouseMotion> mm = p_ev;
+ if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
+ h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
+ v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
}
- if (p_ev.type == InputEvent::MOUSE_MOTION && dragging) {
+ if (mm.is_valid() && dragging) {
just_selected = true;
// TODO: Remove local mouse pos hack if/when InputEventMouseMotion is fixed to support floats
- //drag_accum+=Vector2(p_ev.mouse_motion.relative_x,p_ev.mouse_motion.relative_y);
+ //drag_accum+=Vector2(mm->get_relative().x,mm->get_relative().y);
drag_accum = get_local_mouse_pos() - drag_origin;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = get_child(i)->cast_to<GraphNode>();
@@ -767,7 +770,7 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
}
}
- if (p_ev.type == InputEvent::MOUSE_MOTION && box_selecting) {
+ if (mm.is_valid() && box_selecting) {
box_selecting_to = get_local_mouse_pos();
box_selecting_rect = Rect2(MIN(box_selecting_from.x, box_selecting_to.x),
@@ -794,11 +797,10 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
top_layer->update();
}
- if (p_ev.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> b = p_ev;
+ if (b.is_valid()) {
- const InputEventMouseButton &b = p_ev.mouse_button;
-
- if (b.button_index == BUTTON_RIGHT && b.pressed) {
+ if (b->get_button_index() == BUTTON_RIGHT && b->is_pressed()) {
if (box_selecting) {
box_selecting = false;
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -815,12 +817,12 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
connecting = false;
top_layer->update();
} else {
- emit_signal("popup_request", Vector2(b.global_x, b.global_y));
+ emit_signal("popup_request", b->get_global_pos());
}
}
}
- if (b.button_index == BUTTON_LEFT && !b.pressed && dragging) {
+ if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && dragging) {
if (!just_selected && drag_accum == Vector2() && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) {
//deselect current node
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -855,7 +857,7 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
connections_layer->update();
}
- if (b.button_index == BUTTON_LEFT && b.pressed) {
+ if (b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
GraphNode *gn = NULL;
GraphNode *gn_selected = NULL;
@@ -878,7 +880,7 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
if (gn) {
- if (_filter_input(Vector2(b.x, b.y)))
+ if (_filter_input(b->get_pos()))
return;
dragging = true;
@@ -903,14 +905,14 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
}
} else {
- if (_filter_input(Vector2(b.x, b.y)))
+ if (_filter_input(b->get_pos()))
return;
if (Input::get_singleton()->is_key_pressed(KEY_SPACE))
return;
box_selecting = true;
box_selecting_from = get_local_mouse_pos();
- if (b.mod.control) {
+ if (b->get_control()) {
box_selection_mode_aditive = true;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -921,7 +923,7 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
previus_selected.push_back(gn);
}
- } else if (b.mod.shift) {
+ } else if (b->get_shift()) {
box_selection_mode_aditive = false;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
@@ -947,41 +949,42 @@ void GraphEdit::_gui_input(const InputEvent &p_ev) {
}
}
- if (b.button_index == BUTTON_LEFT && !b.pressed && box_selecting) {
+ if (b->get_button_index() == BUTTON_LEFT && !b->is_pressed() && box_selecting) {
box_selecting = false;
previus_selected.clear();
top_layer->update();
}
- if (b.button_index == BUTTON_WHEEL_UP && b.pressed) {
+ if (b->get_button_index() == BUTTON_WHEEL_UP && b->is_pressed()) {
//too difficult to get right
//set_zoom(zoom*ZOOM_SCALE);
}
- if (b.button_index == BUTTON_WHEEL_DOWN && b.pressed) {
+ if (b->get_button_index() == BUTTON_WHEEL_DOWN && b->is_pressed()) {
//too difficult to get right
//set_zoom(zoom/ZOOM_SCALE);
}
- if (b.button_index == BUTTON_WHEEL_UP) {
- h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b.factor / 8);
+ if (b->get_button_index() == BUTTON_WHEEL_UP) {
+ h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8);
}
- if (b.button_index == BUTTON_WHEEL_DOWN) {
- h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b.factor / 8);
+ if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8);
}
- if (b.button_index == BUTTON_WHEEL_RIGHT) {
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b.factor / 8);
+ if (b->get_button_index() == BUTTON_WHEEL_RIGHT) {
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
}
- if (b.button_index == BUTTON_WHEEL_LEFT) {
- v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b.factor / 8);
+ if (b->get_button_index() == BUTTON_WHEEL_LEFT) {
+ v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
}
}
- if (p_ev.type == InputEvent::KEY && p_ev.key.scancode == KEY_D && p_ev.key.pressed && p_ev.key.mod.command) {
+ Ref<InputEventKey> k = p_ev;
+ if (k.is_valid() && k->get_scancode() == KEY_D && k->is_pressed() && k->get_command()) {
emit_signal("duplicate_nodes_request");
accept_event();
}
- if (p_ev.type == InputEvent::KEY && p_ev.key.scancode == KEY_DELETE && p_ev.key.pressed) {
+ if (k.is_valid() && k->get_scancode() == KEY_DELETE && k->is_pressed()) {
emit_signal("delete_nodes_request");
accept_event();
}
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index ff3867a059..22d053d312 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -119,11 +119,11 @@ private:
void _update_scroll();
void _scroll_moved(double);
- void _gui_input(const InputEvent &p_ev);
+ void _gui_input(const Ref<InputEvent> &p_ev);
Control *connections_layer;
GraphEditFilter *top_layer;
- void _top_layer_input(const InputEvent &p_ev);
+ void _top_layer_input(const Ref<InputEvent> &p_ev);
void _top_layer_draw();
void _connections_layer_draw();
void _update_scroll_offset();
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index f7bb866f6f..fb0ff4f320 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -574,18 +574,19 @@ Color GraphNode::get_connection_output_color(int p_idx) {
return conn_output_cache[p_idx].color;
}
-void GraphNode::_gui_input(const InputEvent &p_ev) {
+void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
- if (p_ev.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_ev;
+ if (mb.is_valid()) {
ERR_EXPLAIN("GraphNode must be the child of a GraphEdit node.");
ERR_FAIL_COND(get_parent_control() == NULL);
print_line("INPUT EVENT BUTTON");
- if (p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
+ if (mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
- Vector2 mpos = Vector2(p_ev.mouse_button.x, p_ev.mouse_button.y);
+ Vector2 mpos = Vector2(mb->get_pos().x, mb->get_pos().y);
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
emit_signal("close_request");
accept_event();
@@ -608,13 +609,14 @@ void GraphNode::_gui_input(const InputEvent &p_ev) {
get_parent_control()->grab_focus();
}
- if (!p_ev.mouse_button.pressed && p_ev.mouse_button.button_index == BUTTON_LEFT) {
+ if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
resizing = false;
}
}
- if (resizing && p_ev.type == InputEvent::MOUSE_MOTION) {
- Vector2 mpos = Vector2(p_ev.mouse_motion.x, p_ev.mouse_motion.y);
+ Ref<InputEventMouseMotion> mm = p_ev;
+ if (resizing && mm.is_valid()) {
+ Vector2 mpos = mm->get_pos();
Vector2 diff = mpos - resizing_from;
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
index e98d0b3d07..056b699aa6 100644
--- a/scene/gui/graph_node.h
+++ b/scene/gui/graph_node.h
@@ -102,7 +102,7 @@ private:
bool has_point(const Point2 &p_point) const;
protected:
- void _gui_input(const InputEvent &p_ev);
+ void _gui_input(const Ref<InputEvent> &p_ev);
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/input_action.cpp b/scene/gui/input_action.cpp
index 5b03338286..311cb4ab13 100644
--- a/scene/gui/input_action.cpp
+++ b/scene/gui/input_action.cpp
@@ -30,95 +30,73 @@
#include "input_action.h"
#include "os/keyboard.h"
-void ShortCut::set_shortcut(const InputEvent &p_shortcut) {
+void ShortCut::set_shortcut(const Ref<InputEvent> &p_shortcut) {
shortcut = p_shortcut;
emit_changed();
}
-InputEvent ShortCut::get_shortcut() const {
+Ref<InputEvent> ShortCut::get_shortcut() const {
return shortcut;
}
-bool ShortCut::is_shortcut(const InputEvent &p_event) const {
+bool ShortCut::is_shortcut(const Ref<InputEvent> &p_event) const {
- bool same = false;
-
- switch (p_event.type) {
-
- case InputEvent::KEY: {
-
- same = (shortcut.key.scancode == p_event.key.scancode && shortcut.key.mod == p_event.key.mod);
-
- } break;
- case InputEvent::JOYPAD_BUTTON: {
-
- same = (shortcut.joy_button.button_index == p_event.joy_button.button_index);
-
- } break;
- case InputEvent::MOUSE_BUTTON: {
-
- same = (shortcut.mouse_button.button_index == p_event.mouse_button.button_index);
-
- } break;
- case InputEvent::JOYPAD_MOTION: {
-
- same = (shortcut.joy_motion.axis == p_event.joy_motion.axis && (shortcut.joy_motion.axis_value < 0) == (p_event.joy_motion.axis_value < 0));
-
- } break;
- default: {};
- }
-
- return same;
+ return shortcut.is_valid() && shortcut->action_match(p_event);
}
String ShortCut::get_as_text() const {
+ if (shortcut.is_valid())
+ return shortcut->as_text();
+ else
+ return "None";
+#if 0
switch (shortcut.type) {
- case InputEvent::NONE: {
+ case Ref<InputEvent>::NONE: {
return "None";
} break;
- case InputEvent::KEY: {
+ case Ref<InputEvent>::KEY: {
String str;
- if (shortcut.key.mod.shift)
+ if (shortcut->get_shift())
str += RTR("Shift+");
- if (shortcut.key.mod.alt)
+ if (shortcut->get_alt())
str += RTR("Alt+");
- if (shortcut.key.mod.control)
+ if (shortcut->get_control())
str += RTR("Ctrl+");
- if (shortcut.key.mod.meta)
+ if (shortcut->get_metakey())
str += RTR("Meta+");
- str += keycode_get_string(shortcut.key.scancode).capitalize();
+ str += keycode_get_string(shortcut->get_scancode()).capitalize();
return str;
} break;
- case InputEvent::JOYPAD_BUTTON: {
+ case Ref<InputEvent>::JOYPAD_BUTTON: {
- String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Button") + " " + itos(shortcut.joy_button.button_index);
+ String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Button") + " " + itos(shortcut.joy_button->get_button_index());
str += ".";
return str;
} break;
- case InputEvent::MOUSE_BUTTON: {
+ case Ref<InputEvent>::MOUSE_BUTTON: {
String str = RTR("Device") + " " + itos(shortcut.device) + ", ";
- switch (shortcut.mouse_button.button_index) {
+ switch (shortcut->get_button_index()) {
case BUTTON_LEFT: str += RTR("Left Button."); break;
case BUTTON_RIGHT: str += RTR("Right Button."); break;
case BUTTON_MIDDLE: str += RTR("Middle Button."); break;
case BUTTON_WHEEL_UP: str += RTR("Wheel Up."); break;
case BUTTON_WHEEL_DOWN: str += RTR("Wheel Down."); break;
- default: str += RTR("Button") + " " + itos(shortcut.mouse_button.button_index) + ".";
+ default: str += RTR("Button") + " " + itos(shortcut->get_button_index()) + ".";
}
return str;
} break;
- case InputEvent::JOYPAD_MOTION: {
+ case Ref<InputEvent>::JOYPAD_MOTION: {
int ax = shortcut.joy_motion.axis;
String str = RTR("Device") + " " + itos(shortcut.device) + ", " + RTR("Axis") + " " + itos(ax) + ".";
@@ -128,24 +106,25 @@ String ShortCut::get_as_text() const {
}
return "";
+#endif
}
bool ShortCut::is_valid() const {
- return shortcut.type != InputEvent::NONE;
+ return shortcut.is_valid();
}
void ShortCut::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_shortcut", "event"), &ShortCut::set_shortcut);
- ClassDB::bind_method(D_METHOD("get_shortcut"), &ShortCut::get_shortcut);
+ ClassDB::bind_method(D_METHOD("set_shortcut", "event:InputEvent"), &ShortCut::set_shortcut);
+ ClassDB::bind_method(D_METHOD("get_shortcut:InputEvent"), &ShortCut::get_shortcut);
ClassDB::bind_method(D_METHOD("is_valid"), &ShortCut::is_valid);
- ClassDB::bind_method(D_METHOD("is_shortcut", "event"), &ShortCut::is_shortcut);
+ ClassDB::bind_method(D_METHOD("is_shortcut", "event:InputEvent"), &ShortCut::is_shortcut);
ClassDB::bind_method(D_METHOD("get_as_text"), &ShortCut::get_as_text);
- ADD_PROPERTY(PropertyInfo(Variant::INPUT_EVENT, "shortcut"), "set_shortcut", "get_shortcut");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shortcut", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), "set_shortcut", "get_shortcut");
}
ShortCut::ShortCut() {
diff --git a/scene/gui/input_action.h b/scene/gui/input_action.h
index c33490ae1d..6d13d8bd40 100644
--- a/scene/gui/input_action.h
+++ b/scene/gui/input_action.h
@@ -30,21 +30,22 @@
#ifndef INPUTACTION_H
#define INPUTACTION_H
+#include "os/input_event.h"
#include "resource.h"
class ShortCut : public Resource {
GDCLASS(ShortCut, Resource);
- InputEvent shortcut;
+ Ref<InputEvent> shortcut;
protected:
static void _bind_methods();
public:
- void set_shortcut(const InputEvent &p_shortcut);
- InputEvent get_shortcut() const;
- bool is_shortcut(const InputEvent &p_Event) const;
+ void set_shortcut(const Ref<InputEvent> &p_shortcut);
+ Ref<InputEvent> get_shortcut() const;
+ bool is_shortcut(const Ref<InputEvent> &p_Event) const;
bool is_valid() const;
String get_as_text() const;
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index bbfe1b61bb..494dde0e20 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -409,14 +409,17 @@ Size2 ItemList::Item::get_icon_size() const {
return icon_region.size;
}
-void ItemList::_gui_input(const InputEvent &p_event) {
+void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
- if (defer_select_single >= 0 && p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (defer_select_single >= 0 && mm.is_valid()) {
defer_select_single = -1;
return;
}
- if (defer_select_single >= 0 && p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_LEFT && !p_event.mouse_button.pressed) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (defer_select_single >= 0 && mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && !mb->is_pressed()) {
select(defer_select_single, true);
@@ -425,12 +428,10 @@ void ItemList::_gui_input(const InputEvent &p_event) {
return;
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && (p_event.mouse_button.button_index == BUTTON_LEFT || (allow_rmb_select && p_event.mouse_button.button_index == BUTTON_RIGHT)) && p_event.mouse_button.pressed) {
-
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid() && (mb->get_button_index() == BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == BUTTON_RIGHT)) && mb->is_pressed()) {
search_string = ""; //any mousepress cancels
- Vector2 pos(mb.x, mb.y);
+ Vector2 pos(mb->get_pos().x, mb->get_pos().y);
Ref<StyleBox> bg = get_stylebox("bg");
pos -= bg->get_offset();
pos.y += scroll_bar->get_value();
@@ -454,11 +455,11 @@ void ItemList::_gui_input(const InputEvent &p_event) {
int i = closest;
- if (select_mode == SELECT_MULTI && items[i].selected && mb.mod.command) {
+ if (select_mode == SELECT_MULTI && items[i].selected && mb->get_command()) {
unselect(i);
emit_signal("multi_selected", i, false);
- } else if (select_mode == SELECT_MULTI && mb.mod.shift && current >= 0 && current < items.size() && current != i) {
+ } else if (select_mode == SELECT_MULTI && mb->get_shift() && current >= 0 && current < items.size() && current != i) {
int from = current;
int to = i;
@@ -472,24 +473,24 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", i, true);
}
- if (p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
}
} else {
- if (!mb.doubleclick && !mb.mod.command && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ if (!mb->is_doubleclick() && !mb->get_command() && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && mb->get_button_index() == BUTTON_LEFT) {
defer_select_single = i;
return;
}
- if (items[i].selected && p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (items[i].selected && mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
} else {
bool selected = !items[i].selected;
- select(i, select_mode == SELECT_SINGLE || !mb.mod.command);
+ select(i, select_mode == SELECT_SINGLE || !mb->get_command());
if (selected) {
if (select_mode == SELECT_SINGLE) {
@@ -498,10 +499,10 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", i, true);
}
- if (p_event.mouse_button.button_index == BUTTON_RIGHT) {
+ if (mb->get_button_index() == BUTTON_RIGHT) {
- emit_signal("item_rmb_selected", i, Vector2(mb.x, mb.y));
- } else if (/*select_mode==SELECT_SINGLE &&*/ mb.doubleclick) {
+ emit_signal("item_rmb_selected", i, Vector2(mb->get_pos().x, mb->get_pos().y));
+ } else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_doubleclick()) {
emit_signal("item_activated", i);
}
@@ -516,21 +517,21 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_WHEEL_UP && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
- scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * p_event.mouse_button.factor / 8);
+ scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * mb->get_factor() / 8);
scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() / 8);
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index == BUTTON_WHEEL_DOWN && p_event.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
- scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * p_event.mouse_button.factor / 8);
+ scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * mb->get_factor() / 8);
scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() / 8);
}
- if (p_event.is_pressed() && items.size() > 0) {
- if (p_event.is_action("ui_up")) {
+ if (p_event->is_pressed() && items.size() > 0) {
+ if (p_event->is_action("ui_up")) {
if (search_string != "") {
@@ -565,7 +566,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_down")) {
+ } else if (p_event->is_action("ui_down")) {
if (search_string != "") {
@@ -599,7 +600,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_page_up")) {
+ } else if (p_event->is_action("ui_page_up")) {
search_string = ""; //any mousepress cancels
@@ -614,7 +615,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
break;
}
}
- } else if (p_event.is_action("ui_page_down")) {
+ } else if (p_event->is_action("ui_page_down")) {
search_string = ""; //any mousepress cancels
@@ -630,7 +631,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
break;
}
}
- } else if (p_event.is_action("ui_left")) {
+ } else if (p_event->is_action("ui_left")) {
search_string = ""; //any mousepress cancels
@@ -642,7 +643,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_right")) {
+ } else if (p_event->is_action("ui_right")) {
search_string = ""; //any mousepress cancels
@@ -654,9 +655,9 @@ void ItemList::_gui_input(const InputEvent &p_event) {
}
accept_event();
}
- } else if (p_event.is_action("ui_cancel")) {
+ } else if (p_event->is_action("ui_cancel")) {
search_string = "";
- } else if (p_event.is_action("ui_select")) {
+ } else if (p_event->is_action("ui_select")) {
if (select_mode == SELECT_MULTI && current >= 0 && current < items.size()) {
if (items[current].selectable && !items[current].disabled && !items[current].selected) {
@@ -667,15 +668,17 @@ void ItemList::_gui_input(const InputEvent &p_event) {
emit_signal("multi_selected", current, false);
}
}
- } else if (p_event.is_action("ui_accept")) {
+ } else if (p_event->is_action("ui_accept")) {
search_string = ""; //any mousepress cance
if (current >= 0 && current < items.size()) {
emit_signal("item_activated", current);
}
- } else if (p_event.type == InputEvent::KEY) {
+ } else {
+
+ Ref<InputEventKey> k = p_event;
- if (p_event.key.unicode) {
+ if (k.is_valid() && k->get_unicode()) {
uint64_t now = OS::get_singleton()->get_ticks_msec();
uint64_t diff = now - search_time_msec;
@@ -686,7 +689,7 @@ void ItemList::_gui_input(const InputEvent &p_event) {
search_string = "";
}
- search_string += String::chr(p_event.key.unicode);
+ search_string += String::chr(k->get_unicode());
for (int i = 0; i < items.size(); i++) {
if (items[i].text.begins_with(search_string)) {
set_current(i);
diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h
index 4b896de77c..c7abc2990f 100644
--- a/scene/gui/item_list.h
+++ b/scene/gui/item_list.h
@@ -104,7 +104,7 @@ private:
real_t icon_scale;
void _scroll_changed(double);
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
protected:
void _notification(int p_what);
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 4ceaeeba04..38debe8a77 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -42,445 +42,442 @@ static bool _is_text_char(CharType c) {
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_';
}
-void LineEdit::_gui_input(InputEvent p_event) {
+void LineEdit::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (b.is_valid()) {
- const InputEventMouseButton &b = p_event.mouse_button;
-
- if (b.pressed && b.button_index == BUTTON_RIGHT) {
- menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
- menu->set_size(Vector2(1, 1));
- menu->popup();
- grab_focus();
- return;
- }
+ if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT) {
+ menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
+ menu->set_size(Vector2(1, 1));
+ menu->popup();
+ grab_focus();
+ return;
+ }
- if (b.button_index != BUTTON_LEFT)
- break;
+ if (b->get_button_index() != BUTTON_LEFT)
+ return;
- _reset_caret_blink_timer();
- if (b.pressed) {
+ _reset_caret_blink_timer();
+ if (b->is_pressed()) {
- shift_selection_check_pre(b.mod.shift);
+ shift_selection_check_pre(b->get_shift());
- set_cursor_at_pixel_pos(b.x);
+ set_cursor_at_pixel_pos(b->get_pos().x);
- if (b.mod.shift) {
+ if (b->get_shift()) {
- selection_fill_at_cursor();
- selection.creating = true;
+ selection_fill_at_cursor();
+ selection.creating = true;
- } else {
+ } else {
- if (b.doubleclick) {
+ if (b->is_doubleclick()) {
- selection.enabled = true;
- selection.begin = 0;
- selection.end = text.length();
- selection.doubleclick = true;
- }
+ selection.enabled = true;
+ selection.begin = 0;
+ selection.end = text.length();
+ selection.doubleclick = true;
+ }
- selection.drag_attempt = false;
+ selection.drag_attempt = false;
- if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
+ if ((cursor_pos < selection.begin) || (cursor_pos > selection.end) || !selection.enabled) {
- selection_clear();
- selection.cursor_start = cursor_pos;
- selection.creating = true;
- } else if (selection.enabled) {
+ selection_clear();
+ selection.cursor_start = cursor_pos;
+ selection.creating = true;
+ } else if (selection.enabled) {
- selection.drag_attempt = true;
- }
+ selection.drag_attempt = true;
}
+ }
- update();
-
- } else {
+ update();
- if ((!selection.creating) && (!selection.doubleclick)) {
- selection_clear();
- }
- selection.creating = false;
- selection.doubleclick = false;
+ } else {
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->show_virtual_keyboard(text, get_global_rect());
+ if ((!selection.creating) && (!selection.doubleclick)) {
+ selection_clear();
}
+ selection.creating = false;
+ selection.doubleclick = false;
- update();
- } break;
- case InputEvent::MOUSE_MOTION: {
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->show_virtual_keyboard(text, get_global_rect());
+ }
- const InputEventMouseMotion &m = p_event.mouse_motion;
+ update();
+ }
- if (m.button_mask & BUTTON_LEFT) {
+ Ref<InputEventMouseMotion> m = p_event;
- if (selection.creating) {
- set_cursor_at_pixel_pos(m.x);
- selection_fill_at_cursor();
- }
- }
+ if (m.is_valid()) {
- } break;
- case InputEvent::KEY: {
+ if (m->get_button_mask() & BUTTON_LEFT) {
- const InputEventKey &k = p_event.key;
+ if (selection.creating) {
+ set_cursor_at_pixel_pos(m->get_pos().x);
+ selection_fill_at_cursor();
+ }
+ }
+ }
- if (!k.pressed)
- return;
- unsigned int code = k.scancode;
+ Ref<InputEventKey> k = p_event;
- if (k.mod.command) {
+ if (k.is_valid()) {
- bool handled = true;
+ if (!k->is_pressed())
+ return;
+ unsigned int code = k->get_scancode();
- switch (code) {
+ if (k->get_command()) {
- case (KEY_X): { // CUT
+ bool handled = true;
- if (editable) {
- cut_text();
- }
+ switch (code) {
- } break;
+ case (KEY_X): { // CUT
- case (KEY_C): { // COPY
+ if (editable) {
+ cut_text();
+ }
- copy_text();
+ } break;
- } break;
+ case (KEY_C): { // COPY
- case (KEY_V): { // PASTE
+ copy_text();
- if (editable) {
+ } break;
- paste_text();
- }
+ case (KEY_V): { // PASTE
- } break;
+ if (editable) {
- case (KEY_Z): { // Simple One level undo
+ paste_text();
+ }
- if (editable) {
+ } break;
- undo();
- }
+ case (KEY_Z): { // Simple One level undo
- } break;
+ if (editable) {
+
+ undo();
+ }
- case (KEY_U): { // Delete from start to cursor
+ } break;
- if (editable) {
+ case (KEY_U): { // Delete from start to cursor
- selection_clear();
- undo_text = text;
- text = text.substr(cursor_pos, text.length() - cursor_pos);
+ if (editable) {
- Ref<Font> font = get_font("font");
+ selection_clear();
+ undo_text = text;
+ text = text.substr(cursor_pos, text.length() - cursor_pos);
- cached_width = 0;
- if (font != NULL) {
- for (int i = 0; i < text.length(); i++)
- cached_width += font->get_char_size(text[i]).width;
- }
+ Ref<Font> font = get_font("font");
- set_cursor_pos(0);
- _text_changed();
+ cached_width = 0;
+ if (font != NULL) {
+ for (int i = 0; i < text.length(); i++)
+ cached_width += font->get_char_size(text[i]).width;
}
- } break;
+ set_cursor_pos(0);
+ _text_changed();
+ }
- case (KEY_Y): { // PASTE (Yank for unix users)
+ } break;
- if (editable) {
+ case (KEY_Y): { // PASTE (Yank for unix users)
- paste_text();
- }
+ if (editable) {
- } break;
- case (KEY_K): { // Delete from cursor_pos to end
+ paste_text();
+ }
- if (editable) {
+ } break;
+ case (KEY_K): { // Delete from cursor_pos to end
- selection_clear();
- undo_text = text;
- text = text.substr(0, cursor_pos);
- _text_changed();
- }
+ if (editable) {
- } break;
- case (KEY_A): { //Select All
- select();
- } break;
- default: { handled = false; }
- }
+ selection_clear();
+ undo_text = text;
+ text = text.substr(0, cursor_pos);
+ _text_changed();
+ }
- if (handled) {
- accept_event();
- return;
- }
+ } break;
+ case (KEY_A): { //Select All
+ select();
+ } break;
+ default: { handled = false; }
}
- _reset_caret_blink_timer();
- if (!k.mod.meta) {
+ if (handled) {
+ accept_event();
+ return;
+ }
+ }
- bool handled = true;
- switch (code) {
+ _reset_caret_blink_timer();
+ if (!k->get_metakey()) {
- case KEY_ENTER:
- case KEY_RETURN: {
+ bool handled = true;
+ switch (code) {
- emit_signal("text_entered", text);
- if (OS::get_singleton()->has_virtual_keyboard())
- OS::get_singleton()->hide_virtual_keyboard();
+ case KEY_ENTER:
+ case KEY_RETURN: {
- return;
- } break;
+ emit_signal("text_entered", text);
+ if (OS::get_singleton()->has_virtual_keyboard())
+ OS::get_singleton()->hide_virtual_keyboard();
- case KEY_BACKSPACE: {
+ return;
+ } break;
- if (!editable)
- break;
+ case KEY_BACKSPACE: {
- if (selection.enabled) {
- undo_text = text;
- selection_delete();
- break;
- }
+ if (!editable)
+ break;
+
+ if (selection.enabled) {
+ undo_text = text;
+ selection_delete();
+ break;
+ }
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int cc = cursor_pos;
- bool prev_char = false;
+ int cc = cursor_pos;
+ bool prev_char = false;
- while (cc > 0) {
- bool ischar = _is_text_char(text[cc - 1]);
+ while (cc > 0) {
+ bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc--;
- }
+ prev_char = ischar;
+ cc--;
+ }
- delete_text(cc, cursor_pos);
+ delete_text(cc, cursor_pos);
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- undo_text = text;
- delete_char();
- }
+ } else {
+ undo_text = text;
+ delete_char();
+ }
- } break;
- case KEY_KP_4: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_left
+ } break;
+ case KEY_KP_4: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
}
- case KEY_LEFT: {
+ // numlock disabled. fallthrough to key_left
+ }
+ case KEY_LEFT: {
#ifndef APPLE_STYLE_KEYS
- if (!k.mod.alt)
+ if (!k->get_alt())
#endif
- shift_selection_check_pre(k.mod.shift);
+ shift_selection_check_pre(k->get_shift());
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- set_cursor_pos(0);
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ set_cursor_pos(0);
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor_pos;
+ bool prev_char = false;
+ int cc = cursor_pos;
- while (cc > 0) {
- bool ischar = _is_text_char(text[cc - 1]);
+ while (cc > 0) {
+ bool ischar = _is_text_char(text[cc - 1]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc--;
- }
+ prev_char = ischar;
+ cc--;
+ }
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- set_cursor_pos(get_cursor_pos() - 1);
- }
+ } else {
+ set_cursor_pos(get_cursor_pos() - 1);
+ }
- shift_selection_check_post(k.mod.shift);
+ shift_selection_check_post(k->get_shift());
- } break;
- case KEY_KP_6: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_right
+ } break;
+ case KEY_KP_6: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
}
- case KEY_RIGHT: {
+ // numlock disabled. fallthrough to key_right
+ }
+ case KEY_RIGHT: {
- shift_selection_check_pre(k.mod.shift);
+ shift_selection_check_pre(k->get_shift());
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- set_cursor_pos(text.length());
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ set_cursor_pos(text.length());
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor_pos;
+ bool prev_char = false;
+ int cc = cursor_pos;
- while (cc < text.length()) {
- bool ischar = _is_text_char(text[cc]);
+ while (cc < text.length()) {
+ bool ischar = _is_text_char(text[cc]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc++;
- }
+ prev_char = ischar;
+ cc++;
+ }
- set_cursor_pos(cc);
+ set_cursor_pos(cc);
- } else {
- set_cursor_pos(get_cursor_pos() + 1);
- }
+ } else {
+ set_cursor_pos(get_cursor_pos() + 1);
+ }
- shift_selection_check_post(k.mod.shift);
+ shift_selection_check_post(k->get_shift());
- } break;
- case KEY_DELETE: {
+ } break;
+ case KEY_DELETE: {
- if (!editable)
- break;
+ if (!editable)
+ break;
- if (k.mod.shift && !k.mod.command && !k.mod.alt) {
- cut_text();
- break;
- }
+ if (k->get_shift() && !k->get_command() && !k->get_alt()) {
+ cut_text();
+ break;
+ }
- if (selection.enabled) {
- undo_text = text;
- selection_delete();
- break;
- }
+ if (selection.enabled) {
+ undo_text = text;
+ selection_delete();
+ break;
+ }
- int text_len = text.length();
+ int text_len = text.length();
- if (cursor_pos == text_len)
- break; // nothing to do
+ if (cursor_pos == text_len)
+ break; // nothing to do
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int cc = cursor_pos;
-
- bool prev_char = false;
+ int cc = cursor_pos;
- while (cc < text.length()) {
+ bool prev_char = false;
- bool ischar = _is_text_char(text[cc]);
+ while (cc < text.length()) {
- if (prev_char && !ischar)
- break;
- prev_char = ischar;
- cc++;
- }
+ bool ischar = _is_text_char(text[cc]);
- delete_text(cursor_pos, cc);
-
- } else {
- undo_text = text;
- set_cursor_pos(cursor_pos + 1);
- delete_char();
+ if (prev_char && !ischar)
+ break;
+ prev_char = ischar;
+ cc++;
}
- } break;
- case KEY_KP_7: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_home
- }
- case KEY_HOME: {
+ delete_text(cursor_pos, cc);
- shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(0);
- shift_selection_check_post(k.mod.shift);
- } break;
- case KEY_KP_1: {
- if (k.unicode != 0) {
- handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_end
+ } else {
+ undo_text = text;
+ set_cursor_pos(cursor_pos + 1);
+ delete_char();
}
- case KEY_END: {
- shift_selection_check_pre(k.mod.shift);
- set_cursor_pos(text.length());
- shift_selection_check_post(k.mod.shift);
- } break;
-
- default: {
+ } break;
+ case KEY_KP_7: {
+ if (k->get_unicode() != 0) {
+ handled = false;
+ break;
+ }
+ // numlock disabled. fallthrough to key_home
+ }
+ case KEY_HOME: {
+ shift_selection_check_pre(k->get_shift());
+ set_cursor_pos(0);
+ shift_selection_check_post(k->get_shift());
+ } break;
+ case KEY_KP_1: {
+ if (k->get_unicode() != 0) {
handled = false;
- } break;
+ break;
+ }
+ // numlock disabled. fallthrough to key_end
}
+ case KEY_END: {
- if (handled) {
- accept_event();
- } else if (!k.mod.alt && !k.mod.command) {
- if (k.unicode >= 32 && k.scancode != KEY_DELETE) {
-
- if (editable) {
- selection_delete();
- CharType ucodestr[2] = { (CharType)k.unicode, 0 };
- append_at_cursor(ucodestr);
- _text_changed();
- accept_event();
- }
+ shift_selection_check_pre(k->get_shift());
+ set_cursor_pos(text.length());
+ shift_selection_check_post(k->get_shift());
+ } break;
- } else {
- return;
+ default: {
+
+ handled = false;
+ } break;
+ }
+
+ if (handled) {
+ accept_event();
+ } else if (!k->get_alt() && !k->get_command()) {
+ if (k->get_unicode() >= 32 && k->get_scancode() != KEY_DELETE) {
+
+ if (editable) {
+ selection_delete();
+ CharType ucodestr[2] = { (CharType)k->get_unicode(), 0 };
+ append_at_cursor(ucodestr);
+ _text_changed();
+ accept_event();
}
- }
- update();
+ } else {
+ return;
+ }
}
- return;
+ update();
+ }
- } break;
+ return;
}
}
diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h
index a969095947..1167cfb6d0 100644
--- a/scene/gui/line_edit.h
+++ b/scene/gui/line_edit.h
@@ -119,7 +119,7 @@ private:
void _editor_settings_changed();
#endif
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
protected:
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index cf468f2257..fe76b16460 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -31,9 +31,9 @@
#include "os/keyboard.h"
#include "scene/main/viewport.h"
-void MenuButton::_unhandled_key_input(InputEvent p_event) {
+void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) {
- if (p_event.is_pressed() && !p_event.is_echo() && (p_event.type == InputEvent::KEY || p_event.type == InputEvent::ACTION || p_event.type == InputEvent::JOYPAD_BUTTON)) {
+ if (p_event->is_pressed() && !p_event->is_echo() && (p_event->cast_to<InputEventKey>() || p_event->cast_to<InputEventJoypadButton>() || p_event->cast_to<InputEventAction>())) {
if (!get_parent() || !is_visible_in_tree() || is_disabled())
return;
@@ -59,10 +59,10 @@ void MenuButton::pressed() {
popup->set_invalidate_click_until_motion();
}
-void MenuButton::_gui_input(InputEvent p_event) {
+void MenuButton::_gui_input(Ref<InputEvent> p_event) {
- /*if (p_event.type==InputEvent::MOUSE_BUTTON && p_event.mouse_button.button_index==BUTTON_LEFT) {
- clicked=p_event.mouse_button.pressed;
+ /*if (p_event.type==InputEvent::MOUSE_BUTTON && p_event->get_button_index()==BUTTON_LEFT) {
+ clicked=p_event->is_pressed();
}
if (clicked && p_event.type==InputEvent::MOUSE_MOTION && popup->is_visible_in_tree()) {
diff --git a/scene/gui/menu_button.h b/scene/gui/menu_button.h
index e07627c07c..6bb23452dd 100644
--- a/scene/gui/menu_button.h
+++ b/scene/gui/menu_button.h
@@ -43,11 +43,11 @@ class MenuButton : public Button {
PopupMenu *popup;
virtual void pressed();
- void _unhandled_key_input(InputEvent p_event);
+ void _unhandled_key_input(Ref<InputEvent> p_event);
Array _get_items() const;
void _set_items(const Array &p_items);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
protected:
static void _bind_methods();
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 7d0b91a366..655d8ed6f6 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -30,7 +30,7 @@
#include "popup.h"
#include "os/keyboard.h"
-void Popup::_gui_input(InputEvent p_event) {
+void Popup::_gui_input(Ref<InputEvent> p_event) {
}
void Popup::_notification(int p_what) {
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 950aa65fa4..0543ae1937 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -45,7 +45,7 @@ class Popup : public Control {
protected:
virtual void _post_popup() {}
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
virtual void _fix_size();
static void _bind_methods();
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index e3f26e0f0b..985d9addc9 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -208,171 +208,170 @@ void PopupMenu::_submenu_timeout() {
}
}
-void PopupMenu::_gui_input(const InputEvent &p_event) {
+void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
- switch (p_event.type) {
+ Ref<InputEventKey> k = p_event;
- case InputEvent::KEY: {
+ if (k.is_valid()) {
- if (!p_event.key.pressed)
- break;
+ if (!k->is_pressed())
+ return;
- switch (p_event.key.scancode) {
+ switch (k->get_scancode()) {
- case KEY_DOWN: {
+ case KEY_DOWN: {
- for (int i = mouse_over + 1; i < items.size(); i++) {
+ for (int i = mouse_over + 1; i < items.size(); i++) {
- if (i < 0 || i >= items.size())
- continue;
+ if (i < 0 || i >= items.size())
+ continue;
- if (!items[i].separator && !items[i].disabled) {
+ if (!items[i].separator && !items[i].disabled) {
- mouse_over = i;
- update();
- break;
- }
+ mouse_over = i;
+ update();
+ break;
}
- } break;
- case KEY_UP: {
+ }
+ } break;
+ case KEY_UP: {
- for (int i = mouse_over - 1; i >= 0; i--) {
+ for (int i = mouse_over - 1; i >= 0; i--) {
- if (i < 0 || i >= items.size())
- continue;
+ if (i < 0 || i >= items.size())
+ continue;
- if (!items[i].separator && !items[i].disabled) {
+ if (!items[i].separator && !items[i].disabled) {
- mouse_over = i;
- update();
- break;
- }
+ mouse_over = i;
+ update();
+ break;
}
- } break;
- case KEY_RETURN:
- case KEY_ENTER: {
+ }
+ } break;
+ case KEY_RETURN:
+ case KEY_ENTER: {
- if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {
+ if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator) {
- activate_item(mouse_over);
- }
- } break;
- }
+ activate_item(mouse_over);
+ }
+ } break;
+ }
+ }
- } break;
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (b.is_valid()) {
- const InputEventMouseButton &b = p_event.mouse_button;
- if (b.pressed)
- break;
+ if (b->is_pressed())
+ return;
- switch (b.button_index) {
+ switch (b->get_button_index()) {
- case BUTTON_WHEEL_DOWN: {
+ case BUTTON_WHEEL_DOWN: {
- if (get_global_position().y + get_size().y > get_viewport_rect().size.y) {
+ if (get_global_position().y + get_size().y > get_viewport_rect().size.y) {
- int vseparation = get_constant("vseparation");
- Ref<Font> font = get_font("font");
+ int vseparation = get_constant("vseparation");
+ Ref<Font> font = get_font("font");
- Point2 pos = get_position();
- int s = (vseparation + font->get_height()) * 3;
- pos.y -= (s * b.factor);
- set_position(pos);
+ Point2 pos = get_position();
+ int s = (vseparation + font->get_height()) * 3;
+ pos.y -= (s * b->get_factor());
+ set_position(pos);
- //update hover
- InputEvent ie;
- ie.type = InputEvent::MOUSE_MOTION;
- ie.mouse_motion.x = b.x;
- ie.mouse_motion.y = b.y + s;
- _gui_input(ie);
- }
- } break;
- case BUTTON_WHEEL_UP: {
+ //update hover
+ Ref<InputEventMouseMotion> ie;
+ ie.instance();
+ ie->set_pos(b->get_pos() + Vector2(0, s));
+ _gui_input(ie);
+ }
+ } break;
+ case BUTTON_WHEEL_UP: {
- if (get_global_position().y < 0) {
+ if (get_global_position().y < 0) {
- int vseparation = get_constant("vseparation");
- Ref<Font> font = get_font("font");
+ int vseparation = get_constant("vseparation");
+ Ref<Font> font = get_font("font");
- Point2 pos = get_position();
- int s = (vseparation + font->get_height()) * 3;
- pos.y += (s * b.factor);
- set_position(pos);
+ Point2 pos = get_position();
+ int s = (vseparation + font->get_height()) * 3;
+ pos.y += (s * b->get_factor());
+ set_position(pos);
- //update hover
- InputEvent ie;
- ie.type = InputEvent::MOUSE_MOTION;
- ie.mouse_motion.x = b.x;
- ie.mouse_motion.y = b.y - s;
- _gui_input(ie);
- }
- } break;
- case BUTTON_LEFT: {
+ //update hover
+ Ref<InputEventMouseMotion> ie;
+ ie.instance();
+ ie->set_pos(b->get_pos() - Vector2(0, s));
+ _gui_input(ie);
+ }
+ } break;
+ case BUTTON_LEFT: {
- int over = _get_mouse_over(Point2(b.x, b.y));
+ int over = _get_mouse_over(b->get_pos());
- if (invalidated_click) {
- invalidated_click = false;
- break;
- }
- if (over < 0) {
- hide();
- break; //non-activable
- }
+ if (invalidated_click) {
+ invalidated_click = false;
+ break;
+ }
+ if (over < 0) {
+ hide();
+ break; //non-activable
+ }
- if (items[over].separator || items[over].disabled)
- break;
+ if (items[over].separator || items[over].disabled)
+ break;
- if (items[over].submenu != "") {
+ if (items[over].submenu != "") {
- _activate_submenu(over);
- return;
- }
- activate_item(over);
+ _activate_submenu(over);
+ return;
+ }
+ activate_item(over);
- } break;
- }
+ } break;
+ }
- //update();
- } break;
- case InputEvent::MOUSE_MOTION: {
+ //update();
+ }
- if (invalidated_click) {
- moved += Vector2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y);
- if (moved.length() > 4)
- invalidated_click = false;
- }
+ Ref<InputEventMouseMotion> m = p_event;
- const InputEventMouseMotion &m = p_event.mouse_motion;
- for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
+ if (m.is_valid()) {
- if (!Rect2(Point2(), get_size()).has_point(Point2(m.x, m.y)) && E->get().has_point(Point2(m.x, m.y))) {
- call_deferred("hide");
- return;
- }
- }
+ if (invalidated_click) {
+ moved += m->get_relative();
+ if (moved.length() > 4)
+ invalidated_click = false;
+ }
- int over = _get_mouse_over(Point2(m.x, m.y));
- int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over);
+ for (List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) {
- if (id < 0) {
- mouse_over = -1;
- update();
- break;
+ if (!Rect2(Point2(), get_size()).has_point(m->get_pos()) && E->get().has_point(m->get_pos())) {
+ call_deferred("hide");
+ return;
}
+ }
- if (items[over].submenu != "" && submenu_over != over) {
- submenu_over = over;
- submenu_timer->start();
- }
+ int over = _get_mouse_over(m->get_pos());
+ int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].ID >= 0 ? items[over].ID : over);
- if (over != mouse_over) {
- mouse_over = over;
- update();
- }
- } break;
+ if (id < 0) {
+ mouse_over = -1;
+ update();
+ return;
+ }
+
+ if (items[over].submenu != "" && submenu_over != over) {
+ submenu_over = over;
+ submenu_timer->start();
+ }
+
+ if (over != mouse_over) {
+ mouse_over = over;
+ update();
+ }
}
}
@@ -820,20 +819,22 @@ int PopupMenu::get_item_count() const {
return items.size();
}
-bool PopupMenu::activate_item_by_event(const InputEvent &p_event, bool p_for_global_only) {
+bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) {
uint32_t code = 0;
- if (p_event.type == InputEvent::KEY) {
- code = p_event.key.scancode;
+ Ref<InputEventKey> k = p_event;
+
+ if (k.is_valid()) {
+ code = k->get_scancode();
if (code == 0)
- code = p_event.key.unicode;
- if (p_event.key.mod.control)
+ code = k->get_unicode();
+ if (k->get_control())
code |= KEY_MASK_CTRL;
- if (p_event.key.mod.alt)
+ if (k->get_alt())
code |= KEY_MASK_ALT;
- if (p_event.key.mod.meta)
+ if (k->get_metakey())
code |= KEY_MASK_META;
- if (p_event.key.mod.shift)
+ if (k->get_shift())
code |= KEY_MASK_SHIFT;
}
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index de809f29d3..7ef532453d 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -79,7 +79,7 @@ class PopupMenu : public Popup {
String _get_accel_text(int p_item) const;
int _get_mouse_over(const Point2 &p_over) const;
virtual Size2 get_minimum_size() const;
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _activate_submenu(int over);
void _submenu_timeout();
@@ -146,7 +146,7 @@ public:
int get_item_count() const;
- bool activate_item_by_event(const InputEvent &p_event, bool p_for_global_only = false);
+ bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
void activate_item(int p_item);
void remove_item(int p_idx);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 6e5f218a66..a142bf5981 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -734,160 +734,155 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
return CURSOR_ARROW;
}
-void RichTextLabel::_gui_input(InputEvent p_event) {
+void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
-
- if (main->first_invalid_line < main->lines.size())
- return;
-
- const InputEventMouseButton &b = p_event.mouse_button;
+ if (b.is_valid()) {
+ if (main->first_invalid_line < main->lines.size())
+ return;
- if (b.button_index == BUTTON_LEFT) {
+ if (b->get_button_index() == BUTTON_LEFT) {
- if (true) {
+ if (true) {
- if (b.pressed && !b.doubleclick) {
- int line = 0;
- Item *item = NULL;
+ if (b->is_pressed() && !b->is_doubleclick()) {
+ int line = 0;
+ Item *item = NULL;
- bool outside;
- _find_click(main, Point2i(b.x, b.y), &item, &line, &outside);
+ bool outside;
+ _find_click(main, b->get_pos(), &item, &line, &outside);
- if (item) {
+ if (item) {
- Variant meta;
- if (!outside && _find_meta(item, &meta)) {
- //meta clicked
+ Variant meta;
+ if (!outside && _find_meta(item, &meta)) {
+ //meta clicked
- emit_signal("meta_clicked", meta);
- } else if (selection.enabled) {
+ emit_signal("meta_clicked", meta);
+ } else if (selection.enabled) {
- selection.click = item;
- selection.click_char = line;
- }
+ selection.click = item;
+ selection.click_char = line;
}
+ }
- } else if (!b.pressed) {
+ } else if (!b->is_pressed()) {
- selection.click = NULL;
- }
+ selection.click = NULL;
}
}
+ }
- if (b.button_index == BUTTON_WHEEL_UP) {
+ if (b->get_button_index() == BUTTON_WHEEL_UP) {
- if (scroll_active)
+ if (scroll_active)
- vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b.factor * 0.5 / 8);
- }
- if (b.button_index == BUTTON_WHEEL_DOWN) {
+ vscroll->set_value(vscroll->get_value() - vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
+ if (b->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (scroll_active)
+ if (scroll_active)
- vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b.factor * 0.5 / 8);
- }
- } break;
- case InputEvent::KEY: {
-
- const InputEventKey &k = p_event.key;
- if (k.pressed && !k.mod.alt && !k.mod.shift && !k.mod.meta) {
- bool handled = true;
- switch (k.scancode) {
- case KEY_PAGEUP: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(vscroll->get_value() - vscroll->get_page());
- } break;
- case KEY_PAGEDOWN: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(vscroll->get_value() + vscroll->get_page());
- } break;
- case KEY_UP: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height());
- } break;
- case KEY_DOWN: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height());
- } break;
- case KEY_HOME: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(0);
- } break;
- case KEY_END: {
-
- if (vscroll->is_visible_in_tree())
- vscroll->set_value(vscroll->get_max());
- } break;
- case KEY_INSERT:
- case KEY_C: {
-
- if (k.mod.command) {
- selection_copy();
- } else {
- handled = false;
- }
+ vscroll->set_value(vscroll->get_value() + vscroll->get_page() * b->get_factor() * 0.5 / 8);
+ }
+ }
- } break;
- default: handled = false;
- }
+ Ref<InputEventKey> k = p_event;
+
+ if (k.is_valid()) {
+ if (k->is_pressed() && !k->get_alt() && !k->get_shift() && !k->get_metakey()) {
+ bool handled = true;
+ switch (k->get_scancode()) {
+ case KEY_PAGEUP: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(vscroll->get_value() - vscroll->get_page());
+ } break;
+ case KEY_PAGEDOWN: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(vscroll->get_value() + vscroll->get_page());
+ } break;
+ case KEY_UP: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height());
+ } break;
+ case KEY_DOWN: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height());
+ } break;
+ case KEY_HOME: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(0);
+ } break;
+ case KEY_END: {
+
+ if (vscroll->is_visible_in_tree())
+ vscroll->set_value(vscroll->get_max());
+ } break;
+ case KEY_INSERT:
+ case KEY_C: {
+
+ if (k->get_command()) {
+ selection_copy();
+ } else {
+ handled = false;
+ }
- if (handled)
- accept_event();
+ } break;
+ default: handled = false;
}
- } break;
- case InputEvent::MOUSE_MOTION: {
+ if (handled)
+ accept_event();
+ }
+ }
- if (main->first_invalid_line < main->lines.size())
- return;
+ Ref<InputEventMouseMotion> m = p_event;
- const InputEventMouseMotion &m = p_event.mouse_motion;
+ if (m.is_valid()) {
+ if (main->first_invalid_line < main->lines.size())
+ return;
- if (selection.click) {
+ if (selection.click) {
- int line = 0;
- Item *item = NULL;
- _find_click(main, Point2i(m.x, m.y), &item, &line);
- if (!item)
- return; // do not update
+ int line = 0;
+ Item *item = NULL;
+ _find_click(main, m->get_pos(), &item, &line);
+ if (!item)
+ return; // do not update
- selection.from = selection.click;
- selection.from_char = selection.click_char;
+ selection.from = selection.click;
+ selection.from_char = selection.click_char;
- selection.to = item;
- selection.to_char = line;
+ selection.to = item;
+ selection.to_char = line;
- bool swap = false;
- if (selection.from->index > selection.to->index)
+ bool swap = false;
+ if (selection.from->index > selection.to->index)
+ swap = true;
+ else if (selection.from->index == selection.to->index) {
+ if (selection.from_char > selection.to_char)
swap = true;
- else if (selection.from->index == selection.to->index) {
- if (selection.from_char > selection.to_char)
- swap = true;
- else if (selection.from_char == selection.to_char) {
+ else if (selection.from_char == selection.to_char) {
- selection.active = false;
- return;
- }
- }
-
- if (swap) {
- SWAP(selection.from, selection.to);
- SWAP(selection.from_char, selection.to_char);
+ selection.active = false;
+ return;
}
+ }
- selection.active = true;
- update();
+ if (swap) {
+ SWAP(selection.from, selection.to);
+ SWAP(selection.from_char, selection.to_char);
}
- } break;
+ selection.active = true;
+ update();
+ }
}
}
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 05d98b3ee8..eedb7e54db 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -272,7 +272,7 @@ private:
void _update_scroll();
void _scroll_changed(double);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
Item *_get_next_item(Item *p_item, bool p_free = false);
bool use_bbcode;
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index bf44493b51..27a16ccc33 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -38,191 +38,188 @@ void ScrollBar::set_can_focus_by_default(bool p_can_focus) {
focus_by_default = p_can_focus;
}
-void ScrollBar::_gui_input(InputEvent p_event) {
+void ScrollBar::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventMouseButton> b = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (b.is_valid()) {
+ accept_event();
- const InputEventMouseButton &b = p_event.mouse_button;
- accept_event();
-
- if (b.button_index == 5 && b.pressed) {
-
- /*
- if (orientation==VERTICAL)
- set_val( get_val() + get_page() / 4.0 );
- else
- */
- set_value(get_value() + get_page() / 4.0);
- accept_event();
- }
-
- if (b.button_index == 4 && b.pressed) {
+ if (b->get_button_index() == 5 && b->is_pressed()) {
- /*
- if (orientation==HORIZONTAL)
- set_val( get_val() - get_page() / 4.0 );
- else
- */
- set_value(get_value() - get_page() / 4.0);
- accept_event();
- }
+ /*
+ if (orientation==VERTICAL)
+ set_val( get_val() + get_page() / 4.0 );
+ else
+ */
+ set_value(get_value() + get_page() / 4.0);
+ accept_event();
+ }
- if (b.button_index != 1)
- return;
+ if (b->get_button_index() == 4 && b->is_pressed()) {
- if (b.pressed) {
+ /*
+ if (orientation==HORIZONTAL)
+ set_val( get_val() - get_page() / 4.0 );
+ else
+ */
+ set_value(get_value() - get_page() / 4.0);
+ accept_event();
+ }
- double ofs = orientation == VERTICAL ? b.y : b.x;
- Ref<Texture> decr = get_icon("decrement");
- Ref<Texture> incr = get_icon("increment");
+ if (b->get_button_index() != 1)
+ return;
- double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
- double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
- double grabber_ofs = get_grabber_offset();
- double grabber_size = get_grabber_size();
- double total = orientation == VERTICAL ? get_size().height : get_size().width;
+ if (b->is_pressed()) {
- if (ofs < decr_size) {
+ double ofs = orientation == VERTICAL ? b->get_pos().y : b->get_pos().x;
+ Ref<Texture> decr = get_icon("decrement");
+ Ref<Texture> incr = get_icon("increment");
- set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
- break;
- }
+ double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
+ double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
+ double grabber_ofs = get_grabber_offset();
+ double grabber_size = get_grabber_size();
+ double total = orientation == VERTICAL ? get_size().height : get_size().width;
- if (ofs > total - incr_size) {
+ if (ofs < decr_size) {
- set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
- break;
- }
+ set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
+ return;
+ }
- ofs -= decr_size;
+ if (ofs > total - incr_size) {
- if (ofs < grabber_ofs) {
+ set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
+ return;
+ }
- set_value(get_value() - get_page());
- break;
- }
+ ofs -= decr_size;
- ofs -= grabber_ofs;
+ if (ofs < grabber_ofs) {
- if (ofs < grabber_size) {
+ set_value(get_value() - get_page());
+ return;
+ }
- drag.active = true;
- drag.pos_at_click = grabber_ofs + ofs;
- drag.value_at_click = get_as_ratio();
- update();
- } else {
+ ofs -= grabber_ofs;
- set_value(get_value() + get_page());
- }
+ if (ofs < grabber_size) {
+ drag.active = true;
+ drag.pos_at_click = grabber_ofs + ofs;
+ drag.value_at_click = get_as_ratio();
+ update();
} else {
- drag.active = false;
- update();
+ set_value(get_value() + get_page());
}
- } break;
- case InputEvent::MOUSE_MOTION: {
+ } else {
- const InputEventMouseMotion &m = p_event.mouse_motion;
+ drag.active = false;
+ update();
+ }
+ }
- accept_event();
+ Ref<InputEventMouseMotion> m = p_event;
- if (drag.active) {
+ if (m.is_valid()) {
- double ofs = orientation == VERTICAL ? m.y : m.x;
- Ref<Texture> decr = get_icon("decrement");
+ accept_event();
- double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
- ofs -= decr_size;
+ if (drag.active) {
- double diff = (ofs - drag.pos_at_click) / get_area_size();
+ double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x;
+ Ref<Texture> decr = get_icon("decrement");
- set_as_ratio(drag.value_at_click + diff);
- } else {
+ double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
+ ofs -= decr_size;
- double ofs = orientation == VERTICAL ? m.y : m.x;
- Ref<Texture> decr = get_icon("decrement");
- Ref<Texture> incr = get_icon("increment");
+ double diff = (ofs - drag.pos_at_click) / get_area_size();
- double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
- double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
- double total = orientation == VERTICAL ? get_size().height : get_size().width;
+ set_as_ratio(drag.value_at_click + diff);
+ } else {
- HighlightStatus new_highlight;
+ double ofs = orientation == VERTICAL ? m->get_pos().y : m->get_pos().x;
+ Ref<Texture> decr = get_icon("decrement");
+ Ref<Texture> incr = get_icon("increment");
- if (ofs < decr_size) {
+ double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width();
+ double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width();
+ double total = orientation == VERTICAL ? get_size().height : get_size().width;
- new_highlight = HIGHLIGHT_DECR;
+ HighlightStatus new_hilite;
- } else if (ofs > total - incr_size) {
+ if (ofs < decr_size) {
- new_highlight = HIGHLIGHT_INCR;
+ new_hilite = HIGHLIGHT_DECR;
- } else {
+ } else if (ofs > total - incr_size) {
- new_highlight = HIGHLIGHT_RANGE;
- }
+ new_hilite = HIGHLIGHT_INCR;
- if (new_highlight != highlight) {
+ } else {
- highlight = new_highlight;
- update();
- }
+ new_hilite = HIGHLIGHT_RANGE;
}
- } break;
- case InputEvent::KEY: {
- const InputEventKey &k = p_event.key;
+ if (new_hilite != highlight) {
- if (!k.pressed)
- return;
+ highlight = new_hilite;
+ update();
+ }
+ }
+ }
- switch (k.scancode) {
+ Ref<InputEventKey> k = p_event;
- case KEY_LEFT: {
+ if (k.is_valid()) {
- if (orientation != HORIZONTAL)
- return;
- set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
+ if (!k->is_pressed())
+ return;
- } break;
- case KEY_RIGHT: {
+ switch (k->get_scancode()) {
- if (orientation != HORIZONTAL)
- return;
- set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
+ case KEY_LEFT: {
- } break;
- case KEY_UP: {
+ if (orientation != HORIZONTAL)
+ return;
+ set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
- if (orientation != VERTICAL)
- return;
+ } break;
+ case KEY_RIGHT: {
- set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
+ if (orientation != HORIZONTAL)
+ return;
+ set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
- } break;
- case KEY_DOWN: {
+ } break;
+ case KEY_UP: {
- if (orientation != VERTICAL)
- return;
- set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
+ if (orientation != VERTICAL)
+ return;
- } break;
- case KEY_HOME: {
+ set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
- set_value(get_min());
+ } break;
+ case KEY_DOWN: {
- } break;
- case KEY_END: {
+ if (orientation != VERTICAL)
+ return;
+ set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
- set_value(get_max());
+ } break;
+ case KEY_HOME: {
- } break;
- }
- break;
+ set_value(get_min());
+
+ } break;
+ case KEY_END: {
+
+ set_value(get_max());
+
+ } break;
}
}
}
@@ -522,87 +519,84 @@ void ScrollBar::_drag_slave_exit() {
drag_slave = NULL;
}
-void ScrollBar::_drag_slave_input(const InputEvent &p_input) {
+void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) {
- switch (p_input.type) {
+ Ref<InputEventMouseButton> mb = p_input;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_input.mouse_button;
+ if (mb->get_button_index() != 1)
+ return;
- if (mb.button_index != 1)
- break;
+ if (mb->is_pressed()) {
+
+ if (drag_slave_touching) {
+ set_fixed_process(false);
+ drag_slave_touching_deaccel = false;
+ drag_slave_touching = false;
+ drag_slave_speed = Vector2();
+ drag_slave_accum = Vector2();
+ last_drag_slave_accum = Vector2();
+ drag_slave_from = Vector2();
+ }
- if (mb.pressed) {
+ if (true) {
+ drag_slave_speed = Vector2();
+ drag_slave_accum = Vector2();
+ last_drag_slave_accum = Vector2();
+ //drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
+ drag_slave_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
+ drag_slave_touching = OS::get_singleton()->has_touchscreen_ui_hint();
+ drag_slave_touching_deaccel = false;
+ time_since_motion = 0;
if (drag_slave_touching) {
- set_fixed_process(false);
- drag_slave_touching_deaccel = false;
- drag_slave_touching = false;
- drag_slave_speed = Vector2();
- drag_slave_accum = Vector2();
- last_drag_slave_accum = Vector2();
- drag_slave_from = Vector2();
+ set_fixed_process(true);
+ time_since_motion = 0;
}
+ }
+
+ } else {
- if (true) {
- drag_slave_speed = Vector2();
- drag_slave_accum = Vector2();
- last_drag_slave_accum = Vector2();
- //drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val());
- drag_slave_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
+ if (drag_slave_touching) {
- drag_slave_touching = OS::get_singleton()->has_touchscreen_ui_hint();
+ if (drag_slave_speed == Vector2()) {
drag_slave_touching_deaccel = false;
- time_since_motion = 0;
- if (drag_slave_touching) {
- set_fixed_process(true);
- time_since_motion = 0;
- }
+ drag_slave_touching = false;
+ set_fixed_process(false);
+ } else {
+
+ drag_slave_touching_deaccel = true;
}
+ }
+ }
+ }
- } else {
+ Ref<InputEventMouseMotion> mm = p_input;
- if (drag_slave_touching) {
+ if (mm.is_valid()) {
- if (drag_slave_speed == Vector2()) {
- drag_slave_touching_deaccel = false;
- drag_slave_touching = false;
- set_fixed_process(false);
- } else {
+ if (drag_slave_touching && !drag_slave_touching_deaccel) {
- drag_slave_touching_deaccel = true;
- }
- }
- }
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- const InputEventMouseMotion &mm = p_input.mouse_motion;
-
- if (drag_slave_touching && !drag_slave_touching_deaccel) {
-
- Vector2 motion = Vector2(mm.relative_x, mm.relative_y);
-
- drag_slave_accum -= motion;
- Vector2 diff = drag_slave_from + drag_slave_accum;
-
- if (orientation == HORIZONTAL)
- set_value(diff.x);
- /*
- else
- drag_slave_accum.x=0;
- */
- if (orientation == VERTICAL)
- set_value(diff.y);
- /*
- else
- drag_slave_accum.y=0;
- */
- time_since_motion = 0;
- }
+ Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
- } break;
+ drag_slave_accum -= motion;
+ Vector2 diff = drag_slave_from + drag_slave_accum;
+
+ if (orientation == HORIZONTAL)
+ set_value(diff.x);
+ /*
+ else
+ drag_slave_accum.x=0;
+ */
+ if (orientation == VERTICAL)
+ set_value(diff.y);
+ /*
+ else
+ drag_slave_accum.y=0;
+ */
+ time_since_motion = 0;
+ }
}
}
@@ -640,11 +634,11 @@ NodePath ScrollBar::get_drag_slave() const {
#if 0
-void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) {
+void ScrollBar::mouse_button(const Point2& p_pos, int b->get_button_index(),bool b->is_pressed(),int p_modifier_mask) {
// wheel!
- if (b.button_index==BUTTON_WHEEL_UP && b.pressed) {
+ if (b->get_button_index()==BUTTON_WHEEL_UP && b->is_pressed()) {
if (orientation==VERTICAL)
set_val( get_val() - get_page() / 4.0 );
@@ -652,7 +646,7 @@ void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pres
set_val( get_val() + get_page() / 4.0 );
}
- if (b.button_index==BUTTON_WHEEL_DOWN && b.pressed) {
+ if (b->get_button_index()==BUTTON_WHEEL_DOWN && b->is_pressed()) {
if (orientation==HORIZONTAL)
set_val( get_val() - get_page() / 4.0 );
@@ -660,10 +654,10 @@ void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pres
set_val( get_val() + get_page() / 4.0 );
}
- if (b.button_index!=BUTTON_LEFT)
+ if (b->get_button_index()!=BUTTON_LEFT)
return;
- if (b.pressed) {
+ if (b->is_pressed()) {
int ofs = orientation==VERTICAL ? p_pos.y : p_pos.x ;
int grabber_ofs = get_grabber_offset();
@@ -692,7 +686,7 @@ void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pres
}
}
-void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.button_index_mask) {
+void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b->get_button_index()_mask) {
if (!drag.active)
return;
@@ -712,9 +706,9 @@ void ScrollBar::mouse_motion(const Point2& p_pos, const Point2& p_rel, int b.but
}
-bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b.pressed,bool p_repeat,int p_modifier_mask) {
+bool ScrollBar::key(unsigned long p_unicode, unsigned long p_scan_code,bool b->is_pressed(),bool p_repeat,int p_modifier_mask) {
- if (!b.pressed)
+ if (!b->is_pressed())
return false;
switch (p_scan_code) {
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index cb6bf227a0..8310e12590 100644
--- a/scene/gui/scroll_bar.h
+++ b/scene/gui/scroll_bar.h
@@ -84,9 +84,9 @@ class ScrollBar : public Range {
bool click_handled;
void _drag_slave_exit();
- void _drag_slave_input(const InputEvent &p_input);
+ void _drag_slave_input(const Ref<InputEvent> &p_input);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
protected:
void _notification(int p_what);
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index a89c2b27c9..70b4ac47f8 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -76,113 +76,109 @@ void ScrollContainer::_cancel_drag() {
drag_from = Vector2();
}
-void ScrollContainer::_gui_input(const InputEvent &p_gui_input) {
+void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
- switch (p_gui_input.type) {
+ Ref<InputEventMouseButton> mb = p_gui_input;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- const InputEventMouseButton &mb = p_gui_input.mouse_button;
-
- if (mb.button_index == BUTTON_WHEEL_UP && mb.pressed) {
- // only horizontal is enabled, scroll horizontally
- if (h_scroll->is_visible() && !v_scroll->is_visible()) {
- h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() / 8 * mb.factor);
- } else if (v_scroll->is_visible_in_tree()) {
- v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() / 8 * mb.factor);
- }
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && mb->is_pressed()) {
+ // only horizontal is enabled, scroll horizontally
+ if (h_scroll->is_visible() && !v_scroll->is_visible()) {
+ h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() / 8 * mb->get_factor());
+ } else if (v_scroll->is_visible_in_tree()) {
+ v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() / 8 * mb->get_factor());
}
+ }
- if (mb.button_index == BUTTON_WHEEL_DOWN && mb.pressed) {
- // only horizontal is enabled, scroll horizontally
- if (h_scroll->is_visible() && !v_scroll->is_visible()) {
- h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() / 8 * mb.factor);
- } else if (v_scroll->is_visible()) {
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() / 8 * mb.factor);
- }
+ if (mb->get_button_index() == BUTTON_WHEEL_DOWN && mb->is_pressed()) {
+ // only horizontal is enabled, scroll horizontally
+ if (h_scroll->is_visible() && !v_scroll->is_visible()) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() / 8 * mb->get_factor());
+ } else if (v_scroll->is_visible()) {
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() / 8 * mb->get_factor());
}
+ }
- if (mb.button_index == BUTTON_WHEEL_LEFT && mb.pressed) {
- if (h_scroll->is_visible_in_tree()) {
- h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * mb.factor / 8);
- }
+ if (mb->get_button_index() == BUTTON_WHEEL_LEFT && mb->is_pressed()) {
+ if (h_scroll->is_visible_in_tree()) {
+ h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * mb->get_factor() / 8);
}
+ }
- if (mb.button_index == BUTTON_WHEEL_RIGHT && mb.pressed) {
- if (h_scroll->is_visible_in_tree()) {
- h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * mb.factor / 8);
- }
+ if (mb->get_button_index() == BUTTON_WHEEL_RIGHT && mb->is_pressed()) {
+ if (h_scroll->is_visible_in_tree()) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * mb->get_factor() / 8);
}
+ }
- if (!OS::get_singleton()->has_touchscreen_ui_hint())
- return;
+ if (!OS::get_singleton()->has_touchscreen_ui_hint())
+ return;
- if (mb.button_index != BUTTON_LEFT)
- break;
+ if (mb->get_button_index() != BUTTON_LEFT)
+ return;
- if (mb.pressed) {
+ if (mb->is_pressed()) {
- if (drag_touching) {
- set_fixed_process(false);
- drag_touching_deaccel = false;
- drag_touching = false;
- drag_speed = Vector2();
- drag_accum = Vector2();
- last_drag_accum = Vector2();
- drag_from = Vector2();
- }
+ if (drag_touching) {
+ set_fixed_process(false);
+ drag_touching_deaccel = false;
+ drag_touching = false;
+ drag_speed = Vector2();
+ drag_accum = Vector2();
+ last_drag_accum = Vector2();
+ drag_from = Vector2();
+ }
- if (true) {
- drag_speed = Vector2();
- drag_accum = Vector2();
- last_drag_accum = Vector2();
- drag_from = Vector2(h_scroll->get_value(), v_scroll->get_value());
- drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
- drag_touching_deaccel = false;
+ if (true) {
+ drag_speed = Vector2();
+ drag_accum = Vector2();
+ last_drag_accum = Vector2();
+ drag_from = Vector2(h_scroll->get_value(), v_scroll->get_value());
+ drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
+ drag_touching_deaccel = false;
+ time_since_motion = 0;
+ if (drag_touching) {
+ set_fixed_process(true);
time_since_motion = 0;
- if (drag_touching) {
- set_fixed_process(true);
- time_since_motion = 0;
- }
}
+ }
- } else {
- if (drag_touching) {
+ } else {
+ if (drag_touching) {
- if (drag_speed == Vector2()) {
- drag_touching_deaccel = false;
- drag_touching = false;
- set_fixed_process(false);
- } else {
+ if (drag_speed == Vector2()) {
+ drag_touching_deaccel = false;
+ drag_touching = false;
+ set_fixed_process(false);
+ } else {
- drag_touching_deaccel = true;
- }
+ drag_touching_deaccel = true;
}
}
+ }
+ }
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- const InputEventMouseMotion &mm = p_gui_input.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_gui_input;
- if (drag_touching && !drag_touching_deaccel) {
+ if (mm.is_valid()) {
- Vector2 motion = Vector2(mm.relative_x, mm.relative_y);
- drag_accum -= motion;
- Vector2 diff = drag_from + drag_accum;
+ if (drag_touching && !drag_touching_deaccel) {
- if (scroll_h)
- h_scroll->set_value(diff.x);
- else
- drag_accum.x = 0;
- if (scroll_v)
- v_scroll->set_value(diff.y);
- else
- drag_accum.y = 0;
- time_since_motion = 0;
- }
+ Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y);
+ drag_accum -= motion;
+ Vector2 diff = drag_from + drag_accum;
- } break;
+ if (scroll_h)
+ h_scroll->set_value(diff.x);
+ else
+ drag_accum.x = 0;
+ if (scroll_v)
+ v_scroll->set_value(diff.y);
+ else
+ drag_accum.y = 0;
+ time_since_motion = 0;
+ }
}
}
diff --git a/scene/gui/scroll_container.h b/scene/gui/scroll_container.h
index bbc6d829ef..e5df3e5e1c 100644
--- a/scene/gui/scroll_container.h
+++ b/scene/gui/scroll_container.h
@@ -64,7 +64,7 @@ class ScrollContainer : public Container {
protected:
Size2 get_minimum_size() const;
- void _gui_input(const InputEvent &p_gui_input);
+ void _gui_input(const Ref<InputEvent> &p_gui_input);
void _notification(int p_what);
void _scroll_moved(float);
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index ae52d6d452..ae2bf0999e 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -37,16 +37,17 @@ Size2 Slider::get_minimum_size() const {
return ms;
}
-void Slider::_gui_input(InputEvent p_event) {
+void Slider::_gui_input(Ref<InputEvent> p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_event;
- InputEventMouseButton &mb = p_event.mouse_button;
- if (mb.button_index == BUTTON_LEFT) {
+ if (mb.is_valid()) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
Ref<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber");
- grab.pos = orientation == VERTICAL ? mb.y : mb.x;
+ grab.pos = orientation == VERTICAL ? mb->get_pos().y : mb->get_pos().x;
+
double grab_width = (double)grabber->get_size().width;
double grab_height = (double)grabber->get_size().height;
double max = orientation == VERTICAL ? get_size().height - grab_height : get_size().width - grab_width;
@@ -59,20 +60,22 @@ void Slider::_gui_input(InputEvent p_event) {
} else {
grab.active = false;
}
- } else if (mb.pressed && mb.button_index == BUTTON_WHEEL_UP) {
+ } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
set_value(get_value() + get_step());
- } else if (mb.pressed && mb.button_index == BUTTON_WHEEL_DOWN) {
+ } else if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_DOWN) {
set_value(get_value() - get_step());
}
+ }
- } else if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
+ if (mm.is_valid()) {
if (grab.active) {
Size2i size = get_size();
Ref<Texture> grabber = get_icon("grabber");
- float motion = (orientation == VERTICAL ? p_event.mouse_motion.y : p_event.mouse_motion.x) - grab.pos;
+ float motion = (orientation == VERTICAL ? mm->get_pos().y : mm->get_pos().x) - grab.pos;
if (orientation == VERTICAL)
motion = -motion;
float areasize = orientation == VERTICAL ? size.height - grabber->get_size().height : size.width - grabber->get_size().width;
@@ -81,42 +84,44 @@ void Slider::_gui_input(InputEvent p_event) {
float umotion = motion / float(areasize);
set_as_ratio(grab.uvalue + umotion);
}
- } else {
+ }
- if (p_event.is_action("ui_left") && p_event.is_pressed()) {
+ if (!mm.is_valid() && !mb.is_valid()) {
+
+ if (p_event->is_action("ui_left") && p_event->is_pressed()) {
if (orientation != HORIZONTAL)
return;
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event.is_action("ui_right") && p_event.is_pressed()) {
+ } else if (p_event->is_action("ui_right") && p_event->is_pressed()) {
if (orientation != HORIZONTAL)
return;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event.is_action("ui_up") && p_event.is_pressed()) {
+ } else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
if (orientation != VERTICAL)
return;
set_value(get_value() + (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event.is_action("ui_down") && p_event.is_pressed()) {
+ } else if (p_event->is_action("ui_down") && p_event->is_pressed()) {
if (orientation != VERTICAL)
return;
set_value(get_value() - (custom_step >= 0 ? custom_step : get_step()));
accept_event();
- } else if (p_event.type == InputEvent::KEY) {
+ } else {
- const InputEventKey &k = p_event.key;
+ Ref<InputEventKey> k = p_event;
- if (!k.pressed)
+ if (!k.is_valid() || !k->is_pressed())
return;
- switch (k.scancode) {
+ switch (k->get_scancode()) {
case KEY_HOME: {
@@ -129,7 +134,7 @@ void Slider::_gui_input(InputEvent p_event) {
accept_event();
} break;
- };
+ }
}
}
}
diff --git a/scene/gui/slider.h b/scene/gui/slider.h
index 61ad76e31e..7194484058 100644
--- a/scene/gui/slider.h
+++ b/scene/gui/slider.h
@@ -48,7 +48,7 @@ class Slider : public Range {
float custom_step;
protected:
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
static void _bind_methods();
bool ticks_on_borders;
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 77bfd3edf7..2eb2028391 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -65,7 +65,7 @@ LineEdit *SpinBox::get_line_edit() {
return line_edit;
}
-void SpinBox::_line_edit_input(const InputEvent &p_event) {
+void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
}
void SpinBox::_range_click_timeout() {
@@ -86,17 +86,19 @@ void SpinBox::_range_click_timeout() {
}
}
-void SpinBox::_gui_input(const InputEvent &p_event) {
+void SpinBox::_gui_input(const Ref<InputEvent> &p_event) {
if (!is_editable()) {
return;
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed) {
- const InputEventMouseButton &mb = p_event.mouse_button;
- bool up = mb.y < (get_size().height / 2);
+ Ref<InputEventMouseButton> mb = p_event;
- switch (mb.button_index) {
+ if (mb.is_valid() && mb->is_pressed()) {
+
+ bool up = mb->get_pos().y < (get_size().height / 2);
+
+ switch (mb->get_button_index()) {
case BUTTON_LEFT: {
@@ -116,28 +118,28 @@ void SpinBox::_gui_input(const InputEvent &p_event) {
case BUTTON_WHEEL_UP: {
if (line_edit->has_focus()) {
- set_value(get_value() + get_step() * mb.factor);
+ set_value(get_value() + get_step() * mb->get_factor());
accept_event();
}
} break;
case BUTTON_WHEEL_DOWN: {
if (line_edit->has_focus()) {
- set_value(get_value() - get_step() * mb.factor);
+ set_value(get_value() - get_step() * mb->get_factor());
accept_event();
}
} break;
}
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == 1) {
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == 1) {
//set_default_cursor_shape(CURSOR_VSIZE);
- Vector2 cpos = Vector2(p_event.mouse_button.x, p_event.mouse_button.y);
+ Vector2 cpos = Vector2(mb->get_pos().x, mb->get_pos().y);
drag.mouse_pos = cpos;
}
- if (p_event.type == InputEvent::MOUSE_BUTTON && !p_event.mouse_button.pressed && p_event.mouse_button.button_index == 1) {
+ if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == 1) {
//set_default_cursor_shape(CURSOR_ARROW);
range_click_timer->stop();
@@ -149,9 +151,12 @@ void SpinBox::_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_MOTION && p_event.mouse_button.button_mask & 1) {
+ Ref<InputEventMouseMotion> mm = p_event;
+
+ if (mm.is_valid() && mm->get_button_mask() & 1) {
+
+ Vector2 cpos = mm->get_pos();
- Vector2 cpos = Vector2(p_event.mouse_motion.x, p_event.mouse_motion.y);
if (drag.enabled) {
float diff_y = drag.mouse_pos.y - cpos.y;
diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h
index 338ae875f0..683ed0c344 100644
--- a/scene/gui/spin_box.h
+++ b/scene/gui/spin_box.h
@@ -49,7 +49,7 @@ class SpinBox : public Range {
String prefix;
String suffix;
- void _line_edit_input(const InputEvent &p_event);
+ void _line_edit_input(const Ref<InputEvent> &p_event);
struct Drag {
float base_val;
@@ -62,7 +62,7 @@ class SpinBox : public Range {
void _line_edit_focus_exit();
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index df24fa84d8..91fd18e2ed 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -270,32 +270,32 @@ void SplitContainer::_notification(int p_what) {
}
}
-void SplitContainer::_gui_input(const InputEvent &p_event) {
+void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
if (collapsed || !_getch(0) || !_getch(1) || dragger_visibility != DRAGGER_VISIBLE)
return;
- if (p_event.type == InputEvent::MOUSE_BUTTON) {
+ Ref<InputEventMouseButton> mb = p_event;
- const InputEventMouseButton &mb = p_event.mouse_button;
+ if (mb.is_valid()) {
- if (mb.button_index == BUTTON_LEFT) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- if (mb.pressed) {
+ if (mb->is_pressed()) {
int sep = get_constant("separation");
if (vertical) {
- if (mb.y > middle_sep && mb.y < middle_sep + sep) {
+ if (mb->get_pos().y > middle_sep && mb->get_pos().y < middle_sep + sep) {
dragging = true;
- drag_from = mb.y;
+ drag_from = mb->get_pos().y;
drag_ofs = expand_ofs;
}
} else {
- if (mb.x > middle_sep && mb.x < middle_sep + sep) {
+ if (mb->get_pos().x > middle_sep && mb->get_pos().x < middle_sep + sep) {
dragging = true;
- drag_from = mb.x;
+ drag_from = mb->get_pos().x;
drag_ofs = expand_ofs;
}
}
@@ -306,13 +306,13 @@ void SplitContainer::_gui_input(const InputEvent &p_event) {
}
}
- if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
- const InputEventMouseMotion &mm = p_event.mouse_motion;
+ if (mm.is_valid()) {
if (dragging) {
- expand_ofs = drag_ofs + ((vertical ? mm.y : mm.x) - drag_from);
+ expand_ofs = drag_ofs + ((vertical ? mm->get_pos().y : mm->get_pos().x) - drag_from);
queue_sort();
emit_signal("dragged", get_split_offset());
}
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index 12722c9f95..94b80cf279 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -59,7 +59,7 @@ private:
void _resort();
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index 0c7a58dc16..6bbfa1aeb0 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -63,11 +63,13 @@ int TabContainer::_get_top_margin() const {
return tab_height + content_height;
}
-void TabContainer::_gui_input(const InputEvent &p_event) {
+void TabContainer::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_BUTTON && p_event.mouse_button.pressed && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
- Point2 pos(p_event.mouse_button.x, p_event.mouse_button.y);
+ if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
+
+ Point2 pos(mb->get_pos().x, mb->get_pos().y);
Size2 size = get_size();
// Click must be on tabs in the tab header area.
@@ -662,4 +664,4 @@ TabContainer::TabContainer() {
align = ALIGN_CENTER;
tabs_visible = true;
popup = NULL;
-} \ No newline at end of file
+}
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 87a99c82b8..1105c6b298 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -63,7 +63,7 @@ private:
protected:
void _child_renamed_callback();
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
virtual void add_child_notify(Node *p_child);
virtual void remove_child_notify(Node *p_child);
diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp
index 797082f17c..d94c33e408 100644
--- a/scene/gui/tabs.cpp
+++ b/scene/gui/tabs.cpp
@@ -79,11 +79,13 @@ Size2 Tabs::get_minimum_size() const {
return ms;
}
-void Tabs::_gui_input(const InputEvent &p_event) {
+void Tabs::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event.type == InputEvent::MOUSE_MOTION) {
+ Ref<InputEventMouseMotion> mm = p_event;
- Point2 pos(p_event.mouse_motion.x, p_event.mouse_motion.y);
+ if (mm.is_valid()) {
+
+ Point2 pos = mm->get_pos();
highlight_arrow = -1;
if (buttons_visible) {
@@ -130,9 +132,11 @@ void Tabs::_gui_input(const InputEvent &p_event) {
return;
}
- if (rb_pressing && p_event.type == InputEvent::MOUSE_BUTTON &&
- !p_event.mouse_button.pressed &&
- p_event.mouse_button.button_index == BUTTON_LEFT) {
+ Ref<InputEventMouseButton> mb = p_event;
+
+ if (rb_pressing && mb.is_valid() &&
+ !mb->is_pressed() &&
+ mb->get_button_index() == BUTTON_LEFT) {
if (rb_hover != -1) {
//pressed
@@ -143,9 +147,9 @@ void Tabs::_gui_input(const InputEvent &p_event) {
update();
}
- if (cb_pressing && p_event.type == InputEvent::MOUSE_BUTTON &&
- !p_event.mouse_button.pressed &&
- p_event.mouse_button.button_index == BUTTON_LEFT) {
+ if (cb_pressing && mb.is_valid() &&
+ !mb->is_pressed() &&
+ mb->get_button_index() == BUTTON_LEFT) {
if (cb_hover != -1) {
//pressed
@@ -156,12 +160,12 @@ void Tabs::_gui_input(const InputEvent &p_event) {
update();
}
- if (p_event.type == InputEvent::MOUSE_BUTTON &&
- p_event.mouse_button.pressed &&
- p_event.mouse_button.button_index == BUTTON_LEFT) {
+ if (mb.is_valid() &&
+ mb->is_pressed() &&
+ mb->get_button_index() == BUTTON_LEFT) {
// clicks
- Point2 pos(p_event.mouse_button.x, p_event.mouse_button.y);
+ Point2 pos(mb->get_pos().x, mb->get_pos().y);
if (buttons_visible) {
diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h
index 131526f298..61b97d2dff 100644
--- a/scene/gui/tabs.h
+++ b/scene/gui/tabs.h
@@ -90,7 +90,7 @@ private:
void _ensure_no_over_offset();
protected:
- void _gui_input(const InputEvent &p_event);
+ void _gui_input(const Ref<InputEvent> &p_event);
void _notification(int p_what);
static void _bind_methods();
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index fb986cfb97..4989a3d863 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1440,1271 +1440,1266 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
r_col = col;
}
-void TextEdit::_gui_input(const InputEvent &p_gui_input) {
+void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
- switch (p_gui_input.type) {
+ Ref<InputEventMouseButton> mb = p_gui_input;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
+ if (completion_active && completion_rect.has_point(mb->get_pos())) {
- const InputEventMouseButton &mb = p_gui_input.mouse_button;
-
- if (completion_active && completion_rect.has_point(Point2(mb.x, mb.y))) {
-
- if (!mb.pressed)
- return;
+ if (!mb->is_pressed())
+ return;
- if (mb.button_index == BUTTON_WHEEL_UP) {
- if (completion_index > 0) {
- completion_index--;
- completion_current = completion_options[completion_index];
- update();
- }
+ if (mb->get_button_index() == BUTTON_WHEEL_UP) {
+ if (completion_index > 0) {
+ completion_index--;
+ completion_current = completion_options[completion_index];
+ update();
}
- if (mb.button_index == BUTTON_WHEEL_DOWN) {
+ }
+ if (mb->get_button_index() == BUTTON_WHEEL_DOWN) {
- if (completion_index < completion_options.size() - 1) {
- completion_index++;
- completion_current = completion_options[completion_index];
- update();
- }
+ if (completion_index < completion_options.size() - 1) {
+ completion_index++;
+ completion_current = completion_options[completion_index];
+ update();
}
+ }
- if (mb.button_index == BUTTON_LEFT) {
+ if (mb->get_button_index() == BUTTON_LEFT) {
- completion_index = CLAMP(completion_line_ofs + (mb.y - completion_rect.pos.y) / get_row_height(), 0, completion_options.size() - 1);
+ completion_index = CLAMP(completion_line_ofs + (mb->get_pos().y - completion_rect.pos.y) / get_row_height(), 0, completion_options.size() - 1);
- completion_current = completion_options[completion_index];
- update();
- if (mb.doubleclick)
- _confirm_completion();
- }
- return;
- } else {
- _cancel_completion();
- _cancel_code_hint();
+ completion_current = completion_options[completion_index];
+ update();
+ if (mb->is_doubleclick())
+ _confirm_completion();
}
+ return;
+ } else {
+ _cancel_completion();
+ _cancel_code_hint();
+ }
- if (mb.pressed) {
+ if (mb->is_pressed()) {
- if (mb.button_index == BUTTON_WHEEL_UP && !mb.mod.command) {
- v_scroll->set_value(v_scroll->get_value() - (3 * mb.factor));
- }
- if (mb.button_index == BUTTON_WHEEL_DOWN && !mb.mod.command) {
- v_scroll->set_value(v_scroll->get_value() + (3 * mb.factor));
- }
- if (mb.button_index == BUTTON_WHEEL_LEFT) {
- h_scroll->set_value(h_scroll->get_value() - (100 * mb.factor));
- }
- if (mb.button_index == BUTTON_WHEEL_RIGHT) {
- h_scroll->set_value(h_scroll->get_value() + (100 * mb.factor));
- }
- if (mb.button_index == BUTTON_LEFT) {
+ if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
+ v_scroll->set_value(v_scroll->get_value() - (3 * mb->get_factor()));
+ }
+ if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
+ v_scroll->set_value(v_scroll->get_value() + (3 * mb->get_factor()));
+ }
+ if (mb->get_button_index() == BUTTON_WHEEL_LEFT) {
+ h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
+ }
+ if (mb->get_button_index() == BUTTON_WHEEL_RIGHT) {
+ h_scroll->set_value(h_scroll->get_value() + (100 * mb->get_factor()));
+ }
+ if (mb->get_button_index() == BUTTON_LEFT) {
- _reset_caret_blink_timer();
+ _reset_caret_blink_timer();
- int row, col;
- _get_mouse_pos(Point2i(mb.x, mb.y), row, col);
+ int row, col;
+ _get_mouse_pos(Point2i(mb->get_pos().x, mb->get_pos().y), row, col);
- if (mb.mod.command && highlighted_word != String()) {
+ if (mb->get_command() && highlighted_word != String()) {
- emit_signal("symbol_lookup", highlighted_word, row, col);
+ emit_signal("symbol_lookup", highlighted_word, row, col);
+ return;
+ }
+
+ // toggle breakpoint on gutter click
+ if (draw_breakpoint_gutter) {
+ int gutter = cache.style_normal->get_margin(MARGIN_LEFT);
+ if (mb->get_pos().x > gutter && mb->get_pos().x <= gutter + cache.breakpoint_gutter_width + 3) {
+ set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row));
+ emit_signal("breakpoint_toggled", row);
return;
}
+ }
- // toggle breakpoint on gutter click
- if (draw_breakpoint_gutter) {
- int gutter = cache.style_normal->get_margin(MARGIN_LEFT);
- if (mb.x > gutter && mb.x <= gutter + cache.breakpoint_gutter_width + 3) {
- set_line_as_breakpoint(row, !is_line_set_as_breakpoint(row));
- emit_signal("breakpoint_toggled", row);
- return;
- }
- }
+ int prev_col = cursor.column;
+ int prev_line = cursor.line;
- int prev_col = cursor.column;
- int prev_line = cursor.line;
+ cursor_set_line(row);
+ cursor_set_column(col);
- cursor_set_line(row);
- cursor_set_column(col);
+ if (mb->get_shift() && (cursor.column != prev_col || cursor.line != prev_line)) {
- if (mb.mod.shift && (cursor.column != prev_col || cursor.line != prev_line)) {
+ if (!selection.active) {
+ selection.active = true;
+ selection.selecting_mode = Selection::MODE_POINTER;
+ selection.from_column = prev_col;
+ selection.from_line = prev_line;
+ selection.to_column = cursor.column;
+ selection.to_line = cursor.line;
+
+ if (selection.from_line > selection.to_line || (selection.from_line == selection.to_line && selection.from_column > selection.to_column)) {
+ SWAP(selection.from_column, selection.to_column);
+ SWAP(selection.from_line, selection.to_line);
+ selection.shiftclick_left = false;
+ } else {
+ selection.shiftclick_left = true;
+ }
+ selection.selecting_line = prev_line;
+ selection.selecting_column = prev_col;
+ update();
+ } else {
- if (!selection.active) {
- selection.active = true;
- selection.selecting_mode = Selection::MODE_POINTER;
- selection.from_column = prev_col;
- selection.from_line = prev_line;
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
- if (selection.from_line > selection.to_line || (selection.from_line == selection.to_line && selection.from_column > selection.to_column)) {
+ if (selection.shiftclick_left) {
SWAP(selection.from_column, selection.to_column);
SWAP(selection.from_line, selection.to_line);
- selection.shiftclick_left = false;
- } else {
- selection.shiftclick_left = true;
+ selection.shiftclick_left = !selection.shiftclick_left;
}
- selection.selecting_line = prev_line;
- selection.selecting_column = prev_col;
- update();
- } else {
+ selection.from_column = cursor.column;
+ selection.from_line = cursor.line;
- if (cursor.line < selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column < selection.selecting_column)) {
-
- if (selection.shiftclick_left) {
- SWAP(selection.from_column, selection.to_column);
- SWAP(selection.from_line, selection.to_line);
- selection.shiftclick_left = !selection.shiftclick_left;
- }
- selection.from_column = cursor.column;
- selection.from_line = cursor.line;
-
- } else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
-
- if (!selection.shiftclick_left) {
- SWAP(selection.from_column, selection.to_column);
- SWAP(selection.from_line, selection.to_line);
- selection.shiftclick_left = !selection.shiftclick_left;
- }
- selection.to_column = cursor.column;
- selection.to_line = cursor.line;
+ } else if (cursor.line > selection.selecting_line || (cursor.line == selection.selecting_line && cursor.column > selection.selecting_column)) {
- } else {
- selection.active = false;
+ if (!selection.shiftclick_left) {
+ SWAP(selection.from_column, selection.to_column);
+ SWAP(selection.from_line, selection.to_line);
+ selection.shiftclick_left = !selection.shiftclick_left;
}
+ selection.to_column = cursor.column;
+ selection.to_line = cursor.line;
- update();
+ } else {
+ selection.active = false;
}
- } else {
-
- //if sel active and dblick last time < something
-
- //else
- selection.active = false;
- selection.selecting_mode = Selection::MODE_POINTER;
- selection.selecting_line = row;
- selection.selecting_column = col;
+ update();
}
- if (!mb.doubleclick && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) {
- //tripleclick select line
- select(cursor.line, 0, cursor.line, text[cursor.line].length());
- selection.selecting_column = 0;
- last_dblclk = 0;
+ } else {
- } else if (mb.doubleclick && text[cursor.line].length()) {
+ //if sel active and dblick last time < something
- //doubleclick select world
- String s = text[cursor.line];
- int beg = CLAMP(cursor.column, 0, s.length());
- int end = beg;
+ //else
+ selection.active = false;
+ selection.selecting_mode = Selection::MODE_POINTER;
+ selection.selecting_line = row;
+ selection.selecting_column = col;
+ }
- if (s[beg] > 32 || beg == s.length()) {
+ if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) {
+ //tripleclick select line
+ select(cursor.line, 0, cursor.line, text[cursor.line].length());
+ selection.selecting_column = 0;
+ last_dblclk = 0;
- bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
+ } else if (mb->is_doubleclick() && text[cursor.line].length()) {
- while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
- beg--;
- }
- while (end < s.length() && s[end + 1] > 32 && (symbol == _is_symbol(s[end + 1]))) {
- end++;
- }
+ //doubleclick select world
+ String s = text[cursor.line];
+ int beg = CLAMP(cursor.column, 0, s.length());
+ int end = beg;
- if (end < s.length())
- end += 1;
+ if (s[beg] > 32 || beg == s.length()) {
- select(cursor.line, beg, cursor.line, end);
+ bool symbol = beg < s.length() && _is_symbol(s[beg]); //not sure if right but most editors behave like this
- selection.selecting_column = beg;
+ while (beg > 0 && s[beg - 1] > 32 && (symbol == _is_symbol(s[beg - 1]))) {
+ beg--;
+ }
+ while (end < s.length() && s[end + 1] > 32 && (symbol == _is_symbol(s[end + 1]))) {
+ end++;
}
- last_dblclk = OS::get_singleton()->get_ticks_msec();
- }
+ if (end < s.length())
+ end += 1;
- update();
- }
+ select(cursor.line, beg, cursor.line, end);
- if (mb.button_index == BUTTON_RIGHT && context_menu_enabled) {
+ selection.selecting_column = beg;
+ }
- menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
- menu->set_size(Vector2(1, 1));
- menu->popup();
- grab_focus();
+ last_dblclk = OS::get_singleton()->get_ticks_msec();
}
- } else {
- if (mb.button_index == BUTTON_LEFT)
- click_select_held->stop();
+ update();
+ }
+
+ if (mb->get_button_index() == BUTTON_RIGHT && context_menu_enabled) {
- // notify to show soft keyboard
- notification(NOTIFICATION_FOCUS_ENTER);
+ menu->set_position(get_global_transform().xform(get_local_mouse_pos()));
+ menu->set_size(Vector2(1, 1));
+ menu->popup();
+ grab_focus();
}
+ } else {
- } break;
- case InputEvent::MOUSE_MOTION: {
+ if (mb->get_button_index() == BUTTON_LEFT)
+ click_select_held->stop();
+
+ // notify to show soft keyboard
+ notification(NOTIFICATION_FOCUS_ENTER);
+ }
+ }
- const InputEventMouseMotion &mm = p_gui_input.mouse_motion;
+ Ref<InputEventMouseMotion> mm = p_gui_input;
- if (select_identifiers_enabled) {
- if (mm.mod.command && mm.button_mask == 0) {
+ if (mm.is_valid()) {
- String new_word = get_word_at_pos(Vector2(mm.x, mm.y));
- if (new_word != highlighted_word) {
- highlighted_word = new_word;
- update();
- }
- } else {
- if (highlighted_word != String()) {
- highlighted_word = String();
- update();
- }
+ if (select_identifiers_enabled) {
+ if (mm->get_command() && mm->get_button_mask() == 0) {
+
+ String new_word = get_word_at_pos(mm->get_pos());
+ if (new_word != highlighted_word) {
+ highlighted_word = new_word;
+ update();
+ }
+ } else {
+ if (highlighted_word != String()) {
+ highlighted_word = String();
+ update();
}
}
+ }
- if (mm.button_mask & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { //ignore if dragging
+ if (mm->get_button_mask() & BUTTON_MASK_LEFT && get_viewport()->gui_get_drag_data() == Variant()) { //ignore if dragging
- if (selection.selecting_mode != Selection::MODE_NONE) {
+ if (selection.selecting_mode != Selection::MODE_NONE) {
- _reset_caret_blink_timer();
+ _reset_caret_blink_timer();
- int row, col;
- _get_mouse_pos(Point2i(mm.x, mm.y), row, col);
+ int row, col;
+ _get_mouse_pos(mm->get_pos(), row, col);
- select(selection.selecting_line, selection.selecting_column, row, col);
+ select(selection.selecting_line, selection.selecting_column, row, col);
- cursor_set_line(row);
- cursor_set_column(col);
- update();
+ cursor_set_line(row);
+ cursor_set_column(col);
+ update();
- click_select_held->start();
- }
+ click_select_held->start();
}
+ }
+ }
- } break;
+ Ref<InputEventKey> k = p_gui_input;
- case InputEvent::KEY: {
+ if (k.is_valid()) {
- InputEventKey k = p_gui_input.key;
+ k = k->duplicate(); //it will be modified later on
#ifdef OSX_ENABLED
- if (k.scancode == KEY_META) {
+ if (k->get_scancode() == KEY_META) {
#else
- if (k.scancode == KEY_CONTROL) {
+ if (k->get_scancode() == KEY_CONTROL) {
#endif
- if (select_identifiers_enabled) {
+ if (select_identifiers_enabled) {
- if (k.pressed) {
+ if (k->is_pressed()) {
- highlighted_word = get_word_at_pos(get_local_mouse_pos());
- update();
+ highlighted_word = get_word_at_pos(get_local_mouse_pos());
+ update();
- } else {
- highlighted_word = String();
- update();
- }
+ } else {
+ highlighted_word = String();
+ update();
}
}
+ }
- if (!k.pressed)
- return;
-
- if (completion_active) {
- if (readonly)
- break;
-
- bool valid = true;
- if (k.mod.command || k.mod.meta)
- valid = false;
-
- if (valid) {
-
- if (!k.mod.alt) {
- if (k.scancode == KEY_UP) {
+ if (!k->is_pressed())
+ return;
- if (completion_index > 0) {
- completion_index--;
- completion_current = completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
+ if (completion_active) {
+ if (readonly)
+ return;
- if (k.scancode == KEY_DOWN) {
+ bool valid = true;
+ if (k->get_command() || k->get_metakey())
+ valid = false;
- if (completion_index < completion_options.size() - 1) {
- completion_index++;
- completion_current = completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
+ if (valid) {
- if (k.scancode == KEY_PAGEUP) {
+ if (!k->get_alt()) {
+ if (k->get_scancode() == KEY_UP) {
- completion_index -= get_constant("completion_lines");
- if (completion_index < 0)
- completion_index = 0;
+ if (completion_index > 0) {
+ completion_index--;
completion_current = completion_options[completion_index];
update();
- accept_event();
- return;
}
+ accept_event();
+ return;
+ }
- if (k.scancode == KEY_PAGEDOWN) {
+ if (k->get_scancode() == KEY_DOWN) {
- completion_index += get_constant("completion_lines");
- if (completion_index >= completion_options.size())
- completion_index = completion_options.size() - 1;
+ if (completion_index < completion_options.size() - 1) {
+ completion_index++;
completion_current = completion_options[completion_index];
update();
- accept_event();
- return;
}
+ accept_event();
+ return;
+ }
- if (k.scancode == KEY_HOME && completion_index > 0) {
+ if (k->get_scancode() == KEY_PAGEUP) {
+ completion_index -= get_constant("completion_lines");
+ if (completion_index < 0)
completion_index = 0;
- completion_current = completion_options[completion_index];
- update();
- accept_event();
- return;
- }
+ completion_current = completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
- if (k.scancode == KEY_END && completion_index < completion_options.size() - 1) {
+ if (k->get_scancode() == KEY_PAGEDOWN) {
+ completion_index += get_constant("completion_lines");
+ if (completion_index >= completion_options.size())
completion_index = completion_options.size() - 1;
- completion_current = completion_options[completion_index];
- update();
- accept_event();
- return;
- }
-
- if (k.scancode == KEY_DOWN) {
+ completion_current = completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
- if (completion_index < completion_options.size() - 1) {
- completion_index++;
- completion_current = completion_options[completion_index];
- update();
- }
- accept_event();
- return;
- }
+ if (k->get_scancode() == KEY_HOME && completion_index > 0) {
- if (k.scancode == KEY_ENTER || k.scancode == KEY_RETURN || k.scancode == KEY_TAB) {
+ completion_index = 0;
+ completion_current = completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
- _confirm_completion();
- accept_event();
- return;
- }
+ if (k->get_scancode() == KEY_END && completion_index < completion_options.size() - 1) {
- if (k.scancode == KEY_BACKSPACE) {
+ completion_index = completion_options.size() - 1;
+ completion_current = completion_options[completion_index];
+ update();
+ accept_event();
+ return;
+ }
- _reset_caret_blink_timer();
+ if (k->get_scancode() == KEY_DOWN) {
- backspace_at_cursor();
- _update_completion_candidates();
- accept_event();
- return;
+ if (completion_index < completion_options.size() - 1) {
+ completion_index++;
+ completion_current = completion_options[completion_index];
+ update();
}
+ accept_event();
+ return;
+ }
- if (k.scancode == KEY_SHIFT) {
- accept_event();
- return;
- }
+ if (k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_RETURN || k->get_scancode() == KEY_TAB) {
+
+ _confirm_completion();
+ accept_event();
+ return;
}
- if (k.unicode > 32) {
+ if (k->get_scancode() == KEY_BACKSPACE) {
_reset_caret_blink_timer();
- const CharType chr[2] = { (CharType)k.unicode, 0 };
- if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
- _consume_pair_symbol(chr[0]);
- } else {
+ backspace_at_cursor();
+ _update_completion_candidates();
+ accept_event();
+ return;
+ }
- // remove the old character if in insert mode
- if (insert_mode) {
- begin_complex_operation();
+ if (k->get_scancode() == KEY_SHIFT) {
+ accept_event();
+ return;
+ }
+ }
- // make sure we don't try and remove empty space
- if (cursor.column < get_line(cursor.line).length()) {
- _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
- }
- }
+ if (k->get_unicode() > 32) {
- _insert_text_at_cursor(chr);
+ _reset_caret_blink_timer();
- if (insert_mode) {
- end_complex_operation();
+ const CharType chr[2] = { (CharType)k->get_unicode(), 0 };
+ if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
+ _consume_pair_symbol(chr[0]);
+ } else {
+
+ // remove the old character if in insert mode
+ if (insert_mode) {
+ begin_complex_operation();
+
+ // make sure we don't try and remove empty space
+ if (cursor.column < get_line(cursor.line).length()) {
+ _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
}
}
- _update_completion_candidates();
- accept_event();
- return;
+ _insert_text_at_cursor(chr);
+
+ if (insert_mode) {
+ end_complex_operation();
+ }
}
- }
+ _update_completion_candidates();
+ accept_event();
- _cancel_completion();
+ return;
+ }
}
- /* TEST CONTROL FIRST!! */
+ _cancel_completion();
+ }
- // some remaps for duplicate functions..
- if (k.mod.command && !k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode == KEY_INSERT) {
+ /* TEST CONTROL FIRST!! */
- k.scancode = KEY_C;
- }
- if (!k.mod.command && k.mod.shift && !k.mod.alt && !k.mod.meta && k.scancode == KEY_INSERT) {
+ // some remaps for duplicate functions..
+ if (k->get_command() && !k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) {
- k.scancode = KEY_V;
- k.mod.command = true;
- k.mod.shift = false;
- }
+ k->set_scancode(KEY_C);
+ }
+ if (!k->get_command() && k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) {
- if (!k.mod.command) {
- _reset_caret_blink_timer();
- }
+ k->set_scancode(KEY_V);
+ k->set_command(true);
+ k->set_shift(false);
+ }
- // save here for insert mode, just in case it is cleared in the following section
- bool had_selection = selection.active;
+ if (!k->get_command()) {
+ _reset_caret_blink_timer();
+ }
- // stuff to do when selection is active..
- if (selection.active) {
+ // save here for insert mode, just in case it is cleared in the following section
+ bool had_selection = selection.active;
- if (readonly)
- break;
+ // stuff to do when selection is active..
+ if (selection.active) {
- bool clear = false;
- bool unselect = false;
- bool dobreak = false;
+ if (readonly)
+ return;
- switch (k.scancode) {
+ bool clear = false;
+ bool unselect = false;
+ bool dobreak = false;
- case KEY_TAB: {
- if (k.mod.shift) {
- indent_selection_left();
- } else {
- indent_selection_right();
- }
- dobreak = true;
- accept_event();
- } break;
- case KEY_X:
- case KEY_C:
- //special keys often used with control, wait...
- clear = (!k.mod.command || k.mod.shift || k.mod.alt);
- break;
- case KEY_DELETE:
- if (!k.mod.shift) {
- accept_event();
- clear = true;
- dobreak = true;
- } else if (k.mod.command || k.mod.alt) {
- dobreak = true;
- }
- break;
- case KEY_BACKSPACE:
+ switch (k->get_scancode()) {
+
+ case KEY_TAB: {
+ if (k->get_shift()) {
+ indent_selection_left();
+ } else {
+ indent_selection_right();
+ }
+ dobreak = true;
+ accept_event();
+ } break;
+ case KEY_X:
+ case KEY_C:
+ //special keys often used with control, wait...
+ clear = (!k->get_command() || k->get_shift() || k->get_alt());
+ break;
+ case KEY_DELETE:
+ if (!k->get_shift()) {
accept_event();
clear = true;
dobreak = true;
+ } else if (k->get_command() || k->get_alt()) {
+ dobreak = true;
+ }
+ break;
+ case KEY_BACKSPACE:
+ accept_event();
+ clear = true;
+ dobreak = true;
+ break;
+ case KEY_LEFT:
+ case KEY_RIGHT:
+ case KEY_UP:
+ case KEY_DOWN:
+ case KEY_PAGEUP:
+ case KEY_PAGEDOWN:
+ case KEY_HOME:
+ case KEY_END:
+ // ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
+ if (k->get_command() || k->get_shift() || k->get_alt())
break;
- case KEY_LEFT:
- case KEY_RIGHT:
- case KEY_UP:
- case KEY_DOWN:
- case KEY_PAGEUP:
- case KEY_PAGEDOWN:
- case KEY_HOME:
- case KEY_END:
- // ignore arrows if any modifiers are held (shift = selecting, others may be used for editor hotkeys)
- if (k.mod.command || k.mod.shift || k.mod.alt)
- break;
- unselect = true;
- break;
+ unselect = true;
+ break;
- default:
- if (k.unicode >= 32 && !k.mod.command && !k.mod.alt && !k.mod.meta)
- clear = true;
- if (auto_brace_completion_enabled && _is_pair_left_symbol(k.unicode))
- clear = false;
- }
+ default:
+ if (k->get_unicode() >= 32 && !k->get_command() && !k->get_alt() && !k->get_metakey())
+ clear = true;
+ if (auto_brace_completion_enabled && _is_pair_left_symbol(k->get_unicode()))
+ clear = false;
+ }
- if (unselect) {
- selection.active = false;
- selection.selecting_mode = Selection::MODE_NONE;
- update();
- }
- if (clear) {
+ if (unselect) {
+ selection.active = false;
+ selection.selecting_mode = Selection::MODE_NONE;
+ update();
+ }
+ if (clear) {
- if (!dobreak) {
- begin_complex_operation();
- }
- selection.active = false;
- update();
- _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
- cursor_set_line(selection.from_line);
- cursor_set_column(selection.from_column);
- update();
+ if (!dobreak) {
+ begin_complex_operation();
}
- if (dobreak)
- break;
+ selection.active = false;
+ update();
+ _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column);
+ cursor_set_line(selection.from_line);
+ cursor_set_column(selection.from_column);
+ update();
}
+ if (dobreak)
+ return;
+ }
- selection.selecting_text = false;
+ selection.selecting_text = false;
- bool scancode_handled = true;
+ bool scancode_handled = true;
- // special scancode test...
+ // special scancode test...
- switch (k.scancode) {
+ switch (k->get_scancode()) {
- case KEY_ENTER:
- case KEY_RETURN: {
+ case KEY_ENTER:
+ case KEY_RETURN: {
- if (readonly)
- break;
+ if (readonly)
+ break;
- String ins = "\n";
+ String ins = "\n";
- //keep indentation
- int space_count = 0;
- for (int i = 0; i < text[cursor.line].length(); i++) {
- if (text[cursor.line][i] == '\t') {
+ //keep indentation
+ int space_count = 0;
+ for (int i = 0; i < text[cursor.line].length(); i++) {
+ if (text[cursor.line][i] == '\t') {
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
+ }
+ space_count = 0;
+ } else if (text[cursor.line][i] == ' ') {
+ space_count++;
+
+ if (space_count == indent_size) {
if (indent_using_spaces) {
ins += space_indent;
} else {
ins += "\t";
}
space_count = 0;
- } else if (text[cursor.line][i] == ' ') {
- space_count++;
-
- if (space_count == indent_size) {
- if (indent_using_spaces) {
- ins += space_indent;
- } else {
- ins += "\t";
- }
- space_count = 0;
- }
- } else {
- break;
}
+ } else {
+ break;
}
- if (auto_indent) {
- // indent once again if previous line will end with ':'
- // (i.e. colon precedes current cursor position)
- if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') {
- if (indent_using_spaces) {
- ins += space_indent;
- } else {
- ins += "\t";
- }
+ }
+ if (auto_indent) {
+ // indent once again if previous line will end with ':'
+ // (i.e. colon precedes current cursor position)
+ if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') {
+ if (indent_using_spaces) {
+ ins += space_indent;
+ } else {
+ ins += "\t";
}
}
+ }
- bool first_line = false;
- if (k.mod.command) {
- if (k.mod.shift) {
- if (cursor.line > 0) {
- cursor_set_line(cursor.line - 1);
- cursor_set_column(text[cursor.line].length());
- } else {
- cursor_set_column(0);
- first_line = true;
- }
- } else {
+ bool first_line = false;
+ if (k->get_command()) {
+ if (k->get_shift()) {
+ if (cursor.line > 0) {
+ cursor_set_line(cursor.line - 1);
cursor_set_column(text[cursor.line].length());
+ } else {
+ cursor_set_column(0);
+ first_line = true;
}
+ } else {
+ cursor_set_column(text[cursor.line].length());
}
+ }
- _insert_text_at_cursor(ins);
- _push_current_op();
+ _insert_text_at_cursor(ins);
+ _push_current_op();
- if (first_line) {
- cursor_set_line(0);
- }
+ if (first_line) {
+ cursor_set_line(0);
+ }
- } break;
- case KEY_ESCAPE: {
- if (completion_hint != "") {
- completion_hint = "";
- update();
- } else {
- scancode_handled = false;
- }
- } break;
- case KEY_TAB: {
- if (k.mod.command) break; // avoid tab when command
+ } break;
+ case KEY_ESCAPE: {
+ if (completion_hint != "") {
+ completion_hint = "";
+ update();
+ } else {
+ scancode_handled = false;
+ }
+ } break;
+ case KEY_TAB: {
+ if (k->get_command()) break; // avoid tab when command
- if (readonly)
- break;
+ if (readonly)
+ break;
- if (selection.active) {
+ if (selection.active) {
- } else {
- if (k.mod.shift) {
-
- //simple unindent
- int cc = cursor.column;
- if (cc > 0 && cc <= text[cursor.line].length()) {
- if (text[cursor.line][cursor.column - 1] == '\t') {
- backspace_at_cursor();
- } else {
- if (cursor.column - indent_size >= 0) {
-
- bool unindent = true;
- for (int i = 1; i <= indent_size; i++) {
- if (text[cursor.line][cursor.column - i] != ' ') {
- unindent = false;
- break;
- }
- }
+ } else {
+ if (k->get_shift()) {
- if (unindent) {
- _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
- cursor_set_column(cursor.column - indent_size);
+ //simple unindent
+ int cc = cursor.column;
+ if (cc > 0 && cc <= text[cursor.line].length()) {
+ if (text[cursor.line][cursor.column - 1] == '\t') {
+ backspace_at_cursor();
+ } else {
+ if (cursor.column - indent_size >= 0) {
+
+ bool unindent = true;
+ for (int i = 1; i <= indent_size; i++) {
+ if (text[cursor.line][cursor.column - i] != ' ') {
+ unindent = false;
+ break;
}
}
+
+ if (unindent) {
+ _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column);
+ cursor_set_column(cursor.column - indent_size);
+ }
}
}
+ }
+ } else {
+ //simple indent
+ if (indent_using_spaces) {
+ _insert_text_at_cursor(space_indent);
} else {
- //simple indent
- if (indent_using_spaces) {
- _insert_text_at_cursor(space_indent);
- } else {
- _insert_text_at_cursor("\t");
- }
+ _insert_text_at_cursor("\t");
}
}
+ }
- } break;
- case KEY_BACKSPACE: {
- if (readonly)
- break;
+ } break;
+ case KEY_BACKSPACE: {
+ if (readonly)
+ break;
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int line = cursor.line;
- int column = cursor.column;
-
- bool prev_char = false;
- bool only_whitespace = true;
-
- while (only_whitespace && line > 0) {
-
- while (column > 0) {
- CharType c = text[line][column - 1];
-
- if (c != '\t' && c != ' ') {
- only_whitespace = false;
- break;
- }
+ int line = cursor.line;
+ int column = cursor.column;
- column--;
- }
+ bool prev_char = false;
+ bool only_whitespace = true;
- if (only_whitespace) {
- line--;
- column = text[line].length();
- }
- }
+ while (only_whitespace && line > 0) {
while (column > 0) {
- bool ischar = _is_text_char(text[line][column - 1]);
+ CharType c = text[line][column - 1];
- if (prev_char && !ischar)
+ if (c != '\t' && c != ' ') {
+ only_whitespace = false;
break;
+ }
- prev_char = ischar;
column--;
}
- _remove_text(line, column, cursor.line, cursor.column);
+ if (only_whitespace) {
+ line--;
+ column = text[line].length();
+ }
+ }
- cursor_set_line(line);
- cursor_set_column(column);
+ while (column > 0) {
+ bool ischar = _is_text_char(text[line][column - 1]);
- } else {
- backspace_at_cursor();
- }
+ if (prev_char && !ischar)
+ break;
- } break;
- case KEY_KP_4: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
+ prev_char = ischar;
+ column--;
}
- // numlock disabled. fallthrough to key_left
+
+ _remove_text(line, column, cursor.line, cursor.column);
+
+ cursor_set_line(line);
+ cursor_set_column(column);
+
+ } else {
+ backspace_at_cursor();
}
- case KEY_LEFT: {
- if (k.mod.shift)
- _pre_shift_selection();
+ } break;
+ case KEY_KP_4: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
+ }
+ // numlock disabled. fallthrough to key_left
+ }
+ case KEY_LEFT: {
+
+ if (k->get_shift())
+ _pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ else
#else
- else if (!k.mod.alt)
+ else if (!k->get_alt())
#endif
- deselect();
+ deselect();
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- cursor_set_column(0);
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ cursor_set_column(0);
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor.column;
- while (cc > 0) {
+ bool prev_char = false;
+ int cc = cursor.column;
+ while (cc > 0) {
- bool ischar = _is_text_char(text[cursor.line][cc - 1]);
+ bool ischar = _is_text_char(text[cursor.line][cc - 1]);
- if (prev_char && !ischar)
- break;
+ if (prev_char && !ischar)
+ break;
- prev_char = ischar;
- cc--;
- }
+ prev_char = ischar;
+ cc--;
+ }
- cursor_set_column(cc);
+ cursor_set_column(cc);
- } else if (cursor.column == 0) {
+ } else if (cursor.column == 0) {
- if (cursor.line > 0) {
- cursor_set_line(cursor.line - 1);
- cursor_set_column(text[cursor.line].length());
- }
- } else {
- cursor_set_column(cursor_get_column() - 1);
+ if (cursor.line > 0) {
+ cursor_set_line(cursor.line - 1);
+ cursor_set_column(text[cursor.line].length());
}
+ } else {
+ cursor_set_column(cursor_get_column() - 1);
+ }
- if (k.mod.shift)
- _post_shift_selection();
+ if (k->get_shift())
+ _post_shift_selection();
- } break;
- case KEY_KP_6: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_right
+ } break;
+ case KEY_KP_6: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
- case KEY_RIGHT: {
+ // numlock disabled. fallthrough to key_right
+ }
+ case KEY_RIGHT: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
#ifdef APPLE_STYLE_KEYS
- else
+ else
#else
- else if (!k.mod.alt)
+ else if (!k->get_alt())
#endif
- deselect();
+ deselect();
#ifdef APPLE_STYLE_KEYS
- if (k.mod.command) {
- cursor_set_column(text[cursor.line].length());
- } else if (k.mod.alt) {
+ if (k->get_command()) {
+ cursor_set_column(text[cursor.line].length());
+ } else if (k->get_alt()) {
#else
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- bool prev_char = false;
- int cc = cursor.column;
- while (cc < text[cursor.line].length()) {
+ bool prev_char = false;
+ int cc = cursor.column;
+ while (cc < text[cursor.line].length()) {
- bool ischar = _is_text_char(text[cursor.line][cc]);
+ bool ischar = _is_text_char(text[cursor.line][cc]);
- if (prev_char && !ischar)
- break;
- prev_char = ischar;
- cc++;
- }
+ if (prev_char && !ischar)
+ break;
+ prev_char = ischar;
+ cc++;
+ }
- cursor_set_column(cc);
+ cursor_set_column(cc);
- } else if (cursor.column == text[cursor.line].length()) {
+ } else if (cursor.column == text[cursor.line].length()) {
- if (cursor.line < text.size() - 1) {
- cursor_set_line(cursor.line + 1);
- cursor_set_column(0);
- }
- } else {
- cursor_set_column(cursor_get_column() + 1);
+ if (cursor.line < text.size() - 1) {
+ cursor_set_line(cursor.line + 1);
+ cursor_set_column(0);
}
+ } else {
+ cursor_set_column(cursor_get_column() + 1);
+ }
- if (k.mod.shift)
- _post_shift_selection();
+ if (k->get_shift())
+ _post_shift_selection();
- } break;
- case KEY_KP_8: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_up
+ } break;
+ case KEY_KP_8: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
- case KEY_UP: {
+ // numlock disabled. fallthrough to key_up
+ }
+ case KEY_UP: {
- if (k.mod.shift)
- _pre_shift_selection();
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ if (k->get_shift())
+ _pre_shift_selection();
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
#ifndef APPLE_STYLE_KEYS
- if (k.mod.command) {
- _scroll_lines_up();
- break;
- }
+ if (k->get_command()) {
+ _scroll_lines_up();
+ break;
+ }
#else
- if (k.mod.command && k.mod.alt) {
- _scroll_lines_up();
- break;
- }
+ if (k->get_command() && k->get_alt()) {
+ _scroll_lines_up();
+ break;
+ }
- if (k.mod.command)
- cursor_set_line(0);
- else
+ if (k->get_command())
+ cursor_set_line(0);
+ else
#endif
- cursor_set_line(cursor_get_line() - 1);
+ cursor_set_line(cursor_get_line() - 1);
- if (k.mod.shift)
- _post_shift_selection();
- _cancel_code_hint();
+ if (k->get_shift())
+ _post_shift_selection();
+ _cancel_code_hint();
- } break;
- case KEY_KP_2: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_down
+ } break;
+ case KEY_KP_2: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
- case KEY_DOWN: {
+ // numlock disabled. fallthrough to key_down
+ }
+ case KEY_DOWN: {
- if (k.mod.shift)
- _pre_shift_selection();
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ if (k->get_shift())
+ _pre_shift_selection();
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
#ifndef APPLE_STYLE_KEYS
- if (k.mod.command) {
- _scroll_lines_down();
- break;
- }
+ if (k->get_command()) {
+ _scroll_lines_down();
+ break;
+ }
#else
- if (k.mod.command && k.mod.alt) {
- _scroll_lines_down();
- break;
- }
+ if (k->get_command() && k->get_alt()) {
+ _scroll_lines_down();
+ break;
+ }
- if (k.mod.command)
- cursor_set_line(text.size() - 1);
- else
+ if (k->get_command())
+ cursor_set_line(text.size() - 1);
+ else
#endif
- cursor_set_line(cursor_get_line() + 1);
+ cursor_set_line(cursor_get_line() + 1);
- if (k.mod.shift)
- _post_shift_selection();
- _cancel_code_hint();
+ if (k->get_shift())
+ _post_shift_selection();
+ _cancel_code_hint();
- } break;
+ } break;
- case KEY_DELETE: {
+ case KEY_DELETE: {
- if (readonly)
- break;
+ if (readonly)
+ break;
- if (k.mod.shift && !k.mod.command && !k.mod.alt) {
- cut();
- break;
- }
+ if (k->get_shift() && !k->get_command() && !k->get_alt()) {
+ cut();
+ break;
+ }
- int curline_len = text[cursor.line].length();
+ int curline_len = text[cursor.line].length();
- if (cursor.line == text.size() - 1 && cursor.column == curline_len)
- break; //nothing to do
+ if (cursor.line == text.size() - 1 && cursor.column == curline_len)
+ break; //nothing to do
- int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
- int next_column;
+ int next_line = cursor.column < curline_len ? cursor.line : cursor.line + 1;
+ int next_column;
#ifdef APPLE_STYLE_KEYS
- if (k.mod.alt) {
+ if (k->get_alt()) {
#else
- if (k.mod.alt) {
- scancode_handled = false;
- break;
- } else if (k.mod.command) {
+ if (k->get_alt()) {
+ scancode_handled = false;
+ break;
+ } else if (k->get_command()) {
#endif
- int last_line = text.size() - 1;
+ int last_line = text.size() - 1;
- int line = cursor.line;
- int column = cursor.column;
+ int line = cursor.line;
+ int column = cursor.column;
- bool prev_char = false;
- bool only_whitespace = true;
+ bool prev_char = false;
+ bool only_whitespace = true;
- while (only_whitespace && line < last_line) {
+ while (only_whitespace && line < last_line) {
- while (column < text[line].length()) {
- CharType c = text[line][column];
-
- if (c != '\t' && c != ' ') {
- only_whitespace = false;
- break;
- }
+ while (column < text[line].length()) {
+ CharType c = text[line][column];
- column++;
+ if (c != '\t' && c != ' ') {
+ only_whitespace = false;
+ break;
}
- if (only_whitespace) {
- line++;
- column = 0;
- }
+ column++;
}
- while (column < text[line].length()) {
+ if (only_whitespace) {
+ line++;
+ column = 0;
+ }
+ }
- bool ischar = _is_text_char(text[line][column]);
+ while (column < text[line].length()) {
- if (prev_char && !ischar)
- break;
- prev_char = ischar;
- column++;
- }
+ bool ischar = _is_text_char(text[line][column]);
- next_line = line;
- next_column = column;
- } else {
- next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
+ if (prev_char && !ischar)
+ break;
+ prev_char = ischar;
+ column++;
}
- _remove_text(cursor.line, cursor.column, next_line, next_column);
- update();
+ next_line = line;
+ next_column = column;
+ } else {
+ next_column = cursor.column < curline_len ? (cursor.column + 1) : 0;
+ }
- } break;
- case KEY_KP_7: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_home
+ _remove_text(cursor.line, cursor.column, next_line, next_column);
+ update();
+
+ } break;
+ case KEY_KP_7: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
+ // numlock disabled. fallthrough to key_home
+ }
#ifdef APPLE_STYLE_KEYS
- case KEY_HOME: {
+ case KEY_HOME: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
- cursor_set_line(0);
+ cursor_set_line(0);
- if (k.mod.shift)
- _post_shift_selection();
- else if (k.mod.command || k.mod.control)
- deselect();
+ if (k->get_shift())
+ _post_shift_selection();
+ else if (k->get_command() || k->get_control())
+ deselect();
- } break;
+ } break;
#else
- case KEY_HOME: {
+ case KEY_HOME: {
- if (k.mod.shift)
- _pre_shift_selection();
-
- if (k.mod.command) {
- cursor_set_line(0);
- cursor_set_column(0);
- } else {
- // compute whitespace symbols seq length
- int current_line_whitespace_len = 0;
- while (current_line_whitespace_len < text[cursor.line].length()) {
- CharType c = text[cursor.line][current_line_whitespace_len];
- if (c != '\t' && c != ' ')
- break;
- current_line_whitespace_len++;
- }
+ if (k->get_shift())
+ _pre_shift_selection();
- if (cursor_get_column() == current_line_whitespace_len)
- cursor_set_column(0);
- else
- cursor_set_column(current_line_whitespace_len);
+ if (k->get_command()) {
+ cursor_set_line(0);
+ cursor_set_column(0);
+ } else {
+ // compute whitespace symbols seq length
+ int current_line_whitespace_len = 0;
+ while (current_line_whitespace_len < text[cursor.line].length()) {
+ CharType c = text[cursor.line][current_line_whitespace_len];
+ if (c != '\t' && c != ' ')
+ break;
+ current_line_whitespace_len++;
}
- if (k.mod.shift)
- _post_shift_selection();
- else if (k.mod.command || k.mod.control)
- deselect();
- _cancel_completion();
- completion_hint = "";
+ if (cursor_get_column() == current_line_whitespace_len)
+ cursor_set_column(0);
+ else
+ cursor_set_column(current_line_whitespace_len);
+ }
- } break;
+ if (k->get_shift())
+ _post_shift_selection();
+ else if (k->get_command() || k->get_control())
+ deselect();
+ _cancel_completion();
+ completion_hint = "";
+
+ } break;
#endif
- case KEY_KP_1: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_end
+ case KEY_KP_1: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
+ // numlock disabled. fallthrough to key_end
+ }
#ifdef APPLE_STYLE_KEYS
- case KEY_END: {
+ case KEY_END: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
- cursor_set_line(text.size() - 1);
+ cursor_set_line(text.size() - 1);
- if (k.mod.shift)
- _post_shift_selection();
- else if (k.mod.command || k.mod.control)
- deselect();
+ if (k->get_shift())
+ _post_shift_selection();
+ else if (k->get_command() || k->get_control())
+ deselect();
- } break;
+ } break;
#else
- case KEY_END: {
+ case KEY_END: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
- if (k.mod.command)
- cursor_set_line(text.size() - 1);
- cursor_set_column(text[cursor.line].length());
+ if (k->get_command())
+ cursor_set_line(text.size() - 1);
+ cursor_set_column(text[cursor.line].length());
- if (k.mod.shift)
- _post_shift_selection();
- else if (k.mod.command || k.mod.control)
- deselect();
+ if (k->get_shift())
+ _post_shift_selection();
+ else if (k->get_command() || k->get_control())
+ deselect();
- _cancel_completion();
- completion_hint = "";
+ _cancel_completion();
+ completion_hint = "";
- } break;
+ } break;
#endif
- case KEY_KP_9: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_pageup
+ case KEY_KP_9: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
- case KEY_PAGEUP: {
+ // numlock disabled. fallthrough to key_pageup
+ }
+ case KEY_PAGEUP: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
- cursor_set_line(cursor_get_line() - get_visible_rows());
+ cursor_set_line(cursor_get_line() - get_visible_rows());
- if (k.mod.shift)
- _post_shift_selection();
+ if (k->get_shift())
+ _post_shift_selection();
- _cancel_completion();
- completion_hint = "";
+ _cancel_completion();
+ completion_hint = "";
- } break;
- case KEY_KP_3: {
- if (k.unicode != 0) {
- scancode_handled = false;
- break;
- }
- // numlock disabled. fallthrough to key_pageup
+ } break;
+ case KEY_KP_3: {
+ if (k->get_unicode() != 0) {
+ scancode_handled = false;
+ break;
}
- case KEY_PAGEDOWN: {
+ // numlock disabled. fallthrough to key_pageup
+ }
+ case KEY_PAGEDOWN: {
- if (k.mod.shift)
- _pre_shift_selection();
+ if (k->get_shift())
+ _pre_shift_selection();
- cursor_set_line(cursor_get_line() + get_visible_rows());
+ cursor_set_line(cursor_get_line() + get_visible_rows());
- if (k.mod.shift)
- _post_shift_selection();
+ if (k->get_shift())
+ _post_shift_selection();
- _cancel_completion();
- completion_hint = "";
+ _cancel_completion();
+ completion_hint = "";
- } break;
- case KEY_A: {
+ } break;
+ case KEY_A: {
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ if (!k->get_command() || k->get_shift() || k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
- select_all();
+ select_all();
- } break;
- case KEY_X: {
- if (readonly) {
- break;
- }
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ } break;
+ case KEY_X: {
+ if (readonly) {
+ break;
+ }
+ if (!k->get_command() || k->get_shift() || k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
- cut();
+ cut();
- } break;
- case KEY_C: {
+ } break;
+ case KEY_C: {
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ if (!k->get_command() || k->get_shift() || k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
- copy();
+ copy();
- } break;
- case KEY_Z: {
+ } break;
+ case KEY_Z: {
- if (!k.mod.command) {
- scancode_handled = false;
- break;
- }
+ if (!k->get_command()) {
+ scancode_handled = false;
+ break;
+ }
- if (k.mod.shift)
- redo();
- else
- undo();
- } break;
- case KEY_V: {
- if (readonly) {
- break;
- }
- if (!k.mod.command || k.mod.shift || k.mod.alt) {
- scancode_handled = false;
- break;
- }
+ if (k->get_shift())
+ redo();
+ else
+ undo();
+ } break;
+ case KEY_V: {
+ if (readonly) {
+ break;
+ }
+ if (!k->get_command() || k->get_shift() || k->get_alt()) {
+ scancode_handled = false;
+ break;
+ }
- paste();
+ paste();
- } break;
- case KEY_SPACE: {
+ } break;
+ case KEY_SPACE: {
#ifdef OSX_ENABLED
- if (completion_enabled && k.mod.meta) { //cmd-space is spotlight shortcut in OSX
+ if (completion_enabled && k->get_metakey()) { //cmd-space is spotlight shortcut in OSX
#else
- if (completion_enabled && k.mod.command) {
+ if (completion_enabled && k->get_command()) {
#endif
- query_code_comple();
- scancode_handled = true;
- } else {
- scancode_handled = false;
- }
+ query_code_comple();
+ scancode_handled = true;
+ } else {
+ scancode_handled = false;
+ }
- } break;
+ } break;
- case KEY_U: {
- if (!k.mod.command || k.mod.shift) {
- scancode_handled = false;
- break;
- } else {
- if (selection.active) {
- int ini = selection.from_line;
- int end = selection.to_line;
- for (int i = ini; i <= end; i++) {
- if (text[i][0] == '#')
- _remove_text(i, 0, i, 1);
- }
- } else {
- if (text[cursor.line][0] == '#')
- _remove_text(cursor.line, 0, cursor.line, 1);
+ case KEY_U: {
+ if (!k->get_command() || k->get_shift()) {
+ scancode_handled = false;
+ break;
+ } else {
+ if (selection.active) {
+ int ini = selection.from_line;
+ int end = selection.to_line;
+ for (int i = ini; i <= end; i++) {
+ if (text[i][0] == '#')
+ _remove_text(i, 0, i, 1);
}
- update();
+ } else {
+ if (text[cursor.line][0] == '#')
+ _remove_text(cursor.line, 0, cursor.line, 1);
}
- } break;
+ update();
+ }
+ } break;
- default: {
+ default: {
- scancode_handled = false;
- } break;
- }
+ scancode_handled = false;
+ } break;
+ }
- if (scancode_handled)
- accept_event();
- /*
- if (!scancode_handled && !k.mod.command && !k.mod.alt) {
+ if (scancode_handled)
+ accept_event();
+ /*
+ if (!scancode_handled && !k->get_command() && !k->get_alt()) {
- if (k.unicode>=32) {
+ if (k->get_unicode()>=32) {
- if (readonly)
- break;
+ if (readonly)
+ break;
- accept_event();
- } else {
+ accept_event();
+ } else {
- break;
- }
- }
+ break;
+ }
+ }
*/
- if (k.scancode == KEY_INSERT) {
- set_insert_mode(!insert_mode);
- accept_event();
- return;
- }
-
- if (!scancode_handled && !k.mod.command) { //for german kbds
+ if (k->get_scancode() == KEY_INSERT) {
+ set_insert_mode(!insert_mode);
+ accept_event();
+ return;
+ }
- if (k.unicode >= 32) {
+ if (!scancode_handled && !k->get_command()) { //for german kbds
- if (readonly)
- break;
+ if (k->get_unicode() >= 32) {
- // remove the old character if in insert mode and no selection
- if (insert_mode && !had_selection) {
- begin_complex_operation();
-
- // make sure we don't try and remove empty space
- if (cursor.column < get_line(cursor.line).length()) {
- _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
- }
- }
+ if (readonly)
+ return;
- const CharType chr[2] = { (CharType)k.unicode, 0 };
+ // remove the old character if in insert mode and no selection
+ if (insert_mode && !had_selection) {
+ begin_complex_operation();
- if (completion_hint != "" && k.unicode == ')') {
- completion_hint = "";
- }
- if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
- _consume_pair_symbol(chr[0]);
- } else {
- _insert_text_at_cursor(chr);
+ // make sure we don't try and remove empty space
+ if (cursor.column < get_line(cursor.line).length()) {
+ _remove_text(cursor.line, cursor.column, cursor.line, cursor.column + 1);
}
+ }
- if (insert_mode && !had_selection) {
- end_complex_operation();
- }
+ const CharType chr[2] = { (CharType)k->get_unicode(), 0 };
- if (selection.active != had_selection) {
- end_complex_operation();
- }
- accept_event();
+ if (completion_hint != "" && k->get_unicode() == ')') {
+ completion_hint = "";
+ }
+ if (auto_brace_completion_enabled && _is_pair_symbol(chr[0])) {
+ _consume_pair_symbol(chr[0]);
} else {
+ _insert_text_at_cursor(chr);
+ }
- break;
+ if (insert_mode && !had_selection) {
+ end_complex_operation();
+ }
+
+ if (selection.active != had_selection) {
+ end_complex_operation();
}
+ accept_event();
+ } else {
}
+ }
- return;
- } break;
+ return;
}
}
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 905ea46bd7..f8f60d2b03 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -337,7 +337,7 @@ protected:
void _insert_text(int p_line, int p_column, const String &p_text, int *r_end_line = NULL, int *r_end_char = NULL);
void _remove_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column);
void _insert_text_at_cursor(const String &p_text);
- void _gui_input(const InputEvent &p_input);
+ void _gui_input(const Ref<InputEvent> &p_input);
void _notification(int p_what);
void _consume_pair_symbol(CharType ch);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index f77b160f57..9ada68f5dc 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1410,10 +1410,12 @@ void Tree::_range_click_timeout() {
}
click_handled = false;
- InputModifierState mod = InputModifierState(); // should be irrelevant..
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
+ ;
blocked++;
- propagate_mouse_event(pos + cache.offset, 0, 0, false, root, BUTTON_LEFT, mod);
+ propagate_mouse_event(pos + cache.offset, 0, 0, false, root, BUTTON_LEFT, mb);
blocked--;
if (range_click_timer->is_one_shot()) {
@@ -1430,7 +1432,7 @@ void Tree::_range_click_timeout() {
}
}
-int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const InputModifierState &p_mod) {
+int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod) {
int item_h = compute_item_height(p_item) + cache.vseparation;
@@ -1522,7 +1524,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
return -1;
}
- if (select_mode == SELECT_MULTI && p_mod.command && c.selectable) {
+ if (select_mode == SELECT_MULTI && p_mod->get_command() && c.selectable) {
if (!c.selected || p_button == BUTTON_RIGHT) {
@@ -1544,7 +1546,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool
if (c.selectable) {
- if (select_mode == SELECT_MULTI && p_mod.shift && selected_item && selected_item != p_item) {
+ if (select_mode == SELECT_MULTI && p_mod->get_shift() && selected_item && selected_item != p_item) {
bool inrange = false;
@@ -1839,537 +1841,534 @@ void Tree::popup_select(int p_option) {
item_edited(popup_edited_item_col, popup_edited_item);
}
-void Tree::_gui_input(InputEvent p_event) {
+void Tree::_gui_input(Ref<InputEvent> p_event) {
- switch (p_event.type) {
+ Ref<InputEventKey> k = p_event;
- case InputEvent::KEY: {
+ if (k.is_valid()) {
- if (!p_event.key.pressed)
- break;
- if (p_event.key.mod.alt || p_event.key.mod.command || (p_event.key.mod.shift && p_event.key.unicode == 0) || p_event.key.mod.meta)
- break;
- if (!root)
- return;
+ if (!k->is_pressed())
+ return;
+ if (k->get_alt() || k->get_command() || (k->get_shift() && k->get_unicode() == 0) || k->get_metakey())
+ return;
+ if (!root)
+ return;
- if (hide_root && !root->get_next_visible())
- return;
+ if (hide_root && !root->get_next_visible())
+ return;
- switch (p_event.key.scancode) {
+ switch (k->get_scancode()) {
#define EXIT_BREAK \
{ \
if (!cursor_can_exit_tree) accept_event(); \
break; \
}
- case KEY_RIGHT: {
-
- //TreeItem *next = NULL;
- if (!selected_item)
- break;
- if (select_mode == SELECT_ROW)
- EXIT_BREAK;
- if (selected_col >= (columns.size() - 1))
- EXIT_BREAK;
- if (select_mode == SELECT_MULTI) {
- selected_col++;
- emit_signal("cell_selected");
- } else {
-
- selected_item->select(selected_col + 1);
- }
+ case KEY_RIGHT: {
+
+ //TreeItem *next = NULL;
+ if (!selected_item)
+ break;
+ if (select_mode == SELECT_ROW)
+ EXIT_BREAK;
+ if (selected_col >= (columns.size() - 1))
+ EXIT_BREAK;
+ if (select_mode == SELECT_MULTI) {
+ selected_col++;
+ emit_signal("cell_selected");
+ } else {
- update();
- ensure_cursor_is_visible();
- accept_event();
+ selected_item->select(selected_col + 1);
+ }
- } break;
- case KEY_LEFT: {
+ update();
+ ensure_cursor_is_visible();
+ accept_event();
- //TreeItem *next = NULL;
- if (!selected_item)
- break;
- if (select_mode == SELECT_ROW)
- EXIT_BREAK;
- if (selected_col <= 0)
- EXIT_BREAK;
- if (select_mode == SELECT_MULTI) {
- selected_col--;
- emit_signal("cell_selected");
- } else {
+ } break;
+ case KEY_LEFT: {
+
+ //TreeItem *next = NULL;
+ if (!selected_item)
+ break;
+ if (select_mode == SELECT_ROW)
+ EXIT_BREAK;
+ if (selected_col <= 0)
+ EXIT_BREAK;
+ if (select_mode == SELECT_MULTI) {
+ selected_col--;
+ emit_signal("cell_selected");
+ } else {
- selected_item->select(selected_col - 1);
- }
+ selected_item->select(selected_col - 1);
+ }
- update();
- accept_event();
+ update();
+ accept_event();
- } break;
- case KEY_DOWN: {
+ } break;
+ case KEY_DOWN: {
- TreeItem *next = NULL;
- if (!selected_item) {
+ TreeItem *next = NULL;
+ if (!selected_item) {
- next = hide_root ? root->get_next_visible() : root;
- selected_item = 0;
- } else {
+ next = hide_root ? root->get_next_visible() : root;
+ selected_item = 0;
+ } else {
- next = selected_item->get_next_visible();
+ next = selected_item->get_next_visible();
- //if (diff < uint64_t(GLOBAL_DEF("gui/incr_search_max_interval_msec",2000))) {
- if (last_keypress != 0) {
- //incr search next
- int col;
- next = _search_item_text(next, incr_search, &col, true);
- if (!next) {
- accept_event();
- return;
- }
+ //if (diff < uint64_t(GLOBAL_DEF("gui/incr_search_max_interval_msec",2000))) {
+ if (last_keypress != 0) {
+ //incr search next
+ int col;
+ next = _search_item_text(next, incr_search, &col, true);
+ if (!next) {
+ accept_event();
+ return;
}
}
+ }
- if (select_mode == SELECT_MULTI) {
+ if (select_mode == SELECT_MULTI) {
- if (!next)
- EXIT_BREAK;
+ if (!next)
+ EXIT_BREAK;
- selected_item = next;
- emit_signal("cell_selected");
- update();
- } else {
+ selected_item = next;
+ emit_signal("cell_selected");
+ update();
+ } else {
- int col = selected_col < 0 ? 0 : selected_col;
+ int col = selected_col < 0 ? 0 : selected_col;
- while (next && !next->cells[col].selectable)
- next = next->get_next_visible();
- if (!next)
- EXIT_BREAK; // do nothing..
- next->select(col);
- }
+ while (next && !next->cells[col].selectable)
+ next = next->get_next_visible();
+ if (!next)
+ EXIT_BREAK; // do nothing..
+ next->select(col);
+ }
- ensure_cursor_is_visible();
- accept_event();
+ ensure_cursor_is_visible();
+ accept_event();
- } break;
- case KEY_UP: {
+ } break;
+ case KEY_UP: {
- TreeItem *prev = NULL;
- if (!selected_item) {
- prev = get_last_item();
- selected_col = 0;
- } else {
+ TreeItem *prev = NULL;
+ if (!selected_item) {
+ prev = get_last_item();
+ selected_col = 0;
+ } else {
- prev = selected_item->get_prev_visible();
- if (last_keypress != 0) {
- //incr search next
- int col;
- prev = _search_item_text(prev, incr_search, &col, true, true);
- if (!prev) {
- accept_event();
- return;
- }
+ prev = selected_item->get_prev_visible();
+ if (last_keypress != 0) {
+ //incr search next
+ int col;
+ prev = _search_item_text(prev, incr_search, &col, true, true);
+ if (!prev) {
+ accept_event();
+ return;
}
}
+ }
- if (select_mode == SELECT_MULTI) {
+ if (select_mode == SELECT_MULTI) {
- if (!prev)
- break;
- selected_item = prev;
- emit_signal("cell_selected");
- update();
- } else {
+ if (!prev)
+ break;
+ selected_item = prev;
+ emit_signal("cell_selected");
+ update();
+ } else {
- int col = selected_col < 0 ? 0 : selected_col;
- while (prev && !prev->cells[col].selectable)
- prev = prev->get_prev_visible();
- if (!prev)
- break; // do nothing..
- prev->select(col);
- }
+ int col = selected_col < 0 ? 0 : selected_col;
+ while (prev && !prev->cells[col].selectable)
+ prev = prev->get_prev_visible();
+ if (!prev)
+ break; // do nothing..
+ prev->select(col);
+ }
- ensure_cursor_is_visible();
- accept_event();
+ ensure_cursor_is_visible();
+ accept_event();
- } break;
- case KEY_PAGEDOWN: {
+ } break;
+ case KEY_PAGEDOWN: {
- TreeItem *next = NULL;
- if (!selected_item)
- break;
- next = selected_item;
+ TreeItem *next = NULL;
+ if (!selected_item)
+ break;
+ next = selected_item;
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
- TreeItem *_n = next->get_next_visible();
- if (_n) {
- next = _n;
- } else {
+ TreeItem *_n = next->get_next_visible();
+ if (_n) {
+ next = _n;
+ } else {
- break;
- }
- }
- if (next == selected_item)
break;
+ }
+ }
+ if (next == selected_item)
+ break;
- if (select_mode == SELECT_MULTI) {
+ if (select_mode == SELECT_MULTI) {
- selected_item = next;
- emit_signal("cell_selected");
- update();
- } else {
+ selected_item = next;
+ emit_signal("cell_selected");
+ update();
+ } else {
- while (next && !next->cells[selected_col].selectable)
- next = next->get_next_visible();
- if (!next)
- EXIT_BREAK; // do nothing..
- next->select(selected_col);
- }
+ while (next && !next->cells[selected_col].selectable)
+ next = next->get_next_visible();
+ if (!next)
+ EXIT_BREAK; // do nothing..
+ next->select(selected_col);
+ }
- ensure_cursor_is_visible();
- } break;
- case KEY_PAGEUP: {
+ ensure_cursor_is_visible();
+ } break;
+ case KEY_PAGEUP: {
- TreeItem *prev = NULL;
- if (!selected_item)
- break;
- prev = selected_item;
+ TreeItem *prev = NULL;
+ if (!selected_item)
+ break;
+ prev = selected_item;
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++) {
- TreeItem *_n = prev->get_prev_visible();
- if (_n) {
- prev = _n;
- } else {
+ TreeItem *_n = prev->get_prev_visible();
+ if (_n) {
+ prev = _n;
+ } else {
- break;
- }
- }
- if (prev == selected_item)
break;
+ }
+ }
+ if (prev == selected_item)
+ break;
- if (select_mode == SELECT_MULTI) {
+ if (select_mode == SELECT_MULTI) {
- selected_item = prev;
- emit_signal("cell_selected");
- update();
- } else {
+ selected_item = prev;
+ emit_signal("cell_selected");
+ update();
+ } else {
- while (prev && !prev->cells[selected_col].selectable)
- prev = prev->get_prev_visible();
- if (!prev)
- EXIT_BREAK; // do nothing..
- prev->select(selected_col);
- }
+ while (prev && !prev->cells[selected_col].selectable)
+ prev = prev->get_prev_visible();
+ if (!prev)
+ EXIT_BREAK; // do nothing..
+ prev->select(selected_col);
+ }
- ensure_cursor_is_visible();
+ ensure_cursor_is_visible();
- } break;
- case KEY_F2:
- case KEY_RETURN:
- case KEY_ENTER: {
-
- if (selected_item) {
- //bring up editor if possible
- if (!edit_selected()) {
- emit_signal("item_activated");
- incr_search.clear();
- }
+ } break;
+ case KEY_F2:
+ case KEY_RETURN:
+ case KEY_ENTER: {
+
+ if (selected_item) {
+ //bring up editor if possible
+ if (!edit_selected()) {
+ emit_signal("item_activated");
+ incr_search.clear();
}
- accept_event();
+ }
+ accept_event();
- } break;
- case KEY_SPACE: {
- if (select_mode == SELECT_MULTI) {
- if (!selected_item)
- break;
- if (selected_item->is_selected(selected_col)) {
- selected_item->deselect(selected_col);
- emit_signal("multi_selected", selected_item, selected_col, false);
- } else if (selected_item->is_selectable(selected_col)) {
- selected_item->select(selected_col);
- emit_signal("multi_selected", selected_item, selected_col, true);
- }
+ } break;
+ case KEY_SPACE: {
+ if (select_mode == SELECT_MULTI) {
+ if (!selected_item)
+ break;
+ if (selected_item->is_selected(selected_col)) {
+ selected_item->deselect(selected_col);
+ emit_signal("multi_selected", selected_item, selected_col, false);
+ } else if (selected_item->is_selectable(selected_col)) {
+ selected_item->select(selected_col);
+ emit_signal("multi_selected", selected_item, selected_col, true);
}
- accept_event();
+ }
+ accept_event();
- } break;
- default: {
+ } break;
+ default: {
- if (p_event.key.unicode > 0) {
+ if (k->get_unicode() > 0) {
- _do_incr_search(String::chr(p_event.key.unicode));
- accept_event();
+ _do_incr_search(String::chr(k->get_unicode()));
+ accept_event();
- return;
- } else {
- if (p_event.key.scancode != KEY_SHIFT)
- last_keypress = 0;
- }
- } break;
+ return;
+ } else {
+ if (k->get_scancode() != KEY_SHIFT)
+ last_keypress = 0;
+ }
+ } break;
- last_keypress = 0;
- }
+ last_keypress = 0;
+ }
+ }
- } break;
+ Ref<InputEventMouseMotion> mm = p_event;
- case InputEvent::MOUSE_MOTION: {
+ if (mm.is_valid()) {
- if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
- update_cache();
- const InputEventMouseMotion &b = p_event.mouse_motion;
+ if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
+ update_cache();
- Ref<StyleBox> bg = cache.bg;
+ Ref<StyleBox> bg = cache.bg;
- Point2 pos = Point2(b.x, b.y) - bg->get_offset();
+ Point2 pos = mm->get_pos() - bg->get_offset();
- Cache::ClickType old_hover = cache.hover_type;
- int old_index = cache.hover_index;
+ Cache::ClickType old_hover = cache.hover_type;
+ int old_index = cache.hover_index;
- cache.hover_type = Cache::CLICK_NONE;
- cache.hover_index = 0;
- if (show_column_titles) {
- pos.y -= _get_title_button_height();
- if (pos.y < 0) {
- pos.x += cache.offset.x;
- int len = 0;
- for (int i = 0; i < columns.size(); i++) {
-
- len += get_column_width(i);
- if (pos.x < len) {
-
- cache.hover_type = Cache::CLICK_TITLE;
- cache.hover_index = i;
- update();
- break;
- }
+ cache.hover_type = Cache::CLICK_NONE;
+ cache.hover_index = 0;
+ if (show_column_titles) {
+ pos.y -= _get_title_button_height();
+ if (pos.y < 0) {
+ pos.x += cache.offset.x;
+ int len = 0;
+ for (int i = 0; i < columns.size(); i++) {
+
+ len += get_column_width(i);
+ if (pos.x < len) {
+
+ cache.hover_type = Cache::CLICK_TITLE;
+ cache.hover_index = i;
+ update();
+ break;
}
}
}
+ }
- if (drop_mode_flags && root) {
+ if (drop_mode_flags && root) {
- Point2 mpos = Point2(b.x, b.y);
- mpos -= cache.bg->get_offset();
- mpos.y -= _get_title_button_height();
- if (mpos.y >= 0) {
+ Point2 mpos = mm->get_pos();
+ mpos -= cache.bg->get_offset();
+ mpos.y -= _get_title_button_height();
+ if (mpos.y >= 0) {
- if (h_scroll->is_visible_in_tree())
- mpos.x += h_scroll->get_value();
- if (v_scroll->is_visible_in_tree())
- mpos.y += v_scroll->get_value();
+ if (h_scroll->is_visible_in_tree())
+ mpos.x += h_scroll->get_value();
+ if (v_scroll->is_visible_in_tree())
+ mpos.y += v_scroll->get_value();
- int col, h, section;
- TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
+ int col, h, section;
+ TreeItem *it = _find_item_at_pos(root, mpos, col, h, section);
- if (it != drop_mode_over || section != drop_mode_section) {
- drop_mode_over = it;
- drop_mode_section = section;
- update();
- }
+ if (it != drop_mode_over || section != drop_mode_section) {
+ drop_mode_over = it;
+ drop_mode_section = section;
+ update();
}
}
+ }
- if (cache.hover_type != old_hover || cache.hover_index != old_index) {
- update();
- }
+ if (cache.hover_type != old_hover || cache.hover_index != old_index) {
+ update();
+ }
- if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE || popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE_EXPRESSION)) {
- //range drag
+ if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE || popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE_EXPRESSION)) {
+ //range drag
- if (!range_drag_enabled) {
+ if (!range_drag_enabled) {
- Vector2 cpos = Vector2(b.x, b.y);
- if (cpos.distance_to(pressing_pos) > 2) {
- range_drag_enabled = true;
- range_drag_capture_pos = cpos;
- range_drag_base = popup_edited_item->get_range(popup_edited_item_col);
- Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
- }
- } else {
-
- TreeItem::Cell &c = popup_edited_item->cells[popup_edited_item_col];
- float diff_y = -b.relative_y;
- diff_y = Math::pow(ABS(diff_y), 1.8f) * SGN(diff_y);
- diff_y *= 0.1;
- range_drag_base = CLAMP(range_drag_base + c.step * diff_y, c.min, c.max);
- popup_edited_item->set_range(popup_edited_item_col, range_drag_base);
- item_edited(popup_edited_item_col, popup_edited_item);
+ Vector2 cpos = mm->get_pos();
+ if (cpos.distance_to(pressing_pos) > 2) {
+ range_drag_enabled = true;
+ range_drag_capture_pos = cpos;
+ range_drag_base = popup_edited_item->get_range(popup_edited_item_col);
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
}
+ } else {
+
+ TreeItem::Cell &c = popup_edited_item->cells[popup_edited_item_col];
+ float diff_y = -mm->get_relative().y;
+ diff_y = Math::pow(ABS(diff_y), 1.8f) * SGN(diff_y);
+ diff_y *= 0.1;
+ range_drag_base = CLAMP(range_drag_base + c.step * diff_y, c.min, c.max);
+ popup_edited_item->set_range(popup_edited_item_col, range_drag_base);
+ item_edited(popup_edited_item_col, popup_edited_item);
}
+ }
- if (drag_touching && !drag_touching_deaccel) {
+ if (drag_touching && !drag_touching_deaccel) {
- drag_accum -= b.relative_y;
- v_scroll->set_value(drag_from + drag_accum);
- drag_speed = -b.speed_y;
- }
- } break;
- case InputEvent::MOUSE_BUTTON: {
+ drag_accum -= mm->get_relative().y;
+ v_scroll->set_value(drag_from + drag_accum);
+ drag_speed = -mm->get_speed().y;
+ }
+ }
- if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
- update_cache();
- const InputEventMouseButton &b = p_event.mouse_button;
+ Ref<InputEventMouseButton> b = p_event;
- if (!b.pressed) {
+ if (b.is_valid()) {
+ if (cache.font.is_null()) // avoid a strange case that may fuckup stuff
+ update_cache();
- if (b.button_index == BUTTON_LEFT) {
+ if (!b->is_pressed()) {
- Ref<StyleBox> bg = cache.bg;
+ if (b->get_button_index() == BUTTON_LEFT) {
- Point2 pos = Point2(b.x, b.y) - bg->get_offset();
- if (show_column_titles) {
- pos.y -= _get_title_button_height();
+ Point2 pos = b->get_pos() - cache.bg->get_offset();
+ if (show_column_titles) {
+ pos.y -= _get_title_button_height();
- if (pos.y < 0) {
- pos.x += cache.offset.x;
- int len = 0;
- for (int i = 0; i < columns.size(); i++) {
+ if (pos.y < 0) {
+ pos.x += cache.offset.x;
+ int len = 0;
+ for (int i = 0; i < columns.size(); i++) {
- len += get_column_width(i);
- if (pos.x < len) {
- emit_signal("column_title_pressed", i);
- break;
- }
+ len += get_column_width(i);
+ if (pos.x < len) {
+ emit_signal("column_title_pressed", i);
+ break;
}
}
}
+ }
- if (single_select_defer) {
- select_single_item(single_select_defer, root, single_select_defer_column);
- single_select_defer = NULL;
- }
+ if (single_select_defer) {
+ select_single_item(single_select_defer, root, single_select_defer_column);
+ single_select_defer = NULL;
+ }
- range_click_timer->stop();
+ range_click_timer->stop();
- if (pressing_for_editor) {
+ if (pressing_for_editor) {
- if (range_drag_enabled) {
+ if (range_drag_enabled) {
- range_drag_enabled = false;
- Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
- warp_mouse(range_drag_capture_pos);
+ range_drag_enabled = false;
+ Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
+ warp_mouse(range_drag_capture_pos);
+ } else {
+ Rect2 rect = get_selected()->get_meta("__focus_rect");
+ if (rect.has_point(Point2(b->get_pos().x, b->get_pos().y))) {
+ edit_selected();
} else {
- Rect2 rect = get_selected()->get_meta("__focus_rect");
- if (rect.has_point(Point2(p_event.mouse_button.x, p_event.mouse_button.y))) {
- edit_selected();
- } else {
- emit_signal("item_double_clicked");
- }
+ emit_signal("item_double_clicked");
}
- pressing_for_editor = false;
}
+ pressing_for_editor = false;
+ }
- if (cache.click_type == Cache::CLICK_BUTTON) {
- // make sure in case of wrong reference after reconstructing whole TreeItems
- cache.click_item = get_item_at_pos(cache.click_pos);
- emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id);
- }
- cache.click_type = Cache::CLICK_NONE;
- cache.click_index = -1;
- cache.click_id = -1;
- cache.click_item = NULL;
- cache.click_column = 0;
+ if (cache.click_type == Cache::CLICK_BUTTON) {
+ // make sure in case of wrong reference after reconstructing whole TreeItems
+ cache.click_item = get_item_at_pos(cache.click_pos);
+ emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id);
+ }
+ cache.click_type = Cache::CLICK_NONE;
+ cache.click_index = -1;
+ cache.click_id = -1;
+ cache.click_item = NULL;
+ cache.click_column = 0;
- if (drag_touching) {
+ if (drag_touching) {
- if (drag_speed == 0) {
- drag_touching_deaccel = false;
- drag_touching = false;
- set_fixed_process(false);
- } else {
+ if (drag_speed == 0) {
+ drag_touching_deaccel = false;
+ drag_touching = false;
+ set_fixed_process(false);
+ } else {
- drag_touching_deaccel = true;
- }
+ drag_touching_deaccel = true;
}
- update();
}
- break;
+ update();
}
+ return;
+ }
- if (range_drag_enabled)
- break;
-
- switch (b.button_index) {
- case BUTTON_RIGHT:
- case BUTTON_LEFT: {
- Ref<StyleBox> bg = cache.bg;
+ if (range_drag_enabled)
+ return;
- Point2 pos = Point2(b.x, b.y) - bg->get_offset();
- cache.click_type = Cache::CLICK_NONE;
- if (show_column_titles && b.button_index == BUTTON_LEFT) {
- pos.y -= _get_title_button_height();
-
- if (pos.y < 0) {
- pos.x += cache.offset.x;
- int len = 0;
- for (int i = 0; i < columns.size(); i++) {
-
- len += get_column_width(i);
- if (pos.x < len) {
-
- cache.click_type = Cache::CLICK_TITLE;
- cache.click_index = i;
- //cache.click_id=;
- update();
- break;
- }
+ switch (b->get_button_index()) {
+ case BUTTON_RIGHT:
+ case BUTTON_LEFT: {
+ Ref<StyleBox> bg = cache.bg;
+
+ Point2 pos = b->get_pos() - bg->get_offset();
+ cache.click_type = Cache::CLICK_NONE;
+ if (show_column_titles && b->get_button_index() == BUTTON_LEFT) {
+ pos.y -= _get_title_button_height();
+
+ if (pos.y < 0) {
+ pos.x += cache.offset.x;
+ int len = 0;
+ for (int i = 0; i < columns.size(); i++) {
+
+ len += get_column_width(i);
+ if (pos.x < len) {
+
+ cache.click_type = Cache::CLICK_TITLE;
+ cache.click_index = i;
+ //cache.click_id=;
+ update();
+ break;
}
- break;
- }
- }
- if (!root || (!root->get_children() && hide_root)) {
- if (b.button_index == BUTTON_RIGHT && allow_rmb_select) {
- emit_signal("empty_tree_rmb_selected", get_local_mouse_pos());
}
break;
}
+ }
+ if (!root || (!root->get_children() && hide_root)) {
+ if (b->get_button_index() == BUTTON_RIGHT && allow_rmb_select) {
+ emit_signal("empty_tree_rmb_selected", get_local_mouse_pos());
+ }
+ break;
+ }
- click_handled = false;
- pressing_for_editor = false;
+ click_handled = false;
+ pressing_for_editor = false;
- blocked++;
- bool handled = propagate_mouse_event(pos + cache.offset, 0, 0, b.doubleclick, root, b.button_index, b.mod);
- blocked--;
+ blocked++;
+ bool handled = propagate_mouse_event(pos + cache.offset, 0, 0, b->is_doubleclick(), root, b->get_button_index(), b);
+ blocked--;
- if (pressing_for_editor) {
- pressing_pos = Point2(b.x, b.y);
- }
+ if (pressing_for_editor) {
+ pressing_pos = b->get_pos();
+ }
- if (b.button_index == BUTTON_RIGHT)
- break;
+ if (b->get_button_index() == BUTTON_RIGHT)
+ break;
- if (drag_touching) {
- set_fixed_process(false);
- drag_touching_deaccel = false;
- drag_touching = false;
- drag_speed = 0;
- drag_from = 0;
- }
+ if (drag_touching) {
+ set_fixed_process(false);
+ drag_touching_deaccel = false;
+ drag_touching = false;
+ drag_speed = 0;
+ drag_from = 0;
+ }
- if (!click_handled) {
- drag_speed = 0;
- drag_accum = 0;
- //last_drag_accum=0;
- drag_from = v_scroll->get_value();
- drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
- drag_touching_deaccel = false;
- if (drag_touching) {
- set_fixed_process(true);
- }
+ if (!click_handled) {
+ drag_speed = 0;
+ drag_accum = 0;
+ //last_drag_accum=0;
+ drag_from = v_scroll->get_value();
+ drag_touching = OS::get_singleton()->has_touchscreen_ui_hint();
+ drag_touching_deaccel = false;
+ if (drag_touching) {
+ set_fixed_process(true);
}
+ }
- } break;
- case BUTTON_WHEEL_UP: {
-
- v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b.factor / 8);
- } break;
- case BUTTON_WHEEL_DOWN: {
+ } break;
+ case BUTTON_WHEEL_UP: {
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b.factor / 8);
- } break;
- }
+ v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
+ } break;
+ case BUTTON_WHEEL_DOWN: {
- } break;
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
+ } break;
+ }
}
}
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 4bee1adc4b..0c07109e7d 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -337,14 +337,14 @@ private:
void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color);
int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item);
void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false);
- int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const InputModifierState &p_mod);
+ int propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool p_doubleclick, TreeItem *p_item, int p_button, const Ref<InputEventWithModifiers> &p_mod);
void text_editor_enter(String p_text);
void _text_editor_modal_close();
void value_editor_changed(double p_value);
void popup_select(int p_option);
- void _gui_input(InputEvent p_event);
+ void _gui_input(Ref<InputEvent> p_event);
void _notification(int p_what);
Size2 get_minimum_size() const;
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index bf91b109ad..0c65c44392 100755
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -2938,9 +2938,9 @@ void Node::_bind_methods() {
BIND_VMETHOD(MethodInfo("_enter_tree"));
BIND_VMETHOD(MethodInfo("_exit_tree"));
BIND_VMETHOD(MethodInfo("_ready"));
- BIND_VMETHOD(MethodInfo("_input", PropertyInfo(Variant::INPUT_EVENT, "event")));
- BIND_VMETHOD(MethodInfo("_unhandled_input", PropertyInfo(Variant::INPUT_EVENT, "event")));
- BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::INPUT_EVENT, "key_event")));
+ BIND_VMETHOD(MethodInfo("_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
+ BIND_VMETHOD(MethodInfo("_unhandled_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
+ BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEventKey")));
//ClassDB::bind_method(D_METHOD("get_child",&Node::get_child,PH("index")));
//ClassDB::bind_method(D_METHOD("get_node",&Node::get_node,PH("path")));
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index a43938c661..b55a925f55 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -379,9 +379,9 @@ bool SceneTree::is_input_handled() {
return input_handled;
}
-void SceneTree::input_event(const InputEvent &p_event) {
+void SceneTree::input_event(const Ref<InputEvent> &p_event) {
- if (is_editor_hint() && (p_event.type == InputEvent::JOYPAD_MOTION || p_event.type == InputEvent::JOYPAD_BUTTON))
+ if (is_editor_hint() && (p_event->cast_to<InputEventJoypadButton>() || p_event->cast_to<InputEventJoypadMotion>()))
return; //avoid joy input on editor
root_lock++;
@@ -389,8 +389,8 @@ void SceneTree::input_event(const InputEvent &p_event) {
input_handled = false;
- InputEvent ev = p_event;
- ev.ID = ++last_id; //this should work better
+ Ref<InputEvent> ev = p_event;
+ ev->set_id(++last_id); //this should work better
#if 0
switch(ev.type) {
@@ -398,9 +398,9 @@ void SceneTree::input_event(const InputEvent &p_event) {
Matrix32 ai = root->get_final_transform().affine_inverse();
Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y));
- ev.mouse_button.x=l.x;
- ev.mouse_button.y=l.y;
+ Vector2 l = ai.xform(Vector2(ev->get_pos().x,ev->get_pos().y));
+ ev->get_pos().x=l.x;
+ ev->get_pos().y=l.y;
ev.mouse_button.global_x=g.x;
ev.mouse_button.global_y=g.y;
@@ -410,13 +410,13 @@ void SceneTree::input_event(const InputEvent &p_event) {
Matrix32 ai = root->get_final_transform().affine_inverse();
Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y));
Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y));
- Vector2 r = ai.xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y));
+ Vector2 r = ai.xform(Vector2(ev->get_relative().x,ev->get_relative().y));
ev.mouse_motion.x=l.x;
ev.mouse_motion.y=l.y;
ev.mouse_motion.global_x=g.x;
ev.mouse_motion.global_y=g.y;
- ev.mouse_motion.relative_x=r.x;
- ev.mouse_motion.relative_y=r.y;
+ ev->get_relative().x=r.x;
+ ev->get_relative().y=r.y;
} break;
case InputEvent::SCREEN_TOUCH: {
@@ -453,12 +453,12 @@ void SceneTree::input_event(const InputEvent &p_event) {
//call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"input","_input",ev);
/*
- if (ev.type==InputEvent::KEY && ev.key.pressed && !ev.key.echo && ev.key.scancode==KEY_F12) {
+ if (ev.type==InputEvent::KEY && ev->is_pressed() && !ev->is_echo() && ev->get_scancode()==KEY_F12) {
print_line("RAM: "+itos(Memory::get_static_mem_usage()));
print_line("DRAM: "+itos(Memory::get_dynamic_mem_usage()));
}
- if (ev.type==InputEvent::KEY && ev.key.pressed && !ev.key.echo && ev.key.scancode==KEY_F11) {
+ if (ev.type==InputEvent::KEY && ev->is_pressed() && !ev->is_echo() && ev->get_scancode()==KEY_F11) {
Memory::dump_static_mem_to_file("memdump.txt");
}
@@ -470,9 +470,13 @@ void SceneTree::input_event(const InputEvent &p_event) {
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check
#endif
- if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote() && ev.type == InputEvent::KEY && ev.key.pressed && !ev.key.echo && ev.key.scancode == KEY_F8) {
- ScriptDebugger::get_singleton()->request_quit();
+ if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote()) {
+ //quit from game window using F8
+ Ref<InputEventKey> k = ev;
+ if (k.is_valid() && k->is_pressed() && !k->is_echo() && k->get_scancode() == KEY_F8) {
+ ScriptDebugger::get_singleton()->request_quit();
+ }
}
_flush_ugc();
@@ -878,7 +882,7 @@ bool SceneTree::is_paused() const {
return pause;
}
-void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p_method, const InputEvent &p_input) {
+void SceneTree::_call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input) {
Map<StringName, Group>::Element *E = group_map.find(p_group);
if (!E)
diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h
index 52d5f5c88c..5d42c66652 100644
--- a/scene/main/scene_main_loop.h
+++ b/scene/main/scene_main_loop.h
@@ -237,7 +237,7 @@ private:
void remove_from_group(const StringName &p_group, Node *p_node);
void _notify_group_pause(const StringName &p_group, int p_notification);
- void _call_input_pause(const StringName &p_group, const StringName &p_method, const InputEvent &p_input);
+ void _call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input);
Variant _call_group_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
Variant _call_group(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
@@ -341,7 +341,7 @@ public:
void set_group(const StringName &p_group, const String &p_name, const Variant &p_value);
virtual void input_text(const String &p_text);
- virtual void input_event(const InputEvent &p_event);
+ virtual void input_event(const Ref<InputEvent> &p_event);
virtual void init();
virtual bool iteration(float p_time);
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index aaf839b072..f62cebe042 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -503,30 +503,36 @@ void Viewport::_notification(int p_what) {
while (physics_picking_events.size()) {
- InputEvent ev = physics_picking_events.front()->get();
+ Ref<InputEvent> ev = physics_picking_events.front()->get();
physics_picking_events.pop_front();
Vector2 pos;
- switch (ev.type) {
- case InputEvent::MOUSE_MOTION: {
- pos.x = ev.mouse_motion.x;
- pos.y = ev.mouse_motion.y;
- motion_tested = true;
- physics_last_mousepos = pos;
- } break;
- case InputEvent::MOUSE_BUTTON: {
- pos.x = ev.mouse_button.x;
- pos.y = ev.mouse_button.y;
-
- } break;
- case InputEvent::SCREEN_DRAG: {
- pos.x = ev.screen_drag.x;
- pos.y = ev.screen_drag.y;
- } break;
- case InputEvent::SCREEN_TOUCH: {
- pos.x = ev.screen_touch.x;
- pos.y = ev.screen_touch.y;
- } break;
+
+ Ref<InputEventMouseMotion> mm = ev;
+
+ if (mm.is_valid()) {
+
+ pos = mm->get_pos();
+ motion_tested = true;
+ physics_last_mousepos = pos;
+ }
+
+ Ref<InputEventMouseButton> mb = ev;
+
+ if (mb.is_valid()) {
+ pos = mb->get_pos();
+ }
+
+ Ref<InputEventScreenDrag> sd = ev;
+
+ if (sd.is_valid()) {
+ pos = sd->get_pos();
+ }
+
+ Ref<InputEventScreenTouch> st = ev;
+
+ if (st.is_valid()) {
+ pos = st->get_pos();
}
if (ss2d) {
@@ -589,7 +595,7 @@ void Viewport::_notification(int p_what) {
if (co) {
co->_input_event(camera, ev, Vector3(), Vector3(), 0);
captured = true;
- if (ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && !ev.mouse_button.pressed) {
+ if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
physics_object_capture = 0;
}
@@ -609,7 +615,7 @@ void Viewport::_notification(int p_what) {
if (ObjectDB::get_instance(last_id)) {
//good, exists
last_object->_input_event(camera, ev, result.position, result.normal, result.shape);
- if (last_object->get_capture_input_on_drag() && ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && ev.mouse_button.pressed) {
+ if (last_object->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
physics_object_capture = last_id;
}
}
@@ -637,14 +643,14 @@ void Viewport::_notification(int p_what) {
last_object = co;
last_id = result.collider_id;
new_collider = last_id;
- if (co->get_capture_input_on_drag() && ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && ev.mouse_button.pressed) {
+ if (co->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
physics_object_capture = last_id;
}
}
}
}
- if (ev.type == InputEvent::MOUSE_MOTION) {
+ if (mm.is_valid()) {
_test_new_mouseover(new_collider);
}
}
@@ -1322,71 +1328,12 @@ Vector2 Viewport::_get_window_offset() const {
return Vector2();
}
-void Viewport::_make_input_local(InputEvent &ev) {
+Ref<InputEvent> Viewport::_make_input_local(const Ref<InputEvent> &ev) {
- switch (ev.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- Vector2 vp_ofs = _get_window_offset();
-
- Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y) - vp_ofs);
-
- ev.mouse_button.x = l.x;
- ev.mouse_button.y = l.y;
- ev.mouse_button.global_x = g.x;
- ev.mouse_button.global_y = g.y;
-
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- Vector2 vp_ofs = _get_window_offset();
-
- Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x, ev.mouse_motion.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_motion.x, ev.mouse_motion.y) - vp_ofs);
- Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x, ev.mouse_motion.relative_y));
- Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x, ev.mouse_motion.speed_y));
-
- ev.mouse_motion.x = l.x;
- ev.mouse_motion.y = l.y;
- ev.mouse_motion.global_x = g.x;
- ev.mouse_motion.global_y = g.y;
- ev.mouse_motion.relative_x = r.x;
- ev.mouse_motion.relative_y = r.y;
- ev.mouse_motion.speed_x = s.x;
- ev.mouse_motion.speed_y = s.y;
-
- } break;
- case InputEvent::SCREEN_TOUCH: {
+ Vector2 vp_ofs = _get_window_offset();
+ Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 vp_ofs = _get_window_offset();
-
- Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 t = ai.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y) - vp_ofs);
-
- ev.screen_touch.x = t.x;
- ev.screen_touch.y = t.y;
-
- } break;
- case InputEvent::SCREEN_DRAG: {
-
- Vector2 vp_ofs = _get_window_offset();
-
- Transform2D ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
- Vector2 t = ai.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y) - vp_ofs);
- Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x, ev.screen_drag.relative_y));
- Vector2 s = ai.basis_xform(Vector2(ev.screen_drag.speed_x, ev.screen_drag.speed_y));
- ev.screen_drag.x = t.x;
- ev.screen_drag.y = t.y;
- ev.screen_drag.relative_x = r.x;
- ev.screen_drag.relative_y = r.y;
- ev.screen_drag.speed_x = s.x;
- ev.screen_drag.speed_y = s.y;
- } break;
- }
+ return ev->xformed_by(ai, -vp_ofs);
}
void Viewport::_vp_input_text(const String &p_text) {
@@ -1396,7 +1343,7 @@ void Viewport::_vp_input_text(const String &p_text) {
}
}
-void Viewport::_vp_input(const InputEvent &p_ev) {
+void Viewport::_vp_input(const Ref<InputEvent> &p_ev) {
if (disable_input)
return;
@@ -1413,12 +1360,11 @@ void Viewport::_vp_input(const InputEvent &p_ev) {
//this one handles system input, p_ev are in system coordinates
//they are converted to viewport coordinates
- InputEvent ev = p_ev;
- _make_input_local(ev);
+ Ref<InputEvent> ev = _make_input_local(p_ev);
input(ev);
}
-void Viewport::_vp_unhandled_input(const InputEvent &p_ev) {
+void Viewport::_vp_unhandled_input(const Ref<InputEvent> &p_ev) {
if (disable_input)
return;
@@ -1439,8 +1385,7 @@ void Viewport::_vp_unhandled_input(const InputEvent &p_ev) {
//this one handles system input, p_ev are in system coordinates
//they are converted to viewport coordinates
- InputEvent ev = p_ev;
- _make_input_local(ev);
+ Ref<InputEvent> ev = _make_input_local(p_ev);
unhandled_input(ev);
}
@@ -1545,18 +1490,22 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_popup->show();
}
-void Viewport::_gui_call_input(Control *p_control, const InputEvent &p_input) {
+void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_input) {
//_block();
- InputEvent ev = p_input;
+ Ref<InputEvent> ev = p_input;
//mouse wheel events can't be stopped
- bool cant_stop_me_now = (ev.type == InputEvent::MOUSE_BUTTON &&
- (ev.mouse_button.button_index == BUTTON_WHEEL_DOWN ||
- ev.mouse_button.button_index == BUTTON_WHEEL_UP ||
- ev.mouse_button.button_index == BUTTON_WHEEL_LEFT ||
- ev.mouse_button.button_index == BUTTON_WHEEL_RIGHT));
+ Ref<InputEventMouseButton> mb = p_input;
+
+ bool cant_stop_me_now = (mb.is_valid() &&
+ (mb->get_button_index() == BUTTON_WHEEL_DOWN ||
+ mb->get_button_index() == BUTTON_WHEEL_UP ||
+ mb->get_button_index() == BUTTON_WHEEL_LEFT ||
+ mb->get_button_index() == BUTTON_WHEEL_RIGHT));
+
+ bool ismouse = ev.is_valid() || p_input->cast_to<InputEventMouseMotion>() != NULL;
CanvasItem *ci = p_control;
while (ci) {
@@ -1573,14 +1522,14 @@ void Viewport::_gui_call_input(Control *p_control, const InputEvent &p_input) {
break;
if (gui.key_event_accepted)
break;
- if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && (ev.type == InputEvent::MOUSE_BUTTON || ev.type == InputEvent::MOUSE_MOTION))
+ if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && ismouse)
break;
}
if (ci->is_set_as_toplevel())
break;
- ev = ev.xform_by(ci->get_transform()); //transform event upwards
+ ev = ev->xformed_by(ci->get_transform()); //transform event upwards
ci = ci->get_parent_item();
}
@@ -1718,9 +1667,9 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che
return false;
}
-void Viewport::_gui_input_event(InputEvent p_event) {
+void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
- if (p_event.ID == gui.cancelled_input_ID) {
+ if (p_event->get_id() == gui.cancelled_input_ID) {
return;
}
//?
@@ -1730,430 +1679,427 @@ void Viewport::_gui_input_event(InputEvent p_event) {
}
*/
- switch (p_event.type) {
+ Ref<InputEventMouseButton> mb = p_event;
- case InputEvent::MOUSE_BUTTON: {
+ if (mb.is_valid()) {
- gui.key_event_accepted = false;
+ gui.key_event_accepted = false;
- Point2 mpos = Point2(p_event.mouse_button.x, p_event.mouse_button.y);
- if (p_event.mouse_button.pressed) {
+ Point2 mpos = mb->get_pos();
+ if (mb->is_pressed()) {
- Size2 pos = mpos;
- if (gui.mouse_focus && p_event.mouse_button.button_index != gui.mouse_focus_button) {
+ Size2 pos = mpos;
+ if (gui.mouse_focus && mb->get_button_index() != gui.mouse_focus_button) {
- //do not steal mouse focus and stuff
+ //do not steal mouse focus and stuff
- } else {
-
- _gui_sort_modal_stack();
- while (!gui.modal_stack.empty()) {
+ } else {
- Control *top = gui.modal_stack.back()->get();
- Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos);
- if (!top->has_point(pos)) {
+ _gui_sort_modal_stack();
+ while (!gui.modal_stack.empty()) {
- if (top->data.modal_exclusive || top->data.modal_frame == Engine::get_singleton()->get_frames_drawn()) {
- //cancel event, sorry, modal exclusive EATS UP ALL
- //alternative, you can't pop out a window the same frame it was made modal (fixes many issues)
- get_tree()->set_input_as_handled();
- return; // no one gets the event if exclusive NO ONE
- }
+ Control *top = gui.modal_stack.back()->get();
+ Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos);
+ if (!top->has_point(pos)) {
- top->notification(Control::NOTIFICATION_MODAL_CLOSE);
- top->_modal_stack_remove();
- top->hide();
- } else {
- break;
+ if (top->data.modal_exclusive || top->data.modal_frame == Engine::get_singleton()->get_frames_drawn()) {
+ //cancel event, sorry, modal exclusive EATS UP ALL
+ //alternative, you can't pop out a window the same frame it was made modal (fixes many issues)
+ get_tree()->set_input_as_handled();
+ return; // no one gets the event if exclusive NO ONE
}
+
+ top->notification(Control::NOTIFICATION_MODAL_CLOSE);
+ top->_modal_stack_remove();
+ top->hide();
+ } else {
+ break;
}
+ }
- //Matrix32 parent_xform;
+ //Matrix32 parent_xform;
- /*
- if (data.parent_canvas_item)
- parent_xform=data.parent_canvas_item->get_global_transform();
- */
+ /*
+ if (data.parent_canvas_item)
+ parent_xform=data.parent_canvas_item->get_global_transform();
+ */
- gui.mouse_focus = _gui_find_control(pos);
- //print_line("has mf "+itos(gui.mouse_focus!=NULL));
- gui.mouse_focus_button = p_event.mouse_button.button_index;
+ gui.mouse_focus = _gui_find_control(pos);
+ //print_line("has mf "+itos(gui.mouse_focus!=NULL));
+ gui.mouse_focus_button = mb->get_button_index();
- if (!gui.mouse_focus) {
- break;
- }
+ if (!gui.mouse_focus) {
+ return;
+ }
- if (p_event.mouse_button.button_index == BUTTON_LEFT) {
- gui.drag_accum = Vector2();
- gui.drag_attempted = false;
- }
+ if (mb->get_button_index() == BUTTON_LEFT) {
+ gui.drag_accum = Vector2();
+ gui.drag_attempted = false;
}
+ }
+
+ mb = mb->xformed_by(Transform2D()); // make a copy of the event
+
+ mb->set_global_pos(pos);
- p_event.mouse_button.global_x = pos.x;
- p_event.mouse_button.global_y = pos.y;
+ pos = gui.focus_inv_xform.xform(pos);
- pos = gui.focus_inv_xform.xform(pos);
- p_event.mouse_button.x = pos.x;
- p_event.mouse_button.y = pos.y;
+ mb->set_pos(pos);
#ifdef DEBUG_ENABLED
- if (ScriptDebugger::get_singleton()) {
+ if (ScriptDebugger::get_singleton()) {
- Array arr;
- arr.push_back(gui.mouse_focus->get_path());
- arr.push_back(gui.mouse_focus->get_class());
- ScriptDebugger::get_singleton()->send_message("click_ctrl", arr);
- }
+ Array arr;
+ arr.push_back(gui.mouse_focus->get_path());
+ arr.push_back(gui.mouse_focus->get_class());
+ ScriptDebugger::get_singleton()->send_message("click_ctrl", arr);
+ }
/*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) {
- print_line(String(gui.mouse_focus->get_path())+" - "+pos);
- }*/
+ print_line(String(gui.mouse_focus->get_path())+" - "+pos);
+ }*/
#endif
- if (p_event.mouse_button.button_index == BUTTON_LEFT) { //assign focus
- CanvasItem *ci = gui.mouse_focus;
- while (ci) {
+ if (mb->get_button_index() == BUTTON_LEFT) { //assign focus
+ CanvasItem *ci = gui.mouse_focus;
+ while (ci) {
- Control *control = ci->cast_to<Control>();
- if (control) {
- if (control->get_focus_mode() != Control::FOCUS_NONE) {
- if (control != gui.key_focus) {
- control->grab_focus();
- }
- break;
+ Control *control = ci->cast_to<Control>();
+ if (control) {
+ if (control->get_focus_mode() != Control::FOCUS_NONE) {
+ if (control != gui.key_focus) {
+ control->grab_focus();
}
-
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
- break;
+ break;
}
- if (ci->is_set_as_toplevel())
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
break;
-
- ci = ci->get_parent_item();
}
- }
- if (gui.mouse_focus->can_process()) {
- _gui_call_input(gui.mouse_focus, p_event);
- }
+ if (ci->is_set_as_toplevel())
+ break;
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID);
- get_tree()->set_input_as_handled();
+ ci = ci->get_parent_item();
+ }
+ }
- if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ if (gui.mouse_focus->can_process()) {
+ _gui_call_input(gui.mouse_focus, mb);
+ }
- //alternate drop use (when using force_drag(), as proposed by #5342
- if (gui.mouse_focus) {
- _gui_drop(gui.mouse_focus, pos, false);
- }
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", mb->get_id());
+ get_tree()->set_input_as_handled();
- gui.drag_data = Variant();
+ if (gui.drag_data.get_type() != Variant::NIL && mb->get_button_index() == BUTTON_LEFT) {
- if (gui.drag_preview) {
- memdelete(gui.drag_preview);
- gui.drag_preview = NULL;
- }
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
- //change mouse accordingly
+ //alternate drop use (when using force_drag(), as proposed by #5342
+ if (gui.mouse_focus) {
+ _gui_drop(gui.mouse_focus, pos, false);
}
- _gui_cancel_tooltip();
- //gui.tooltip_popup->hide();
+ gui.drag_data = Variant();
- } else {
+ if (gui.drag_preview) {
+ memdelete(gui.drag_preview);
+ gui.drag_preview = NULL;
+ }
+ _propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
+ //change mouse accordingly
+ }
- if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) {
+ _gui_cancel_tooltip();
+ //gui.tooltip_popup->hide();
- if (gui.mouse_over) {
- Size2 pos = mpos;
- pos = gui.focus_inv_xform.xform(pos);
+ } else {
- _gui_drop(gui.mouse_over, pos, false);
- }
+ if (gui.drag_data.get_type() != Variant::NIL && mb->get_button_index() == BUTTON_LEFT) {
- if (gui.drag_preview && p_event.mouse_button.button_index == BUTTON_LEFT) {
- memdelete(gui.drag_preview);
- gui.drag_preview = NULL;
- }
+ if (gui.mouse_over) {
+ Size2 pos = mpos;
+ pos = gui.focus_inv_xform.xform(pos);
- gui.drag_data = Variant();
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
- //change mouse accordingly
+ _gui_drop(gui.mouse_over, pos, false);
}
- if (!gui.mouse_focus) {
- //release event is only sent if a mouse focus (previously pressed button) exists
- break;
+ if (gui.drag_preview && mb->get_button_index() == BUTTON_LEFT) {
+ memdelete(gui.drag_preview);
+ gui.drag_preview = NULL;
}
- Size2 pos = mpos;
- p_event.mouse_button.global_x = pos.x;
- p_event.mouse_button.global_y = pos.y;
- pos = gui.focus_inv_xform.xform(pos);
- p_event.mouse_button.x = pos.x;
- p_event.mouse_button.y = pos.y;
+ gui.drag_data = Variant();
+ _propagate_viewport_notification(this, NOTIFICATION_DRAG_END);
+ //change mouse accordingly
+ }
- if (gui.mouse_focus->can_process()) {
- _gui_call_input(gui.mouse_focus, p_event);
- }
+ if (!gui.mouse_focus) {
+ //release event is only sent if a mouse focus (previously pressed button) exists
+ return;
+ }
- if (p_event.mouse_button.button_index == gui.mouse_focus_button) {
- gui.mouse_focus = NULL;
- gui.mouse_focus_button = -1;
- }
+ Size2 pos = mpos;
- /*if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) {
- _propagate_viewport_notification(this,NOTIFICATION_DRAG_END);
- gui.drag_data=Variant(); //always clear
- }*/
+ mb = mb->xformed_by(Transform2D()); //make a copy
+ mb->set_global_pos(pos);
+ pos = gui.focus_inv_xform.xform(pos);
+ mb->set_pos(pos);
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID);
- get_tree()->set_input_as_handled();
+ if (gui.mouse_focus->can_process()) {
+ _gui_call_input(gui.mouse_focus, mb);
}
- } break;
- case InputEvent::MOUSE_MOTION: {
- gui.key_event_accepted = false;
- Point2 mpos = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y);
+ if (mb->get_button_index() == gui.mouse_focus_button) {
+ gui.mouse_focus = NULL;
+ gui.mouse_focus_button = -1;
+ }
- gui.last_mouse_pos = mpos;
+ /*if (gui.drag_data.get_type()!=Variant::NIL && mb->get_button_index()==BUTTON_LEFT) {
+ _propagate_viewport_notification(this,NOTIFICATION_DRAG_END);
+ gui.drag_data=Variant(); //always clear
+ }*/
- Control *over = NULL;
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", mb->get_id());
+ get_tree()->set_input_as_handled();
+ }
+ }
- // D&D
- if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ Ref<InputEventMouseMotion> mm = p_event;
- gui.drag_accum += Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y);
- float len = gui.drag_accum.length();
- if (len > 10) {
+ if (mm.is_valid()) {
- { //attempt grab, try parent controls too
- CanvasItem *ci = gui.mouse_focus;
- while (ci) {
+ gui.key_event_accepted = false;
+ Point2 mpos = mm->get_pos();
- Control *control = ci->cast_to<Control>();
- if (control) {
+ gui.last_mouse_pos = mpos;
- gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum);
- if (gui.drag_data.get_type() != Variant::NIL) {
+ Control *over = NULL;
- gui.mouse_focus = NULL;
- }
+ // D&D
+ if (!gui.drag_attempted && gui.mouse_focus && mm->get_button_mask() & BUTTON_MASK_LEFT) {
+
+ gui.drag_accum += mm->get_relative();
+ float len = gui.drag_accum.length();
+ if (len > 10) {
- if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
- break;
+ { //attempt grab, try parent controls too
+ CanvasItem *ci = gui.mouse_focus;
+ while (ci) {
+
+ Control *control = ci->cast_to<Control>();
+ if (control) {
+
+ gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum);
+ if (gui.drag_data.get_type() != Variant::NIL) {
+
+ gui.mouse_focus = NULL;
}
- if (ci->is_set_as_toplevel())
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
break;
-
- ci = ci->get_parent_item();
}
- }
- gui.drag_attempted = true;
- if (gui.drag_data.get_type() != Variant::NIL) {
+ if (ci->is_set_as_toplevel())
+ break;
- _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN);
+ ci = ci->get_parent_item();
}
}
+
+ gui.drag_attempted = true;
+ if (gui.drag_data.get_type() != Variant::NIL) {
+
+ _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN);
+ }
}
+ }
- if (gui.mouse_focus) {
- over = gui.mouse_focus;
- //recompute focus_inv_xform again here
+ if (gui.mouse_focus) {
+ over = gui.mouse_focus;
+ //recompute focus_inv_xform again here
- } else {
+ } else {
- over = _gui_find_control(mpos);
- }
+ over = _gui_find_control(mpos);
+ }
- if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) {
+ if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) {
- Control *top = gui.modal_stack.back()->get();
- if (over != top && !top->is_a_parent_of(over)) {
+ Control *top = gui.modal_stack.back()->get();
+ if (over != top && !top->is_a_parent_of(over)) {
- break; // don't send motion event to anything below modal stack top
- }
+ return; // don't send motion event to anything below modal stack top
}
+ }
- if (over != gui.mouse_over) {
+ if (over != gui.mouse_over) {
- if (gui.mouse_over)
- gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT);
+ if (gui.mouse_over)
+ gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT);
- _gui_cancel_tooltip();
+ _gui_cancel_tooltip();
- if (over)
- over->notification(Control::NOTIFICATION_MOUSE_ENTER);
- }
+ if (over)
+ over->notification(Control::NOTIFICATION_MOUSE_ENTER);
+ }
- gui.mouse_over = over;
+ gui.mouse_over = over;
- if (gui.drag_preview) {
- gui.drag_preview->set_position(mpos);
- }
+ if (gui.drag_preview) {
+ gui.drag_preview->set_position(mpos);
+ }
- if (!over) {
- OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW);
- break;
- }
+ if (!over) {
+ OS::get_singleton()->set_cursor_shape(OS::CURSOR_ARROW);
+ return;
+ }
- Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
- Size2 pos = localizer.xform(mpos);
- Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x, p_event.mouse_motion.speed_y));
- Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y));
+ Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse();
+ Size2 pos = localizer.xform(mpos);
+ Vector2 speed = localizer.basis_xform(mm->get_speed());
+ Vector2 rel = localizer.basis_xform(mm->get_relative());
- p_event.mouse_motion.global_x = mpos.x;
- p_event.mouse_motion.global_y = mpos.y;
- p_event.mouse_motion.speed_x = speed.x;
- p_event.mouse_motion.speed_y = speed.y;
- p_event.mouse_motion.relative_x = rel.x;
- p_event.mouse_motion.relative_y = rel.y;
+ mm = mm->xformed_by(Transform2D()); //make a copy
- if (p_event.mouse_motion.button_mask == 0) {
- //nothing pressed
+ mm->set_global_pos(mpos);
+ mm->set_speed(speed);
+ mm->set_relative(rel);
- bool can_tooltip = true;
+ if (mm->get_button_mask() == 0) {
+ //nothing pressed
- if (!gui.modal_stack.empty()) {
- if (gui.modal_stack.back()->get() != over && !gui.modal_stack.back()->get()->is_a_parent_of(over))
- can_tooltip = false;
- }
+ bool can_tooltip = true;
- bool is_tooltip_shown = false;
+ if (!gui.modal_stack.empty()) {
+ if (gui.modal_stack.back()->get() != over && !gui.modal_stack.back()->get()->is_a_parent_of(over))
+ can_tooltip = false;
+ }
- if (gui.tooltip_popup) {
- if (can_tooltip) {
- String tooltip = over->get_tooltip(gui.tooltip->get_global_transform().xform_inv(mpos));
+ bool is_tooltip_shown = false;
- if (tooltip.length() == 0)
- _gui_cancel_tooltip();
- else if (tooltip == gui.tooltip_label->get_text())
- is_tooltip_shown = true;
- } else
+ if (gui.tooltip_popup) {
+ if (can_tooltip) {
+ String tooltip = over->get_tooltip(gui.tooltip->get_global_transform().xform_inv(mpos));
+
+ if (tooltip.length() == 0)
_gui_cancel_tooltip();
- }
+ else if (tooltip == gui.tooltip_label->get_text())
+ is_tooltip_shown = true;
+ } else
+ _gui_cancel_tooltip();
+ }
- if (can_tooltip && !is_tooltip_shown) {
+ if (can_tooltip && !is_tooltip_shown) {
- gui.tooltip = over;
- gui.tooltip_pos = mpos; //(parent_xform * get_transform()).affine_inverse().xform(pos);
- gui.tooltip_timer = gui.tooltip_delay;
- }
+ gui.tooltip = over;
+ gui.tooltip_pos = mpos; //(parent_xform * get_transform()).affine_inverse().xform(pos);
+ gui.tooltip_timer = gui.tooltip_delay;
}
+ }
- //pos = gui.focus_inv_xform.xform(pos);
+ //pos = gui.focus_inv_xform.xform(pos);
- p_event.mouse_motion.x = pos.x;
- p_event.mouse_motion.y = pos.y;
+ mm->set_pos(pos);
- Control::CursorShape cursor_shape = over->get_cursor_shape(pos);
- OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape);
+ Control::CursorShape cursor_shape = over->get_cursor_shape(pos);
+ OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape);
- if (over->can_process()) {
- _gui_call_input(over, p_event);
- }
+ if (over->can_process()) {
+ _gui_call_input(over, mm);
+ }
- get_tree()->set_input_as_handled();
+ get_tree()->set_input_as_handled();
- if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) {
+ if (gui.drag_data.get_type() != Variant::NIL && mm->get_button_mask() & BUTTON_MASK_LEFT) {
- bool can_drop = _gui_drop(over, pos, true);
+ bool can_drop = _gui_drop(over, pos, true);
- if (!can_drop) {
- OS::get_singleton()->set_cursor_shape(OS::CURSOR_FORBIDDEN);
- } else {
- OS::get_singleton()->set_cursor_shape(OS::CURSOR_CAN_DROP);
- }
- //change mouse accordingly i guess
+ if (!can_drop) {
+ OS::get_singleton()->set_cursor_shape(OS::CURSOR_FORBIDDEN);
+ } else {
+ OS::get_singleton()->set_cursor_shape(OS::CURSOR_CAN_DROP);
}
+ //change mouse accordingly i guess
+ }
+ }
- } break;
- case InputEvent::ACTION:
- case InputEvent::JOYPAD_BUTTON:
- case InputEvent::JOYPAD_MOTION:
- case InputEvent::KEY: {
+ if (mm.is_null() && mb.is_null() && p_event->is_action_type()) {
- if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) {
- gui.key_focus->release_focus();
- }
+ if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) {
+ gui.key_focus->release_focus();
+ }
- if (gui.key_focus) {
+ if (gui.key_focus) {
- gui.key_event_accepted = false;
- if (gui.key_focus->can_process()) {
- gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input, p_event);
- if (gui.key_focus) //maybe lost it
- gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input, p_event);
- }
+ gui.key_event_accepted = false;
+ if (gui.key_focus->can_process()) {
+ gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input, p_event);
+ if (gui.key_focus) //maybe lost it
+ gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input, p_event);
+ }
- if (gui.key_event_accepted) {
+ if (gui.key_event_accepted) {
- get_tree()->set_input_as_handled();
- break;
- }
+ get_tree()->set_input_as_handled();
+ return;
}
+ }
- if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !gui.modal_stack.empty()) {
+ if (p_event->is_pressed() && p_event->is_action("ui_cancel") && !gui.modal_stack.empty()) {
- _gui_sort_modal_stack();
- Control *top = gui.modal_stack.back()->get();
- if (!top->data.modal_exclusive) {
+ _gui_sort_modal_stack();
+ Control *top = gui.modal_stack.back()->get();
+ if (!top->data.modal_exclusive) {
- top->notification(Control::NOTIFICATION_MODAL_CLOSE);
- top->_modal_stack_remove();
- top->hide();
- }
+ top->notification(Control::NOTIFICATION_MODAL_CLOSE);
+ top->_modal_stack_remove();
+ top->hide();
}
+ }
- Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm
+ Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm
- //keyboard focus
- //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) {
+ //keyboard focus
+ //if (from && p_event->is_pressed() && !p_event->get_alt() && !p_event->get_metakey() && !p_event->key->get_command()) {
- if (from && p_event.is_pressed()) {
- Control *next = NULL;
+ if (from && p_event->is_pressed()) {
+ Control *next = NULL;
- if (p_event.is_action("ui_focus_next")) {
+ if (p_event->is_action("ui_focus_next")) {
- next = from->find_next_valid_focus();
- }
-
- if (p_event.is_action("ui_focus_prev")) {
+ next = from->find_next_valid_focus();
+ }
- next = from->find_prev_valid_focus();
- }
+ if (p_event->is_action("ui_focus_prev")) {
- if (p_event.is_action("ui_up")) {
+ next = from->find_prev_valid_focus();
+ }
- next = from->_get_focus_neighbour(MARGIN_TOP);
- }
+ if (p_event->is_action("ui_up")) {
- if (p_event.is_action("ui_left")) {
+ next = from->_get_focus_neighbour(MARGIN_TOP);
+ }
- next = from->_get_focus_neighbour(MARGIN_LEFT);
- }
+ if (p_event->is_action("ui_left")) {
- if (p_event.is_action("ui_right")) {
+ next = from->_get_focus_neighbour(MARGIN_LEFT);
+ }
- next = from->_get_focus_neighbour(MARGIN_RIGHT);
- }
+ if (p_event->is_action("ui_right")) {
- if (p_event.is_action("ui_down")) {
+ next = from->_get_focus_neighbour(MARGIN_RIGHT);
+ }
- next = from->_get_focus_neighbour(MARGIN_BOTTOM);
- }
+ if (p_event->is_action("ui_down")) {
- if (next) {
- next->grab_focus();
- get_tree()->set_input_as_handled();
- }
+ next = from->_get_focus_neighbour(MARGIN_BOTTOM);
}
- } break;
+ if (next) {
+ next->grab_focus();
+ get_tree()->set_input_as_handled();
+ }
+ }
}
}
@@ -2366,33 +2312,30 @@ void Viewport::_gui_grab_click_focus(Control *p_control) {
if (gui.mouse_focus == p_control)
return;
- InputEvent ie;
- ie.type = InputEvent::MOUSE_BUTTON;
- InputEventMouseButton &mb = ie.mouse_button;
+ Ref<InputEventMouseButton> mb;
+ mb.instance();
//send unclic
Point2 click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos);
- mb.x = click.x;
- mb.y = click.y;
- mb.button_index = gui.mouse_focus_button;
- mb.pressed = false;
- gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, ie);
+ mb->set_pos(click);
+ mb->set_button_index(gui.mouse_focus_button);
+ mb->set_pressed(false);
+ gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb);
gui.mouse_focus = p_control;
gui.focus_inv_xform = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse();
click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos);
- mb.x = click.x;
- mb.y = click.y;
- mb.button_index = gui.mouse_focus_button;
- mb.pressed = true;
- gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, ie);
+ mb->set_pos(click);
+ mb->set_button_index(gui.mouse_focus_button);
+ mb->set_pressed(true);
+ gui.mouse_focus->call_deferred(SceneStringNames::get_singleton()->_gui_input, mb);
}
}
///////////////////////////////
-void Viewport::input(const InputEvent &p_event) {
+void Viewport::input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!is_inside_tree());
@@ -2401,20 +2344,20 @@ void Viewport::input(const InputEvent &p_event) {
//get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check
}
-void Viewport::unhandled_input(const InputEvent &p_event) {
+void Viewport::unhandled_input(const Ref<InputEvent> &p_event) {
ERR_FAIL_COND(!is_inside_tree());
get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", p_event);
//call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev);
- if (!get_tree()->input_handled && p_event.type == InputEvent::KEY) {
+ if (!get_tree()->input_handled && p_event->cast_to<InputEventKey>() != NULL) {
get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", p_event);
//call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev);
}
if (physics_object_picking && !get_tree()->input_handled) {
- if (p_event.type == InputEvent::MOUSE_BUTTON || p_event.type == InputEvent::MOUSE_MOTION || p_event.type == InputEvent::SCREEN_DRAG || p_event.type == InputEvent::SCREEN_TOUCH) {
+ if (p_event->cast_to<InputEventMouseButton>() || p_event->cast_to<InputEventMouseMotion>() || p_event->cast_to<InputEventScreenDrag>() || p_event->cast_to<InputEventScreenTouch>()) {
physics_picking_events.push_back(p_event);
}
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index e0f9cf1de2..7470cefb49 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -158,7 +158,7 @@ private:
bool gen_mipmaps;
bool physics_object_picking;
- List<InputEvent> physics_picking_events;
+ List<Ref<InputEvent> > physics_picking_events;
ObjectID physics_object_capture;
ObjectID physics_object_over;
Vector2 physics_last_mousepos;
@@ -237,14 +237,14 @@ private:
bool disable_input;
- void _gui_call_input(Control *p_control, const InputEvent &p_input);
+ void _gui_call_input(Control *p_control, const Ref<InputEvent> &p_input);
void _gui_sort_subwindows();
void _gui_sort_roots();
void _gui_sort_modal_stack();
Control *_gui_find_control(const Point2 &p_global);
Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform);
- void _gui_input_event(InputEvent p_event);
+ void _gui_input_event(Ref<InputEvent> p_event);
void update_worlds();
@@ -253,10 +253,10 @@ private:
void _vp_enter_tree();
void _vp_exit_tree();
- void _vp_input(const InputEvent &p_ev);
+ void _vp_input(const Ref<InputEvent> &p_ev);
void _vp_input_text(const String &p_text);
- void _vp_unhandled_input(const InputEvent &p_ev);
- void _make_input_local(InputEvent &ev);
+ void _vp_unhandled_input(const Ref<InputEvent> &p_ev);
+ Ref<InputEvent> _make_input_local(const Ref<InputEvent> &ev);
friend class Control;
@@ -388,8 +388,8 @@ public:
void set_use_own_world(bool p_world);
bool is_using_own_world() const;
- void input(const InputEvent &p_event);
- void unhandled_input(const InputEvent &p_event);
+ void input(const Ref<InputEvent> &p_event);
+ void unhandled_input(const Ref<InputEvent> &p_event);
void set_disable_input(bool p_disable);
bool is_input_disabled() const;