IGUISpriteBank.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #pragma once
  5. #include "IReferenceCounted.h"
  6. #include "irrArray.h"
  7. #include "SColor.h"
  8. #include "rect.h"
  9. namespace irr
  10. {
  11. namespace video
  12. {
  13. class ITexture;
  14. } // end namespace video
  15. namespace gui
  16. {
  17. //! A single sprite frame.
  18. // Note for implementer: Can't fix variable names to uppercase as this is a public interface used since a while
  19. struct SGUISpriteFrame
  20. {
  21. SGUISpriteFrame() :
  22. textureNumber(0), rectNumber(0)
  23. {
  24. }
  25. SGUISpriteFrame(u32 textureIndex, u32 positionIndex) :
  26. textureNumber(textureIndex), rectNumber(positionIndex)
  27. {
  28. }
  29. //! Texture index in IGUISpriteBank
  30. u32 textureNumber;
  31. //! Index in IGUISpriteBank::getPositions()
  32. u32 rectNumber;
  33. };
  34. //! A sprite composed of several frames.
  35. // Note for implementer: Can't fix variable names to uppercase as this is a public interface used since a while
  36. struct SGUISprite
  37. {
  38. SGUISprite() :
  39. frameTime(0) {}
  40. SGUISprite(const SGUISpriteFrame &firstFrame) :
  41. frameTime(0)
  42. {
  43. Frames.push_back(firstFrame);
  44. }
  45. core::array<SGUISpriteFrame> Frames;
  46. u32 frameTime;
  47. };
  48. //! Sprite bank interface.
  49. /** See http://http://irrlicht.sourceforge.net/forum//viewtopic.php?f=9&t=25742
  50. * for more information how to use the spritebank.
  51. */
  52. class IGUISpriteBank : public virtual IReferenceCounted
  53. {
  54. public:
  55. //! Returns the list of rectangles held by the sprite bank
  56. virtual core::array<core::rect<s32>> &getPositions() = 0;
  57. //! Returns the array of animated sprites within the sprite bank
  58. virtual core::array<SGUISprite> &getSprites() = 0;
  59. //! Returns the number of textures held by the sprite bank
  60. virtual u32 getTextureCount() const = 0;
  61. //! Gets the texture with the specified index
  62. virtual video::ITexture *getTexture(u32 index) const = 0;
  63. //! Adds a texture to the sprite bank
  64. virtual void addTexture(video::ITexture *texture) = 0;
  65. //! Changes one of the textures in the sprite bank
  66. virtual void setTexture(u32 index, video::ITexture *texture) = 0;
  67. //! Add the texture and use it for a single non-animated sprite.
  68. /** The texture and the corresponding rectangle and sprite will all be added to the end of each array.
  69. \returns The index of the sprite or -1 on failure */
  70. virtual s32 addTextureAsSprite(video::ITexture *texture) = 0;
  71. //! Clears sprites, rectangles and textures
  72. virtual void clear() = 0;
  73. //! Draws a sprite in 2d with position and color
  74. /**
  75. \param index Index of SGUISprite to draw
  76. \param pos Target position - depending on center value either the left-top or the sprite center is used as pivot
  77. \param clip Clipping rectangle, can be 0 when clipping is not wanted.
  78. \param color Color with which the image is drawn.
  79. Note that the alpha component is used. If alpha is other than
  80. 255, the image will be transparent.
  81. \param starttime Tick when the first frame was drawn (only difference currenttime-starttime matters).
  82. \param currenttime To calculate the frame of animated sprites
  83. \param loop When true animations are looped
  84. \param center When true pivot is set to the sprite-center. So it affects pos.
  85. */
  86. virtual void draw2DSprite(u32 index, const core::position2di &pos,
  87. const core::rect<s32> *clip = 0,
  88. const video::SColor &color = video::SColor(255, 255, 255, 255),
  89. u32 starttime = 0, u32 currenttime = 0,
  90. bool loop = true, bool center = false) = 0;
  91. //! Draws a sprite in 2d with destination rectangle and colors
  92. /**
  93. \param index Index of SGUISprite to draw
  94. \param destRect The sprite will be scaled to fit this target rectangle
  95. \param clip Clipping rectangle, can be 0 when clipping is not wanted.
  96. \param colors Array of 4 colors denoting the color values of
  97. the corners of the destRect
  98. \param timeTicks Current frame for animated sprites
  99. (same as currenttime-starttime in other draw2DSprite function)
  100. \param loop When true animations are looped
  101. */
  102. virtual void draw2DSprite(u32 index, const core::rect<s32> &destRect,
  103. const core::rect<s32> *clip = 0,
  104. const video::SColor *const colors = 0,
  105. u32 timeTicks = 0,
  106. bool loop = true) = 0;
  107. //! Draws a sprite batch in 2d using an array of positions and a color
  108. virtual void draw2DSpriteBatch(const core::array<u32> &indices, const core::array<core::position2di> &pos,
  109. const core::rect<s32> *clip = 0,
  110. const video::SColor &color = video::SColor(255, 255, 255, 255),
  111. u32 starttime = 0, u32 currenttime = 0,
  112. bool loop = true, bool center = false) = 0;
  113. };
  114. } // end namespace gui
  115. } // end namespace irr