Skip to content

Commit

Permalink
SLUDGE: Move global variable thumbnailWidth/Height to GraphicsManager
Browse files Browse the repository at this point in the history
  • Loading branch information
yinsimei committed Apr 27, 2018
1 parent 4ce71f3 commit 5ced495
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
5 changes: 3 additions & 2 deletions engines/sludge/builtin.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions engines/sludge/graphics.cpp
Expand Up @@ -83,6 +83,10 @@ void GraphicsManager::init() {
_currentBurnR = 0;
_currentBurnG = 0;
_currentBurnB = 0;

// Thumbnail
_thumbWidth = 0;
_thumbHeight = 0;
}

void GraphicsManager::kill() {
Expand Down
7 changes: 6 additions & 1 deletion engines/sludge/graphics.h
Expand Up @@ -167,7 +167,8 @@ class GraphicsManager {
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);
Expand Down Expand Up @@ -222,6 +223,10 @@ class GraphicsManager {
// Colors
uint _currentBlankColour;
byte _currentBurnR, _currentBurnG, _currentBurnB;

// Thumbnail
int _thumbWidth;
int _thumbHeight;
};

} // End of namespace Sludge
Expand Down
3 changes: 1 addition & 2 deletions engines/sludge/sludger.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -167,7 +167,6 @@ void initSludge() {
launchResult = nullptr;

lastFramesPerSecond = -1;
thumbWidth = thumbHeight = 0;
allowAnyFilename = true;
noStack = nullptr;
numBIFNames = numUserFunc = 0;
Expand Down
23 changes: 16 additions & 7 deletions engines/sludge/thumbnail.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5ced495

Please sign in to comment.