Window.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. static const int WINDOW_MIN_SIZE = 4;
  27. //! Window movement and resizing modes
  28. enum WindowDragMode
  29. {
  30. DRAG_NONE,
  31. DRAG_MOVE,
  32. DRAG_RESIZE_TOPLEFT,
  33. DRAG_RESIZE_TOP,
  34. DRAG_RESIZE_TOPRIGHT,
  35. DRAG_RESIZE_RIGHT,
  36. DRAG_RESIZE_BOTTOMRIGHT,
  37. DRAG_RESIZE_BOTTOM,
  38. DRAG_RESIZE_BOTTOMLEFT,
  39. DRAG_RESIZE_LEFT
  40. };
  41. //! Window that can optionally by moved or resized
  42. class Window : public BorderImage
  43. {
  44. public:
  45. //! Construct with name
  46. Window(const std::string& name = std::string());
  47. //! Destruct
  48. virtual ~Window();
  49. //! Load parameters from an XML file
  50. virtual XMLElement loadParameters(XMLFile* file, const std::string& elementName, ResourceCache* cache);
  51. //! React to mouse drag start
  52. virtual void onDragStart(const IntVector2& position, const IntVector2& screenPosition, unsigned buttons);
  53. //! React to mouse drag motion
  54. virtual void onDragMove(const IntVector2& position, const IntVector2& screenPosition, unsigned buttons);
  55. //! React to mouse drag end
  56. virtual void onDragEnd(const IntVector2& position, const IntVector2& screenPosition);
  57. //! Set whether can be moved
  58. void setMovable(bool enable);
  59. //! Set whether can be resized
  60. void setResizable(bool enable);
  61. //! Set minimum size
  62. void setMinSize(const IntVector2& minSize);
  63. //! Set minimum size
  64. void setMinSize(int width, int height);
  65. //! Set maximum size
  66. void setMaxSize(const IntVector2& maxSize);
  67. //! Set maximum size
  68. void setMaxSize(int width, int height);
  69. //! Set resize area width at edges
  70. void setResizeBorder(const IntRect& rect);
  71. //! Set resize area width at edges
  72. void setResizeBorder(int left, int top, int right, int bottom);
  73. //! Return whether is movable
  74. bool isMovable() const { return mMovable; }
  75. //! Return whether is resizable
  76. bool isResizable() const { return mResizable; }
  77. //! Return minimum size
  78. const IntVector2& getMinSize() const { return mMinSize; }
  79. //! Return maximum size
  80. const IntVector2& getMaxSize() const { return mMaxSize; }
  81. //! Return resize area width at edges
  82. const IntRect& getResizeBorder() const { return mResizeBorder; }
  83. protected:
  84. //! Validate window size
  85. void validateSize();
  86. //! Validate window position
  87. void validatePosition();
  88. //! Check whether alignment supports moving and resizing
  89. bool checkAlignment() const;
  90. //! Movable flag
  91. bool mMovable;
  92. //! Resizable flag
  93. bool mResizable;
  94. //! Minimum size
  95. IntVector2 mMinSize;
  96. //! Maximum size
  97. IntVector2 mMaxSize;
  98. //! Resize area width at edges
  99. IntRect mResizeBorder;
  100. //! Current drag mode
  101. WindowDragMode mDragMode;
  102. //! Mouse position at drag start
  103. IntVector2 mDragStartPosition;
  104. //! Original position at drag start
  105. IntVector2 mOriginalPosition;
  106. //! Original size at drag start
  107. IntVector2 mOriginalSize;
  108. };
  109. #endif // UI_WINDOW_H