summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/gui/graph_edit.cpp22
-rw-r--r--scene/gui/graph_edit.h1
-rw-r--r--scene/gui/item_list.cpp6
-rw-r--r--scene/gui/rich_text_label.cpp10
-rw-r--r--scene/gui/scroll_container.cpp11
-rw-r--r--scene/gui/text_edit.cpp97
-rw-r--r--scene/gui/text_edit.h3
-rw-r--r--scene/gui/tree.cpp6
-rw-r--r--scene/main/viewport.cpp24
9 files changed, 140 insertions, 40 deletions
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 946a8c47a3..da52fb39e0 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -964,6 +964,19 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
emit_signal("delete_nodes_request");
accept_event();
}
+
+ Ref<InputEventMagnifyGesture> magnify_gesture = p_ev;
+ if (magnify_gesture.is_valid()) {
+
+ set_zoom_custom(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position());
+ }
+
+ Ref<InputEventPanGesture> pan_gesture = p_ev;
+ if (pan_gesture.is_valid()) {
+
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
void GraphEdit::clear_connections() {
@@ -975,6 +988,11 @@ void GraphEdit::clear_connections() {
void GraphEdit::set_zoom(float p_zoom) {
+ set_zoom_custom(p_zoom, get_size() / 2);
+}
+
+void GraphEdit::set_zoom_custom(float p_zoom, const Vector2 &p_center) {
+
p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM);
if (zoom == p_zoom)
return;
@@ -982,7 +1000,7 @@ void GraphEdit::set_zoom(float p_zoom) {
zoom_minus->set_disabled(zoom == MIN_ZOOM);
zoom_plus->set_disabled(zoom == MAX_ZOOM);
- Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + get_size() / 2) / zoom;
+ Vector2 sbofs = (Vector2(h_scroll->get_value(), v_scroll->get_value()) + p_center) / zoom;
zoom = p_zoom;
top_layer->update();
@@ -992,7 +1010,7 @@ void GraphEdit::set_zoom(float p_zoom) {
if (is_visible_in_tree()) {
- Vector2 ofs = sbofs * zoom - get_size() / 2;
+ Vector2 ofs = sbofs * zoom - p_center;
h_scroll->set_value(ofs.x);
v_scroll->set_value(ofs.y);
}
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 4656b50133..e8e530848d 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -179,6 +179,7 @@ public:
bool is_valid_connection_type(int p_type, int p_with_type) const;
void set_zoom(float p_zoom);
+ void set_zoom_custom(float p_zoom, const Vector2 &p_center);
float get_zoom() const;
GraphEditFilter *get_top_layer() const { return top_layer; }
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 5e4dedcb48..51ab49e643 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -713,6 +713,12 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) {
}
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ scroll_bar->set_value(scroll_bar->get_value() + scroll_bar->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
void ItemList::ensure_current_is_visible() {
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 71e02cb2f7..124c268c8a 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -817,6 +817,16 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ if (scroll_active)
+
+ vscroll->set_value(vscroll->get_value() + vscroll->get_page() * pan_gesture->get_delta().y * 0.5 / 8);
+
+ return;
+ }
+
Ref<InputEventKey> k = p_event;
if (k.is_valid()) {
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 9022d67a4a..a71a1c5f92 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -180,6 +180,17 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) {
time_since_motion = 0;
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_gui_input;
+ if (pan_gesture.is_valid()) {
+
+ if (h_scroll->is_visible_in_tree()) {
+ h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
+ }
+ if (v_scroll->is_visible_in_tree()) {
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
+ }
}
void ScrollContainer::_update_scrollbar_position() {
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 21842d4d58..2c47c4e827 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1777,46 +1777,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (mb->is_pressed()) {
if (mb->get_button_index() == BUTTON_WHEEL_UP && !mb->get_command()) {
- float scroll_factor = 3 * mb->get_factor();
- if (scrolling) {
- target_v_scroll = (target_v_scroll - scroll_factor);
- } else {
- target_v_scroll = (v_scroll->get_value() - scroll_factor);
- }
-
- if (smooth_scroll_enabled) {
- if (target_v_scroll <= 0) {
- target_v_scroll = 0;
- }
- scrolling = true;
- set_physics_process(true);
- } else {
- v_scroll->set_value(target_v_scroll);
- }
+ _scroll_up(3 * mb->get_factor());
}
if (mb->get_button_index() == BUTTON_WHEEL_DOWN && !mb->get_command()) {
- float scroll_factor = 3 * mb->get_factor();
- if (scrolling) {
- target_v_scroll = (target_v_scroll + scroll_factor);
- } else {
- target_v_scroll = (v_scroll->get_value() + scroll_factor);
- }
-
- if (smooth_scroll_enabled) {
- int max_v_scroll = get_total_unhidden_rows();
- if (!scroll_past_end_of_file_enabled) {
- max_v_scroll -= get_visible_rows();
- max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows());
- }
-
- if (target_v_scroll > max_v_scroll) {
- target_v_scroll = max_v_scroll;
- }
- scrolling = true;
- set_physics_process(true);
- } else {
- v_scroll->set_value(target_v_scroll);
- }
+ _scroll_down(3 * mb->get_factor());
}
if (mb->get_button_index() == BUTTON_WHEEL_LEFT) {
h_scroll->set_value(h_scroll->get_value() - (100 * mb->get_factor()));
@@ -1973,6 +1937,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+ const Ref<InputEventPanGesture> pan_gesture = p_gui_input;
+ if (pan_gesture.is_valid()) {
+
+ const real_t delta = pan_gesture->get_delta().y;
+ if (delta < 0) {
+ _scroll_up(-delta);
+ } else {
+ _scroll_down(delta);
+ }
+ h_scroll->set_value(h_scroll->get_value() + pan_gesture->get_delta().x * 100);
+ return;
+ }
+
Ref<InputEventMouseMotion> mm = p_gui_input;
if (mm.is_valid()) {
@@ -3066,6 +3043,50 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
}
}
+void TextEdit::_scroll_up(real_t p_delta) {
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll - p_delta);
+ } else {
+ target_v_scroll = (v_scroll->get_value() - p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ if (target_v_scroll <= 0) {
+ target_v_scroll = 0;
+ }
+ scrolling = true;
+ set_physics_process(true);
+ } else {
+ v_scroll->set_value(target_v_scroll);
+ }
+}
+
+void TextEdit::_scroll_down(real_t p_delta) {
+
+ if (scrolling) {
+ target_v_scroll = (target_v_scroll + p_delta);
+ } else {
+ target_v_scroll = (v_scroll->get_value() + p_delta);
+ }
+
+ if (smooth_scroll_enabled) {
+ int max_v_scroll = get_total_unhidden_rows();
+ if (!scroll_past_end_of_file_enabled) {
+ max_v_scroll -= get_visible_rows();
+ max_v_scroll = CLAMP(max_v_scroll, 0, get_total_unhidden_rows());
+ }
+
+ if (target_v_scroll > max_v_scroll) {
+ target_v_scroll = max_v_scroll;
+ }
+ scrolling = true;
+ set_physics_process(true);
+ } else {
+ v_scroll->set_value(target_v_scroll);
+ }
+}
+
void TextEdit::_pre_shift_selection() {
if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) {
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index b1c7b14e58..bb9ca87d06 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -328,6 +328,9 @@ class TextEdit : public Control {
void _update_selection_mode_word();
void _update_selection_mode_line();
+ void _scroll_up(real_t p_delta);
+ void _scroll_down(real_t p_delta);
+
void _pre_shift_selection();
void _post_shift_selection();
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 749ff51f57..9213296c55 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2612,6 +2612,12 @@ void Tree::_gui_input(Ref<InputEvent> p_event) {
} break;
}
}
+
+ Ref<InputEventPanGesture> pan_gesture = p_event;
+ if (pan_gesture.is_valid()) {
+
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
+ }
}
bool Tree::edit_selected() {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 0a02f471c1..1f539041fd 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2013,6 +2013,30 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
}
}
+ Ref<InputEventGesture> gesture_event = p_event;
+ if (gesture_event.is_valid()) {
+
+ Size2 pos = gesture_event->get_position();
+
+ Control *over = _gui_find_control(pos);
+ if (over) {
+
+ if (over->can_process()) {
+
+ gesture_event = gesture_event->xformed_by(Transform2D()); //make a copy
+ if (over == gui.mouse_focus) {
+ pos = gui.focus_inv_xform.xform(pos);
+ } else {
+ pos = over->get_global_transform_with_canvas().affine_inverse().xform(pos);
+ }
+ gesture_event->set_position(pos);
+ _gui_call_input(over, gesture_event);
+ }
+ get_tree()->set_input_as_handled();
+ return;
+ }
+ }
+
Ref<InputEventScreenDrag> drag_event = p_event;
if (drag_event.is_valid()) {