Window.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Copyright (c) 2008-2013 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 Urho3D
  25. {
  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. /// %Window %UI element that can optionally by moved or resized.
  41. class Window : public BorderImage
  42. {
  43. OBJECT(Window);
  44. public:
  45. /// Construct.
  46. Window(Context* context);
  47. /// Destruct.
  48. virtual ~Window();
  49. /// Register object factory.
  50. static void RegisterObject(Context* context);
  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 begin.
  54. virtual void OnDragBegin(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. /// Return whether is movable.
  66. bool IsMovable() const { return movable_; }
  67. /// Return whether is resizable.
  68. bool IsResizable() const { return resizable_; }
  69. /// Return resize area width at edges.
  70. const IntRect& GetResizeBorder() const { return resizeBorder_; }
  71. protected:
  72. /// Identify drag mode (move/resize.)
  73. WindowDragMode GetDragMode(const IntVector2& position) const;
  74. /// Set cursor shape based on drag mode.
  75. void SetCursorShape(WindowDragMode mode, Cursor* cursor) const;
  76. /// Validate window position.
  77. void ValidatePosition();
  78. /// Check whether alignment supports moving and resizing.
  79. bool CheckAlignment() const;
  80. /// Movable flag.
  81. bool movable_;
  82. /// Resizable flag.
  83. bool resizable_;
  84. /// Resize area width at edges.
  85. IntRect resizeBorder_;
  86. /// Current drag mode.
  87. WindowDragMode dragMode_;
  88. /// Mouse position at drag begin.
  89. IntVector2 dragBeginCursor_;
  90. /// Original position at drag begin.
  91. IntVector2 dragBeginPosition_;
  92. /// Original size at drag begin.
  93. IntVector2 dragBeginSize_;
  94. };
  95. }