| 39 | #include "editor_title_bar.h" |
| 40 | |
| 41 | void EditorTitleBar::gui_input(const Ref<InputEvent> &p_event) { |
| 42 | if (!can_move) { |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | Ref<InputEventMouseMotion> mm = p_event; |
| 47 | if (mm.is_valid() && moving) { |
| 48 | if (mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) { |
| 49 | Window *w = Object::cast_to<Window>(get_viewport()); |
| 50 | if (w) { |
| 51 | Point2 mouse = DisplayServer::get_singleton()->mouse_get_position(); |
| 52 | w->set_position(mouse - click_pos); |
| 53 | } |
| 54 | } else { |
| 55 | moving = false; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | Ref<InputEventMouseButton> mb = p_event; |
| 60 | if (mb.is_valid() && has_point(mb->get_position())) { |
| 61 | Window *w = Object::cast_to<Window>(get_viewport()); |
| 62 | if (w) { |
| 63 | if (mb->get_button_index() == MouseButton::LEFT) { |
| 64 | if (mb->is_pressed()) { |
| 65 | if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_WINDOW_DRAG)) { |
| 66 | DisplayServer::get_singleton()->window_start_drag(w->get_window_id()); |
| 67 | } else { |
| 68 | click_pos = DisplayServer::get_singleton()->mouse_get_position() - w->get_position(); |
| 69 | moving = true; |
| 70 | } |
| 71 | } else { |
| 72 | moving = false; |
| 73 | } |
| 74 | } |
| 75 | if (mb->get_button_index() == MouseButton::LEFT && mb->is_double_click() && mb->is_pressed()) { |
| 76 | if (DisplayServer::get_singleton()->window_maximize_on_title_dbl_click()) { |
| 77 | if (w->get_mode() == Window::MODE_WINDOWED) { |
| 78 | w->set_mode(Window::MODE_MAXIMIZED); |
| 79 | } else if (w->get_mode() == Window::MODE_MAXIMIZED) { |
| 80 | w->set_mode(Window::MODE_WINDOWED); |
| 81 | } |
| 82 | } else if (DisplayServer::get_singleton()->window_minimize_on_title_dbl_click()) { |
| 83 | w->set_mode(Window::MODE_MINIMIZED); |
| 84 | } |
| 85 | moving = false; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | void EditorTitleBar::set_center_control(Control *p_center_control) { |
| 92 | center_control = p_center_control; |
no test coverage detected