Window.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. public:
  45. //! Construct with name
  46. Window(const std::string& name = std::string());
  47. //! Destruct
  48. virtual ~Window();
  49. //! Set UI element style from XML data
  50. virtual void setStyle(const XMLElement& element, ResourceCache* cache);
  51. //! React to mouse hover
  52. virtual void onHover(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  53. //! React to mouse drag start
  54. virtual void onDragStart(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  55. //! React to mouse drag motion
  56. virtual void onDragMove(const IntVector2& position, const IntVector2& screenPosition, int buttons, int qualifiers, Cursor* cursor);
  57. //! React to mouse drag end
  58. virtual void onDragEnd(const IntVector2& position, const IntVector2& screenPosition, Cursor* cursor);
  59. //! Set whether can be moved
  60. void setMovable(bool enable);
  61. //! Set whether can be resized
  62. void setResizable(bool enable);
  63. //! Set resize area width at edges
  64. void setResizeBorder(const IntRect& rect);
  65. //! Set resize area width at edges
  66. void setResizeBorder(int left, int top, int right, int bottom);
  67. //! Return whether is movable
  68. bool isMovable() const { return mMovable; }
  69. //! Return whether is resizable
  70. bool isResizable() const { return mResizable; }
  71. //! Return resize area width at edges
  72. const IntRect& getResizeBorder() const { return mResizeBorder; }
  73. protected:
  74. //! Identify drag mode (move/resize)
  75. WindowDragMode identifyDragMode(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 mMovable;
  84. //! Resizable flag
  85. bool mResizable;
  86. //! Resize area width at edges
  87. IntRect mResizeBorder;
  88. //! Current drag mode
  89. WindowDragMode mDragMode;
  90. //! Mouse position at drag start
  91. IntVector2 mDragStartPosition;
  92. //! Original position at drag start
  93. IntVector2 mOriginalPosition;
  94. //! Original size at drag start
  95. IntVector2 mOriginalSize;
  96. };
  97. #endif // UI_WINDOW_H