Window.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 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. #ifndef UI_WINDOW_H
  24. #define UI_WINDOW_H
  25. #include "BorderImage.h"
  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. //! A window that can optionally by moved or resized
  41. class Window : public BorderImage
  42. {
  43. DEFINE_TYPE(Window);
  44. using UIElement::setStyle;
  45. public:
  46. //! Construct with name
  47. Window(const std::string& name = std::string());
  48. //! Destruct
  49. virtual ~Window();
  50. //! Set UI element style from XML data
  51. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  52. //! React to mouse hover
  53. virtual void onHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  54. //! React to mouse drag start
  55. virtual void onDragStart(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  56. //! React to mouse drag motion
  57. virtual void onDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  58. //! React to mouse drag end
  59. virtual void onDragEnd(const IntVector2& position, const IntVector2& screenPosition, Cursor* cursor);
  60. //! Set whether can be moved
  61. void setMovable(bool enable);
  62. //! Set whether can be resized
  63. void setResizable(bool enable);
  64. //! Set resize area width at edges
  65. void setResizeBorder(const IntRect& rect);
  66. //! Set resize area width at edges
  67. void setResizeBorder(int left, int top, int right, int bottom);
  68. //! Return whether is movable
  69. bool isMovable() const { return mMovable; }
  70. //! Return whether is resizable
  71. bool isResizable() const { return mResizable; }
  72. //! Return resize area width at edges
  73. const IntRect& getResizeBorder() const { return mResizeBorder; }
  74. protected:
  75. //! Identify drag mode (move/resize)
  76. WindowDragMode identifyDragMode(const IntVector2& position) const;
  77. //! Set cursor shape based on drag mode
  78. void setCursorShape(WindowDragMode mode, Cursor* cursor) const;
  79. //! Validate window position
  80. void validatePosition();
  81. //! Check whether alignment supports moving and resizing
  82. bool checkAlignment() const;
  83. //! Movable flag
  84. bool mMovable;
  85. //! Resizable flag
  86. bool mResizable;
  87. //! Resize area width at edges
  88. IntRect mResizeBorder;
  89. //! Current drag mode
  90. WindowDragMode mDragMode;
  91. //! Mouse position at drag start
  92. IntVector2 mDragStartPosition;
  93. //! Original position at drag start
  94. IntVector2 mOriginalPosition;
  95. //! Original size at drag start
  96. IntVector2 mOriginalSize;
  97. };
  98. #endif // UI_WINDOW_H