From 025b2a93e9ce6386fd842dbd467188b5cff30038 Mon Sep 17 00:00:00 2001 From: Nicola Mettifogo Date: Sat, 20 Dec 2008 08:15:09 +0000 Subject: Moved mask creation/handling to Gfx. svn-id: r35447 --- engines/parallaction/gfxbase.cpp | 22 +++++++++++++++++++++- engines/parallaction/graphics.cpp | 4 ++++ engines/parallaction/graphics.h | 17 +++++++++++++++++ engines/parallaction/objects.h | 3 --- engines/parallaction/parallaction.cpp | 9 --------- engines/parallaction/parser_br.cpp | 8 +------- 6 files changed, 43 insertions(+), 20 deletions(-) (limited to 'engines/parallaction') diff --git a/engines/parallaction/gfxbase.cpp b/engines/parallaction/gfxbase.cpp index 782e4df681..9d4389855e 100644 --- a/engines/parallaction/gfxbase.cpp +++ b/engines/parallaction/gfxbase.cpp @@ -32,7 +32,10 @@ namespace Parallaction { -GfxObj::GfxObj(uint objType, Frames *frames, const char* name) : _frames(frames), _keep(true), x(0), y(0), z(0), _flags(kGfxObjNormal), type(objType), frame(0), layer(3), scale(100) { +GfxObj::GfxObj(uint objType, Frames *frames, const char* name) : + _frames(frames), _keep(true), x(0), y(0), z(0), _flags(kGfxObjNormal), + type(objType), frame(0), layer(3), scale(100), _hasMask(false) { + if (name) { _name = strdup(name); } else { @@ -43,6 +46,7 @@ GfxObj::GfxObj(uint objType, Frames *frames, const char* name) : _frames(frames) GfxObj::~GfxObj() { delete _frames; free(_name); + _mask.free(); } void GfxObj::release() { @@ -136,6 +140,14 @@ void Gfx::clearGfxObjects(uint filter) { } +void Gfx::loadGfxObjMask(const char *name, GfxObj *obj) { + Common::Rect rect; + obj->getRect(0, rect); + obj->_mask.create(rect.width(), rect.height()); + _vm->_disk->loadMask(_tokens[1], obj->_mask); + obj->_hasMask = true; +} + void Gfx::showGfxObj(GfxObj* obj, bool visible) { if (!obj) { return; @@ -146,6 +158,14 @@ void Gfx::showGfxObj(GfxObj* obj, bool visible) { } else { obj->clearFlags(kGfxObjVisible); } + + if (obj->_hasMask && _backgroundInfo->hasMask) { + if (visible) { + _backgroundInfo->mask.bltOr(obj->x, obj->y, obj->_mask, 0, 0, obj->_mask.w, obj->_mask.h); + } else { + _backgroundInfo->mask.bltCopy(obj->x, obj->y, _backgroundInfo->maskBackup, obj->x, obj->y, obj->_mask.w, obj->_mask.h); + } + } } diff --git a/engines/parallaction/graphics.cpp b/engines/parallaction/graphics.cpp index 4828d7ad7d..c675b2c510 100644 --- a/engines/parallaction/graphics.cpp +++ b/engines/parallaction/graphics.cpp @@ -803,6 +803,10 @@ void Gfx::setBackground(uint type, BackgroundInfo *info) { setPalette(_backgroundInfo->palette); } + if (_backgroundInfo->hasMask) { + _backgroundInfo->maskBackup.clone(_backgroundInfo->mask); + } + if (_gameType == GType_BRA) { int width = CLIP(info->width, (int)_vm->_screenWidth, info->width); int height = CLIP(info->height, (int)_vm->_screenHeight, info->height); diff --git a/engines/parallaction/graphics.h b/engines/parallaction/graphics.h index 0f4c332ad6..4e6ab7b037 100644 --- a/engines/parallaction/graphics.h +++ b/engines/parallaction/graphics.h @@ -140,6 +140,15 @@ public: MaskBuffer() : w(0), internalWidth(0), h(0), size(0), data(0), bigEndian(true) { } + void clone(const MaskBuffer &buf) { + if (!buf.data) + return; + + create(buf.w, buf.h); + bigEndian = buf.bigEndian; + memcpy(data, buf.data, size); + } + void create(uint16 width, uint16 height) { free(); @@ -378,6 +387,10 @@ public: uint transparentKey; uint scale; + MaskBuffer _mask; + bool _hasMask; + + GfxObj(uint type, Frames *frames, const char *name = NULL); virtual ~GfxObj(); @@ -413,6 +426,7 @@ struct BackgroundInfo { Graphics::Surface bg; MaskBuffer mask; + MaskBuffer maskBackup; PathBuffer path; Palette palette; @@ -442,6 +456,7 @@ struct BackgroundInfo { ~BackgroundInfo() { bg.free(); mask.free(); + maskBackup.free(); path.free(); x = 0; y = 0; @@ -607,6 +622,8 @@ public: void bltMaskScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, uint scale, byte transparentColor); void bltMaskNoScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, byte transparentColor); void bltNoMaskNoScale(const Common::Rect& r, byte *data, Graphics::Surface *surf, byte transparentColor); + + void loadGfxObjMask(const char *name, GfxObj *obj); }; diff --git a/engines/parallaction/objects.h b/engines/parallaction/objects.h index 77be772adc..e52d1f361f 100644 --- a/engines/parallaction/objects.h +++ b/engines/parallaction/objects.h @@ -193,13 +193,10 @@ struct Dialogue { struct GetData { uint32 _icon; GfxObj *gfxobj; - MaskBuffer _mask[2]; - bool hasMask; GetData() { _icon = 0; gfxobj = NULL; - hasMask = false; } }; struct SpeakData { diff --git a/engines/parallaction/parallaction.cpp b/engines/parallaction/parallaction.cpp index d26ba3fe5a..b76c2ae034 100644 --- a/engines/parallaction/parallaction.cpp +++ b/engines/parallaction/parallaction.cpp @@ -521,15 +521,6 @@ void Parallaction::showZone(ZonePtr z, bool visible) { if ((z->_type & 0xFFFF) == kZoneGet) { _gfx->showGfxObj(z->u.get->gfxobj, visible); - - GetData *data = z->u.get; - if (data->hasMask && _gfx->_backgroundInfo->hasMask) { - if (visible) { - _gfx->_backgroundInfo->mask.bltOr(data->gfxobj->x, data->gfxobj->y, data->_mask[0], 0, 0, data->_mask->w, data->_mask->h); - } else { - _gfx->_backgroundInfo->mask.bltCopy(data->gfxobj->x, data->gfxobj->y, data->_mask[1], 0, 0, data->_mask->w, data->_mask->h); - } - } } } diff --git a/engines/parallaction/parser_br.cpp b/engines/parallaction/parser_br.cpp index 6b05f5018a..526cc1397d 100644 --- a/engines/parallaction/parser_br.cpp +++ b/engines/parallaction/parser_br.cpp @@ -788,13 +788,7 @@ void LocationParser_br::parseGetData(ZonePtr z) { if (!scumm_stricmp(_tokens[0], "mask")) { if (ctxt.info->hasMask) { - Common::Rect rect; - data->gfxobj->getRect(0, rect); - data->_mask[0].create(rect.width(), rect.height()); - _vm->_disk->loadMask(_tokens[1], data->_mask[0]); - data->_mask[1].create(rect.width(), rect.height()); - data->_mask[1].bltCopy(0, 0, ctxt.info->mask, data->gfxobj->x, data->gfxobj->y, data->_mask->w, data->_mask->h); - data->hasMask = true; + _vm->_gfx->loadGfxObjMask(_tokens[1], data->gfxobj); } else { warning("Mask for zone '%s' ignored, since background doesn't have one", z->_name); } -- cgit v1.2.3