BsImageSprite.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. ~ImageSprite();
  41. /**
  42. * @brief Recreates internal sprite data according the specified description structure.
  43. *
  44. * @param desc Describes the geometry and material of the sprite.
  45. * @param groupId Group identifier that forces different materials to be used for
  46. * different groups (e.g. you don't want the sprites to
  47. * share the same material if they use different world transform matrices)
  48. */
  49. void update(const IMAGE_SPRITE_DESC& desc, UINT64 groupId);
  50. private:
  51. /**
  52. * @brief Clears internal geometry buffers.
  53. */
  54. void clearMesh();
  55. };
  56. }