[Scummvm-cvs-logs] SF.net SVN: scummvm:[41524] scummvm/branches/gsoc2009-draci/engines/draci
dkasak13 at users.sourceforge.net
dkasak13 at users.sourceforge.net
Sun Jun 14 20:59:31 CEST 2009
Revision: 41524
http://scummvm.svn.sourceforge.net/scummvm/?rev=41524&view=rev
Author: dkasak13
Date: 2009-06-14 18:59:31 +0000 (Sun, 14 Jun 2009)
Log Message:
-----------
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.
Modified Paths:
--------------
scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
scummvm/branches/gsoc2009-draci/engines/draci/draci.h
scummvm/branches/gsoc2009-draci/engines/draci/font.cpp
scummvm/branches/gsoc2009-draci/engines/draci/font.h
Modified: scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp 2009-06-14 16:33:20 UTC (rev 41523)
+++ scummvm/branches/gsoc2009-draci/engines/draci/draci.cpp 2009-06-14 18:59:31 UTC (rev 41524)
@@ -49,7 +49,7 @@
// 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 @@
// 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 @@
_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();
Modified: scummvm/branches/gsoc2009-draci/engines/draci/draci.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/draci.h 2009-06-14 16:33:20 UTC (rev 41523)
+++ scummvm/branches/gsoc2009-draci/engines/draci/draci.h 2009-06-14 18:59:31 UTC (rev 41524)
@@ -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 @@
bool hasFeature(Engine::EngineFeature f) const;
+ Font _font;
+
private:
Common::RandomSource _rnd;
};
Modified: scummvm/branches/gsoc2009-draci/engines/draci/font.cpp
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/font.cpp 2009-06-14 16:33:20 UTC (rev 41523)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.cpp 2009-06-14 18:59:31 UTC (rev 41524)
@@ -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 @@
}
/**
+ * @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 @@
for (int y = 0; y < yPixelsToDraw; ++y) {
for (int x = 0; x <= xPixelsToDraw; ++x) {
+ int curr = y * _maxCharWidth + x;
+ 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
- int curr = y * _maxCharWidth + x;
- ptr[x] = _charData[charOffset + curr];
+ ptr[x] = colour;
}
// Advance to next row
Modified: scummvm/branches/gsoc2009-draci/engines/draci/font.h
===================================================================
--- scummvm/branches/gsoc2009-draci/engines/draci/font.h 2009-06-14 16:33:20 UTC (rev 41523)
+++ scummvm/branches/gsoc2009-draci/engines/draci/font.h 2009-06-14 18:59:31 UTC (rev 41524)
@@ -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 @@
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 @@
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 @@
*/
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list