Window.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "BorderImage.h"
  25. /// %Window movement and resizing modes.
  26. enum WindowDragMode
  27. {
  28. DRAG_NONE,
  29. DRAG_MOVE,
  30. DRAG_RESIZE_TOPLEFT,
  31. DRAG_RESIZE_TOP,
  32. DRAG_RESIZE_TOPRIGHT,
  33. DRAG_RESIZE_RIGHT,
  34. DRAG_RESIZE_BOTTOMRIGHT,
  35. DRAG_RESIZE_BOTTOM,
  36. DRAG_RESIZE_BOTTOMLEFT,
  37. DRAG_RESIZE_LEFT
  38. };
  39. /// %Window %UI element that can optionally by moved or resized.
  40. class Window : public BorderImage
  41. {
  42. OBJECT(Window);
  43. using UIElement::SetStyle;
  44. public:
  45. /// Construct.
  46. Window(Context* context);
  47. /// Destruct.
  48. virtual ~Window();
  49. /// Register object factory.
  50. static void RegisterObject(Context* context);
  51. /// %Set UI element style from XML data.
  52. virtual void SetStyle(const XMLElement& element);
  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 start.
  56. virtual void OnDragStart(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  57. /// React to mouse drag motion.
  58. virtual void OnDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  59. /// React to mouse drag end.
  60. virtual void OnDragEnd(const IntVector2& position, const IntVector2& screenPosition, Cursor* cursor);
  61. /// %Set whether can be moved.
  62. void SetMovable(bool enable);
  63. /// %Set whether can be resized.
  64. void SetResizable(bool enable);
  65. /// %Set resize area width at edges.
  66. void SetResizeBorder(const IntRect& rect);
  67. /// Return whether is movable.
  68. bool IsMovable() const { return movable_; }
  69. /// Return whether is resizable.
  70. bool IsResizable() const { return resizable_; }
  71. /// Return resize area width at edges.
  72. const IntRect& GetResizeBorder() const { return resizeBorder_; }
  73. protected:
  74. /// Identify drag mode (move/resize.)
  75. WindowDragMode GetDragMode(const IntVector2& position) const;
  76. /// %Set cursor shape based on drag mode.
  77. void SetCursorShape(WindowDragMode mode, Cursor* cursor) const;
  78. /// Validate window position.
  79. void ValidatePosition();
  80. /// Check whether alignment supports moving and resizing.
  81. bool CheckAlignment() const;
  82. /// Movable flag.
  83. bool movable_;
  84. /// Resizable flag.
  85. bool resizable_;
  86. /// Resize area width at edges.
  87. IntRect resizeBorder_;
  88. /// Current drag mode.
  89. WindowDragMode dragMode_;
  90. /// Mouse position at drag start.
  91. IntVector2 dragStartCursor_;
  92. /// Original position at drag start.
  93. IntVector2 dragStartPosition_;
  94. /// Original size at drag start.
  95. IntVector2 dragStartSize_;
  96. };