2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:40:49 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2004-05-01 08:44:00 +00:00
|
|
|
// Font management and font drawing header file
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2006-07-23 15:16:50 +00:00
|
|
|
#ifndef SAGA_FONT_H
|
|
|
|
#define SAGA_FONT_H
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
#include "saga/list.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/gfx.h"
|
|
|
|
|
2004-04-12 21:40:49 +00:00
|
|
|
namespace Saga {
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
#define FONT_SHOWUNDEFINED 1 // Define to draw undefined characters * as ?'s
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
// The first defined character (!) is the only one that may
|
2004-05-01 08:44:00 +00:00
|
|
|
// have a valid offset of '0'
|
2004-10-27 21:32:28 +00:00
|
|
|
#define FONT_FIRSTCHAR 33
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
#define FONT_CH_SPACE 32
|
|
|
|
#define FONT_CH_QMARK 63
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-30 21:11:48 +00:00
|
|
|
// Minimum font header size without font data
|
2004-05-01 08:44:00 +00:00
|
|
|
// (6 + 512 + 256 + 256 + 256 )
|
2004-10-27 21:32:28 +00:00
|
|
|
#define FONT_DESCSIZE 1286
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
#define FONT_CHARCOUNT 256
|
|
|
|
#define FONT_CHARMASK 0xFFU
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
#define SAGA_FONT_HEADER_LEN 6
|
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
#define TEXT_CENTERLIMIT 50
|
|
|
|
#define TEXT_MARGIN 10
|
|
|
|
#define TEXT_LINESPACING 2
|
|
|
|
|
2005-11-03 18:20:12 +00:00
|
|
|
enum FontEffectFlags {
|
|
|
|
kFontNormal = 0,
|
|
|
|
kFontOutline = 1 << 0,
|
|
|
|
kFontShadow = 1 << 1,
|
|
|
|
kFontBold = 1 << 2,
|
|
|
|
kFontCentered = 1 << 3,
|
|
|
|
kFontDontmap = 1 << 4
|
|
|
|
};
|
|
|
|
|
|
|
|
enum KnownFont {
|
|
|
|
kKnownFontSmall,
|
|
|
|
kKnownFontMedium,
|
|
|
|
kKnownFontBig,
|
|
|
|
|
|
|
|
kKnownFontPause,
|
|
|
|
kKnownFontScript,
|
2005-11-03 22:23:23 +00:00
|
|
|
kKnownFontVerb
|
2005-11-03 18:20:12 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
struct TextListEntry {
|
2005-07-19 19:05:52 +00:00
|
|
|
bool display;
|
|
|
|
bool useRect;
|
2005-07-14 17:46:21 +00:00
|
|
|
Common::Point point;
|
2005-07-19 19:05:52 +00:00
|
|
|
Common::Rect rect;
|
2005-11-26 12:08:05 +00:00
|
|
|
KnownColor knownColor;
|
|
|
|
KnownColor effectKnownColor;
|
2005-07-14 17:46:21 +00:00
|
|
|
FontEffectFlags flags;
|
2005-11-03 18:20:12 +00:00
|
|
|
KnownFont font;
|
2005-07-14 17:46:21 +00:00
|
|
|
const char *text;
|
|
|
|
TextListEntry() {
|
2005-07-30 21:11:48 +00:00
|
|
|
memset(this, 0, sizeof(*this));
|
2005-07-14 17:46:21 +00:00
|
|
|
}
|
2004-08-03 00:06:18 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
class TextList: public SortedList<TextListEntry> {
|
|
|
|
public:
|
|
|
|
|
|
|
|
TextListEntry *addEntry(const TextListEntry &entry) {
|
|
|
|
return pushBack(entry).operator->();
|
|
|
|
}
|
2004-08-03 00:06:18 +00:00
|
|
|
};
|
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
struct FontHeader {
|
|
|
|
int charHeight;
|
|
|
|
int charWidth;
|
|
|
|
int rowLength;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
struct FontCharEntry {
|
2004-04-12 21:40:49 +00:00
|
|
|
int index;
|
2005-07-14 17:46:21 +00:00
|
|
|
int byteWidth;
|
2004-04-12 21:40:49 +00:00
|
|
|
int width;
|
|
|
|
int flag;
|
|
|
|
int tracking;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
struct FontStyle {
|
|
|
|
FontHeader header;
|
|
|
|
FontCharEntry fontCharEntry[256];
|
|
|
|
byte *font;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
struct FontData {
|
|
|
|
FontStyle normal;
|
|
|
|
FontStyle outline;
|
2004-04-25 14:42:14 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-03 00:06:18 +00:00
|
|
|
class Font {
|
|
|
|
public:
|
|
|
|
Font(SagaEngine *vm);
|
|
|
|
~Font(void);
|
2005-11-03 18:20:12 +00:00
|
|
|
int getStringWidth(KnownFont font, const char *text, size_t count, FontEffectFlags flags) {
|
|
|
|
return getStringWidth(knownFont2FontIdx(font), text, count, flags);
|
2005-07-14 17:46:21 +00:00
|
|
|
}
|
2005-11-03 18:20:12 +00:00
|
|
|
int getHeight(KnownFont font) {
|
|
|
|
return getHeight(knownFont2FontIdx(font));
|
2005-08-07 14:54:11 +00:00
|
|
|
}
|
2005-11-03 18:20:12 +00:00
|
|
|
int getHeight(KnownFont font, const char *text, int width, FontEffectFlags flags) {
|
|
|
|
return getHeight(knownFont2FontIdx(font), text, width, flags);
|
|
|
|
}
|
|
|
|
void textDraw(KnownFont font, Surface *ds, const char *string, const Common::Point &point, int color, int effectColor, FontEffectFlags flags) {
|
|
|
|
textDraw(knownFont2FontIdx(font), ds, string, point, color, effectColor, flags);
|
|
|
|
}
|
|
|
|
void textDrawRect(KnownFont font, Surface *ds, const char *text, const Common::Rect &rect, int color, int effectColor, FontEffectFlags flags) {
|
|
|
|
textDrawRect(knownFont2FontIdx(font), ds, text, rect, color, effectColor, flags);
|
2005-07-14 17:46:21 +00:00
|
|
|
}
|
2005-11-03 18:20:12 +00:00
|
|
|
|
|
|
|
private:
|
2005-11-19 12:41:23 +00:00
|
|
|
enum FontId {
|
|
|
|
kSmallFont,
|
|
|
|
kMediumFont,
|
|
|
|
kBigFont,
|
|
|
|
kIHNMUnknown,
|
|
|
|
kIHNMFont8,
|
|
|
|
kIHNMUnknown2,
|
|
|
|
kIHNMMainFont
|
|
|
|
};
|
|
|
|
|
|
|
|
Font::FontId knownFont2FontIdx(KnownFont font);
|
2005-11-03 18:20:12 +00:00
|
|
|
|
|
|
|
int getStringWidth(FontId fontId, const char *text, size_t count, FontEffectFlags flags);
|
|
|
|
int getHeight(FontId fontId, const char *text, int width, FontEffectFlags flags);
|
|
|
|
void textDrawRect(FontId fontId, Surface *ds, const char *text, const Common::Rect &rect, int color, int effectColor, FontEffectFlags flags);
|
|
|
|
void textDraw(FontId fontId, Surface *ds, const char *string, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
|
|
|
|
|
|
|
|
void loadFont(uint32 fontResourceId);
|
|
|
|
void createOutline(FontData *font);
|
|
|
|
void draw(FontId fontId, Surface *ds, const char *text, size_t count, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
|
|
|
|
void outFont(const FontStyle &drawFont, Surface *ds, const char *text, size_t count, const Common::Point &point, int color, FontEffectFlags flags);
|
|
|
|
|
|
|
|
FontData *getFont(FontId fontId) {
|
|
|
|
validate(fontId);
|
|
|
|
return _fonts[fontId];
|
|
|
|
}
|
|
|
|
|
2005-11-03 22:23:23 +00:00
|
|
|
int getHeight(FontId fontId) {
|
2005-11-03 18:20:12 +00:00
|
|
|
return getFont(fontId)->normal.header.charHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void validate(FontId fontId) {
|
|
|
|
if (!valid(fontId)) {
|
|
|
|
error("Font::validate: Invalid font id.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool valid(FontId fontId) {
|
|
|
|
return ((fontId >= 0) && (fontId < _loadedFonts));
|
|
|
|
}
|
|
|
|
int getByteLen(int numBits) const {
|
|
|
|
int byteLength = numBits / 8;
|
|
|
|
|
|
|
|
if (numBits % 8) {
|
|
|
|
byteLength++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return byteLength;
|
|
|
|
}
|
2005-07-14 17:46:21 +00:00
|
|
|
|
2004-08-03 00:06:18 +00:00
|
|
|
static const int _charMap[256];
|
|
|
|
SagaEngine *_vm;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-03 00:06:18 +00:00
|
|
|
bool _initialized;
|
|
|
|
|
2005-07-14 17:46:21 +00:00
|
|
|
int _loadedFonts;
|
|
|
|
FontData **_fonts;
|
2004-08-03 00:06:18 +00:00
|
|
|
};
|
2004-04-12 21:40:49 +00:00
|
|
|
|
|
|
|
} // End of namespace Saga
|
|
|
|
|
2004-05-01 08:44:00 +00:00
|
|
|
#endif
|