Texture.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. {
  10. bild = 0;
  11. lastGr = Point(0, 0);
  12. id = -1;
  13. changed = 0;
  14. }
  15. // Destructor
  16. Texture::~Texture()
  17. {
  18. if (bild) bild->release();
  19. }
  20. // Sets a pointer to the image that contains the texture
  21. // b: The pointer to the image
  22. void Texture::setImageZ(Image* b)
  23. {
  24. if (bild != b) changed = 1;
  25. if (bild) bild->release();
  26. bild = b;
  27. }
  28. // Sets the image that contains the texture by copying it
  29. // b: The image to be copied
  30. void Texture::setImage(Image* b)
  31. {
  32. if (!b) return;
  33. if (bild != b) changed = 1;
  34. if (!bild || bild->getWidth() != b->getWidth()
  35. || bild->getHeight() != b->getHeight())
  36. {
  37. if (!bild) bild = new Image();
  38. bild->newImage(b->getWidth(), b->getHeight(), 0);
  39. }
  40. bild->drawImage(0, 0, bild->getWidth(), bild->getHeight(), *b);
  41. b->release();
  42. }
  43. // Returns a pointer to the image
  44. Image* Texture::getImage() const
  45. {
  46. return bild ? dynamic_cast<Image*>(bild->getThis()) : 0;
  47. }
  48. // Returns a pointer to the image without increased reference counter
  49. Image* Texture::zImage() const
  50. {
  51. return bild;
  52. }
  53. // Returns the id of the texture if it was registered in a TextureList.
  54. // (see Framework::zTextureRegister())
  55. int Texture::getId() const
  56. {
  57. return id;
  58. }
  59. TextureDirection Framework::Texture::getDirection() const
  60. {
  61. return direction;
  62. }