[Scummvm-cvs-logs] scummvm master -> 1dda0f6c406524e1b998da27743631d2ba227505

dreammaster dreammaster at scummvm.org
Thu Jun 11 01:51:43 CEST 2015


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
1dda0f6c40 SHERLOCK: Split up font handling into a new Fonts surface base class


Commit: 1dda0f6c406524e1b998da27743631d2ba227505
    https://github.com/scummvm/scummvm/commit/1dda0f6c406524e1b998da27743631d2ba227505
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2015-06-10T19:46:14-04:00

Commit Message:
SHERLOCK: Split up font handling into a new Fonts surface base class

This will be needed for Rose Tattoo, which needs to be able to
write text to arbitrary surfaces

Changed paths:
  A engines/sherlock/fonts.cpp
  A engines/sherlock/fonts.h
    engines/sherlock/module.mk
    engines/sherlock/screen.cpp
    engines/sherlock/screen.h
    engines/sherlock/surface.cpp
    engines/sherlock/surface.h



diff --git a/engines/sherlock/fonts.cpp b/engines/sherlock/fonts.cpp
new file mode 100644
index 0000000..3ef2082
--- /dev/null
+++ b/engines/sherlock/fonts.cpp
@@ -0,0 +1,110 @@
+/* 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 "common/system.h"
+#include "sherlock/fonts.h"
+#include "sherlock/resources.h"
+#include "sherlock/surface.h"
+
+namespace Sherlock {
+
+ImageFile *Fonts::_font;
+int Fonts::_fontNumber;
+int Fonts::_fontHeight;
+
+void Fonts::init() {
+	_font = nullptr;
+}
+
+void Fonts::free() {
+	delete _font;
+}
+
+void Fonts::setFont(int fontNumber) {
+	_fontNumber = fontNumber;
+	Common::String fname = Common::String::format("FONT%d.VGS", fontNumber + 1);
+
+	// Discard any previous font and read in new one
+	delete _font;
+	_font = new ImageFile(fname);
+
+	// Iterate through the frames to find the tallest font character
+	_fontHeight = 0;
+	for (uint idx = 0; idx < _font->size(); ++idx)
+		_fontHeight = MAX((uint16)_fontHeight, (*_font)[idx]._frame.h);
+}
+
+void Fonts::writeString(Surface *surface, const Common::String &str,
+		const Common::Point &pt, int overrideColor) {
+	Common::Point charPos = pt;
+
+	for (const char *c = str.c_str(); *c; ++c) {
+		if (*c == ' ')
+			charPos.x += 5;
+		else {
+			assert(Common::isPrint(*c));
+			ImageFrame &frame = (*_font)[*c - 33];
+			surface->transBlitFrom(frame, charPos, false, overrideColor);
+			charPos.x += frame._frame.w + 1;
+		}
+	}
+}
+
+int Fonts::stringWidth(const Common::String &str) {
+	int width = 0;
+
+	for (const char *c = str.c_str(); *c; ++c)
+		width += charWidth(*c);
+
+	return width;
+}
+
+int Fonts::stringHeight(const Common::String &str) {
+	int height = 0;
+
+	for (const char *c = str.c_str(); *c; ++c)
+		height = MAX(height, charHeight(*c));
+
+	return height;
+}
+
+int Fonts::charWidth(unsigned char c) {
+	if (c == ' ')
+		return 5;
+	else if (Common::isPrint(c))
+		return (*_font)[c - 33]._frame.w + 1;
+	else
+		return 0;
+}
+
+int Fonts::charHeight(unsigned char c) {
+	int idx = c - 33;
+	if (c == ' ')
+		idx = 0;
+	else if (c == 225)
+		idx = 136;
+
+	const ImageFrame &img = (*_font)[idx];
+	return img._height + img._offset.y + 1;
+}
+
+} // End of namespace Sherlock
diff --git a/engines/sherlock/fonts.h b/engines/sherlock/fonts.h
new file mode 100644
index 0000000..50d89f3
--- /dev/null
+++ b/engines/sherlock/fonts.h
@@ -0,0 +1,90 @@
+/* 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.
+ *
+ */
+
+#ifndef SHERLOCK_FONTS_H
+#define SHERLOCK_FONTS_H
+
+#include "common/rect.h"
+#include "common/platform.h"
+#include "graphics/surface.h"
+
+namespace Sherlock {
+
+class ImageFile;
+class Surface;
+
+class Fonts {
+private:
+	static ImageFile *_font;
+protected:
+	static int _fontNumber;
+	static int _fontHeight;
+
+	static void writeString(Surface *surface, const Common::String &str, 
+		const Common::Point &pt, int overrideColor = 0);
+public:
+	/**
+	 * Initialise the font manager
+	 */
+	static void init();
+
+	/**
+	 * Frees the font manager
+	 */
+	static void free();
+
+	/**
+	 * Set the font to use for writing text on the screen
+	 */
+	void setFont(int fontNumber);
+
+	/**
+	 * Returns the width of a string in pixels
+	 */
+	int stringWidth(const Common::String &str);
+
+	/**
+	 * Returns the height of a string in pixels (i.e. the tallest displayed character)
+	 */
+	int stringHeight(const Common::String &str);
+
+	/**
+	 * Returns the width of a character in pixels
+	 */
+	int charWidth(unsigned char c);
+
+	/**
+	 * Returns the width of a character in pixels
+	 */
+	int charHeight(unsigned char c);
+
+	/**
+	 * Return the font height
+	 */
+	int fontHeight() const { return _fontHeight; }
+
+
+};
+
+} // End of namespace Sherlock
+
+#endif
diff --git a/engines/sherlock/module.mk b/engines/sherlock/module.mk
index 55c1ea7..d97fcdd 100644
--- a/engines/sherlock/module.mk
+++ b/engines/sherlock/module.mk
@@ -25,6 +25,7 @@ MODULE_OBJS = \
 	debugger.o \
 	detection.o \
 	events.o \
