editor_title_bar.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /**************************************************************************/
  2. /* editor_title_bar.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "editor_title_bar.h"
  31. void EditorTitleBar::gui_input(const Ref<InputEvent> &p_event) {
  32. if (!can_move) {
  33. return;
  34. }
  35. Ref<InputEventMouseMotion> mm = p_event;
  36. if (mm.is_valid() && moving) {
  37. if (mm->get_button_mask().has_flag(MouseButtonMask::LEFT)) {
  38. Window *w = Object::cast_to<Window>(get_viewport());
  39. if (w) {
  40. Point2 mouse = DisplayServer::get_singleton()->mouse_get_position();
  41. w->set_position(mouse - click_pos);
  42. }
  43. } else {
  44. moving = false;
  45. }
  46. }
  47. Ref<InputEventMouseButton> mb = p_event;
  48. if (mb.is_valid() && has_point(mb->get_position())) {
  49. Window *w = Object::cast_to<Window>(get_viewport());
  50. if (w) {
  51. if (mb->get_button_index() == MouseButton::LEFT) {
  52. if (mb->is_pressed()) {
  53. click_pos = DisplayServer::get_singleton()->mouse_get_position() - w->get_position();
  54. moving = true;
  55. } else {
  56. moving = false;
  57. }
  58. }
  59. if (mb->get_button_index() == MouseButton::LEFT && mb->is_double_click() && mb->is_pressed()) {
  60. if (DisplayServer::get_singleton()->window_maximize_on_title_dbl_click()) {
  61. if (w->get_mode() == Window::MODE_WINDOWED) {
  62. w->set_mode(Window::MODE_MAXIMIZED);
  63. } else if (w->get_mode() == Window::MODE_MAXIMIZED) {
  64. w->set_mode(Window::MODE_WINDOWED);
  65. }
  66. } else if (DisplayServer::get_singleton()->window_minimize_on_title_dbl_click()) {
  67. w->set_mode(Window::MODE_MINIMIZED);
  68. }
  69. moving = false;
  70. }
  71. }
  72. }
  73. }
  74. void EditorTitleBar::set_can_move_window(bool p_enabled) {
  75. can_move = p_enabled;
  76. set_process_input(can_move);
  77. }
  78. bool EditorTitleBar::get_can_move_window() const {
  79. return can_move;
  80. }