1 /* ScummVM - Graphic Adventure Engine
2  *
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.
6  *
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.
11  *
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.
16  *
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.
20  *
21  */
22 
23 /*
24  * This code is based on Broken Sword 2.5 engine
25  *
26  * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
27  *
28  * Licensed under GNU GPL v2
29  *
30  */
31 
32 #ifndef SWORD25_TEXT_H
33 #define SWORD25_TEXT_H
34 
35 #include "sword25/kernel/common.h"
36 #include "common/rect.h"
37 #include "sword25/gfx/renderobject.h"
38 
39 namespace Sword25 {
40 
41 class Kernel;
42 class FontResource;
43 class ResourceManager;
44 
45 class Text : public RenderObject {
46 	friend class RenderObject;
47 
48 public:
49 	/**
50 	    @brief Setzt den Font mit dem der Text dargestellt werden soll.
51 	    @param Font der Dateiname der Fontdatei.
52 	    @return Gibt false zur�ck, wenn der Font nicht gefunden wurde.
53 	*/
54 	bool setFont(const Common::String &font);
55 
56 	/**
57 	    @brief Setzt den darzustellenden Text.
58 	    @param Text der darzustellende Text
59 	*/
60 	void setText(const Common::String &text);
61 
62 	/**
63 	    @brief Setzt den Alphawert des Textes.
64 	    @param Alpha der neue Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
65 	*/
66 	void setAlpha(int alpha);
67 
68 	/**
69 	    @brief Legt fest, ob der Text automatisch umgebrochen werden soll.
70 
71 	    Wenn dieses Attribut auf true gesetzt ist, wird der Text umgebrochen, sofern er l�nger als GetAutoWrapThreshold() ist.
72 
73 	    @param AutoWrap gibt an, ob der automatische Umbruch aktiviert oder deaktiviert werden soll.
74 	    @remark Dieses Attribut wird mit dem Wert false initialisiert.
75 	*/
76 	void setAutoWrap(bool autoWrap);
77 
78 	/**
79 	    @brief Legt die L�ngengrenze des Textes in Pixeln fest, ab der ein automatischer Zeilenumbruch vorgenommen wird.
80 	    @remark Dieses Attribut wird mit dem Wert 300 initialisiert.
81 	    @remark Eine automatische Formatierung wird nur vorgenommen, wenn diese durch einen Aufruf von SetAutoWrap() aktiviert wurde.
82 	*/
83 	void setAutoWrapThreshold(uint32 autoWrapThreshold);
84 
85 	/**
86 	    @brief Gibt den dargestellten Text zur�ck.
87 	*/
getText()88 	const Common::String &getText() {
89 		return _text;
90 	}
91 
92 	/**
93 	    @brief Gibt den Namen das momentan benutzten Fonts zur�ck.
94 	*/
getFont()95 	const Common::String &getFont() {
96 		return _font;
97 	}
98 
99 	/**
100 	    @brief Setzt die Farbe des Textes.
101 	    @param Color eine 24-Bit RGB Farbe, die die Farbe des Textes festlegt.
102 	*/
103 	void setColor(uint32 modulationColor);
104 
105 	/**
106 	    @brief Gibt den Alphawert des Textes zur�ck.
107 	    @return Der Alphawert des Textes (0 = keine Deckung, 255 = volle Deckung).
108 	*/
getAlpha()109 	int getAlpha() const {
110 		return _modulationColor >> 24;
111 	}
112 
113 	/**
114 	    @brief Gibt die Farbe des Textes zur�ck.
115 	    @return Eine 24-Bit RGB Farbe, die die Farbe des Textes angibt.
116 	*/
getColor()117 	int getColor() const {
118 		return _modulationColor & 0x00ffffff;
119 	}
120 
121 	/**
122 	    @brief Gibt zur�ck, ob die automatische Formatierung aktiviert ist.
123 	*/
isAutoWrapActive()124 	bool isAutoWrapActive() const {
125 		return _autoWrap;
126 	}
127 
128 	/**
129 	    @brief Gibt die L�ngengrenze des Textes in Pixeln zur�ck, ab der eine automatische Formatierung vorgenommen wird.
130 	*/
getAutoWrapThreshold()131 	uint32 getAutoWrapThreshold() const {
132 		return _autoWrapThreshold;
133 	}
134 
135 	virtual bool  persist(OutputPersistenceBlock &writer);
136 	virtual bool  unpersist(InputPersistenceBlock &reader);
137 
138 protected:
139 	virtual bool doRender(RectangleList *updateRects);
140 
141 private:
142 	Text(RenderObjectPtr<RenderObject> parentPtr);
143 	Text(InputPersistenceBlock &reader, RenderObjectPtr<RenderObject> parentPtr, uint handle);
144 
145 	uint32 _modulationColor;
146 	Common::String _font;
147 	Common::String _text;
148 	bool _autoWrap;
149 	uint32 _autoWrapThreshold;
150 
151 	struct Line {
152 		Common::Rect bbox;
153 		Common::String text;
154 	};
155 
156 	Common::Array<Line> _lines;
157 
158 	void updateFormat();
159 	void updateMetrics(FontResource &fontResource);
160 	ResourceManager *getResourceManager();
161 	FontResource *lockFontResource();
162 };
163 
164 } // End of namespace Sword25
165 
166 #endif
167