| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- #include "Texture.h"
- #include "Image.h"
- using namespace Framework;
- // Contents of the Texture class
- // Constructor
- Texture::Texture(TextureDirection dir)
- : ReferenceCounter(),
- direction(dir),
- bufferChanged(0)
- {
- bild = 0;
- lastGr = Point(0, 0);
- id = -1;
- changed = 0;
- }
- // Destructor
- Texture::~Texture()
- {
- if (bild) bild->release();
- }
- // Sets a pointer to the image that contains the texture
- // b: The pointer to the image
- void Texture::setImageZ(Image* b)
- {
- if (bild != b) changed = 1;
- if (bild) bild->release();
- bild = b;
- }
- // Sets the image that contains the texture by copying it
- // b: The image to be copied
- void Texture::setImage(Image* b)
- {
- if (!b) return;
- if (bild != b) changed = 1;
- if (!bild || bild->getWidth() != b->getWidth()
- || bild->getHeight() != b->getHeight())
- {
- if (!bild) bild = new Image();
- bild->newImage(b->getWidth(), b->getHeight(), 0);
- }
- bild->drawImage(0, 0, bild->getWidth(), bild->getHeight(), *b);
- b->release();
- }
- // Returns a pointer to the image
- Image* Texture::getImage() const
- {
- return bild ? dynamic_cast<Image*>(bild->getThis()) : 0;
- }
- // Returns a pointer to the image without increased reference counter
- Image* Texture::zImage() const
- {
- return bild;
- }
- // Returns the id of the texture if it was registered in a TextureList.
- // (see Framework::zTextureRegister())
- int Texture::getId() const
- {
- return id;
- }
- TextureDirection Framework::Texture::getDirection() const
- {
- return direction;
- }
- bool Framework::Texture::hasBufferChanged() const
- {
- return bufferChanged;
- }
- void Framework::Texture::setBufferChanged(bool changed)
- {
- bufferChanged = changed;
- }
- void Framework::Texture::setName(const char* name)
- {
- this->name = name;
- }
|