summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredia Huya-Kouadio <fhuyakou@gmail.com>2023-04-05 16:29:03 -0700
committerYuri Sizov <yuris@humnom.net>2023-04-26 14:32:20 +0200
commitbceb910f3a2c1cf864f0a6a675c995e4bf87252e (patch)
treedbc563b3817cb333c9426fc5f2abd6a0f23b929d
parenteae3d61d7fba3305057d048b1c30c0bae8739e42 (diff)
Make `EditorPropertyLayersGrid` responsive to touch taps
(cherry picked from commit aa7a4d56f029fb5e3a3f2f4b569047bc546bf134)
-rw-r--r--editor/editor_properties.cpp106
-rw-r--r--editor/editor_properties.h3
2 files changed, 62 insertions, 47 deletions
diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp
index b8e491b243..01a574def6 100644
--- a/editor/editor_properties.cpp
+++ b/editor/editor_properties.cpp
@@ -868,56 +868,75 @@ String EditorPropertyLayersGrid::get_tooltip(const Point2 &p_pos) const {
return String();
}
+void EditorPropertyLayersGrid::_update_hovered(const Vector2 &p_position) {
+ bool expand_was_hovered = expand_hovered;
+ expand_hovered = expand_rect.has_point(p_position);
+ if (expand_hovered != expand_was_hovered) {
+ queue_redraw();
+ }
+
+ if (!expand_hovered) {
+ for (int i = 0; i < flag_rects.size(); i++) {
+ if (flag_rects[i].has_point(p_position)) {
+ // Used to highlight the hovered flag in the layers grid.
+ hovered_index = i;
+ queue_redraw();
+ return;
+ }
+ }
+ }
+
+ // Remove highlight when no square is hovered.
+ if (hovered_index != -1) {
+ hovered_index = -1;
+ queue_redraw();
+ }
+}
+
+void EditorPropertyLayersGrid::_on_hover_exit() {
+ if (expand_hovered) {
+ expand_hovered = false;
+ queue_redraw();
+ }
+ if (hovered_index != -1) {
+ hovered_index = -1;
+ queue_redraw();
+ }
+}
+
+void EditorPropertyLayersGrid::_update_flag() {
+ if (hovered_index >= 0) {
+ // Toggle the flag.
+ // We base our choice on the hovered flag, so that it always matches the hovered flag.
+ if (value & (1 << hovered_index)) {
+ value &= ~(1 << hovered_index);
+ } else {
+ value |= (1 << hovered_index);
+ }
+
+ emit_signal(SNAME("flag_changed"), value);
+ queue_redraw();
+ } else if (expand_hovered) {
+ expanded = !expanded;
+ update_minimum_size();
+ queue_redraw();
+ }
+}
+
void EditorPropertyLayersGrid::gui_input(const Ref<InputEvent> &p_ev) {
if (read_only) {
return;
}
const Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid()) {
- bool expand_was_hovered = expand_hovered;
- expand_hovered = expand_rect.has_point(mm->get_position());
- if (expand_hovered != expand_was_hovered) {
- queue_redraw();
- }
-
- if (!expand_hovered) {
- for (int i = 0; i < flag_rects.size(); i++) {
- if (flag_rects[i].has_point(mm->get_position())) {
- // Used to highlight the hovered flag in the layers grid.
- hovered_index = i;
- queue_redraw();
- return;
- }
- }
- }
-
- // Remove highlight when no square is hovered.
- if (hovered_index != -1) {
- hovered_index = -1;
- queue_redraw();
- }
-
+ _update_hovered(mm->get_position());
return;
}
const Ref<InputEventMouseButton> mb = p_ev;
if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
- if (hovered_index >= 0) {
- // Toggle the flag.
- // We base our choice on the hovered flag, so that it always matches the hovered flag.
- if (value & (1 << hovered_index)) {
- value &= ~(1 << hovered_index);
- } else {
- value |= (1 << hovered_index);
- }
-
- emit_signal(SNAME("flag_changed"), value);
- queue_redraw();
- } else if (expand_hovered) {
- expanded = !expanded;
- update_minimum_size();
- queue_redraw();
- }
+ _update_hovered(mb->get_position());
+ _update_flag();
}
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
if (hovered_index >= 0) {
@@ -1052,14 +1071,7 @@ void EditorPropertyLayersGrid::_notification(int p_what) {
} break;
case NOTIFICATION_MOUSE_EXIT: {
- if (expand_hovered) {
- expand_hovered = false;
- queue_redraw();
- }
- if (hovered_index != -1) {
- hovered_index = -1;
- queue_redraw();
- }
+ _on_hover_exit();
} break;
}
}
diff --git a/editor/editor_properties.h b/editor/editor_properties.h
index 14a2699ad8..0d54025c7b 100644
--- a/editor/editor_properties.h
+++ b/editor/editor_properties.h
@@ -273,6 +273,9 @@ private:
void _rename_pressed(int p_menu);
void _rename_operation_confirm();
+ void _update_hovered(const Vector2 &p_position);
+ void _on_hover_exit();
+ void _update_flag();
Size2 get_grid_size() const;
protected: