BsImageSprite.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "BsPrerequisites.h"
  3. #include "BsSprite.h"
  4. #include "BsVector2.h"
  5. #include "BsColor.h"
  6. namespace BansheeEngine
  7. {
  8. /**
  9. * @brief Image sprite description structure used for initializing or updating an image sprite.
  10. */
  11. struct IMAGE_SPRITE_DESC
  12. {
  13. IMAGE_SPRITE_DESC()
  14. :width(0), height(0), anchor(SA_TopLeft), borderLeft(0), borderRight(0),
  15. borderTop(0), borderBottom(0), uvScale(1.0f, 1.0f), uvOffset(0.0f, 0.0f), transparent(true)
  16. { }
  17. UINT32 width; /**< Width of the image in pixels. */
  18. UINT32 height; /**< Height of the image in pixels. */
  19. SpriteAnchor anchor; /**< Determines where in the provided bounds will the sprite be placed. */
  20. Vector2 uvScale; /**< Scale applied to UV width/height used for rendering the sprite. */
  21. Vector2 uvOffset; /**< Offset applied to UV coordinates when rendering the sprite. */
  22. bool transparent; /**< Should the sprite be rendered with transparency. */
  23. SpriteTexturePtr texture; /**< Texture to overlay on the sprite. */
  24. Color color; /**< Color tint to apply to the sprite. */
  25. /** Borders (in texels) that allow you to control how is the texture scaled.
  26. * If borders are 0 the texture will be scaled uniformly. If they are not null
  27. * only the area inside the borders will be scaled and the outside are will remain
  28. * the original size as in the texture. This allows you to implement "Scale9Grid"
  29. * functionality.
  30. */
  31. UINT32 borderLeft, borderRight, borderTop, borderBottom;
  32. };
  33. /**
  34. * @brief A sprite consisting of a single image represented by a sprite texture.
  35. */
  36. class BS_EXPORT ImageSprite : public Sprite
  37. {
  38. public:
  39. ImageSprite();
  40. /**
  41. * @brief Recreates internal sprite data according the specified description structure.
  42. *
  43. * @param desc Describes the geometry and material of the sprite.
  44. * @param groupId Group identifier that forces different materials to be used for
  45. * different groups (e.g. you don't want the sprites to
  46. * share the same material if they use different world transform matrices)
  47. */
  48. void update(const IMAGE_SPRITE_DESC& desc, UINT64 groupId);
  49. };
  50. }