diff options
author | Nicola Mettifogo | 2008-06-30 01:36:50 +0000 |
---|---|---|
committer | Nicola Mettifogo | 2008-06-30 01:36:50 +0000 |
commit | 2779b851ab4328bce306b58e49df515bca58f1ab (patch) | |
tree | 28233fd641f21c5e632b1f1cdb4cf3502a2b2f9a /engines/parallaction/gfxbase.cpp | |
parent | 0a3d03797a29203d8ea3970b54a893d9ac53e20d (diff) | |
download | scummvm-rg350-2779b851ab4328bce306b58e49df515bca58f1ab.tar.gz scummvm-rg350-2779b851ab4328bce306b58e49df515bca58f1ab.tar.bz2 scummvm-rg350-2779b851ab4328bce306b58e49df515bca58f1ab.zip |
Small cleanup/shuffling of Gfx code.
svn-id: r32847
Diffstat (limited to 'engines/parallaction/gfxbase.cpp')
-rw-r--r-- | engines/parallaction/gfxbase.cpp | 220 |
1 files changed, 215 insertions, 5 deletions
diff --git a/engines/parallaction/gfxbase.cpp b/engines/parallaction/gfxbase.cpp index 66b1ceecf7..cdf4c9cdf6 100644 --- a/engines/parallaction/gfxbase.cpp +++ b/engines/parallaction/gfxbase.cpp @@ -92,6 +92,7 @@ GfxObj* Gfx::loadAnim(const char *name) { // animation Z is not set here, but controlled by game scripts and user interaction. // it is always >=0 and <screen height obj->type = kGfxObjTypeAnim; + _gfxobjList.push_back(obj); return obj; } @@ -102,6 +103,7 @@ GfxObj* Gfx::loadGet(const char *name) { obj->z = kGfxObjGetZ; // this preset Z value ensures that get zones are drawn after doors but before animations obj->type = kGfxObjTypeGet; + _gfxobjList.push_back(obj); return obj; } @@ -111,6 +113,7 @@ GfxObj* Gfx::loadDoor(const char *name) { obj->z = kGfxObjDoorZ; // this preset Z value ensures that doors are drawn first obj->type = kGfxObjTypeDoor; + _gfxobjList.push_back(obj); return obj; } @@ -119,16 +122,17 @@ void Gfx::clearGfxObjects() { } void Gfx::showGfxObj(GfxObj* obj, bool visible) { - if (!obj || obj->isVisible() == visible) { - return; - } +// if (!obj || obj->isVisible() == visible) { +// return; +// } + + assert(obj); if (visible) { obj->setFlags(kGfxObjVisible); - _gfxobjList.push_back(obj); } else { obj->clearFlags(kGfxObjVisible); - _gfxobjList.remove(obj); +// _gfxobjList.remove(obj); } } @@ -174,4 +178,210 @@ void Gfx::drawGfxObjects(Graphics::Surface &surf) { } } + + +void Gfx::drawText(Font *font, Graphics::Surface* surf, uint16 x, uint16 y, const char *text, byte color) { + byte *dst = (byte*)surf->getBasePtr(x, y); + font->setColor(color); + font->drawString(dst, surf->w, text); +} + +void Gfx::drawWrappedText(Font *font, Graphics::Surface* surf, char *text, byte color, int16 wrapwidth) { + + uint16 lines = 0; + uint16 linewidth = 0; + + uint16 rx = 10; + uint16 ry = 4; + + uint16 blankWidth = font->getStringWidth(" "); + uint16 tokenWidth = 0; + + char token[MAX_TOKEN_LEN]; + + if (wrapwidth == -1) + wrapwidth = _vm->_screenWidth; + + while (strlen(text) > 0) { + + text = parseNextToken(text, token, MAX_TOKEN_LEN, " ", true); + + if (!scumm_stricmp(token, "%p")) { + lines++; + rx = 10; + ry = 4 + lines*10; // y + + strcpy(token, "> ......."); + strncpy(token+2, _password, strlen(_password)); + tokenWidth = font->getStringWidth(token); + } else { + tokenWidth = font->getStringWidth(token); + + linewidth += tokenWidth; + + if (linewidth > wrapwidth) { + // wrap line + lines++; + rx = 10; // x + ry = 4 + lines*10; // y + linewidth = tokenWidth; + } + + if (!scumm_stricmp(token, "%s")) { + sprintf(token, "%d", _score); + } + + } + + drawText(font, surf, rx, ry, token, color); + + rx += tokenWidth + blankWidth; + linewidth += blankWidth; + + text = Common::ltrim(text); + } + +} + + +// this is the maximum size of an unpacked frame in BRA +byte _unpackedBitmap[640*401]; + +#if 0 +void Gfx::unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, byte transparentColor) { + + byte *d = _unpackedBitmap; + + while (size > 0) { + + uint8 p = *data++; + size--; + uint8 color = p & 0xF; + uint8 repeat = (p & 0xF0) >> 4; + if (repeat == 0) { + repeat = *data++; + size--; + } + + memset(d, color, repeat); + d += repeat; + } + + blt(r, _unpackedBitmap, surf, z, transparentColor); +} +#endif +void Gfx::unpackBlt(const Common::Rect& r, byte *data, uint size, Graphics::Surface *surf, uint16 z, byte transparentColor) { + + byte *d = _unpackedBitmap; + uint pixelsLeftInLine = r.width(); + + while (size > 0) { + uint8 p = *data++; + size--; + uint8 color = p & 0xF; + uint8 repeat = (p & 0xF0) >> 4; + if (repeat == 0) { + repeat = *data++; + size--; + } + if (repeat == 0) { + // end of line + repeat = pixelsLeftInLine; + pixelsLeftInLine = r.width(); + } else { + pixelsLeftInLine -= repeat; + } + + memset(d, color, repeat); + d += repeat; + } + + blt(r, _unpackedBitmap, surf, z, transparentColor); +} + + +void Gfx::blt(const Common::Rect& r, byte *data, Graphics::Surface *surf, uint16 z, byte transparentColor) { + + Common::Point dp; + Common::Rect q(r); + + Common::Rect clipper(surf->w, surf->h); + + q.clip(clipper); + if (!q.isValidRect()) return; + + dp.x = q.left; + dp.y = q.top; + + q.translate(-r.left, -r.top); + + byte *s = data + q.left + q.top * r.width(); + byte *d = (byte*)surf->getBasePtr(dp.x, dp.y); + + uint sPitch = r.width() - q.width(); + uint dPitch = surf->w - q.width(); + + + if (_varRenderMode == 2) { + + for (uint16 i = 0; i < q.height(); i++) { + + for (uint16 j = 0; j < q.width(); j++) { + if (*s != transparentColor) { + if (_backgroundInfo.mask.data && (z < LAYER_FOREGROUND)) { + byte v = _backgroundInfo.mask.getValue(dp.x + j, dp.y + i); + if (z >= v) *d = 5; + } else { + *d = 5; + } + } + + s++; + d++; + } + + s += sPitch; + d += dPitch; + } + + } else { + if (_backgroundInfo.mask.data && (z < LAYER_FOREGROUND)) { + + for (uint16 i = 0; i < q.height(); i++) { + + for (uint16 j = 0; j < q.width(); j++) { + if (*s != transparentColor) { + byte v = _backgroundInfo.mask.getValue(dp.x + j, dp.y + i); + if (z >= v) *d = *s; + } + + s++; + d++; + } + + s += sPitch; + d += dPitch; + } + + } else { + + for (uint16 i = q.top; i < q.bottom; i++) { + for (uint16 j = q.left; j < q.right; j++) { + if (*s != transparentColor) + *d = *s; + + s++; + d++; + } + + s += sPitch; + d += dPitch; + } + + } + } + +} + + } // namespace Parallaction |