Texture.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "Texture.h"
  2. #include "Image.h"
  3. using namespace Framework;
  4. // Contents of the Texture class
  5. // Constructor
  6. Texture::Texture(TextureDirection dir)
  7. : ReferenceCounter(),
  8. direction(dir),
  9. bufferChanged(0)
  10. {
  11. bild = 0;
  12. lastGr = Point(0, 0);
  13. id = -1;
  14. changed = 0;
  15. }
  16. // Destructor
  17. Texture::~Texture()
  18. {
  19. if (bild) bild->release();
  20. }
  21. // Sets a pointer to the image that contains the texture
  22. // b: The pointer to the image
  23. void Texture::setImageZ(Image* b)
  24. {
  25. if (bild != b) changed = 1;
  26. if (bild) bild->release();
  27. bild = b;
  28. }
  29. // Sets the image that contains the texture by copying it
  30. // b: The image to be copied
  31. void Texture::setImage(Image* b)
  32. {
  33. if (!b) return;
  34. if (bild != b) changed = 1;
  35. if (!bild || bild->getWidth() != b->getWidth()
  36. || bild->getHeight() != b->getHeight())
  37. {
  38. if (!bild) bild = new Image();
  39. bild->newImage(b->getWidth(), b->getHeight(), 0);
  40. }
  41. bild->drawImage(0, 0, bild->getWidth(), bild->getHeight(), *b);
  42. b->release();
  43. }
  44. // Returns a pointer to the image
  45. Image* Texture::getImage() const
  46. {
  47. return bild ? dynamic_cast<Image*>(bild->getThis()) : 0;
  48. }
  49. // Returns a pointer to the image without increased reference counter
  50. Image* Texture::zImage() const
  51. {
  52. return bild;
  53. }
  54. // Returns the id of the texture if it was registered in a TextureList.
  55. // (see Framework::zTextureRegister())
  56. int Texture::getId() const
  57. {
  58. return id;
  59. }
  60. TextureDirection Framework::Texture::getDirection() const
  61. {
  62. return direction;
  63. }
  64. bool Framework::Texture::hasBufferChanged() const
  65. {
  66. return bufferChanged;
  67. }
  68. void Framework::Texture::setBufferChanged(bool changed)
  69. {
  70. bufferChanged = changed;
  71. }
  72. void Framework::Texture::setName(const char* name)
  73. {
  74. this->name = name;
  75. }