Window.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. /// \file
  4. #pragma once
  5. #include "../UI/BorderImage.h"
  6. namespace Urho3D
  7. {
  8. /// %Window movement and resizing modes.
  9. enum WindowDragMode
  10. {
  11. DRAG_NONE,
  12. DRAG_MOVE,
  13. DRAG_RESIZE_TOPLEFT,
  14. DRAG_RESIZE_TOP,
  15. DRAG_RESIZE_TOPRIGHT,
  16. DRAG_RESIZE_RIGHT,
  17. DRAG_RESIZE_BOTTOMRIGHT,
  18. DRAG_RESIZE_BOTTOM,
  19. DRAG_RESIZE_BOTTOMLEFT,
  20. DRAG_RESIZE_LEFT
  21. };
  22. /// %Window %UI element that can optionally by moved or resized.
  23. class URHO3D_API Window : public BorderImage
  24. {
  25. URHO3D_OBJECT(Window, BorderImage);
  26. public:
  27. /// Construct.
  28. explicit Window(Context* context);
  29. /// Destruct.
  30. ~Window() override;
  31. /// Register object factory.
  32. /// @nobind
  33. static void RegisterObject(Context* context);
  34. /// Return UI rendering batches.
  35. void GetBatches(Vector<UIBatch>& batches, Vector<float>& vertexData, const IntRect& currentScissor) override;
  36. /// React to mouse hover.
  37. void OnHover(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  38. /// React to mouse drag begin.
  39. void
  40. OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  41. /// React to mouse drag motion.
  42. void OnDragMove
  43. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons, QualifierFlags qualifiers,
  44. Cursor* cursor) override;
  45. /// React to mouse drag end.
  46. void
  47. OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags releaseButtons, Cursor* cursor) override;
  48. /// React to mouse drag cancel.
  49. void
  50. OnDragCancel(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags cancelButtons, Cursor* cursor) override;
  51. /// Set whether can be moved.
  52. /// @property
  53. void SetMovable(bool enable);
  54. /// Set whether can be resized.
  55. /// @property
  56. void SetResizable(bool enable);
  57. /// Set whether resizing width is fixed.
  58. /// @property
  59. void SetFixedWidthResizing(bool enable);
  60. /// Set whether resizing height is fixed.
  61. /// @property
  62. void SetFixedHeightResizing(bool enable);
  63. /// Set resize area width at edges.
  64. /// @property
  65. void SetResizeBorder(const IntRect& rect);
  66. /// Set modal flag. When the modal flag is set, the focused window needs to be dismissed first to allow other UI elements to gain focus.
  67. /// @property
  68. void SetModal(bool modal);
  69. /// Set modal shade color.
  70. /// @property
  71. void SetModalShadeColor(const Color& color);
  72. /// Set modal frame color.
  73. /// @property
  74. void SetModalFrameColor(const Color& color);
  75. /// Set modal frame size.
  76. /// @property
  77. void SetModalFrameSize(const IntVector2& size);
  78. /// Set whether model window can be dismissed with the escape key. Default true.
  79. /// @property
  80. void SetModalAutoDismiss(bool enable);
  81. /// Return whether is movable.
  82. /// @property
  83. bool IsMovable() const { return movable_; }
  84. /// Return whether is resizable.
  85. /// @property
  86. bool IsResizable() const { return resizable_; }
  87. /// Return whether is resizing width is fixed.
  88. /// @property
  89. bool GetFixedWidthResizing() const { return fixedWidthResizing_; }
  90. /// Return whether is resizing height is fixed.
  91. /// @property
  92. bool GetFixedHeightResizing() const { return fixedHeightResizing_; }
  93. /// Return resize area width at edges.
  94. /// @property
  95. const IntRect& GetResizeBorder() const { return resizeBorder_; }
  96. /// Return modal flag.
  97. /// @property
  98. bool IsModal() const { return modal_; }
  99. /// Get modal shade color.
  100. /// @property
  101. const Color& GetModalShadeColor() const { return modalShadeColor_; }
  102. /// Get modal frame color.
  103. /// @property
  104. const Color& GetModalFrameColor() const { return modalFrameColor_; }
  105. /// Get modal frame size.
  106. /// @property
  107. const IntVector2& GetModalFrameSize() const { return modalFrameSize_; }
  108. /// Return whether can be dismissed with escape key.
  109. /// @property
  110. bool GetModalAutoDismiss() const { return modalAutoDismiss_; }
  111. protected:
  112. /// Identify drag mode (move/resize).
  113. WindowDragMode GetDragMode(const IntVector2& position) const;
  114. /// Set cursor shape based on drag mode.
  115. void SetCursorShape(WindowDragMode mode, Cursor* cursor) const;
  116. /// Validate window position.
  117. void ValidatePosition();
  118. /// Check whether alignment supports moving and resizing.
  119. bool CheckAlignment() const;
  120. /// Movable flag.
  121. bool movable_;
  122. /// Resizable flag.
  123. bool resizable_;
  124. /// Fixed width resize flag.
  125. bool fixedWidthResizing_;
  126. /// Fixed height resize flag.
  127. bool fixedHeightResizing_;
  128. /// Resize area width at edges.
  129. IntRect resizeBorder_;
  130. /// Current drag mode.
  131. WindowDragMode dragMode_;
  132. /// Mouse position at drag begin.
  133. IntVector2 dragBeginCursor_;
  134. /// Original position at drag begin.
  135. IntVector2 dragBeginPosition_;
  136. /// Original size at drag begin.
  137. IntVector2 dragBeginSize_;
  138. /// Modal flag.
  139. bool modal_;
  140. /// Modal auto dismiss (with escape key) flag. Default true.
  141. bool modalAutoDismiss_;
  142. /// Modal shade color, used when modal flag is set.
  143. Color modalShadeColor_;
  144. /// Modal frame color, used when modal flag is set.
  145. Color modalFrameColor_;
  146. /// Modal frame size, used when modal flag is set.
  147. IntVector2 modalFrameSize_;
  148. };
  149. }