forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextNode.h
More file actions
388 lines (317 loc) · 14 KB
/
textNode.h
File metadata and controls
388 lines (317 loc) · 14 KB
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file textNode.h
* @author drose
* @date 2002-03-13
*/
#ifndef TEXTNODE_H
#define TEXTNODE_H
#include "pandabase.h"
#include "config_text.h"
#include "textEncoder.h"
#include "textProperties.h"
#include "textFont.h"
#include "textAssembler.h"
#include "pandaNode.h"
#include "luse.h"
#include "geom.h"
/**
* The primary interface to this module. This class does basic text assembly;
* given a string of text and a TextFont object, it creates a piece of
* geometry that may be placed in the 3-d or 2-d world to represent the
* indicated text.
*
* The TextNode may be used in one of two ways. Naively, it may simply be
* parented directly into the scene graph and rendered as if it were a
* GeomNode; in this mode, the actual polygon geometry that renders the text
* is not directly visible or accessible, but remains hidden within the
* TextNode.
*
* The second way TextNode may be used is as a text generator. To use it in
* this way, do not parent the TextNode to the scene graph; instead, set the
* properties of the text and call generate() to return an ordinary node,
* containing ordinary geometry, which you may use however you like. Each
* time you call generate() a new node is returned.
*/
class EXPCL_PANDA_TEXT TextNode : public PandaNode, public TextEncoder, public TextProperties {
PUBLISHED:
explicit TextNode(const string &name);
explicit TextNode(const string &name, const TextProperties ©);
protected:
TextNode(const TextNode ©);
virtual PandaNode *make_copy() const;
PUBLISHED:
~TextNode();
enum FlattenFlags {
FF_none = 0x0000,
FF_light = 0x0001,
FF_medium = 0x0002,
FF_strong = 0x0004,
FF_dynamic_merge = 0x0008,
};
INLINE PN_stdfloat get_line_height() const;
INLINE void set_max_rows(int max_rows);
INLINE void clear_max_rows();
INLINE bool has_max_rows() const;
INLINE int get_max_rows() const;
INLINE bool has_overflow() const;
INLINE void set_frame_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
INLINE void set_frame_color(const LColor &frame_color);
INLINE LColor get_frame_color() const;
INLINE void set_card_border(PN_stdfloat size, PN_stdfloat uv_portion);
INLINE void clear_card_border();
INLINE PN_stdfloat get_card_border_size() const;
INLINE PN_stdfloat get_card_border_uv_portion() const;
INLINE bool has_card_border() const;
INLINE void set_card_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
INLINE void set_card_color(const LColor &card_color);
INLINE LColor get_card_color() const;
INLINE void set_card_texture(Texture *card_texture);
INLINE void clear_card_texture();
INLINE bool has_card_texture() const;
INLINE Texture *get_card_texture() const;
INLINE void set_frame_as_margin(PN_stdfloat left, PN_stdfloat right,
PN_stdfloat bottom, PN_stdfloat top);
INLINE void set_frame_actual(PN_stdfloat left, PN_stdfloat right,
PN_stdfloat bottom, PN_stdfloat top);
INLINE void clear_frame();
INLINE bool has_frame() const;
INLINE bool is_frame_as_margin() const;
INLINE LVecBase4 get_frame_as_set() const;
INLINE LVecBase4 get_frame_actual() const;
INLINE void set_frame_line_width(PN_stdfloat line_width);
INLINE PN_stdfloat get_frame_line_width() const;
INLINE void set_frame_corners(bool corners);
INLINE bool get_frame_corners() const;
INLINE void set_card_as_margin(PN_stdfloat left, PN_stdfloat right,
PN_stdfloat bottom, PN_stdfloat top);
INLINE void set_card_actual(PN_stdfloat left, PN_stdfloat right,
PN_stdfloat bottom, PN_stdfloat top);
INLINE void set_card_decal(bool card_decal);
INLINE void clear_card();
INLINE bool has_card() const;
INLINE bool get_card_decal() const;
INLINE bool is_card_as_margin() const;
INLINE LVecBase4 get_card_as_set() const;
INLINE LVecBase4 get_card_actual() const;
INLINE LVecBase4 get_card_transformed() const;
INLINE void set_transform(const LMatrix4 &transform);
INLINE LMatrix4 get_transform() const;
INLINE void set_coordinate_system(CoordinateSystem cs);
INLINE CoordinateSystem get_coordinate_system() const;
INLINE void set_usage_hint(Geom::UsageHint usage_hint);
INLINE Geom::UsageHint get_usage_hint() const;
INLINE void set_flatten_flags(int flatten_flags);
INLINE int get_flatten_flags() const;
// These methods are inherited from TextProperties, but we override here so
// we can flag the TextNode as dirty when they have been changed.
INLINE void set_font(TextFont *font);
INLINE void clear_font();
INLINE void set_small_caps(bool small_caps);
INLINE void clear_small_caps();
INLINE void set_small_caps_scale(PN_stdfloat small_caps_scale);
INLINE void clear_small_caps_scale();
INLINE void set_slant(PN_stdfloat slant);
INLINE void clear_slant();
INLINE void set_align(Alignment align_type);
INLINE void clear_align();
INLINE void set_indent(PN_stdfloat indent);
INLINE void clear_indent();
INLINE void set_wordwrap(PN_stdfloat wordwrap);
INLINE void clear_wordwrap();
INLINE void set_text_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
INLINE void set_text_color(const LColor &text_color);
INLINE void clear_text_color();
INLINE void set_shadow_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a);
INLINE void set_shadow_color(const LColor &shadow_color);
INLINE void clear_shadow_color();
INLINE void set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset);
INLINE void set_shadow(const LVecBase2 &shadow_offset);
INLINE void clear_shadow();
INLINE void set_bin(const string &bin);
INLINE void clear_bin();
INLINE int set_draw_order(int draw_order);
INLINE void clear_draw_order();
INLINE void set_tab_width(PN_stdfloat tab_width);
INLINE void clear_tab_width();
INLINE void set_glyph_scale(PN_stdfloat glyph_scale);
INLINE void clear_glyph_scale();
INLINE void set_glyph_shift(PN_stdfloat glyph_shift);
INLINE void clear_glyph_shift();
// These methods are inherited from TextEncoder, but we override here so we
// can flag the TextNode as dirty when they have been changed.
INLINE void set_text(const string &text);
INLINE void set_text(const string &text, Encoding encoding);
INLINE void clear_text();
INLINE void append_text(const string &text);
INLINE void append_unicode_char(wchar_t character);
// After the text has been set, you can query this to determine how it will
// be wordwrapped.
INLINE string get_wordwrapped_text() const;
// These methods calculate the width of a single character or a line of text
// in the current font.
PN_stdfloat calc_width(wchar_t character) const;
INLINE PN_stdfloat calc_width(const string &line) const;
bool has_exact_character(wchar_t character) const;
bool has_character(wchar_t character) const;
bool is_whitespace(wchar_t character) const;
// Direct support for wide-character strings.
INLINE void set_wtext(const wstring &wtext);
INLINE void append_wtext(const wstring &text);
INLINE wstring get_wordwrapped_wtext() const;
PN_stdfloat calc_width(const wstring &line) const;
virtual void output(ostream &out) const;
virtual void write(ostream &out, int indent_level = 0) const;
// The following functions return information about the text that was last
// built (and is currently visible).
INLINE PN_stdfloat get_left() const;
INLINE PN_stdfloat get_right() const;
INLINE PN_stdfloat get_bottom() const;
INLINE PN_stdfloat get_top() const;
INLINE PN_stdfloat get_height() const;
INLINE PN_stdfloat get_width() const;
INLINE LPoint3 get_upper_left_3d() const;
INLINE LPoint3 get_lower_right_3d() const;
INLINE int get_num_rows() const;
PT(PandaNode) generate();
INLINE void update();
INLINE void force_update();
PandaNode *get_internal_geom() const;
PUBLISHED:
MAKE_PROPERTY(max_rows, get_max_rows, set_max_rows);
MAKE_PROPERTY(frame_color, get_frame_color, set_frame_color);
MAKE_PROPERTY(card_color, get_card_color, set_card_color);
MAKE_PROPERTY(card_texture, get_card_texture, set_card_texture);
MAKE_PROPERTY(frame_line_width, get_frame_line_width, set_frame_line_width);
MAKE_PROPERTY(frame_corners, get_frame_corners, set_frame_corners);
MAKE_PROPERTY(transform, get_transform, set_transform);
MAKE_PROPERTY(coordinate_system, get_coordinate_system, set_coordinate_system);
MAKE_PROPERTY(usage_hint, get_usage_hint, set_usage_hint);
MAKE_PROPERTY(flatten_flags, get_flatten_flags, set_flatten_flags);
MAKE_PROPERTY(text, get_text, set_text);
MAKE_PROPERTY2(font, has_font, get_font, set_font, clear_font);
MAKE_PROPERTY2(small_caps, has_small_caps, get_small_caps,
set_small_caps, clear_small_caps);
MAKE_PROPERTY2(small_caps_scale, has_small_caps_scale, get_small_caps_scale,
set_small_caps_scale, clear_small_caps_scale);
MAKE_PROPERTY2(slant, has_slant, get_slant, set_slant, clear_slant);
MAKE_PROPERTY2(underscore, has_underscore, get_underscore,
set_underscore, clear_underscore);
MAKE_PROPERTY2(underscore_height, has_underscore_height, get_underscore_height,
set_underscore_height, clear_underscore_height);
MAKE_PROPERTY2(align, has_align, get_align, set_align, clear_align);
MAKE_PROPERTY2(indent, has_indent, get_indent, set_indent, clear_indent);
MAKE_PROPERTY2(wordwrap, has_wordwrap, get_wordwrap, set_wordwrap, clear_wordwrap);
MAKE_PROPERTY2(preserve_trailing_whitespace,
has_preserve_trailing_whitespace, get_preserve_trailing_whitespace,
set_preserve_trailing_whitespace, clear_preserve_trailing_whitespace);
MAKE_PROPERTY2(text_color, has_text_color, get_text_color,
set_text_color, clear_text_color);
MAKE_PROPERTY2(shadow_color, has_shadow_color, get_shadow_color,
set_shadow_color, clear_shadow_color);
MAKE_PROPERTY2(shadow, has_shadow, get_shadow, set_shadow, clear_shadow);
MAKE_PROPERTY2(bin, has_bin, get_bin, set_bin, clear_bin);
MAKE_PROPERTY2(draw_order, has_draw_order, get_draw_order,
set_draw_order, clear_draw_order);
MAKE_PROPERTY2(tab_width, has_tab_width, get_tab_width,
set_tab_width, clear_tab_width);
MAKE_PROPERTY2(glyph_scale, has_glyph_scale, get_glyph_scale,
set_glyph_scale, clear_glyph_scale);
MAKE_PROPERTY2(glyph_shift, has_glyph_shift, get_glyph_shift,
set_glyph_shift, clear_glyph_shift);
MAKE_PROPERTY2(text_scale, has_text_scale, get_text_scale,
set_text_scale, clear_text_scale);
public:
// From parent class PandaNode
virtual int get_unsafe_to_apply_attribs() const;
virtual void apply_attribs_to_vertices(const AccumulatedAttribs &attribs,
int attrib_types,
GeomTransformer &transformer);
virtual CPT(TransformState)
calc_tight_bounds(LPoint3 &min_point, LPoint3 &max_point,
bool &found_any,
const TransformState *transform,
Thread *current_thread) const;
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
virtual bool is_renderable() const;
virtual void compute_internal_bounds(CPT(BoundingVolume) &internal_bounds,
int &internal_vertices,
int pipeline_stage,
Thread *current_thread) const;
virtual void r_prepare_scene(GraphicsStateGuardianBase *gsg,
const RenderState *node_state,
GeomTransformer &transformer,
Thread *current_thread);
private:
INLINE void invalidate_no_measure();
INLINE void invalidate_with_measure();
INLINE void check_rebuild() const;
INLINE void check_measure() const;
void do_rebuild();
void do_measure();
PT(PandaNode) make_frame();
PT(PandaNode) make_card();
PT(PandaNode) make_card_with_border();
static int count_geoms(PandaNode *node);
PT(PandaNode) _internal_geom;
PT(Texture) _card_texture;
LColor _frame_color;
LColor _card_color;
enum Flags {
F_has_frame = 0x0001,
F_frame_as_margin = 0x0002,
F_has_card = 0x0004,
F_card_as_margin = 0x0008,
F_has_card_texture = 0x0010,
F_frame_corners = 0x0020,
F_card_transp = 0x0040,
F_has_card_border = 0x0080,
F_needs_rebuild = 0x0100,
F_needs_measure = 0x0200,
F_has_overflow = 0x0400,
F_card_decal = 0x0800,
};
int _flags;
int _max_rows;
GeomEnums::UsageHint _usage_hint;
int _flatten_flags;
bool _dynamic_merge;
PN_stdfloat _frame_width;
PN_stdfloat _card_border_size;
PN_stdfloat _card_border_uv_portion;
LVector2 _frame_ul, _frame_lr;
LVector2 _card_ul, _card_lr;
LMatrix4 _transform;
CoordinateSystem _coordinate_system;
LPoint3 _ul3d, _lr3d;
// Returned from TextAssembler:
LVector2 _text_ul, _text_lr;
int _num_rows;
wstring _wordwrapped_wtext;
static PStatCollector _text_generate_pcollector;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
PandaNode::init_type();
TextProperties::init_type();
register_type(_type_handle, "TextNode",
PandaNode::get_class_type(),
TextProperties::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "textNode.I"
#endif