mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-09 03:10:22 +00:00
ac7b1e326d
The resource file format Hugo uses has named entries. Because of this, the original Glk code added to Hugo does a whole mess of reading in a picture, then copying it to a dummy pic file with a dummy number, just so a call to glk_image_draw could detect it. Since this isn't the first time I've had to deal with named resources, it ended up being cleaner to add a new variation of glk_image_draw and glk_image_draw_scaled that can take in a string image parameter. That way, I was able to set up an archive class to represent the resource file, and pass the resource name directly without worrying about dummy picture numbers & files
160 lines
3.2 KiB
C++
160 lines
3.2 KiB
C++
/* ScummVM - Graphic Adventure Engine
|
|
*
|
|
* ScummVM is the legal property of its developers, whose names
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
* file distributed with this source distribution.
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
*
|
|
*/
|
|
|
|
#ifndef GLK_PICTURE_H
|
|
#define GLK_PICTURE_H
|
|
|
|
#include "common/array.h"
|
|
#include "graphics/managed_surface.h"
|
|
|
|
namespace Glk {
|
|
|
|
/**
|
|
* Picture/image class
|
|
*/
|
|
struct Picture : Graphics::ManagedSurface {
|
|
private:
|
|
int _transColor;
|
|
public:
|
|
int _refCount;
|
|
Common::String _name;
|
|
bool _scaled;
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
Picture() : Graphics::ManagedSurface(), _refCount(0), _scaled(false), _transColor(0x7777) {}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
Picture(int width, int height, const Graphics::PixelFormat &fmt);
|
|
/**
|
|
* Increment reference counter
|
|
*/
|
|
void increment();
|
|
|
|
/**
|
|
* Decrement reference counter
|
|
*/
|
|
void decrement();
|
|
|
|
/**
|
|
* Draw the picture
|
|
*/
|
|
void drawPicture(const Common::Point &destPos, const Common::Rect &box);
|
|
|
|
/**
|
|
* Get the transparency color
|
|
*/
|
|
uint getTransparentColor() const { return _transColor; }
|
|
|
|
/**
|
|
* Set the transparency color
|
|
*/
|
|
void setTransparentColor(uint color) { _transColor = color; }
|
|
};
|
|
|
|
/**
|
|
* Picture entry in the in-memory store
|
|
*/
|
|
struct PictureEntry {
|
|
Picture *_picture;
|
|
Picture *_scaled;
|
|
PictureEntry() : _picture(nullptr), _scaled(nullptr) {}
|
|
};
|
|
|
|
/**
|
|
* Pictures manager
|
|
*/
|
|
class Pictures {
|
|
private:
|
|
int _refCount;
|
|
Common::Array<PictureEntry> _store;
|
|
Common::Array<Common::String> _adaptivePics;
|
|
Common::Array<byte> _savedPalette;
|
|
private:
|
|
/**
|
|
* Stores an original picture in the store
|
|
*/
|
|
void storeOriginal(Picture *pic);
|
|
|
|
/**
|
|
* Stores a scaled picture in the store
|
|
*/
|
|
void storeScaled(Picture *pic);
|
|
public:
|
|
/**
|
|
* Constructor
|
|
*/
|
|
Pictures();
|
|
|
|
/**
|
|
* Destructor
|
|
*/
|
|
~Pictures() { clear(); }
|
|
|
|
/**
|
|
* Clear the picture list
|
|
*/
|
|
void clear();
|
|
|
|
/**
|
|
* Increments the count of the number of pictures in use
|
|
*/
|
|
void increment();
|
|
|
|
/**
|
|
* Decrements the count of the number of pictures in use
|
|
*/
|
|
void decrement();
|
|
|
|
/**
|
|
* Searches for an existing picture entry
|
|
*/
|
|
PictureEntry *search(const Common::String &name);
|
|
|
|
/**
|
|
* Stores a picture in the store
|
|
*/
|
|
void store(Picture *pic);
|
|
|
|
/**
|
|
* Retrieves a picture from the store
|
|
*/
|
|
Picture *retrieve(const Common::String &name, bool scaled);
|
|
|
|
/**
|
|
* Load a given picture
|
|
*/
|
|
Picture *load(const Common::String &name);
|
|
|
|
/**
|
|
* Rescale the passed picture to a new picture of a given size
|
|
*/
|
|
Picture *scale(Picture *src, size_t sx, size_t sy);
|
|
};
|
|
|
|
} // End of namespace Glk
|
|
|
|
#endif
|