SLUDGE: Move global variable thumbnailWidth/Height to GraphicsManager

This commit is contained in:
Simei Yin 2018-04-27 14:15:09 +02:00
parent 4ce71f3922
commit 5ced495769
5 changed files with 30 additions and 12 deletions

View File

@ -58,7 +58,7 @@ int speechMode = 0;
Variable *launchResult = NULL;
extern int lastFramesPerSecond, thumbWidth, thumbHeight;
extern int lastFramesPerSecond;
extern bool allowAnyFilename;
extern VariableStack *noStack;
extern StatusStuff *nowStatus;
@ -2460,13 +2460,14 @@ builtIn(showThumbnail) {
builtIn(setThumbnailSize) {
UNUSEDALL
int thumbHeight, thumbWidth;
if (!getValueType(thumbHeight, SVT_INT, fun->stack->thisVar))
return BR_ERROR;
trimStack(fun->stack);
if (!getValueType(thumbWidth, SVT_INT, fun->stack->thisVar))
return BR_ERROR;
trimStack(fun->stack);
if (!g_sludge->_gfxMan->checkSizeValide(thumbWidth, thumbHeight)) {
if (!g_sludge->_gfxMan->setThumbnailSize(thumbWidth, thumbHeight)) {
Common::String buff = Common::String::format("%i x %i", thumbWidth, thumbWidth);
fatal("Invalid thumbnail size", buff);
return BR_ERROR;

View File

@ -83,6 +83,10 @@ void GraphicsManager::init() {
_currentBurnR = 0;
_currentBurnG = 0;
_currentBurnB = 0;
// Thumbnail
_thumbWidth = 0;
_thumbHeight = 0;
}
void GraphicsManager::kill() {

View File

@ -167,7 +167,8 @@ public:
void saveColors(Common::WriteStream *stream);
void loadColors(Common::SeekableReadStream *stream);
// Thumb nail
// Thumbnail
bool setThumbnailSize(int thumbWidth, int thumbHeight);
bool saveThumbnail(Common::WriteStream *stream);
bool skipThumbnail(Common::SeekableReadStream *stream);
void showThumbnail(const Common::String &filename, int x, int y);
@ -222,6 +223,10 @@ private:
// Colors
uint _currentBlankColour;
byte _currentBurnR, _currentBurnG, _currentBurnB;
// Thumbnail
int _thumbWidth;
int _thumbHeight;
};
} // End of namespace Sludge

View File

@ -79,7 +79,7 @@ Variable *globalVars;
int numGlobals = 0;
extern Variable *launchResult;
extern int lastFramesPerSecond, thumbWidth, thumbHeight;
extern int lastFramesPerSecond;
extern bool allowAnyFilename;
extern byte fadeMode;
@ -167,7 +167,6 @@ void initSludge() {
launchResult = nullptr;
lastFramesPerSecond = -1;
thumbWidth = thumbHeight = 0;
allowAnyFilename = true;
noStack = nullptr;
numBIFNames = numUserFunc = 0;

View File

@ -35,14 +35,23 @@
namespace Sludge {
int thumbWidth = 0, thumbHeight = 0;
bool GraphicsManager::setThumbnailSize(int thumbWidth, int thumbHeight)
{
if (checkSizeValide(thumbWidth, thumbHeight))
{
_thumbWidth = thumbWidth;
_thumbHeight = thumbHeight;
return true;
}
return false;
}
bool GraphicsManager::saveThumbnail(Common::WriteStream *stream) {
stream->writeUint32LE(thumbWidth);
stream->writeUint32LE(thumbHeight);
stream->writeUint32LE(_thumbWidth);
stream->writeUint32LE(_thumbHeight);
if (thumbWidth && thumbHeight) {
if (_thumbWidth && _thumbHeight) {
if (!freeze())
return false;
@ -117,12 +126,12 @@ void GraphicsManager::showThumbnail(const Common::String &filename, int atX, int
}
bool GraphicsManager::skipThumbnail(Common::SeekableReadStream *stream) {
thumbWidth = stream->readUint32LE();
thumbHeight = stream->readUint32LE();
_thumbWidth = stream->readUint32LE();
_thumbHeight = stream->readUint32LE();
// Load image
Graphics::Surface tmp;
if (thumbWidth & thumbHeight) {
if (_thumbWidth & _thumbHeight) {
if (!ImgLoader::loadPNGImage(stream, &tmp))
return false;
else