CGE2: Implement Font.

This commit is contained in:
uruk 2014-06-06 16:45:02 +02:00
parent f2c0069765
commit 63a153165a
4 changed files with 86 additions and 24 deletions

View File

@ -70,6 +70,7 @@ CGE2Engine::CGE2Engine(OSystem *syst, const ADGameDescription *gameDescription)
_vol[i] = nullptr;
_eventManager = nullptr;
_blinkSprite = nullptr;
_font = nullptr;
_quitFlag = false;
_bitmapPalette = nullptr;
@ -115,6 +116,7 @@ void CGE2Engine::init() {
_point[i] = new V3D();
_sys = new System(this);
_eventManager = new EventManager(this);
_font = new Font(this);
}
void CGE2Engine::deinit() {
@ -146,6 +148,7 @@ void CGE2Engine::deinit() {
delete _eventManager;
if (_blinkSprite != nullptr)
delete _blinkSprite;
delete _font;
}
bool CGE2Engine::hasFeature(EngineFeature f) const {

View File

@ -56,6 +56,7 @@ class Hero;
class Bitmap;
class System;
class EventManager;
class Font;
#define kScrWidth 320
#define kScrHeight 240
@ -79,20 +80,6 @@ enum CallbackType {
enum Action { kNear, kMTake, kFTake, kActions };
class Font {
char _path[kPathMax];
void load();
CGE2Engine *_vm;
public:
uint8 *_widthArr;
uint16 *_pos;
uint8 *_map;
Font(CGE2Engine *vm, const char *name);
~Font();
uint16 width(const char *text);
void save();
};
class CGE2Engine : public Engine {
private:
uint32 _lastFrame, _lastTick;
@ -241,6 +228,7 @@ public:
Sprite *_vol[2];
EventManager *_eventManager;
Sprite *_blinkSprite;
Font *_font;
private:
void init();
void deinit();

View File

@ -27,27 +27,83 @@
#include "cge2/general.h"
#include "cge2/talk.h"
//#include "cge2/game.h"
//#include "cge2/events.h"
#include "cge2/cge2_main.h"
namespace CGE2 {
Font::Font(CGE2Engine *vm, const char *name) : _vm(vm) {
warning("STUB: Font::Font()");
Font::Font(CGE2Engine *vm) : _vm(vm) {
_map = new uint8[kMapSize];
_pos = new uint16[kPosSize];
_widthArr = new uint8[kWidSize];
assert((_map != NULL) && (_pos != NULL) && (_widthArr != NULL));
load();
}
Font::~Font() {
warning("STUB: Font::~Font()");
delete[] _map;
delete[] _pos;
delete[] _widthArr;
}
void Font::load() {
warning("STUB: Font::load()");
char *path = "CGE.CFT";
if (!_vm->_resman->exist(path))
error("Missing configuration file! %s", path);
EncryptedStream fontFile(_vm, path);
assert(!fontFile.err());
fontFile.read(_widthArr, kWidSize);
assert(!fontFile.err());
uint16 p = 0;
for (uint16 i = 0; i < kPosSize; i++) {
_pos[i] = p;
p += _widthArr[i];
}
fontFile.read(_map, p);
path = "CGE.TXC";
if (!_vm->_resman->exist(path))
error("Missing configuration file! %s", path);
// Reading in _colorSet:
EncryptedStream colorFile(_vm, path);
assert(!colorFile.err());
char tmpStr[kLineMax + 1];
Common::String line;
int n = 0;
for (line = colorFile.readLine(); !colorFile.eos(); line = colorFile.readLine()){
if (line.size() == 0)
continue;
Common::strlcpy(tmpStr, line.c_str(), sizeof(tmpStr));
char *p;
if ((p = _vm->token(tmpStr)) == NULL)
error("Wrong line! (%d) in %s", colorFile.getLineCount(), path);
_colorSet[n][0] = _vm->number(p);
for (int i = 1; i < 4; i++) {
if ((p = _vm->token(nullptr)) == NULL)
error("Wrong line! (%d) in %s", colorFile.getLineCount(), path);
_colorSet[n][i] = _vm->number(p);
}
n++;
}
}
uint16 Font::width(const char *text) {
warning("STUB: Font::width()");
return 0;
uint16 w = 0;
if (!text)
return 0;
while (*text)
w += _widthArr[(unsigned char)*(text++)];
return w;
}
Talk::Talk(CGE2Engine *vm, const char *text, TextBoxStyle mode, bool wideSpace)

View File

@ -33,8 +33,6 @@
namespace CGE2 {
#define kTextColFG kVgaColDark // foreground color
#define kTextColBG kVgaColGray // background color
#define kTextHMargin (6&~1) // EVEN horizontal margins!
#define kTextVMargin 5 // vertical margins
#define kTextLineSpace 2 // line spacing
@ -44,6 +42,23 @@ namespace CGE2 {
#define kMapSize (256*8)
#define kFontHigh 8
#define kFontExt ".CFT"
#define kCaptionSide 24
#define kInfName 101
#define kSayName 102
#define kColorNum 6
class Font {
void load();
CGE2Engine *_vm;
public:
uint8 *_widthArr;
uint16 *_pos;
uint8 *_map;
uint8 _colorSet[kColorNum][4];
Font(CGE2Engine *vm);
~Font();
uint16 width(const char *text);
};
enum TextBoxStyle { kTBPure, kTBRect, kTBRound };