Hooked up the pathfinder so that it seems to work. Animation opcode 0x12.
[scummvm-innocent.git] / engines / saga / font.h
blob0064c22afc214d47c133761bab041530680a1e8d
1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 // Font management and font drawing header file
28 #ifndef SAGA_FONT_H
29 #define SAGA_FONT_H
31 #include "saga/gfx.h"
33 namespace Saga {
35 #define FONT_SHOWUNDEFINED 1 // Define to draw undefined characters * as ?'s
37 // The first defined character (!) is the only one that may
38 // have a valid offset of '0'
39 #define FONT_FIRSTCHAR 33
41 #define FONT_CH_TAB 9
42 #define FONT_CH_SPACE 32
43 #define FONT_CH_QMARK 63
45 // Minimum font header size without font data
46 // (6 + 512 + 256 + 256 + 256 )
47 #define FONT_DESCSIZE 1286
49 #define FONT_CHARCOUNT 256
50 #define FONT_CHARMASK 0xFFU
52 #define SAGA_FONT_HEADER_LEN 6
54 #define TEXT_CENTERLIMIT 50
55 #define TEXT_MARGIN 10
56 #define TEXT_LINESPACING 2
58 enum FontEffectFlags {
59 kFontNormal = 0,
60 kFontOutline = 1 << 0,
61 kFontShadow = 1 << 1,
62 kFontBold = 1 << 2,
63 kFontCentered = 1 << 3,
64 kFontDontmap = 1 << 4
67 enum KnownFont {
68 kKnownFontSmall,
69 kKnownFontMedium,
70 kKnownFontBig,
72 kKnownFontPause,
73 kKnownFontScript,
74 kKnownFontVerb
77 struct TextListEntry {
78 bool display;
79 bool useRect;
80 Common::Point point;
81 Common::Rect rect;
82 KnownColor knownColor;
83 KnownColor effectKnownColor;
84 FontEffectFlags flags;
85 KnownFont font;
86 const char *text;
87 TextListEntry() {
88 memset(this, 0, sizeof(*this));
91 bool operator==(const TextListEntry &e) const {
92 return 0 == memcmp(this, &e, sizeof(*this));
96 class TextList: public Common::List<TextListEntry> {
97 public:
99 TextListEntry *addEntry(const TextListEntry &entry) {
100 Common::List<TextListEntry>::push_back(entry);
101 return &*--Common::List<TextListEntry>::end();
105 struct FontHeader {
106 int charHeight;
107 int charWidth;
108 int rowLength;
111 struct FontCharEntry {
112 int index;
113 int byteWidth;
114 int width;
115 int flag;
116 int tracking;
119 struct FontStyle {
120 FontHeader header;
121 FontCharEntry fontCharEntry[256];
122 byte *font;
125 struct FontData {
126 FontStyle normal;
127 FontStyle outline;
130 class Font {
131 public:
132 Font(SagaEngine *vm);
133 ~Font(void);
134 int getStringWidth(KnownFont font, const char *text, size_t count, FontEffectFlags flags) {
135 return getStringWidth(knownFont2FontIdx(font), text, count, flags);
137 int getHeight(KnownFont font) {
138 return getHeight(knownFont2FontIdx(font));
140 int getHeight(KnownFont font, const char *text, int width, FontEffectFlags flags) {
141 return getHeight(knownFont2FontIdx(font), text, width, flags);
143 void textDraw(KnownFont font, const char *string, const Common::Point &point, int color, int effectColor, FontEffectFlags flags) {
144 textDraw(knownFont2FontIdx(font), string, point, color, effectColor, flags);
146 void textDrawRect(KnownFont font, const char *text, const Common::Rect &rect, int color, int effectColor, FontEffectFlags flags) {
147 textDrawRect(knownFont2FontIdx(font), text, rect, color, effectColor, flags);
149 void setFontMapping(int mapping) {
150 _fontMapping = mapping;
153 private:
154 enum FontId {
155 kSmallFont,
156 kMediumFont,
157 kBigFont,
158 kIHNMUnknown,
159 kIHNMFont8,
160 kIHNMUnknown2,
161 kIHNMMainFont
164 Font::FontId knownFont2FontIdx(KnownFont font);
165 int translateChar(int charId);
167 int getStringWidth(FontId fontId, const char *text, size_t count, FontEffectFlags flags);
168 int getHeight(FontId fontId, const char *text, int width, FontEffectFlags flags);
169 void textDrawRect(FontId fontId, const char *text, const Common::Rect &rect, int color, int effectColor, FontEffectFlags flags);
170 void textDraw(FontId fontId, const char *string, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
172 void loadFont(uint32 fontResourceId);
173 void createOutline(FontData *font);
174 void draw(FontId fontId, const char *text, size_t count, const Common::Point &point, int color, int effectColor, FontEffectFlags flags);
175 void outFont(const FontStyle &drawFont, const char *text, size_t count, const Common::Point &point, int color, FontEffectFlags flags);
177 FontData *getFont(FontId fontId) {
178 validate(fontId);
179 return _fonts[fontId];
182 int getHeight(FontId fontId) {
183 return getFont(fontId)->normal.header.charHeight;
186 void validate(FontId fontId) {
187 if (!valid(fontId)) {
188 error("Font::validate: Invalid font id.");
191 bool valid(FontId fontId) {
192 return ((fontId >= 0) && (fontId < _loadedFonts));
194 int getByteLen(int numBits) const {
195 int byteLength = numBits / 8;
197 if (numBits % 8) {
198 byteLength++;
201 return byteLength;
204 static const int _charMap[128];
205 SagaEngine *_vm;
207 int _fontMapping;
209 int _loadedFonts;
210 FontData **_fonts;
213 } // End of namespace Saga
215 #endif