STARK: Don't store the image size twice

This commit is contained in:
Bastien Bouclet 2015-12-24 18:44:44 +01:00
parent defa657429
commit 2561233424
2 changed files with 21 additions and 11 deletions

View File

@ -41,9 +41,7 @@ VisualImageXMG::VisualImageXMG(Gfx::Driver *gfx) :
Visual(TYPE),
_gfx(gfx),
_texture(nullptr),
_surface(nullptr),
_width(0),
_height(0) {
_surface(nullptr) {
_surfaceRenderer = _gfx->createSurfaceRenderer();
}
@ -61,12 +59,10 @@ void VisualImageXMG::setHotSpot(const Common::Point &hotspot) {
}
void VisualImageXMG::load(Common::ReadStream *stream) {
delete _texture;
assert(!_surface && !_texture);
// Decode the XMG
_surface = Formats::XMGDecoder::decode(stream);
_width = _surface->w;
_height = _surface->h;
_texture = _gfx->createTexture(_surface);
}
@ -76,7 +72,9 @@ void VisualImageXMG::render(const Common::Point &position, bool useOffset) {
}
bool VisualImageXMG::isPointSolid(const Common::Point &point) const {
if (_width < 32 && _height < 32) {
assert(_surface);
if (_surface->w < 32 && _surface->h < 32) {
return true; // Small images are always solid
}
@ -85,4 +83,14 @@ bool VisualImageXMG::isPointSolid(const Common::Point &point) const {
return ((*ptr) & 0xFF000000) == 0xFF000000;
}
int VisualImageXMG::getWidth() const {
assert(_surface);
return _surface->w;
}
int VisualImageXMG::getHeight() const {
assert(_surface);
return _surface->h;
}
} // End of namespace Stark

View File

@ -60,11 +60,13 @@ public:
/** Perform a transparency hit test on an image point */
bool isPointSolid(const Common::Point &point) const;
int getWidth() const { return _width; }
int getHeight() const { return _height; }
/** Get the width in pixels */
int getWidth() const;
/** Get the height in pixels */
int getHeight() const;
private:
int _width;
int _height;
Gfx::Driver *_gfx;
Gfx::SurfaceRenderer *_surfaceRenderer;
Gfx::Texture *_texture;