IGUISpriteBank.h 4.7 KB

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