aboutsummaryrefslogtreecommitdiff
path: root/engines/tony/font.h
blob: 82ce686ec086c84da3c4afa7694a51ea98c5d80c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
/* ScummVM - Graphic Adventure Engine
 *
 * 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.
 *
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */
/*
 * This code is based on original Tony Tough source code
 *
 * Copyright (c) 1997-2003 Nayma Software
 */

#ifndef TONY_FONT_H
#define TONY_FONT_H

#include "common/system.h"
#include "common/coroutines.h"
#include "tony/gfxcore.h"
#include "tony/resid.h"

namespace Tony {

class RMInput;
class RMInventory;
class RMItem;
class RMLoc;
class RMLocation;
class RMPointer;

/**
 * Manages a font, in which there is a different surface for each letter
 */
class RMFont : public RMGfxTaskSetPrior {
protected:
	int nLetters;
	RMGfxSourceBuffer8RLEByte *m_letter;
public:
	int m_fontDimx, m_fontDimy;

private:
	int m_dimx, m_dimy;

	class RMFontPrimitive : public RMGfxPrimitive {
	public:
		RMFontPrimitive() : RMGfxPrimitive() {}
		RMFontPrimitive(RMGfxTask *task) : RMGfxPrimitive(task) {}
		virtual ~RMFontPrimitive() { }
		virtual RMGfxPrimitive *Duplicate() {
			return new RMFontPrimitive(*this);
		}

		int m_nChar;
	};

protected:
	// Loads the font
	void Load(uint32 resID, int nChars, int dimx, int dimy, uint32 palResID = RES_F_PAL);
	void Load(const byte *buf, int nChars, int dimx, int dimy, uint32 palResID = RES_F_PAL);

	// Remove the font
	void Unload(void);

protected:
	// Conversion form character to font index
	virtual int ConvertToLetter(byte nChar) = 0;

	// Character width
	virtual int LetterLength(int nChar, int nNext = 0) = 0;

public:
	virtual int LetterHeight(void) = 0;

public:
	RMFont();
	virtual ~RMFont();

	// Initialisation and closing
	virtual void Init(void) = 0;
	virtual void Close(void);

	// Drawing
	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBug, RMGfxPrimitive *prim);

	// Create a primitive for a letter
	RMGfxPrimitive *MakeLetterPrimitive(byte bChar, int &nLength);

	// Length in pixels of a string with the current font
	int StringLen(const RMString &text);
	int StringLen(char bChar, char bNext = 0);
};


class RMFontColor : public virtual RMFont {
private:
	byte m_r, m_g, m_b;

public:
	RMFontColor();
	virtual ~RMFontColor();
	virtual void SetBaseColor(byte r, byte g, byte b);
};


class RMFontWithTables : public virtual RMFont {
protected:
	int cTable[256];
	int lTable[256];
	int lDefault;
	int hDefault;
	signed char l2Table[256][256];

protected:
	// Overloaded methods
	int ConvertToLetter(byte nChar) {
		return cTable[nChar];
	}
	int LetterLength(int nChar, int nNext = 0) {
		return (nChar != -1 ? lTable[(byte)nChar] + l2Table[(byte)nChar][(byte)nNext] : lDefault);
	}

public:
	int LetterHeight() {
		return hDefault;
	}
	virtual ~RMFontWithTables() {}
};


class RMFontParla : public RMFontColor, public RMFontWithTables {
public:
	void Init(void);
	virtual ~RMFontParla() {}
};

class RMFontObj : public RMFontColor, public RMFontWithTables {
private:
	void SetBothCase(int nChar, int nNext, signed char spiazz);

public:
	void Init(void);
	virtual ~RMFontObj() {}
};

class RMFontMacc : public RMFontColor, public RMFontWithTables {
public:
	void Init(void);
	virtual ~RMFontMacc() {}
};

class RMFontCredits : public RMFontColor, public RMFontWithTables {
public:
	void Init(void);
	virtual ~RMFontCredits() {}
	virtual void SetBaseColor(byte r, byte g, byte b) {}
};

/**
 * Manages writing text onto9 the screen
 */
class RMText : public RMGfxWoodyBuffer {
private:
	static RMFontColor *m_fonts[4];
	static RMGfxClearTask m_clear;
	int maxLineLength;

public:
	enum HORALIGN {
	    HLEFT,
	    HLEFTPAR,
	    HCENTER,
	    HRIGHT
	};

	enum VERALIGN {
	    VTOP,
	    VCENTER,
	    VBOTTOM
	};

private:
	HORALIGN aHorType;
	VERALIGN aVerType;
	byte m_r, m_g, m_b;

protected:
	virtual void ClipOnScreen(RMGfxPrimitive *prim);

public:
	RMText();
	virtual ~RMText();
	static void InitStatics();
	static void Unload();

	// Set the alignment type
	void SetAlignType(HORALIGN aHor, VERALIGN aVer) {
		aHorType = aHor;
		aVerType = aVer;
	}

	// Sets the maximum length of a line in pixels (used to format the text)
	void SetMaxLineLength(int max);

