ScummVM API documentation
qd_screen_text.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef QDENGINE_QDCORE_QD_SCREEN_TEXT_H
23#define QDENGINE_QDCORE_QD_SCREEN_TEXT_H
24
25#include "common/stream.h"
26
27#include "qdengine/parser/xml_fwd.h"
28#include "qdengine/xmath.h"
29#include "qdengine/system/graphics/gr_screen_region.h"
30#include "qdengine/system/graphics/gr_font.h"
31
32namespace QDEngine {
33
34class qdGameObjectState;
35
36const int QD_FONT_TYPE_NONE = -1;
37
40public:
47 };
48
57 };
58
61
62 bool operator == (const qdScreenTextFormat &fmt) const {
63 return (_color == fmt._color &&
64 _arrangement == fmt._arrangement &&
65 _alignment == fmt._alignment &&
66 _hover_color == fmt._hover_color &&
67 _font_type == fmt.font_type() &&
68 _global_depend == fmt.is_global_depend());
69 }
70
71 bool operator != (const qdScreenTextFormat &fmt) const {
72 return !(*this == fmt);
73 }
74
75 void set_arrangement(arrangement_t al) {
76 _arrangement = al;
77 }
78 arrangement_t arrangement() const {
79 return _arrangement;
80 }
81
82 void set_alignment(alignment_t al) {
83 _alignment = al;
84 }
85 alignment_t alignment() const {
86 return _alignment;
87 }
88
89 void set_color(int color) {
90 _color = color;
91 }
92 int color() const {
93 return _color;
94 }
95
96 void set_hover_color(int color) {
97 _hover_color = color;
98 }
99 int hover_color() const {
100 return _hover_color;
101 }
102
103 static const qdScreenTextFormat &default_format();
104 static const qdScreenTextFormat &global_text_format();
105 static void set_global_text_format(const qdScreenTextFormat &frmt);
106 static const qdScreenTextFormat &global_topic_format();
107 static void set_global_topic_format(const qdScreenTextFormat &frmt);
108
109 void set_font_type(int tp) {
110 _font_type = tp;
111 }
112 int font_type() const {
113 return _font_type;
114 }
115
116 bool is_global_depend() const {
117 return _global_depend;
118 }
119 void toggle_global_depend(bool flag = true) {
120 _global_depend = flag;
121 }
122
123 bool load_script(const xml::tag *p);
124 bool save_script(Common::WriteStream &fh, int indent = 0) const;
125
126private:
127
129 arrangement_t _arrangement;
131 alignment_t _alignment;
133 int _color;
135 int _hover_color;
136
138 int _font_type;
139
142 bool _global_depend;
143};
144
147public:
148 qdScreenText(const char *p, const Vect2i &pos = Vect2i(0, 0), qdGameObjectState *owner = NULL);
149 qdScreenText(const char *p, const qdScreenTextFormat &fmt, const Vect2i &pos = Vect2i(0, 0), qdGameObjectState *owner = NULL);
151
154 return _pos;
155 }
157 void set_screen_pos(const Vect2i &pos) {
158 _pos = pos;
159 }
160
161 const char *data() const {
162 return _data.c_str();
163 }
165
168 void set_data(const char *p);
169
171 int size_x() const {
172 return _size.x;
173 }
175 int size_y() const {
176 return _size.y;
177 }
178
179 qdScreenTextFormat::arrangement_t arrangement() const {
180 return _text_format.arrangement();
181 }
182 qdScreenTextFormat::alignment_t alignment() const {
183 return _text_format.alignment();
184 }
185
186 qdScreenTextFormat text_format() const {
187 return _text_format;
188 }
189 void set_text_format(const qdScreenTextFormat &fmt) {
190 _text_format = fmt;
191 }
192
193 grScreenRegion screen_region() const {
194 return grScreenRegion(_pos.x, _pos.y, _size.x, _size.y);
195 }
196
198 void redraw(const Vect2i &owner_pos) const;
199
200 uint32 color() const {
201 return _text_format.color();
202 }
203 void set_color(uint32 col) {
204 _text_format.set_color(col);
205 }
206
209 return _owner;
210 }
213 _owner = p;
214 }
215 bool is_owned_by(const qdNamedObject *p) const;
216
218 bool hit(int x, int y) const {
219 if (x >= _pos.x && x < _pos.x + _size.x) {
220 if (y >= _pos.y && y < _pos.y + _size.y)
221 return true;
222 }
223 return false;
224 }
225
226 void set_hover_mode(bool state) {
227 _hover_mode = state;
228 }
229
230 // форматирует текст так, чтобы его ширина не превышала max_width (размер в пикселах)
231 bool format_text(int max_width);
232
233private:
234
236 Vect2i _pos;
238 Vect2i _size;
239
241 Common::String _data;
242
244 bool _hover_mode;
245
247 qdScreenTextFormat _text_format;
248
250 mutable qdGameObjectState *_owner;
251};
252
253} // namespace QDEngine
254
255#endif // QDENGINE_QDCORE_QD_SCREEN_TEXT_H
Definition: str.h:59
Definition: stream.h:77
Definition: xmath.h:268
Состояние динамического объекта - базовый класс.
Definition: qd_game_object_state.h:91
Поименованный объект.
Definition: qd_named_object.h:70
Обозначает отсутствие шрифта
Definition: qd_screen_text.h:39
arrangement_t
Расположение относительно других текстов.
Definition: qd_screen_text.h:42
@ ARRANGE_HORIZONTAL
Выравнивание по горизонтали.
Definition: qd_screen_text.h:44
@ ARRANGE_VERTICAL
Выравнивание по вертикали.
Definition: qd_screen_text.h:46
alignment_t
Выравнивание текста.
Definition: qd_screen_text.h:50
@ ALIGN_CENTER
по центру
Definition: qd_screen_text.h:54
@ ALIGN_RIGHT
по правому краю
Definition: qd_screen_text.h:56
@ ALIGN_LEFT
по левому краю
Definition: qd_screen_text.h:52
Экранный текст.
Definition: qd_screen_text.h:146
void set_owner(qdGameObjectState *p)
Устанавливает владельца текста.
Definition: qd_screen_text.h:212
int size_x() const
Горизонтальный размер текста в пикселах.
Definition: qd_screen_text.h:171
int size_y() const
Вертикальный размер текста в пикселах.
Definition: qd_screen_text.h:175
Vect2i screen_pos()
Экранные координаты центра текста.
Definition: qd_screen_text.h:153
void set_data(const char *p)
Устанавливает текст.
void set_screen_pos(const Vect2i &pos)
Устанавливает экранные координаты центра текста.
Definition: qd_screen_text.h:157
qdGameObjectState * owner() const
Возвращает указатель на владельца текста.
Definition: qd_screen_text.h:208
bool hit(int x, int y) const
Проверка попадания точки в текст, параметры в экранных координатах.
Definition: qd_screen_text.h:218
void redraw(const Vect2i &owner_pos) const
Отрисовка текста.
Базовый класс для игровых ресурсов.
Definition: console.h:28