aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2016-09-27 02:34:20 +0300
committerFilippos Karapetis2016-10-03 00:34:36 +0300
commit88f3fc07603d132b12d366509e547e4367787700 (patch)
tree92f48c2e79a91cc238a7312615fc4204f93a8a75
parent8c7c42d13d652abd8e7982fb402cc70150e15491 (diff)
downloadscummvm-rg350-88f3fc07603d132b12d366509e547e4367787700.tar.gz
scummvm-rg350-88f3fc07603d132b12d366509e547e4367787700.tar.bz2
scummvm-rg350-88f3fc07603d132b12d366509e547e4367787700.zip
CHEWY: Implement initial sprite drawing, font loading and text drawing
-rw-r--r--engines/chewy/chewy.cpp3
-rw-r--r--engines/chewy/graphics.cpp41
-rw-r--r--engines/chewy/graphics.h8
-rw-r--r--engines/chewy/resource.cpp63
-rw-r--r--engines/chewy/resource.h14
5 files changed, 127 insertions, 2 deletions
diff --git a/engines/chewy/chewy.cpp b/engines/chewy/chewy.cpp
index a91bd2fe91..0f2e9c30a8 100644
--- a/engines/chewy/chewy.cpp
+++ b/engines/chewy/chewy.cpp
@@ -86,6 +86,9 @@ Common::Error ChewyEngine::run() {
//_graphics->playVideo(0);
_graphics->drawImage("episode1.tgp", 0);
+ _graphics->drawSprite("det1.taf", 0, 200, 100);
+ _graphics->loadFont("6x8.tff");
+ _graphics->drawText("This is a test", 200, 80);
_graphics->showCursor();
_graphics->setCursor(0);
//_sound->playSpeech(1);
diff --git a/engines/chewy/graphics.cpp b/engines/chewy/graphics.cpp
index 612551d5e0..db3b094c75 100644
--- a/engines/chewy/graphics.cpp
+++ b/engines/chewy/graphics.cpp
@@ -24,6 +24,7 @@
#include "common/events.h"
#include "graphics/cursorman.h"
#include "graphics/palette.h"
+#include "graphics/surface.h"
#include "chewy/graphics.h"
#include "chewy/resource.h"
@@ -53,12 +54,26 @@ Graphics::Graphics(ChewyEngine *vm) : _vm(vm) {
_curCursor = 0;
_curCursorFrame = 0;
_cursorSprites = new SpriteResource("cursor.taf");
+ _font = nullptr;
}
Graphics::~Graphics() {
+ delete _font;
delete _cursorSprites;
}
+void Graphics::drawSprite(Common::String filename, int spriteNum, uint x, uint y) {
+ SpriteResource *res = new SpriteResource(filename);
+ TAFChunk *sprite = res->getSprite(spriteNum);
+
+ drawTransparent(x, y, sprite->data, sprite->width, sprite->height, 0);
+ g_system->updateScreen();
+
+ delete[] sprite->data;
+ delete sprite;
+ delete res;
+}
+
void Graphics::drawImage(Common::String filename, int imageNum) {
BackgroundResource *res = new BackgroundResource(filename);
TBFChunk *image = res->getImage(imageNum);
@@ -72,6 +87,32 @@ void Graphics::drawImage(Common::String filename, int imageNum) {
delete res;
}
+void Graphics::loadFont(Common::String filename) {
+ _font = new Font(filename);
+}
+
+void Graphics::drawTransparent(uint16 x, uint16 y, byte *data, uint16 width, uint16 height, byte transparentColor) {
+ ::Graphics::Surface *screen = g_system->lockScreen();
+ for (uint textX = 0; textX < width; textX++) {
+ for (uint textY = 0; textY < height; textY++) {
+ byte *src = data + (textY * width) + textX;
+ byte *dst = (byte *)screen->getBasePtr(textX + x, textY + y);
+ if (*src != transparentColor)
+ *dst = *src;
+ }
+ }
+ g_system->unlockScreen();
+}
+
+void Graphics::drawText(Common::String text, uint x, uint y) {
+ ::Graphics::Surface *textSurface = _font->getLine(text);
+
+ drawTransparent(x, y, (byte *)textSurface->getPixels(), textSurface->pitch, textSurface->h, 0xFF);
+
+ textSurface->free();
+ delete textSurface;
+}
+
void Graphics::playVideo(uint num) {
CfoDecoder *cfoDecoder = new CfoDecoder(_vm->_mixer);
VideoResource *videoResource = new VideoResource("cut.tap");
diff --git a/engines/chewy/graphics.h b/engines/chewy/graphics.h
index 28af8fedc6..a3f6005942 100644
--- a/engines/chewy/graphics.h
+++ b/engines/chewy/graphics.h
@@ -28,6 +28,7 @@
namespace Chewy {
class SpriteResource;
+class Font;
class Graphics {
public:
@@ -35,7 +36,11 @@ public:
virtual ~Graphics();
void drawImage(Common::String filename, int imageNum);
+ void drawSprite(Common::String filename, int spriteNum, uint x, uint y);
void playVideo(uint num);
+ void loadFont(Common::String filename);
+ void drawText(Common::String text, uint x, uint y);
+
void setCursor(uint num, bool newCursor = true);
void showCursor();
void hideCursor();
@@ -43,11 +48,14 @@ public:
void nextCursor();
private:
+ void drawTransparent(uint16 x, uint16 y, byte *data, uint16 width, uint16 height, byte transparentColor);
+
ChewyEngine *_vm;
uint _curCursor;
uint _curCursorFrame;
SpriteResource *_cursorSprites;
+ Font *_font;
};
} // End of namespace Chewy
diff --git a/engines/chewy/resource.cpp b/engines/chewy/resource.cpp
index 13bd9d2e97..368f589cc1 100644
--- a/engines/chewy/resource.cpp
+++ b/engines/chewy/resource.cpp
@@ -21,9 +21,12 @@
*/
#include "common/debug.h"
+#include "common/rect.h"
#include "common/stream.h"
#include "common/substream.h"
#include "common/textconsole.h"
+#include "graphics/pixelformat.h"
+#include "graphics/surface.h"
#include "chewy/chewy.h"
#include "chewy/resource.h"
@@ -34,13 +37,11 @@ namespace Chewy {
// ======================
// back/episode1.gep
// cut/blende.rnd
-// misc/*.taf, room/*.taf
// misc/exit.eib
// misc/inventar.iib
// misc/inventar.sib
// room/csp.int
// room/test.rdi
-// txt/*.tff
// txt/*.tap
// txt/diah.adh
// txt/inv_st.s and txt/room_st.s
@@ -323,4 +324,62 @@ Common::SeekableReadStream *VideoResource::getVideoStream(uint num) {
return new Common::SeekableSubReadStream(&_stream, chunk->pos, chunk->pos + chunk->size);
}
+Font::Font(Common::String filename) {
+ const uint32 headerFont = MKTAG('T', 'F', 'F', '\0');
+ Common::File stream;
+
+ stream.open(filename);
+
+ uint32 header = stream.readUint32BE();
+
+ if (header != headerFont)
+ error("Invalid resource - %s", filename.c_str());
+
+ stream.skip(4); // total memory
+ _count = stream.readUint16LE();
+ _first = stream.readUint16LE();
+ _last = stream.readUint16LE();
+ _width = stream.readUint16LE();
+ _height = stream.readUint16LE();
+
+ _fontSurface.create(_width * _count, _height, ::Graphics::PixelFormat::createFormatCLUT8());
+
+ byte cur;
+ int bitIndex = 7;
+ byte *p;
+
+ cur = stream.readByte();
+
+ for (uint n = 0; n < _count; n++) {
+ for (uint y = 0; y < _height; y++) {
+ for (uint x = n * _width; x < n * _width + _width; x++) {
+ p = (byte *)_fontSurface.getBasePtr(x, y);
+ *p = (cur & (1 << bitIndex)) ? 0 : 0xFF;
+
+ bitIndex--;
+ if (bitIndex < 0) {
+ bitIndex = 7;
+ cur = stream.readByte();
+ }
+ }
+ }
+ }
+}
+
+Font::~Font() {
+ _fontSurface.free();
+}
+
+::Graphics::Surface *Font::getLine(Common::String text) {
+ ::Graphics::Surface *line = new ::Graphics::Surface();
+ line->create(text.size() * _width, _height, ::Graphics::PixelFormat::createFormatCLUT8());
+
+ for (uint i = 0; i < text.size(); i++) {
+ int c = text[i];
+ line->copyRectToSurface(_fontSurface, i * _width, 0, Common::Rect((c - _first) * _width, 0, (c - _first) * _width + _width, _height));
+ }
+
+ return line;
+}
+
} // End of namespace Chewy
diff --git a/engines/chewy/resource.h b/engines/chewy/resource.h
index 04a0598803..6d2126c1e6 100644
--- a/engines/chewy/resource.h
+++ b/engines/chewy/resource.h
@@ -32,6 +32,7 @@
#include "common/hash-str.h"
#include "common/random.h"
#include "common/stream.h"
+#include "graphics/surface.h"
namespace Chewy {
@@ -185,6 +186,19 @@ public:
Common::SeekableReadStream *getVideoStream(uint num);
};
+class Font {
+public:
+ Font(Common::String filename);
+ virtual ~Font();
+
+ ::Graphics::Surface *getLine(Common::String text);
+
+private:
+ uint16 _count, _first, _last, _width, _height;
+
+ ::Graphics::Surface _fontSurface;
+};
+
} // End of namespace Chewy
#endif