Window.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, int buttons, int qualifiers, Cursor* cursor) override;
  56. /// React to mouse drag begin.
  57. void
  58. OnDragBegin(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor) override;
  59. /// React to mouse drag motion.
  60. void OnDragMove
  61. (const IntVector2& position, const IntVector2& screenPosition, const IntVector2& deltaPos, int buttons, int qualifiers,
  62. Cursor* cursor) override;
  63. /// React to mouse drag end.
  64. void
  65. OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, int dragButtons, int buttons, Cursor* cursor) override;
  66. /// React to mouse drag cancel.
  67. void
  68. OnDragCancel(const IntVector2& position, const IntVector2& screenPosition, int dragButtons, int buttons, Cursor* cursor) override;
  69. /// Set whether can be moved.
  70. void SetMovable(bool enable);
  71. /// Set whether can be resized.
  72. void SetResizable(bool enable);
  73. /// Set whether resizing width is fixed.
  74. void SetFixedWidthResizing(bool enable);
  75. /// Set whether resizing height is fixed.
  76. void SetFixedHeightResizing(bool enable);
  77. /// Set resize area width at edges.
  78. void SetResizeBorder(const IntRect& rect);
  79. /// 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.
  80. void SetModal(bool modal);
  81. /// Set modal shade color.
  82. void SetModalShadeColor(const Color& color);
  83. /// Set modal frame color.
  84. void SetModalFrameColor(const Color& color);
  85. /// Set modal frame size.
  86. void SetModalFrameSize(const IntVector2& size);
  87. /// Set whether model window can be dismissed with the escape key. Default true.
  88. void SetModalAutoDismiss(bool enable);
  89. /// Return whether is movable.
  90. bool IsMovable() const { return movable_; }
  91. /// Return whether is resizable.
  92. bool IsResizable() const { return resizable_; }
  93. /// Return whether is resizing width is fixed.
  94. bool GetFixedWidthResizing() const { return fixedWidthResizing_; }
  95. /// Return whether is resizing height is fixed.
  96. bool GetFixedHeightResizing() const { return fixedHeightResizing_; }
  97. /// Return resize area width at edges.
  98. const IntRect& GetResizeBorder() const { return resizeBorder_; }
  99. /// Return modal flag.
  100. bool IsModal() const { return modal_; }
  101. /// Get modal shade color.
  102. const Color& GetModalShadeColor() const { return modalShadeColor_; }
  103. /// Get modal frame color.
  104. const Color& GetModalFrameColor() const { return modalFrameColor_; }
  105. /// Get modal frame size.
  106. const IntVector2& GetModalFrameSize() const { return modalFrameSize_; }
  107. /// Return whether can be dismissed with escape key.
  108. bool GetModalAutoDismiss() const { return modalAutoDismiss_; }
  109. protected:
  110. /// Identify drag mode (move/resize).
  111. WindowDragMode GetDragMode(const IntVector2& position) const;
  112. /// Set cursor shape based on drag mode.
  113. void SetCursorShape(WindowDragMode mode, Cursor* cursor) const;
  114. /// Validate window position.
  115. void ValidatePosition();
  116. /// Check whether alignment supports moving and resizing.
  117. bool CheckAlignment() const;
  118. /// Movable flag.
  119. bool movable_;
  120. /// Resizable flag.
  121. bool resizable_;
  122. /// Fixed width resize flag.
  123. bool fixedWidthResizing_;
  124. /// Fixed height resize flag.
  125. bool fixedHeightResizing_;
  126. /// Resize area width at edges.
  127. IntRect resizeBorder_;
  128. /// Current drag mode.
  129. WindowDragMode dragMode_;
  130. /// Mouse position at drag begin.
  131. IntVector2 dragBeginCursor_;
  132. /// Original position at drag begin.
  133. IntVector2 dragBeginPosition_;
  134. /// Original size at drag begin.
  135. IntVector2 dragBeginSize_;
  136. /// Modal flag.
  137. bool modal_;
  138. /// Modal auto dismiss (with escape key) flag. Default true.
  139. bool modalAutoDismiss_;
  140. /// Modal shade color, used when modal flag is set.
  141. Color modalShadeColor_;
  142. /// Modal frame color, used when modal flag is set.
  143. Color modalFrameColor_;
  144. /// Modal frame size, used when modal flag is set.
  145. IntVector2 modalFrameSize_;
  146. };
  147. }