Window.h 3.8 KB

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