aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Kasak2009-06-14 18:59:31 +0000
committerDenis Kasak2009-06-14 18:59:31 +0000
commit718f84fb9703f894f11d5d6e76b34bc0e345da42 (patch)
tree9ce804e087ed9070aeae5ffeaa7d5fea51707fde
parent149b45f7a59c5319c912d13d8259b63b5fbb2a21 (diff)
downloadscummvm-rg350-718f84fb9703f894f11d5d6e76b34bc0e345da42.tar.gz
scummvm-rg350-718f84fb9703f894f11d5d6e76b34bc0e345da42.tar.bz2
scummvm-rg350-718f84fb9703f894f11d5d6e76b34bc0e345da42.zip
Added a Font _font variable to the engine instance. Fixed font colour handling by replacing the appropriate colours before drawing. Added Font::setColour() method for changing the current font colour. Added include guards to draci/font.h. Moved kFontBig and kFontSmall constants to draci/font.cpp to prevent redefinition errors.
svn-id: r41524
-rw-r--r--engines/draci/draci.cpp18
-rw-r--r--engines/draci/draci.h4
-rw-r--r--engines/draci/font.cpp50
-rw-r--r--engines/draci/font.h28
4 files changed, 88 insertions, 12 deletions
diff --git a/engines/draci/draci.cpp b/engines/draci/draci.cpp
index a75080d31d..103f595a12 100644
--- a/engines/draci/draci.cpp
+++ b/engines/draci/draci.cpp
@@ -49,7 +49,7 @@ DraciEngine::DraciEngine(OSystem *syst, const ADGameDescription *gameDesc)
// However this is the place to specify all default directories
//Common::File::addDefaultDirectory(_gameDataPath + "sound/");
-
+
// Here is the right place to set up the engine specific debug levels
Common::addDebugChannel(kDraciGeneralDebugLevel, "general", "Draci general debug level");
Common::addDebugChannel(kDraciBytecodeDebugLevel, "bytecode", "GPL bytecode instructions");
@@ -63,6 +63,9 @@ int DraciEngine::init() {
// Initialize graphics using following:
initGraphics(320, 200, false);
+ // Load default font
+ _font.setFont(kFontBig);
+
// Basic archive test
debugC(2, kDraciGeneralDebugLevel, "Running archive tests...");
Common::String path("INIT.DFW");
@@ -132,21 +135,20 @@ int DraciEngine::go() {
_system->fillScreen(255);
// Draw big string
- Font font(kFontBig);
Common::String testString = "Testing, testing, read all about it!";
Graphics::Surface *surf = _system->lockScreen();
- font.drawString(surf, testString,
- (320 - font.getStringWidth(testString, 1)) / 2, 130, 1);
+ _font.drawString(surf, testString,
+ (320 - _font.getStringWidth(testString, 1)) / 2, 130, 1);
// Draw small string
- font.setFont(kFontSmall);
+ _font.setFont(kFontSmall);
testString = "I'm smaller than the font above me.";
- font.drawString(surf, testString,
- (320 - font.getStringWidth(testString, 1)) / 2, 150, 1);
+ _font.drawString(surf, testString,
+ (320 - _font.getStringWidth(testString, 1)) / 2, 150, 1);
// Overflow handling test
testString = "Checking overflooooooooooooooooooooooooow...";
- font.drawString(surf, testString, 50, 170, 1);
+ _font.drawString(surf, testString, 50, 170, 1);
_system->unlockScreen();
_system->updateScreen();
diff --git a/engines/draci/draci.h b/engines/draci/draci.h
index aabbe4482b..8a0e073101 100644
--- a/engines/draci/draci.h
+++ b/engines/draci/draci.h
@@ -30,6 +30,8 @@
#include "engines/engine.h"
#include "engines/advancedDetector.h"
+#include "draci/font.h"
+
namespace Draci {
class DraciEngine : public Engine {
@@ -43,6 +45,8 @@ public:
bool hasFeature(Engine::EngineFeature f) const;
+ Font _font;
+
private:
Common::RandomSource _rnd;
};
diff --git a/engines/draci/font.cpp b/engines/draci/font.cpp
index 104b341fd1..99f1d37a23 100644
--- a/engines/draci/font.cpp
+++ b/engines/draci/font.cpp
@@ -30,10 +30,25 @@
namespace Draci {
+const Common::String kFontSmall("Small.fon");
+const Common::String kFontBig("Big.fon");
+
+Font::Font() :
+ _fontHeight(0), _maxCharWidth(0),
+ _charWidths(NULL), _charData(0) {
+
+ setFont(kFontBig);
+
+ _currentFontColour = _fontColour1;
+}
+
Font::Font(const Common::String &filename) :
_fontHeight(0), _maxCharWidth(0),
_charWidths(NULL), _charData(0) {
+
setFont(filename);
+
+ _currentFontColour = _fontColour1;
}
Font::~Font() {
@@ -41,6 +56,15 @@ Font::~Font() {
}
/**
+ * @brief Sets the varying font colour
+ * @param colour The new font colour
+ */
+
+void Font::setColour(uint8 colour) {
+ _currentFontColour = colour;
+}
+
+/**
* @brief Loads fonts from a file
* @param path Path to font file
* @return true if the font was loaded successfully, false otherwise
@@ -135,9 +159,31 @@ void Font::drawChar(Graphics::Surface *dst, uint8 chr, int tx, int ty) const {
for (int y = 0; y < yPixelsToDraw; ++y) {
for (int x = 0; x <= xPixelsToDraw; ++x) {
- // Paint pixel
int curr = y * _maxCharWidth + x;
- ptr[x] = _charData[charOffset + curr];
+ int colour = _charData[charOffset + curr];
+
+ // Replace colour with font colours
+ switch (colour) {
+
+ case 254:
+ colour = _currentFontColour;
+ break;
+
+ case 253:
+ colour = _fontColour2;
+ break;
+
+ case 252:
+ colour = _fontColour3;
+ break;
+
+ case 251:
+ colour = _fontColour4;
+ break;
+ }
+
+ // Paint pixel
+ ptr[x] = colour;
}
// Advance to next row
diff --git a/engines/draci/font.h b/engines/draci/font.h
index ddc6eaec7e..7a50f4099d 100644
--- a/engines/draci/font.h
+++ b/engines/draci/font.h
@@ -23,12 +23,15 @@
*
*/
+#ifndef FONT_H
+#define FONT_H
+
#include "graphics/font.h"
namespace Draci {
-const Common::String kFontSmall("Small.fon");
-const Common::String kFontBig("Big.fon");
+extern const Common::String kFontSmall;
+extern const Common::String kFontBig;
/**
* Represents the game's fonts. See docs for setFont() for font format details.
@@ -37,8 +40,11 @@ const Common::String kFontBig("Big.fon");
class Font {
public:
+
+ Font();
Font(const Common::String &filename);
~Font();
+
bool setFont(const Common::String &filename);
uint8 getFontHeight() const { return _fontHeight; };
uint8 getMaxCharWidth() const { return _maxCharWidth; };
@@ -47,6 +53,7 @@ public:
void drawString(Graphics::Surface *dst, Common::String &str,
int x, int y, int spacing = 0) const;
int getStringWidth(Common::String &str, int spacing = 0) const;
+ void setColour(uint8 colour);
private:
uint8 _fontHeight;
@@ -66,8 +73,25 @@ private:
*/
static const unsigned int kCharIndexOffset = 32;
+ /** Default font colours. They all seem to remain constant except for the
+ * first one which varies depending on the character speaking.
+ * _overFontColour is set to transparent.
+ * TODO: Find out what _fontColour1 should actually be when the game starts
+ */
+
+ static const uint8 _fontColour1 = 2;
+ static const uint8 _fontColour2 = 0;
+ static const uint8 _fontColour3 = 3;
+ static const uint8 _fontColour4 = 4;
+ static const uint8 _overFontColour = 255;
+
+ /** The varying font colour; initially set to _fontColour1 */
+ uint8 _currentFontColour;
+
/** Internal function for freeing fonts when destructing/loading another */
void freeFont();
};
} // End of namespace Draci
+
+#endif // FONT_H