Window.h 6.3 KB

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