aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support
diff options
context:
space:
mode:
authorPaul Gilbert2016-10-02 15:39:45 -0400
committerPaul Gilbert2016-10-02 15:39:45 -0400
commitdd2ee74cc099e1cf7b6a179886581188b5dfbca3 (patch)
treeabeeb76f6170cc3b597e1463edaecc3f62426a49 /engines/titanic/support
parent3d25e260f783586c9a1a53dfa5bd0216d5277360 (diff)
downloadscummvm-rg350-dd2ee74cc099e1cf7b6a179886581188b5dfbca3.tar.gz
scummvm-rg350-dd2ee74cc099e1cf7b6a179886581188b5dfbca3.tar.bz2
scummvm-rg350-dd2ee74cc099e1cf7b6a179886581188b5dfbca3.zip
TITANIC: Change mouse cursor to use transparency
Diffstat (limited to 'engines/titanic/support')
-rw-r--r--engines/titanic/support/mouse_cursor.cpp35
-rw-r--r--engines/titanic/support/mouse_cursor.h4
-rw-r--r--engines/titanic/support/movie.cpp2
-rw-r--r--engines/titanic/support/movie.h10
-rw-r--r--engines/titanic/support/raw_surface.cpp134
-rw-r--r--engines/titanic/support/transparency_surface.cpp79
-rw-r--r--engines/titanic/support/transparency_surface.h (renamed from engines/titanic/support/raw_surface.h)26
-rw-r--r--engines/titanic/support/video_surface.cpp45
-rw-r--r--engines/titanic/support/video_surface.h11
9 files changed, 142 insertions, 204 deletions
diff --git a/engines/titanic/support/mouse_cursor.cpp b/engines/titanic/support/mouse_cursor.cpp
index 0cefc368fa..66c28d705e 100644
--- a/engines/titanic/support/mouse_cursor.cpp
+++ b/engines/titanic/support/mouse_cursor.cpp
@@ -32,6 +32,8 @@
namespace Titanic {
+#define CURSOR_SIZE 64
+
static const int CURSOR_DATA[NUM_CURSORS][4] = {
{ 1, 136, 19, 18 },
{ 2, 139, 1, 1 },
@@ -52,7 +54,7 @@ static const int CURSOR_DATA[NUM_CURSORS][4] = {
CMouseCursor::CursorEntry::~CursorEntry() {
delete _videoSurface;
- delete _frameSurface;
+ delete _transSurface;
}
CMouseCursor::CMouseCursor(CScreenManager *screenManager) :
@@ -75,16 +77,16 @@ void CMouseCursor::loadCursorImages() {
CURSOR_DATA[idx][3]);
// Create the surface
- CVideoSurface *surface = _screenManager->createSurface(64, 64);
+ CVideoSurface *surface = _screenManager->createSurface(CURSOR_SIZE, CURSOR_SIZE);
_cursors[idx]._videoSurface = surface;
// Open the cursors video and move to the given frame
OSMovie movie(key, surface);
movie.setFrame(idx);
- Graphics::ManagedSurface *frameSurface = movie.duplicateFrame();
- _cursors[idx]._frameSurface = frameSurface;
- surface->setTransparencySurface(frameSurface);
+ Graphics::ManagedSurface *transSurface = movie.duplicateTransparency();
+ _cursors[idx]._transSurface = transSurface;
+ surface->setTransparencySurface(transSurface);
}
}
@@ -101,12 +103,23 @@ void CMouseCursor::setCursor(CursorId cursorId) {
if (cursorId != _cursorId) {
CursorEntry &ce = _cursors[cursorId - 1];
- CVideoSurface &surface = *ce._videoSurface;
- surface.lock();
-
- CursorMan.replaceCursor(surface.getPixels(), surface.getWidth(), surface.getHeight(),
- ce._centroid.x, ce._centroid.y, 0, false, &g_vm->_screen->format);
- surface.unlock();
+ CVideoSurface &srcSurface = *ce._videoSurface;
+ srcSurface.lock();
+
+ CVideoSurface *surface = CScreenManager::_currentScreenManagerPtr->createSurface(
+ CURSOR_SIZE, CURSOR_SIZE);
+ Rect srcRect(0, 0, CURSOR_SIZE, CURSOR_SIZE);
+ surface->lock();
+ surface->getRawSurface()->fillRect(srcRect, srcSurface.getTransparencyColor());
+ surface->blitFrom(Point(0, 0), &srcSurface, &srcRect);
+
+ CursorMan.replaceCursor(surface->getPixels(), CURSOR_SIZE, CURSOR_SIZE,
+ ce._centroid.x, ce._centroid.y, surface->getTransparencyColor(),
+ false, &g_vm->_screen->format);
+
+ srcSurface.unlock();
+ surface->unlock();
+ delete surface;
_cursorId = cursorId;
}
diff --git a/engines/titanic/support/mouse_cursor.h b/engines/titanic/support/mouse_cursor.h
index 74fb1f6113..5bf6895a67 100644
--- a/engines/titanic/support/mouse_cursor.h
+++ b/engines/titanic/support/mouse_cursor.h
@@ -55,10 +55,10 @@ class CVideoSurface;
class CMouseCursor {
struct CursorEntry {
CVideoSurface *_videoSurface;
- Graphics::ManagedSurface *_frameSurface;
+ Graphics::ManagedSurface *_transSurface;
Common::Point _centroid;
- CursorEntry() : _videoSurface(nullptr), _frameSurface(nullptr) {}
+ CursorEntry() : _videoSurface(nullptr), _transSurface(nullptr) {}
~CursorEntry();
};
private:
diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp
index a605cc3465..eff0e0c754 100644
--- a/engines/titanic/support/movie.cpp
+++ b/engines/titanic/support/movie.cpp
@@ -203,7 +203,7 @@ void OSMovie::setFrameRate(double rate) {
_aviSurface.setFrameRate(rate);
}
-Graphics::ManagedSurface *OSMovie::duplicateFrame() const {
+Graphics::ManagedSurface *OSMovie::duplicateTransparency() const {
return _aviSurface.duplicateTransparency();
}
diff --git a/engines/titanic/support/movie.h b/engines/titanic/support/movie.h
index 8c89f9e6dd..be34244d96 100644
--- a/engines/titanic/support/movie.h
+++ b/engines/titanic/support/movie.h
@@ -130,9 +130,9 @@ public:
virtual void setFrameRate(double rate) = 0;
/**
- * Creates a duplicate of the movie's frame
- */
- virtual Graphics::ManagedSurface *duplicateFrame() const = 0;
+ * Creates a duplicate of the transparency surface
+ */
+ virtual Graphics::ManagedSurface *duplicateTransparency() const = 0;
/**
* Removes the movie from the list of currently playing movies
@@ -229,9 +229,9 @@ public:
virtual void setFrameRate(double rate);
/**
- * Creates a duplicate of the frame info
+ * Creates a duplicate of the transparency surface
*/
- virtual Graphics::ManagedSurface *duplicateFrame() const;
+ virtual Graphics::ManagedSurface *duplicateTransparency() const;
};
} // End of namespace Titanic
diff --git a/engines/titanic/support/raw_surface.cpp b/engines/titanic/support/raw_surface.cpp
deleted file mode 100644
index 4123b86e68..0000000000
--- a/engines/titanic/support/raw_surface.cpp
+++ /dev/null
@@ -1,134 +0,0 @@
-/* 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.
- *
- */
-
-#include "titanic/support/raw_surface.h"
-#include "common/algorithm.h"
-
-namespace Titanic {
-
-CRawSurface::CRawSurface(const Graphics::Surface *surface, TransparencyMode transMode) {
- _width = surface->w;
- _pixelsBaseP = (byte *)surface->getPixels();
- _pixelsP = nullptr;
- _pitch = 0;
- _runLength = 0;
- _flag = false;
- _flag1 = false;
- _flag2 = true;
-
- switch (transMode) {
- case TRANS_MASK0:
- case TRANS_ALPHA0:
- _flag2 = false;
- _flag1 = true;
- break;
- case TRANS_MASK255:
- case TRANS_ALPHA255:
- _flag2 = true;
- _flag1 = false;
- break;
- case TRANS_DEFAULT:
- if ((_pixelsBaseP[0] == 0 && _pixelsBaseP[2] < 0x80) ||
- (_pixelsBaseP[0] != 0 && _pixelsBaseP[1] < 0x80)) {
- _flag1 = true;
- _flag2 = false;
- }
- break;
- default:
- break;
- }
-}
-
-void CRawSurface::setRow(int yp) {
- for (int y = 0; y < yp; ++yp) {
- resetPitch();
- skipPitch();
- }
-}
-
-void CRawSurface::setCol(int xp) {
- while (xp > 0)
- xp -= moveX(xp);
-}
-
-void CRawSurface::skipPitch() {
- setCol(_pitch);
-}
-
-int CRawSurface::moveX(int xp) {
- if (_runLength) {
- if (!_flag) {
- --_runLength;
- --_pitch;
- ++_pixelsP;
- return 1;
- }
- } else {
- while (!*_pixelsBaseP) {
- _runLength = *++_pixelsBaseP;
- ++_pixelsBaseP;
-
- if (_runLength) {
- _pixelsP = _pixelsBaseP;
- _pixelsBaseP += _runLength;
- if (_runLength & 1)
- ++_pixelsBaseP;
-
- _flag = false;
- --_pitch;
- --_runLength;
- return 1;
- }
- }
-
- _runLength = *_pixelsBaseP;
- _pixelsP = _pixelsBaseP + 1;
- _pixelsBaseP += 2;
- _flag = true;
- }
-
- if (xp < 0 || xp > _pitch)
- xp = _pitch;
-
- int len = MIN(_runLength, xp);
- _pitch -= len;
- _runLength -= len;
- return len;
-}
-
-uint CRawSurface::getPixel() const {
- return _flag1 ? 0xFF - *_pixelsP : *_pixelsP;
-}
-
-bool CRawSurface::isPixelTransparent1() const {
- return _flag1 ? *_pixelsP == 0xF0 : *_pixelsP == 0x10;
-}
-
-bool CRawSurface::isPixelTransparent2() const {
- return _flag2 ? *_pixelsP == 0xF0 : *_pixelsP == 0x10;
-}
-
-void CRawSurface::resetPitch() {
- _pitch = _width;
-}
-
-} // End of namespace Titanic
diff --git a/engines/titanic/support/transparency_surface.cpp b/engines/titanic/support/transparency_surface.cpp
new file mode 100644
index 0000000000..d956c77a58
--- /dev/null
+++ b/engines/titanic/support/transparency_surface.cpp
@@ -0,0 +1,79 @@
+/* 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.
+ *
+ */
+
+#include "titanic/support/transparency_surface.h"
+#include "common/algorithm.h"
+#include "common/textconsole.h"
+
+namespace Titanic {
+
+CTransparencySurface::CTransparencySurface(const Graphics::Surface *surface,
+ TransparencyMode transMode) : _surface(surface) {
+ _pitch = 0;
+ _runLength = 0;
+ _flag = false;
+ _flag1 = false;
+ _flag2 = true;
+
+ switch (transMode) {
+ case TRANS_MASK0:
+ case TRANS_ALPHA0:
+ _flag2 = false;
+ _flag1 = true;
+ break;
+ case TRANS_MASK255:
+ case TRANS_ALPHA255:
+ _flag2 = true;
+ _flag1 = false;
+ break;
+ case TRANS_DEFAULT:
+ error("TRANS_DEFAULT not supported in transparency surface");
+ default:
+ break;
+ }
+}
+
+int CTransparencySurface::moveX() {
+ if (++_pos.x >= _surface->w) {
+ _pos.x = 0;
+ ++_pos.y;
+ }
+
+ return 1;
+}
+
+uint CTransparencySurface::getPixel() const {
+ const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y);
+ return _flag1 ? 0xFF - *pixelP : *pixelP;
+}
+
+bool CTransparencySurface::isPixelTransparent1() const {
+ const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y);
+ return _flag1 ? *pixelP == 0xF0 : *pixelP == 0x10;
+}
+
+bool CTransparencySurface::isPixelTransparent2() const {
+ const byte *pixelP = (const byte *)_surface->getBasePtr(_pos.x, _pos.y);
+ return _flag2 ? *pixelP == 0xF0 : *pixelP == 0x10;
+}
+
+} // End of namespace Titanic
diff --git a/engines/titanic/support/raw_surface.h b/engines/titanic/support/transparency_surface.h
index 69efc1e3db..5593dfa66d 100644
--- a/engines/titanic/support/raw_surface.h
+++ b/engines/titanic/support/transparency_surface.h
@@ -20,9 +20,10 @@
*
*/
-#ifndef TITANIC_RAW_SURFACE_H
-#define TITANIC_RAW_SURFACE_H
+#ifndef TITANIC_TRANSPARENCY_SURFACE_H
+#define TITANIC_TRANSPARENCY_SURFACE_H
+#include "common/rect.h"
#include "graphics/surface.h"
namespace Titanic {
@@ -32,24 +33,21 @@ enum TransparencyMode {
TRANS_ALPHA255 = 3, TRANS_DEFAULT = 4
};
-class CRawSurface {
+class CTransparencySurface {
private:
- const byte *_pixelsBaseP;
- const byte *_pixelsP;
+ const Graphics::Surface *_surface;
+ Common::Point _pos;
int _pitch;
int _runLength;
bool _flag;
- int _width;
bool _flag1;
bool _flag2;
public:
- CRawSurface(const Graphics::Surface *surface, TransparencyMode transMode);
+ CTransparencySurface(const Graphics::Surface *surface, TransparencyMode transMode);
- void setRow(int yp);
+ void setRow(int yp) { _pos.y = yp; }
- void setCol(int xp);
-
- void skipPitch();
+ void setCol(int xp) { _pos.x = xp; }
uint getPixel() const;
@@ -57,11 +55,9 @@ public:
bool isPixelTransparent2() const;
- void resetPitch();
-
- int moveX(int xp);
+ int moveX();
};
} // End of namespace Titanic
-#endif /* TITANIC_RAW_SURFACE_H */
+#endif /* TITANIC_TRANSPARENCY_SURFACE_H */
diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp
index fa87e6df0c..8e2fb40a27 100644
--- a/engines/titanic/support/video_surface.cpp
+++ b/engines/titanic/support/video_surface.cpp
@@ -22,8 +22,8 @@
#include "titanic/support/video_surface.h"
#include "titanic/support/image_decoders.h"
-#include "titanic/support/raw_surface.h"
#include "titanic/support/screen_manager.h"
+#include "titanic/support/transparency_surface.h"
#include "titanic/titanic.h"
namespace Titanic {
@@ -198,40 +198,28 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi
bool isAlpha = src->_transparencyMode == TRANS_ALPHA0 ||
src->_transparencyMode == TRANS_ALPHA255;
- CRawSurface rawSurface(src->getTransparencySurface(), src->_transparencyMode);
+ CTransparencySurface transSurface(src->getTransparencySurface(), src->_transparencyMode);
if (flipFlag)
- rawSurface.setRow(srcRect.top);
+ transSurface.setRow(srcRect.top);
else
- rawSurface.setRow(src->getHeight() - srcRect.bottom);
+ transSurface.setRow(src->getHeight() - srcRect.bottom);
for (int srcY = srcRect.top; srcY < srcRect.bottom; ++srcY) {
// Prepare for copying the line
const uint16 *lineSrcP = srcPtr;
uint16 *lineDestP = destPtr;
- rawSurface.resetPitch();
- rawSurface.setCol(srcRect.left);
+ transSurface.setRow(srcY);
+ transSurface.setCol(srcRect.left);
int srcWidth = srcRect.width();
while (srcWidth > 0) {
- int move = rawSurface.moveX(0);
+ int move = transSurface.moveX();
if (move <= 1) {
- if (!rawSurface.isPixelTransparent2()) {
- copyPixel(lineDestP, lineSrcP, rawSurface.getPixel() >> 3,
+ if (!transSurface.isPixelTransparent2()) {
+ copyPixel(lineDestP, lineSrcP, transSurface.getPixel() >> 3,
is16Bit, isAlpha);
}
- } else {
- if (move > srcWidth)
- move = srcWidth;
-
- if (rawSurface.isPixelTransparent1()) {
- Common::copy(lineSrcP, lineSrcP + move, lineDestP);
- } else if (!rawSurface.isPixelTransparent2()) {
- byte transVal = rawSurface.getPixel() >> 3;
- for (int idx = 0; idx < move; ++idx) {
- copyPixel(lineDestP + idx, lineSrcP + idx, transVal, is16Bit, isAlpha);
- }
- }
}
lineSrcP += move;
@@ -240,7 +228,6 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi
}
// Move to next line
- rawSurface.skipPitch();
srcPtr = flipFlag ? srcPtr + getWidth() : srcPtr - getWidth();
destPtr -= destArea.w;
}
@@ -487,13 +474,11 @@ uint16 OSVideoSurface::getPixel(const Common::Point &pt) {
if (pt.x >= 0 && pt.y >= 0 && pt.x < getWidth() && pt.y < getHeight()) {
if (_transparencySurface) {
- CRawSurface rawSurface(&_transparencySurface->rawSurface(), _transparencyMode);
- rawSurface.setRow(_transBlitFlag ? pt.y : getHeight() - pt.y - 1);
- rawSurface.resetPitch();
- rawSurface.setCol(pt.x);
- rawSurface.moveX(0);
+ CTransparencySurface transSurface(&_transparencySurface->rawSurface(), _transparencyMode);
+ transSurface.setRow(_transBlitFlag ? pt.y : getHeight() - pt.y - 1);
+ transSurface.setCol(pt.x);
- if (rawSurface.isPixelTransparent2())
+ if (transSurface.isPixelTransparent2())
return getTransparencyColor();
}
@@ -637,8 +622,8 @@ void OSVideoSurface::transPixelate() {
unlock();
}
-Graphics::ManagedSurface *OSVideoSurface::dupMovieFrame() const {
- return _movie ? _movie->duplicateFrame() : nullptr;
+Graphics::ManagedSurface *OSVideoSurface::dupMovieTransparency() const {
+ return _movie ? _movie->duplicateTransparency() : nullptr;
}
int OSVideoSurface::freeSurface() {
diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h
index 37ff7917dc..3625a3555c 100644
--- a/engines/titanic/support/video_surface.h
+++ b/engines/titanic/support/video_surface.h
@@ -30,8 +30,8 @@
#include "titanic/support/direct_draw.h"
#include "titanic/support/movie.h"
#include "titanic/support/movie_range_info.h"
-#include "titanic/support/raw_surface.h"
#include "titanic/support/rect.h"
+#include "titanic/support/transparency_surface.h"
#include "titanic/core/list.h"
#include "titanic/core/resource_key.h"
@@ -277,9 +277,9 @@ public:
virtual bool hasFrame();
/**
- * Duplicates movie frame surface
+ * Duplicates movie transparency surface
*/
- virtual Graphics::ManagedSurface *dupMovieFrame() const = 0;
+ virtual Graphics::ManagedSurface *dupMovieTransparency() const = 0;
/**
* Frees the underlying surface
@@ -509,10 +509,9 @@ public:
virtual void transPixelate();
/**
- * Duplicates movie frame surface
+ * Duplicates movie transparency surface
*/
- virtual Graphics::ManagedSurface *dupMovieFrame() const;
-
+ virtual Graphics::ManagedSurface *dupMovieTransparency() const;
/**
* Frees the underlying surface