summaryrefslogtreecommitdiffstats
path: root/scene/gui/graph_edit.cpp
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/graph_edit.cpp
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/graph_edit.cpp')
-rw-r--r--scene/gui/graph_edit.cpp81
1 files changed, 42 insertions, 39 deletions
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();
}