Cursor.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. #include "Image.h"
  25. #include <SDL_mouse.h>
  26. namespace Urho3D
  27. {
  28. /// %Cursor shapes recognized by the UI subsystem.
  29. enum CursorShape
  30. {
  31. CS_NORMAL = 0,
  32. CS_RESIZEVERTICAL,
  33. CS_RESIZEDIAGONAL_TOPRIGHT,
  34. CS_RESIZEHORIZONTAL,
  35. CS_RESIZEDIAGONAL_TOPLEFT,
  36. CS_ACCEPTDROP,
  37. CS_REJECTDROP,
  38. CS_BUSY,
  39. CS_MAX_SHAPES
  40. };
  41. /// %Cursor image and hotspot information.
  42. struct CursorShapeInfo
  43. {
  44. /// Texture.
  45. SharedPtr<Texture> texture_;
  46. /// Image rectangle.
  47. IntRect imageRect_;
  48. /// Hotspot coordinates.
  49. IntVector2 hotSpot_;
  50. /// OS cursor.
  51. SDL_Cursor* osCursor_;
  52. };
  53. /// Mouse cursor %UI element.
  54. class Cursor : public BorderImage
  55. {
  56. OBJECT(Cursor);
  57. public:
  58. /// Construct.
  59. Cursor(Context* context);
  60. /// Destruct.
  61. virtual ~Cursor();
  62. /// Register object factory.
  63. static void RegisterObject(Context* context);
  64. /// Return UI rendering batches.
  65. virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor);
  66. /// Define a shape.
  67. void DefineShape(CursorShape shape, Image* image, const IntRect& imageRect, const IntVector2& hotSpot, bool osMouseVisible = false);
  68. /// Set current shape.
  69. void SetShape(CursorShape shape);
  70. /// Get current shape.
  71. CursorShape GetShape() const { return shape_; }
  72. /// Set shapes attribute.
  73. void SetShapesAttr(VariantVector value);
  74. /// Return shapes attribute.
  75. VariantVector GetShapesAttr() const;
  76. protected:
  77. /// Current shape index.
  78. CursorShape shape_;
  79. /// Shape definitions.
  80. CursorShapeInfo shapeInfos_[CS_MAX_SHAPES];
  81. };
  82. }