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 */
41 class 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
57 TextProperties();
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
213 public:
214 const RenderState *get_text_state() const;
215 const RenderState *get_shadow_state() const;
216
217 private:
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
272 public:
273 static TypeHandle get_class_type() {
274 return _type_handle;
275 }
276 static void init_type() {
277 register_type(_type_handle, "TextProperties");
278 }
279
280 private:
281 static TypeHandle _type_handle;
282};
283
284#include "textProperties.I"
285
286#endif
RenderState
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition renderState.h:47
TextFont
An encapsulation of a font; i.e.
Definition textFont.h:32
TextProperties::set_glyph_shift
set_glyph_shift
Specifies a vertical amount to shift each letter of the text as it is placed.
Definition textProperties.h:207
TextProperties::get_shadow_state
const RenderState * get_shadow_state() const
Returns a RenderState object suitable for rendering the shadow of this text with these properties.
Definition textProperties.cxx:420
TextProperties::set_underscore_height
set_underscore_height
Specifies the vertical height of the underscore, relative to the text baseline.
Definition textProperties.h:187
TextProperties::has_direction
has_direction
Definition textProperties.h:211
TextProperties::get_slant
get_slant
Returns the factor by which the text is specified to slant to the right.
Definition textProperties.h:183
TextProperties::set_shadow
set_shadow
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
Definition textProperties.h:198
TextProperties::get_draw_order
get_draw_order
Returns the drawing order set with set_draw_order().
Definition textProperties.h:201
TextProperties::set_align
set_align
Specifies the alignment of the text within its margins.
Definition textProperties.h:188
TextProperties::clear_bin
clear_bin
Removes the effect of a previous call to set_bin().
Definition textProperties.h:199
TextProperties::get_underscore_height
get_underscore_height
Returns the vertical height of the underscore; see set_underscore_height().
Definition textProperties.h:187
TextProperties::get_small_caps
get_small_caps
Returns the small_caps flag.
Definition textProperties.h:180
TextProperties::get_glyph_shift
get_glyph_shift
Returns the vertical shift of each letter as specified by set_glyph_shift().
Definition textProperties.h:207
TextProperties::clear_font
clear_font
Restores the default font to the text.
Definition textProperties.h:178
TextProperties::has_text_color
has_text_color
Returns true if a text color was specified with set_text_color().
Definition textProperties.h:195
TextProperties::clear_shadow
clear_shadow
Specifies that a shadow will not be drawn behind the text.
Definition textProperties.h:198
TextProperties::get_text_state
const RenderState * get_text_state() const
Returns a RenderState object suitable for rendering text with these properties.
Definition textProperties.cxx:393
TextProperties::set_draw_order
set_draw_order
Sets the drawing order of text created by the TextNode.
Definition textProperties.h:201
TextProperties::set_wordwrap
set_wordwrap
Sets the text up to automatically wordwrap when it exceeds the indicated width.
Definition textProperties.h:190
TextProperties::clear_indent
clear_indent
Removes the indent setting from the text.
Definition textProperties.h:189
TextProperties::clear_shadow_color
clear_shadow_color
Removes the shadow color specification.
Definition textProperties.h:197
TextProperties::get_preserve_trailing_whitespace
get_preserve_trailing_whitespace
Returns the preserve_trailing_whitespace flag.
Definition textProperties.h:193
TextProperties::clear_direction
clear_direction
Clears the text direction setting.
Definition textProperties.h:211
TextProperties::get_glyph_scale
get_glyph_scale
Returns the scale factor of each letter as specified by set_glyph_scale().
Definition textProperties.h:205
TextProperties::set_underscore
set_underscore
Sets the underscore flag.
Definition textProperties.h:185
TextProperties::set_font
set_font
Sets the font that will be used when making text.
Definition textProperties.h:178
TextProperties::set_small_caps_scale
set_small_caps_scale
Sets the scale factor applied to lowercase letters from their uppercase equivalents,...
Definition textProperties.h:182
TextProperties::set_tab_width
set_tab_width
Sets the width of each tab stop, in screen units.
Definition textProperties.h:203
TextProperties::get_shadow
get_shadow
Returns the offset of the shadow as set by set_shadow().
Definition textProperties.h:198
TextProperties::get_bin
get_bin
Returns the drawing bin set with set_bin(), or empty string if no bin has been set.
Definition textProperties.h:199
TextProperties::clear_text_color
clear_text_color
Removes the text color specification; the text will be colored whatever it was in the source font fil...
Definition textProperties.h:195
TextProperties::set_glyph_scale
set_glyph_scale
Specifies the factor by which to scale each letter of the text as it is placed, in addition to any sc...
Definition textProperties.h:205
TextProperties::get_font
get_font
Returns the font currently in use, if any.
Definition textProperties.h:178
TextProperties::get_small_caps_scale
get_small_caps_scale
Returns the scale factor applied to lowercase letters from their uppercase equivalents,...
Definition textProperties.h:182
TextProperties::get_underscore
get_underscore
Returns the underscore flag.
Definition textProperties.h:185
TextProperties::clear_wordwrap
clear_wordwrap
Removes the wordwrap setting from the text.
Definition textProperties.h:190
TextProperties::is_any_specified
bool is_any_specified() const
Returns true if any properties have been specified, false otherwise.
Definition textProperties.I:26
TextProperties::set_indent
set_indent
Specifies the amount of extra space that is inserted before the first character of each line.
Definition textProperties.h:189
TextProperties::set_default_font
static void set_default_font(TextFont *)
Specifies the default font to be used for any TextNode whose font is uninitialized or NULL.
Definition textProperties.I:35
TextProperties::get_direction
get_direction
Returns the direction of the text as specified by set_direction().
Definition textProperties.h:211
TextProperties::add_properties
void add_properties(const TextProperties &other)
Sets any properties that are explicitly specified in other on this object.
Definition textProperties.cxx:188
TextProperties::get_tab_width
get_tab_width
Returns the width set via set_tab_width().
Definition textProperties.h:203
TextProperties::clear
void clear()
Unsets all properties that have been specified so far, and resets the TextProperties structure to its...
Definition textProperties.cxx:179
TextProperties::has_bin
has_bin
Returns true if an explicit drawing bin has been set via set_bin(), false otherwise.
Definition textProperties.h:199
TextProperties::clear_align
clear_align
Restores the default alignment of the text.
Definition textProperties.h:188
TextProperties::set_preserve_trailing_whitespace
set_preserve_trailing_whitespace
Sets the preserve_trailing_whitespace flag.
Definition textProperties.h:193
TextProperties::set_text_color
set_text_color
Sets the color of the text.
Definition textProperties.h:195
TextProperties::get_default_font
static TextFont * get_default_font()
Specifies the default font to be used for any TextNode whose font is uninitialized or NULL.
Definition textProperties.I:47
TextProperties::set_direction
set_direction
Specifies the text direction.
Definition textProperties.h:211
TextProperties::set_text_scale
set_text_scale
Specifies the factor by which to scale the text, in addition to any scalings imposed by the node,...
Definition textProperties.h:209
TextProperties::get_text_scale
get_text_scale
Returns the scale factor of the text as specified by set_text_scale().
Definition textProperties.h:209
TextProperties::set_small_caps
set_small_caps
Sets the small_caps flag.
Definition textProperties.h:180
TextProperties::set_slant
set_slant
Specifies the factor by which the text slants to the right.
Definition textProperties.h:183
TextProperties::set_bin
set_bin
Names the CullBin that the text geometry should be assigned to.
Definition textProperties.h:199
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
config_text.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
luse.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
renderState.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textFont.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
textProperties.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.