summaryrefslogtreecommitdiffstats
path: root/scene/gui
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 /scene/gui
parent93f9a83062dbe74474a4a7928758c5cf5588238e (diff)
downloadredot-engine-5b3709d3096df737b8bb2344446be818b0389bfe.tar.gz
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
Diffstat (limited to 'scene/gui')
-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
49 files changed, 2593 insertions, 2577 deletions
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;