Panda3D
Loading...
Searching...
No Matches
textProperties.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file textProperties.h
10 * @author drose
11 * @date 2004-04-06
12 */
13
14#ifndef TEXTPROPERTIES_H
15#define TEXTPROPERTIES_H
16
17#include "pandabase.h"
18
19#include "config_text.h"
20#include "luse.h"
21#include "textFont.h"
22#include "pointerTo.h"
23#include "renderState.h"
24
25/**
26 * This defines the set of visual properties that may be assigned to the
27 * individual characters of the text. (Properties which affect the overall
28 * block of text can only be specified on the TextNode directly).
29 *
30 * Typically, there is just one set of properties on a given block of text,
31 * which is set directly on the TextNode (TextNode inherits from
32 * TextProperties). That makes all of the text within a particular block have
33 * the same appearance.
34 *
35 * This separate class exists in order to implement multiple different kinds
36 * of text appearing within one block. The text string itself may reference a
37 * TextProperties structure by name using the \1 and \2 tokens embedded within
38 * the string; each nested TextProperties structure modifies the appearance of
39 * subsequent text within the block.
40 */
41class EXPCL_PANDA_TEXT TextProperties {
42PUBLISHED:
43 enum Alignment {
44 A_left,
45 A_right,
46 A_center,
47 A_boxed_left,
48 A_boxed_right,
49 A_boxed_center
50 };
51
52 enum Direction {
53 D_ltr,
54 D_rtl,
55 };
56
58 TextProperties(const TextProperties &copy);
59 void operator = (const TextProperties &copy);
60
61 bool operator == (const TextProperties &other) const;
62 INLINE bool operator != (const TextProperties &other) const;
63
64 void clear();
65 INLINE bool is_any_specified() const;
66
67 INLINE static void set_default_font(TextFont *);
68 INLINE static TextFont *get_default_font();
69
70 INLINE void set_font(TextFont *font);
71 INLINE void clear_font();
72 INLINE bool has_font() const;
73 INLINE TextFont *get_font() const;
74
75 INLINE void set_small_caps(bool small_caps);
76 INLINE void clear_small_caps();
77 INLINE bool has_small_caps() const;
78 INLINE bool get_small_caps() const;
79
80 INLINE void set_small_caps_scale(PN_stdfloat small_caps_scale);
81 INLINE void clear_small_caps_scale();
82 INLINE bool has_small_caps_scale() const;
83 INLINE PN_stdfloat get_small_caps_scale() const;
84
85 INLINE void set_slant(PN_stdfloat slant);
86 INLINE void clear_slant();
87 INLINE bool has_slant() const;
88 INLINE PN_stdfloat get_slant() const;
89
90 INLINE void set_underscore(bool underscore);
91 INLINE void clear_underscore();
92 INLINE bool has_underscore() const;
93 INLINE bool get_underscore() const;
94
95 INLINE void set_underscore_height(PN_stdfloat underscore_height);
96 INLINE void clear_underscore_height();
97 INLINE bool has_underscore_height() const;
98 INLINE PN_stdfloat get_underscore_height() const;
99
100 INLINE void set_align(Alignment align_type);
101 INLINE void clear_align();
102 INLINE bool has_align() const;
103 INLINE Alignment get_align() const;
104
105 INLINE void set_indent(PN_stdfloat indent);
106 INLINE void clear_indent();
107 INLINE bool has_indent() const;
108 INLINE PN_stdfloat get_indent() const;
109
110 INLINE void set_wordwrap(PN_stdfloat wordwrap);
111 INLINE void clear_wordwrap();
112 INLINE bool has_wordwrap() const;
113 INLINE PN_stdfloat get_wordwrap() const;
114
115 INLINE void set_preserve_trailing_whitespace(bool preserve_trailing_whitespace);
116 INLINE void clear_preserve_trailing_whitespace();
117 INLINE bool has_preserve_trailing_whitespace() const;
118 INLINE bool get_preserve_trailing_whitespace() const;
119
120 INLINE void set_text_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
121 INLINE void set_text_color(const LColor &text_color);
122 INLINE void clear_text_color();
123 INLINE bool has_text_color() const;
124 INLINE LColor get_text_color() const;
125
126 INLINE void set_shadow_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
127 INLINE void set_shadow_color(const LColor &shadow_color);
128 INLINE void clear_shadow_color();
129 INLINE bool has_shadow_color() const;
130 INLINE LColor get_shadow_color() const;
131
132 INLINE void set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset);
133 INLINE void set_shadow(const LVecBase2 &shadow_offset);
134 INLINE void clear_shadow();
135 INLINE bool has_shadow() const;
136 INLINE LVector2 get_shadow() const;
137
138 INLINE void set_bin(const std::string &bin);
139 INLINE void clear_bin();
140 INLINE bool has_bin() const;
141 INLINE const std::string &get_bin() const;
142
143 INLINE int set_draw_order(int draw_order);
144 INLINE void clear_draw_order();
145 INLINE bool has_draw_order() const;
146 INLINE int get_draw_order() const;
147
148 INLINE void set_tab_width(PN_stdfloat tab_width);
149 INLINE void clear_tab_width();
150 INLINE bool has_tab_width() const;
151 INLINE PN_stdfloat get_tab_width() const;
152
153 INLINE void set_glyph_scale(PN_stdfloat glyph_scale);
154 INLINE void clear_glyph_scale();
155 INLINE bool has_glyph_scale() const;
156 INLINE PN_stdfloat get_glyph_scale() const;
157
158 INLINE void set_glyph_shift(PN_stdfloat glyph_shift);
159 INLINE void clear_glyph_shift();
160 INLINE bool has_glyph_shift() const;
161 INLINE PN_stdfloat get_glyph_shift() const;
162
163 INLINE void set_text_scale(PN_stdfloat text_scale);
164 INLINE void clear_text_scale();
165 INLINE bool has_text_scale() const;
166 INLINE PN_stdfloat get_text_scale() const;
167
168 INLINE void set_direction(Direction direction);
169 INLINE void clear_direction();
170 INLINE bool has_direction() const;
171 INLINE Direction get_direction() const;
172
173 void add_properties(const TextProperties &other);
174
175 void write(std::ostream &out, int indent_level = 0) const;
176
177PUBLISHED:
178 MAKE_PROPERTY2(font, has_font, get_font, set_font, clear_font);
179 MAKE_PROPERTY2(small_caps, has_small_caps, get_small_caps,
180 set_small_caps, clear_small_caps);
181 MAKE_PROPERTY2(small_caps_scale, has_small_caps_scale, get_small_caps_scale,
182 set_small_caps_scale, clear_small_caps_scale);
183 MAKE_PROPERTY2(slant, has_slant, get_slant, set_slant, clear_slant);
184 MAKE_PROPERTY2(underscore, has_underscore, get_underscore,
185 set_underscore, clear_underscore);
186 MAKE_PROPERTY2(underscore_height, has_underscore_height, get_underscore_height,
187 set_underscore_height, clear_underscore_height);
188 MAKE_PROPERTY2(align, has_align, get_align, set_align, clear_align);
189 MAKE_PROPERTY2(indent, has_indent, get_indent, set_indent, clear_indent);
190 MAKE_PROPERTY2(wordwrap, has_wordwrap, get_wordwrap, set_wordwrap, clear_wordwrap);
191 MAKE_PROPERTY2(preserve_trailing_whitespace,
192 has_preserve_trailing_whitespace, get_preserve_trailing_whitespace,
193 set_preserve_trailing_whitespace, clear_preserve_trailing_whitespace);
194 MAKE_PROPERTY2(text_color, has_text_color, get_text_color,
195 set_text_color, clear_text_color);
196 MAKE_PROPERTY2(shadow_color, has_shadow_color, get_shadow_color,
197 set_shadow_color, clear_shadow_color);
198 MAKE_PROPERTY2(shadow, has_shadow, get_shadow, set_shadow, clear_shadow);
199 MAKE_PROPERTY2(bin, has_bin, get_bin, set_bin, clear_bin);
200 MAKE_PROPERTY2(draw_order, has_draw_order, get_draw_order,
201 set_draw_order, clear_draw_order);
202 MAKE_PROPERTY2(tab_width, has_tab_width, get_tab_width,
203 set_tab_width, clear_tab_width);
204 MAKE_PROPERTY2(glyph_scale, has_glyph_scale, get_glyph_scale,
205 set_glyph_scale, clear_glyph_scale);
206 MAKE_PROPERTY2(glyph_shift, has_glyph_shift, get_glyph_shift,
207 set_glyph_shift, clear_glyph_shift);
208 MAKE_PROPERTY2(text_scale, has_text_scale, get_text_scale,
209 set_text_scale, clear_text_scale);
210 MAKE_PROPERTY2(direction, has_direction, get_direction,
211 set_direction, clear_direction);
212
213public:
214 const RenderState *get_text_state() const;
215 const RenderState *get_shadow_state() const;
216
217private:
218 static void load_default_font();
219
220 enum Flags {
221 F_has_font = 0x00000001,
222 F_has_small_caps = 0x00000002,
223 F_has_small_caps_scale = 0x00000004,
224 F_has_slant = 0x00000008,
225 F_has_align = 0x00000010,
226 F_has_indent = 0x00000020,
227 F_has_wordwrap = 0x00000040,
228 F_has_preserve_trailing_whitespace = 0x00000080,
229 F_has_text_color = 0x00000100,
230 F_has_shadow_color = 0x00000200,
231 F_has_shadow = 0x00000400,
232 F_has_bin = 0x00000800,
233 F_has_draw_order = 0x00001000,
234 F_has_tab_width = 0x00002000,
235 F_has_glyph_scale = 0x00004000,
236 F_has_glyph_shift = 0x00008000,
237 F_has_underscore = 0x00010000,
238 F_has_underscore_height = 0x00020000,
239 F_has_text_scale = 0x00040000,
240 F_has_direction = 0x00080000,
241 };
242
243 int _specified;
244
245 PT(TextFont) _font;
246 bool _small_caps;
247 PN_stdfloat _small_caps_scale;
248 PN_stdfloat _slant;
249 bool _underscore;
250 PN_stdfloat _underscore_height;
251 Alignment _align;
252 PN_stdfloat _indent_width;
253 PN_stdfloat _wordwrap_width;
254 bool _preserve_trailing_whitespace;
255 LColor _text_color;
256 LColor _shadow_color;
257 LVector2 _shadow_offset;
258 std::string _bin;
259 int _draw_order;
260 PN_stdfloat _tab_width;
261 PN_stdfloat _glyph_scale;
262 PN_stdfloat _glyph_shift;
263 PN_stdfloat _text_scale;
264 Direction _direction;
265
266 mutable CPT(RenderState) _text_state;
267 mutable CPT(RenderState) _shadow_state;
268
269 static PT(TextFont) _default_font;
270 static bool _loaded_default_font;
271
272public:
273 static TypeHandle get_class_type() {
274 return _type_handle;
275 }
276 static void init_type() {
277 register_type(_type_handle, "TextProperties");
278 }
279
280private:
281 static TypeHandle _type_handle;
282};
283
284#include "textProperties.I"
285
286#endif
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
An encapsulation of a font; i.e.
Definition textFont.h:32
This defines the set of visual properties that may be assigned to the individual characters of the te...
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.