Window.h 6.3 KB

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