aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/support/font.h
blob: 591fb4661cf8d2cde82873948f12617714f91e62 (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
/* 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.
 *
 */

#ifndef TITANIC_FONT_H
#define TITANIC_FONT_H

#include "common/scummsys.h"
#include "common/array.h"
#include "titanic/support/rect.h"
#include "titanic/support/string.h"
#include "titanic/support/text_cursor.h"

namespace Titanic {

enum TextCommand { TEXTCMD_NPC = 26, TEXTCMD_SET_COLOR = 27 };

enum WriteCharacterResult {
	WC_IN_BOUNDS = 0, WC_OUTSIDE_TOP = -1, WC_OUTSIDE_BOTTOM = -2,
	WC_OUTSIDE_LEFT = -3, WC_OUTSIDE_RIGHT = -4
};

class CVideoSurface;

class STFont {
	struct CharEntry {
		uint _width;
		uint _offset;
	};
private:
	/**
	 * Copys a rectangle representing a character in the font data to
	 * a given destination position in the surface
	 */
	void copyRect(CVideoSurface *surface, const Common::Point &destPos, 
		Rect &srcRect);

	/**
	 * Write a character
	 */
	WriteCharacterResult writeChar(CVideoSurface *surface, unsigned char c, 
		const Common::Point &pt, const Rect &destRect, const Rect *srcRect);

	/**
	 * Extends a passed text area by the space required for
	 * the given character
	 */
	void extendBounds(Point &textSize, byte c, int maxWidth) const;

	/**
	 * Called at spacing between words, checks for line wrapping
	 */
	void checkLineWrap(Point &textSize, int maxWidth, const char *&str) const;
public:
	byte *_dataPtr;
	size_t _dataSize;
	int _fontHeight;
	uint _dataWidth;
	CharEntry _chars[256];
	byte _fontR, _fontG, _fontB;
public:
	STFont();
	~STFont();

	/**
	 * Load a specified font
	 */
	void load(int fontNumber);

	/**
	 * Return the width in pixels of the specified text
	 */
	int stringWidth(const CString &text) const;

	/**
	 * Write a string to the specified surface
	 * @returns		The index of the last character that was visible
	 *				with the drawing area
	 */
	int writeString(CVideoSurface *surface, const Rect &rect1, const Rect &destRect,
		int yOffset, const CString &str, CTextCursor *textCursor);

	/**
	 * Get the text area a string will fit into
	 * @param str		String
	 * @param maxWidth	Maximum width in pixels
	 * @param sizeOut	Optional pointer to output size (width, height)
	 * @returns			Required height
	 */
	int getTextBounds(const CString &str, int maxWidth, Point *sizeOut) const;

	/**
	 * Sets the font color
	 */
	void setColor(byte r, byte g, byte b);

	/**
	 * Gets the font color
	 */
	uint16 getColor() const;
};

} // End of namespace Titanic

#endif /* TITANIC_FONT_H */