Window.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. /// \file
  23. #pragma once
  24. #include "../UI/BorderImage.h"
  25. namespace Urho3D
  26. {
  27. /// %Window movement and resizing modes.
  28. enum WindowDragMode
  29. {
  30. DRAG_NONE,
  31. DRAG_MOVE,
  32. DRAG_RESIZE_TOPLEFT,
  33. DRAG_RESIZE_TOP,
  34. DRAG_RESIZE_TOPRIGHT,
  35. DRAG_RESIZE_RIGHT,
  36. DRAG_RESIZE_BOTTOMRIGHT,
  37. DRAG_RESIZE_BOTTOM,
  38. DRAG_RESIZE_BOTTOMLEFT,
  39. DRAG_RESIZE_LEFT
  40. };
  41. /// %Window %UI element that can optionally by moved or resized.
  42. class URHO3D_API Window : public BorderImage
  43. {
  44. URHO3D_OBJECT(Window, BorderImage);
  45. public:
  46. /// Construct.
  47. explicit Window(Context* context);
  48. /// Destruct.
  49. ~Window() override;
  50. /// Register object factory.
  51. static void RegisterObject(Context* context);
  52. /// Return UI rendering batches.
  53. void GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData, const IntRect& currentScissor) override;
  54. /// React to mouse hover.
  55. void OnHover(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  56. /// React to mouse drag begin.
  57. void
  58. OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags buttons, QualifierFlags qualifiers, Cursor* cursor) override;
  59. /// React to mouse drag motion.
  60. void OnDragMove
  61. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, MouseButtonFlags buttons, QualifierFlags qualifiers,
  62. Cursor* cursor) override;
  63. /// React to mouse drag end.
  64. void
  65. OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags releaseButtons, Cursor* cursor) override;
  66. /// React to mouse drag cancel.
  67. void
  68. OnDragCancel(const IntVector2& position, const IntVector2& screenPosition, MouseButtonFlags dragButtons, MouseButtonFlags cancelButtons, Cursor* cursor) override;
  69. /// Set whether can be moved.
  70. /// @property
  71. void SetMovable(bool enable);
  72. /// Set whether can be resized.
  73. /// @property
  74. void SetResizable(bool enable);
  75. /// Set whether resizing width is fixed.
  76. /// @property
  77. void SetFixedWidthResizing(bool enable);
  78. /// Set whether resizing height is fixed.
  79. /// @property
  80. void SetFixedHeightResizing(bool enable);
  81. /// Set resize area width at edges.
  82. /// @property
  83. void SetResizeBorder(const IntRect& rect);
  84. /// 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.
  85. /// @property
  86. void SetModal(bool modal);
  87. /// Set modal shade color.
  88. /// @property
  89. void SetModalShadeColor(const Color& color);
  90. /// Set modal frame color.
  91. /// @property
  92. void SetModalFrameColor(const Color& color);
  93. /// Set modal frame size.
  94. /// @property
  95. void SetModalFrameSize(const IntVector2& size);
  96. /// Set whether model window can be dismissed with the escape key. Default true.
  97. /// @property
  98. void SetModalAutoDismiss(bool enable);
  99. /// Return whether is movable.
  100. /// @property
  101. bool IsMovable() const { return movable_; }
  102. /// Return whether is resizable.
  103. /// @property
  104. bool IsResizable() const { return resizable_; }
  105. /// Return whether is resizing width is fixed.
  106. /// @property
  107. bool GetFixedWidthResizing() const { return fixedWidthResizing_; }
  108. /// Return whether is resizing height is fixed.
  109. /// @property
  110. bool GetFixedHeightResizing() const { return fixedHeightResizing_; }
  111. /// Return resize area width at edges.
  112. /// @property
  113. const IntRect& GetResizeBorder() const { return resizeBorder_; }
  114. /// Return modal flag.
  115. /// @property
  116. bool IsModal() const { return modal_; }
  117. /// Get modal shade color.
  118. /// @property
  119. const Color& GetModalShadeColor() const { return modalShadeColor_; }
  120. /// Get modal frame color.
  121. /// @property
  122. const Color& GetModalFrameColor() const { return modalFrameColor_; }
  123. /// Get modal frame size.
  124. /// @property
  125. const IntVector2& GetModalFrameSize() const { return modalFrameSize_; }
  126. /// Return whether can be dismissed with escape key.
  127. /// @property
  128. bool GetModalAutoDismiss() const { return modalAutoDismiss_; }
  129. protected:
  130. /// Identify drag mode (move/resize).
  131. WindowDragMode GetDragMode(const IntVector2& position) const;
  132. /// Set cursor shape based on drag mode.
  133. void SetCursorShape(WindowDragMode mode, Cursor* cursor) const;
  134. /// Validate window position.
  135. void ValidatePosition();
  136. /// Check whether alignment supports moving and resizing.
  137. bool CheckAlignment() const;
  138. /// Movable flag.
  139. bool movable_;
  140. /// Resizable flag.
  141. bool resizable_;
  142. /// Fixed width resize flag.
  143. bool fixedWidthResizing_;
  144. /// Fixed height resize flag.
  145. bool fixedHeightResizing_;
  146. /// Resize area width at edges.
  147. IntRect resizeBorder_;
  148. /// Current drag mode.
  149. WindowDragMode dragMode_;
  150. /// Mouse position at drag begin.
  151. IntVector2 dragBeginCursor_;
  152. /// Original position at drag begin.
  153. IntVector2 dragBeginPosition_;
  154. /// Original size at drag begin.
  155. IntVector2 dragBeginSize_;
  156. /// Modal flag.
  157. bool modal_;
  158. /// Modal auto dismiss (with escape key) flag. Default true.
  159. bool modalAutoDismiss_;
  160. /// Modal shade color, used when modal flag is set.
  161. Color modalShadeColor_;
  162. /// Modal frame color, used when modal flag is set.
  163. Color modalFrameColor_;
  164. /// Modal frame size, used when modal flag is set.
  165. IntVector2 modalFrameSize_;
  166. };
  167. }