+	fonts.o \
 	inventory.o \
 	journal.o \
 	map.o \
diff --git a/engines/sherlock/screen.cpp b/engines/sherlock/screen.cpp
index 99e09b4..d16296f 100644
--- a/engines/sherlock/screen.cpp
+++ b/engines/sherlock/screen.cpp
@@ -34,11 +34,12 @@ Screen::Screen(SherlockEngine *vm) : Surface(g_system->getWidth(), g_system->get
 		_backBuffer(&_backBuffer1) {
 	_transitionSeed = 1;
 	_fadeStyle = false;
-	_font = nullptr;
-	_fontHeight = 0;
 	Common::fill(&_cMap[0], &_cMap[PALETTE_SIZE], 0);
 	Common::fill(&_sMap[0], &_sMap[PALETTE_SIZE], 0);
 	Common::fill(&_tMap[0], &_tMap[PALETTE_SIZE], 0);
+	
+	// Set up the initial font
+	Fonts::init();
 	setFont(IS_SERRATED_SCALPEL ? 1 : 4);
 
 	// Rose Tattoo specific fields
@@ -48,31 +49,7 @@ Screen::Screen(SherlockEngine *vm) : Surface(g_system->getWidth(), g_system->get
 }
 
 Screen::~Screen() {
-	delete _font;
-}
-
-void Screen::setFont(int fontNumb) {
-	// Interactive demo doesn't use fonts
-	if (!_vm->_interactiveFl)
-		return;
-
-	if (_vm->getPlatform() == Common::kPlatform3DO) {
-		// 3DO seems to use 3DO fonts
-		// TODO
-		return;
-	}
-
-	_fontNumber = fontNumb;
-	Common::String fname = Common::String::format("FONT%d.VGS", fontNumb + 1);
-
-	// Discard any previous font and read in new one
-	delete _font;
-	_font = new ImageFile(fname);
-
-	// Iterate through the frames to find the tallest font character
-	_fontHeight = 0;
-	for (uint idx = 0; idx < _font->size(); ++idx)
-		_fontHeight = MAX((uint16)_fontHeight, (*_font)[idx]._frame.h);
+	Fonts::free();
 }
 
 void Screen::update() {
@@ -499,37 +476,8 @@ void Screen::gPrint(const Common::Point &pt, byte color, const char *formatStr,
 	writeString(str, pt, color);
 }
 
-int Screen::stringWidth(const Common::String &str) {
-	int width = 0;
-
-	for (const char *c = str.c_str(); *c; ++c)
-		width += charWidth(*c);
-
-	return width;
-}
-
-int Screen::charWidth(char c) {
-	if (c == ' ')
-		return 5;
-	else if (Common::isPrint(c))
-		return (*_font)[c - 33]._frame.w + 1;
-	else
-		return 0;
-}
-
-void Screen::writeString(const Common::String &str, const Common::Point &pt, byte color) {
-	Common::Point charPos = pt;
-
-	for (const char *c = str.c_str(); *c; ++c) {
-		if (*c == ' ')
-			charPos.x += 5;
-		else {
-			assert(Common::isPrint(*c));
-			ImageFrame &frame = (*_font)[*c - 33];
-			_backBuffer->transBlitFrom(frame, charPos, false, color);
-			charPos.x += frame._frame.w + 1;
-		}
-	}
+void Screen::writeString(const Common::String &str, const Common::Point &pt, byte overrideColor) {
+	Fonts::writeString(_backBuffer, str, pt, overrideColor);
 }
 
 void Screen::vgaBar(const Common::Rect &r, int color) {
diff --git a/engines/sherlock/screen.h b/engines/sherlock/screen.h
index 661cc48..9d3ed0c 100644
--- a/engines/sherlock/screen.h
+++ b/engines/sherlock/screen.h
@@ -60,11 +60,8 @@ class SherlockEngine;
 class Screen : public Surface {
 private:
 	SherlockEngine *_vm;
-	int _fontNumber;
 	Common::List<Common::Rect> _dirtyRects;
 	uint32 _transitionSeed;
-	ImageFile *_font;
-	int _fontHeight;
 	Surface _sceneSurface;
 
 	// Rose Tattoo fields
@@ -84,7 +81,7 @@ private:
 	/**
 	 * Draws the given string into the back buffer using the images stored in _font
 	 */
-	void writeString(const Common::String &str, const Common::Point &pt, byte color);
+	virtual void writeString(const Common::String &str, const Common::Point &pt, byte overrideColor);
 protected:
 	/**
 	 * Adds a rectangle to the list of modified areas of the screen during the
@@ -104,11 +101,6 @@ public:
 	virtual ~Screen();
 
 	/**
-	 * Set the font to use for writing text on the screen
-	 */
-	void setFont(int fontNumber);
-
-	/**
 	 * Handles updating any dirty areas of the screen Surface object to the physical screen
 	 */
 	void update();
@@ -211,21 +203,6 @@ public:
 	void blockMove(const Common::Point &scorllPos);
 
 	/**
-	 * Returns the width of a string in pixels
-	 */
-	int stringWidth(const Common::String &str);
-
-	/**
-	 * Returns the width of a character in pixels
-	 */
-	int charWidth(char c);
-
-	/**
-	 * Return the font height
-	 */
-	int fontHeight() const { return _fontHeight; }
-
-	/**
 	 * Fills an area on the back buffer, and then copies it to the screen
 	 */
 	void vgaBar(const Common::Rect &r, int color);
diff --git a/engines/sherlock/surface.cpp b/engines/sherlock/surface.cpp
index 0f6fa94..436227e 100644
--- a/engines/sherlock/surface.cpp
+++ b/engines/sherlock/surface.cpp
@@ -30,11 +30,11 @@ namespace Sherlock {
 
 const int TRANSPARENCY = 0xFF;
 
-Surface::Surface(uint16 width, uint16 height, Common::Platform platform) : _freePixels(true) {
+Surface::Surface(uint16 width, uint16 height, Common::Platform platform) : Fonts(), _freePixels(true) {
 	create(width, height, platform);
 }
 
-Surface::Surface() : _freePixels(false) {
+Surface::Surface() : Fonts(), _freePixels(false) {
 }
 
 Surface::~Surface() {
@@ -277,6 +277,10 @@ void Surface::setPixels(byte *pixels, int width, int height) {
 	_surface.setPixels(pixels);
 }
 
+void Surface::writeString(const Common::String &str, const Common::Point &pt, byte overrideColor) {
+	Fonts::writeString(this, str, pt, overrideColor);
+}
+
 void Surface::maskArea(const ImageFrame &src, const Common::Point &pt, int scrollX) {
 	// TODO
 	error("TODO: maskArea");
diff --git a/engines/sherlock/surface.h b/engines/sherlock/surface.h
index dc2ba7b..d42dd5c 100644
--- a/engines/sherlock/surface.h
+++ b/engines/sherlock/surface.h
@@ -26,6 +26,7 @@
 #include "common/rect.h"
 #include "common/platform.h"
 #include "graphics/surface.h"
+#include "sherlock/fonts.h"
 
 namespace Sherlock {
 
@@ -33,7 +34,7 @@ namespace Sherlock {
 
 struct ImageFrame;
 
-class Surface {
+class Surface: public Fonts {
 private:
 	bool _freePixels;
 
@@ -70,6 +71,11 @@ protected:
 	Graphics::Surface _surface;
 
 	virtual void addDirtyRect(const Common::Rect &r) {}
+
+	/**
+	 * Draws the given string into the back buffer using the images stored in _font
+	 */
+	virtual void writeString(const Common::String &str, const Common::Point &pt, byte overrideColor);
 public:
 	Surface(uint16 width, uint16 height, Common::Platform platform);
 	Surface();






More information about the Scummvm-git-logs mailing list