Sprite.pkg 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. $#include "Sprite.h"
  2. enum BlendMode{};
  3. /// %UI element which allows sub-pixel positioning and size, as well as rotation. Only other Sprites should be added as child elements.
  4. class Sprite : public UIElement
  5. {
  6. public:
  7. /// Construct.
  8. Sprite(Context* context);
  9. /// Destruct.
  10. virtual ~Sprite();
  11. /// Set floating point position.
  12. void SetPosition(const Vector2& position);
  13. /// Set floating point position.
  14. void SetPosition(float x, float y);
  15. /// Set hotspot for positioning and rotation.
  16. void SetHotSpot(const IntVector2& hotSpot);
  17. /// Set hotspot for positioning and rotation.
  18. void SetHotSpot(int x, int y);
  19. /// Set scale. Scale also affects child sprites.
  20. void SetScale(const Vector2& scale);
  21. /// Set scale. Scale also affects child sprites.
  22. void SetScale(float x, float y);
  23. /// Set uniform scale. Scale also affects child sprites.
  24. void SetScale(float scale);
  25. /// Set rotation angle.
  26. void SetRotation(float angle);
  27. /// Set texture.
  28. void SetTexture(Texture* texture);
  29. /// Set part of texture to use as the image.
  30. void SetImageRect(const IntRect& rect);
  31. /// Use whole texture as the image.
  32. void SetFullImageRect();
  33. /// Set blend mode.
  34. void SetBlendMode(BlendMode mode);
  35. /// Return floating point position.
  36. const Vector2& GetPosition() const { return floatPosition_; }
  37. /// Return hotspot.
  38. const IntVector2& GetHotSpot() const { return hotSpot_; }
  39. /// Return scale.
  40. const Vector2& GetScale() const { return scale_; }
  41. /// Return rotation angle.
  42. float GetRotation() const { return rotation_; }
  43. /// Return texture.
  44. Texture* GetTexture() const { return texture_; }
  45. /// Return image rectangle.
  46. const IntRect& GetImageRect() const { return imageRect_; }
  47. /// Return blend mode.
  48. BlendMode GetBlendMode() const { return blendMode_; }
  49. /// Set texture attribute.
  50. void SetTextureAttr(ResourceRef value);
  51. /// Return texture attribute.
  52. ResourceRef GetTextureAttr() const;
  53. /// Update and return rendering transform, also used to transform child sprites.
  54. const Matrix3x4& GetTransform() const;
  55. };
  56. /// Create sprite without lua GC.
  57. Sprite* NewSprite(Context* context);
  58. /// Delete sprite.
  59. void Delete(Sprite* sprite);
  60. ${
  61. static Sprite* NewSprite(Context* context)
  62. {
  63. return new Sprite(context);
  64. }
  65. static void Delete(Sprite* sprite)
  66. {
  67. delete sprite;
  68. }
  69. $}