	// Write the text
	void WriteText(const RMString &text, int font, int *time = NULL);
	void WriteText(const RMString &text, RMFontColor *font, int *time = NULL);

	// Overloaded function to decide when you delete the object from the OT list
	virtual void RemoveThis(CORO_PARAM, bool &result);

	// Overloading of the Draw to center the text, if necessary
	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);

	// Set the base colour
	void SetColor(byte r, byte g, byte b) {
		m_r = r;
		m_g = g;
		m_b = b;
	}
};

/**
 * Manages text in a dialog
 */
class RMTextDialog : public RMText {
protected:
	int m_startTime;
	int m_time;
	bool m_bSkipStatus;
	RMPoint dst;
	uint32 hEndDisplay;
	bool m_bShowed;
	bool m_bForceTime;
	bool m_bForceNoTime;
	uint32 hCustomSkip;
	uint32 hCustomSkip2;
	RMInput *m_input;
	bool m_bAlwaysDisplay;
	bool m_bNoTab;

public:
	RMTextDialog();
	virtual ~RMTextDialog();

	// Write the text
	void WriteText(const RMString &text, int font, int *time = NULL);
	void WriteText(const RMString &text, RMFontColor *font, int *time = NULL);

	// Overloaded function to decide when you delete the object from the OT list
	virtual void RemoveThis(CORO_PARAM, bool &result);

	// Overloaded de-registration
	virtual void Unregister(void);

	// Overloading of the Draw to center the text, if necessary
	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);

	// Set the position
	void SetPosition(const RMPoint &pt) {
		dst = pt;
	}

	// Waiting
	void WaitForEndDisplay(CORO_PARAM);
	void SetCustomSkipHandle(uint32 hCustomSkip);
	void SetCustomSkipHandle2(uint32 hCustomSkip);
	void SetSkipStatus(bool bEnabled);
	void SetForcedTime(uint32 dwTime);
	void SetNoTab(void);
	void ForceTime(void);
	void ForceNoTime(void);
	void SetAlwaysDisplay(void);

	// Set the input device, to allow skip from mouse
	void SetInput(RMInput *input);

	void Show(void);
	void Hide(CORO_PARAM);
};

class RMTextDialogScrolling : public RMTextDialog {
protected:
	RMLocation *curLoc;
	RMPoint startScroll;

	virtual void ClipOnScreen(RMGfxPrimitive *prim);

public:
	RMTextDialogScrolling();
	RMTextDialogScrolling(RMLocation *loc);
	virtual ~RMTextDialogScrolling();

	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);
};


/**
 * Manages the name of a selected item on the screen
 */
class RMTextItemName : protected RMText {
protected:
	RMPoint m_mpos;
	RMPoint m_curscroll;
	RMItem *m_item;
	RMString m_itemName;

public:
	RMTextItemName();
	virtual ~RMTextItemName();

	void SetMouseCoord(const RMPoint &m) {
		m_mpos = m;
	}

	void DoFrame(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMLocation &loc, RMPointer &ptr, RMInventory &inv);
	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);

	RMPoint GetHotspot();
	RMItem *GetSelectedItem();
	bool IsItemSelected();
	bool IsNormalItemSelected();

	virtual void RemoveThis(CORO_PARAM, bool &result) {
		result = true;
	}
};


/**
 * Manages the selection of screen items in a box
 */
class RMDialogChoice : public RMGfxWoodyBuffer {
private:
	int m_curSelection;
	int m_numChoices;
	RMText *m_drawedStrings;
	RMPoint *m_ptDrawStrings;
	int m_curAdded;
	bool m_bShow;
	RMGfxSourceBuffer8 DlgText;
	RMGfxSourceBuffer8 DlgTextLine;
	RMPoint m_ptDrawPos;
	uint32 hUnreg;
	bool bRemoveFromOT;

protected:
	void Prepare(CORO_PARAM);
	void SetSelected(CORO_PARAM, int pos);

public:
	virtual void RemoveThis(CORO_PARAM, bool &result);
	virtual void Draw(CORO_PARAM, RMGfxTargetBuffer &bigBuf, RMGfxPrimitive *prim);
	void Unregister(void);

public:
	// Initialisation
	RMDialogChoice();
	virtual ~RMDialogChoice();

	// Initialisation and closure
	void Init(void);
	void Close(void);

	// Sets the number of possible sentences, which then be added with AddChoice()
	void SetNumChoices(int num);

	// Adds a string with the choice
	void AddChoice(const RMString &string);

	// Show and hide the selection, with possible animations.
	// NOTE: If no parameter is passed to Show(), it is the obligation of
	// caller to ensure that the class is inserted into OT list
	void Show(CORO_PARAM, RMGfxTargetBuffer *bigBuf = NULL);
	void Hide(CORO_PARAM);

	// Polling Update
	void DoFrame(CORO_PARAM, RMPoint ptMousePos);

	// Returns the currently selected item, or -1 if none is selected
	int GetSelection(void);
};

} // End of namespace Tony

#endif