aboutsummaryrefslogtreecommitdiff
path: root/engines/sword25/gfx/text.h
blob: 873eb333805b34947a6337c3614f2cd9ca65b2d5 (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
/* 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 Broken Sword 2.5 engine
 *
 * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
 *
 * Licensed under GNU GPL v2
 *
 */

#ifndef SWORD25_TEXT_H
#define SWORD25_TEXT_H

#include "sword25/kernel/common.h"
#include "common/rect.h"
#include "sword25/gfx/renderobject.h"

namespace Sword25 {

class Kernel;
class FontResource;
class ResourceManager;

class Text : public RenderObject {
	friend class RenderObject;

public:
	/**
	    @brief Setzt den Font mit dem der Text dargestellt werden soll.
	    @param Font der Dateiname der Fontdatei.
	    @return Gibt false zur�ck, wenn der Font nicht gefunden wurde.
	*/
	bool setFont(const Common::String &font);

	/**
	    @brief Setzt den darzustellenden Text.
	    @param Text der darzustellende Text
	*/
	void setText(const Common::String &text);

	/**
	    @brief Setzt den Alphawert des Textes.
	    @param Alpha der neue Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
	*/
	void setAlpha(int alpha);

	/**
	    @brief Legt fest, ob der Text automatisch umgebrochen werden soll.

	    Wenn dieses Attribut auf true gesetzt ist, wird der Text umgebrochen, sofern er l�nger als GetAutoWrapThreshold() ist.

	    @param AutoWrap gibt an, ob der automatische Umbruch aktiviert oder deaktiviert werden soll.
	    @remark Dieses Attribut wird mit dem Wert false initialisiert.
	*/
	void setAutoWrap(bool autoWrap);

	/**
	    @brief Legt die L�ngengrenze des Textes in Pixeln fest, ab der ein automatischer Zeilenumbruch vorgenommen wird.
	    @remark Dieses Attribut wird mit dem Wert 300 initialisiert.
	    @remark Eine automatische Formatierung wird nur vorgenommen, wenn diese durch einen Aufruf von SetAutoWrap() aktiviert wurde.
	*/
	void setAutoWrapThreshold(uint32 autoWrapThreshold);

	/**
	    @brief Gibt den dargestellten Text zur�ck.
	*/
	const Common::String &getText() {
		return _text;
	}

	/**
	    @brief Gibt den Namen das momentan benutzten Fonts zur�ck.
	*/
	const Common::String &getFont() {
		return _font;
	}

	/**
	    @brief Setzt die Farbe des Textes.
	    @param Color eine 24-Bit RGB Farbe, die die Farbe des Textes festlegt.
	*/
	void setColor(uint32 modulationColor);

	/**
	    @brief Gibt den Alphawert des Textes zur�ck.
	    @return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
	*/
	int getAlpha() const {
		return _modulationColor >> 24;
	}

	/**
	    @brief Gibt die Farbe des Textes zur�ck.
	    @return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
	*/
	int getColor() const {
		return _modulationColor & 0x00ffffff;
	}

	/**
	    @brief Gibt zur�ck, ob die automatische Formatierung aktiviert ist.
	*/
	bool isAutoWrapActive() const {
		return _autoWrap;
	}

	/**
	    @brief Gibt die L�ngengrenze des Textes in Pixeln zur�ck, ab der eine automatische Formatierung vorgenommen wird.
	*/
	uint32 getAutoWrapThreshold() const {
		return _autoWrapThreshold;
	}

	virtual bool  persist(OutputPersistenceBlock &writer);
	virtual bool  unpersist(InputPersistenceBlock &reader);

protected:
	virtual bool doRender(RectangleList *updateRects);

private:
	Text(RenderObjectPtr<RenderObject> parentPtr);
	Text(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPtr, uint handle);

	uint32 _modulationColor;
	Common::String _font;
	Common::String _text;
	bool _autoWrap;
	uint32 _autoWrapThreshold;

	struct Line {
		Common::Rect bbox;
		Common::String text;
	};

	Common::Array<Line> _lines;

	void updateFormat();
	void updateMetrics(FontResource &fontResource);
	ResourceManager *getResourceManager();
	FontResource *lockFontResource();
};

} // End of namespace Sword25

#endif