Cursor.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #pragma once
  24. #include "BorderImage.h"
  25. enum CursorShape
  26. {
  27. CS_NORMAL = 0,
  28. CS_RESIZEVERTICAL,
  29. CS_RESIZEDIAGONAL_TOPRIGHT,
  30. CS_RESIZEHORIZONTAL,
  31. CS_RESIZEDIAGONAL_TOPLEFT,
  32. CS_ACCEPTDROP,
  33. CS_REJECTDROP,
  34. CS_MAX_SHAPES
  35. };
  36. /// Cursor image and hotspot information
  37. struct CursorShapeInfo
  38. {
  39. SharedPtr<Texture> texture_;
  40. IntRect imageRect_;
  41. IntVector2 hotSpot_;
  42. };
  43. /// Mouse cursor UI element
  44. class Cursor : public BorderImage
  45. {
  46. OBJECT(Cursor);
  47. using UIElement::SetStyle;
  48. public:
  49. /// Construct with name
  50. Cursor(Context* context);
  51. /// Destruct
  52. virtual ~Cursor();
  53. /// Register object factory
  54. static void RegisterObject(Context* context);
  55. /// Set UI element style from XML data
  56. virtual void SetStyle(const XMLElement& element);
  57. /// Return UI rendering batches
  58. virtual void GetBatches(PODVector<UIBatch>& batches, PODVector<UIQuad>& quads, const IntRect& currentScissor);
  59. /// Define a shape
  60. void DefineShape(CursorShape shape, Texture* texture, const IntRect& imageRect, const IntVector2& hotSpot);
  61. /// Set shape
  62. void SetShape(CursorShape shape);
  63. /// Get current shape
  64. CursorShape GetShape() const { return shape_; }
  65. protected:
  66. /// Current shape index
  67. CursorShape shape_;
  68. /// Shape definitions
  69. CursorShapeInfo shapeInfos_[CS_MAX_SHAPES];
  70. };