22 if (font ==
nullptr) {
38 invalidate_with_measure();
49 invalidate_with_measure();
80 return (_flags & F_has_overflow) != 0;
87set_frame_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
88 set_frame_color(LColor(r, g, b, a));
95set_frame_color(
const LColor &frame_color) {
97 if (_frame_color != frame_color) {
98 _frame_color = frame_color;
99 invalidate_no_measure();
106INLINE LColor TextNode::
107get_frame_color()
const {
115INLINE
void TextNode::
116set_card_border(PN_stdfloat size, PN_stdfloat uv_portion) {
118 if ((_flags & F_has_card_border) == 0 || _card_border_size != size || _card_border_uv_portion != uv_portion) {
119 _flags |= F_has_card_border;
120 _card_border_size = size;
121 _card_border_uv_portion = uv_portion;
122 invalidate_no_measure();
129INLINE
void TextNode::
132 if (_flags & F_has_card_border) {
133 _flags &= ~F_has_card_border;
134 invalidate_no_measure();
141INLINE PN_stdfloat TextNode::
142get_card_border_size()
const {
144 return _card_border_size;
150INLINE PN_stdfloat TextNode::
151get_card_border_uv_portion()
const {
153 return _card_border_uv_portion;
159INLINE
bool TextNode::
160has_card_border()
const {
162 return (_flags & F_has_card_border) != 0;
168INLINE
void TextNode::
169set_card_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
170 set_card_color(LColor(r, g, b, a));
176INLINE
void TextNode::
177set_card_color(
const LColor &card_color) {
179 if (_card_color != card_color) {
180 _card_color = card_color;
181 invalidate_no_measure();
188INLINE LColor TextNode::
189get_card_color()
const {
197INLINE
void TextNode::
198set_card_texture(
Texture *card_texture) {
199 if (card_texture ==
nullptr) {
200 clear_card_texture();
203 if ((_flags & F_has_card_texture) == 0 || _card_texture != card_texture) {
204 _flags |= F_has_card_texture;
205 _card_texture = card_texture;
206 invalidate_no_measure();
214INLINE
void TextNode::
215clear_card_texture() {
217 if (_flags & F_has_card_texture) {
218 _flags &= ~F_has_card_texture;
219 _card_texture =
nullptr;
220 invalidate_no_measure();
227INLINE
bool TextNode::
228has_card_texture()
const {
230 return (_flags & F_has_card_texture) != 0;
237get_card_texture()
const {
239 return _card_texture;
249set_frame_as_margin(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
251 _flags |= (F_has_frame | F_frame_as_margin);
252 _frame_ul.set(left, top);
253 _frame_lr.set(right, bottom);
254 invalidate_no_measure();
264set_frame_actual(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
266 _flags |= F_has_frame;
267 _flags &= ~F_frame_as_margin;
268 _frame_ul.set(left, top);
269 _frame_lr.set(right, bottom);
270 invalidate_no_measure();
279 _flags &= ~F_has_frame;
280 invalidate_no_measure();
286INLINE
bool TextNode::
289 return (_flags & F_has_frame) != 0;
302 nassertr((_flags & F_has_frame) != 0,
false);
303 return (_flags & F_frame_as_margin) != 0;
315 nassertr((_flags & F_has_frame) != 0, LVecBase4(0.0, 0.0, 0.0, 0.0));
316 return LVecBase4(_frame_ul[0], _frame_lr[0], _frame_lr[1], _frame_ul[1]);
331 if (_flags & F_has_frame) {
332 if (_flags & F_frame_as_margin) {
334 return LVecBase4(_text_ul[0] - _frame_ul[0],
335 _text_lr[0] + _frame_lr[0],
336 _text_lr[1] - _frame_lr[1],
337 _text_ul[1] + _frame_ul[1]);
339 return LVecBase4(_frame_ul[0], _frame_lr[0], _frame_lr[1], _frame_ul[1]);
343 return LVecBase4(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
353 _frame_width = frame_width;
354 invalidate_no_measure();
375 _flags |= F_frame_corners;
377 _flags &= ~F_frame_corners;
379 invalidate_no_measure();
385INLINE
bool TextNode::
386get_frame_corners()
const {
388 return (_flags & F_frame_corners) != 0;
398set_card_as_margin(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
400 _flags |= (F_has_card | F_card_as_margin);
401 _card_ul.set(left, top);
402 _card_lr.set(right, bottom);
403 invalidate_no_measure();
413set_card_actual(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top) {
415 _flags |= F_has_card;
416 _flags &= ~F_card_as_margin;
417 _card_ul.set(left, top);
418 _card_lr.set(right, bottom);
419 invalidate_no_measure();
431 _flags |= F_card_decal;
433 _flags &= ~F_card_decal;
435 invalidate_no_measure();
444 _flags &= ~F_has_card;
445 invalidate_no_measure();
451INLINE
bool TextNode::
454 return (_flags & F_has_card) != 0;
463 return (_flags & F_card_decal) != 0;
476 nassertr((_flags & F_has_card) != 0,
false);
477 return (_flags & F_card_as_margin) != 0;
489 nassertr((_flags & F_has_card) != 0, LVecBase4(0.0, 0.0, 0.0, 0.0));
490 return LVecBase4(_card_ul[0], _card_lr[0], _card_lr[1], _card_ul[1]);
505 if (_flags & F_has_card) {
506 if (_flags & F_card_as_margin) {
508 return LVecBase4(_text_ul[0] - _card_ul[0],
509 _text_lr[0] + _card_lr[0],
510 _text_lr[1] - _card_lr[1],
511 _text_ul[1] + _card_ul[1]);
513 return LVecBase4(_card_ul[0], _card_lr[0], _card_lr[1], _card_ul[1]);
517 return LVecBase4(_text_ul[0], _text_lr[0], _text_lr[1], _text_ul[1]);
532 LPoint3 ul = LPoint3(card[0], 0.0, card[3]) * _transform;
533 LPoint3 lr = LPoint3(card[1], 0.0, card[2]) * _transform;
535 return LVecBase4(ul[0], lr[0], lr[2], ul[2]);
544 _transform = transform;
545 invalidate_with_measure();
551INLINE LMatrix4 TextNode::
552get_transform()
const {
563 _coordinate_system = coordinate_system;
564 invalidate_with_measure();
570INLINE CoordinateSystem TextNode::
571get_coordinate_system()
const {
573 return _coordinate_system;
585 _usage_hint = usage_hint;
586 invalidate_no_measure();
637 _flatten_flags = flatten_flags;
646 return _flatten_flags;
657 invalidate_with_measure();
667 invalidate_with_measure();
688 invalidate_with_measure();
694INLINE
void TextNode::
697 TextProperties::clear_small_caps();
698 invalidate_with_measure();
710 invalidate_with_measure();
716INLINE
void TextNode::
717clear_small_caps_scale() {
719 TextProperties::clear_small_caps_scale();
720 invalidate_with_measure();
726INLINE
void TextNode::
727set_slant(PN_stdfloat slant) {
730 invalidate_with_measure();
736INLINE
void TextNode::
739 TextProperties::clear_slant();
740 invalidate_with_measure();
746INLINE
void TextNode::
747set_align(TextNode::Alignment align_type) {
750 invalidate_with_measure();
756INLINE
void TextNode::
760 invalidate_with_measure();
771 invalidate_with_measure();
777INLINE
void TextNode::
781 invalidate_with_measure();
792 invalidate_with_measure();
803 invalidate_with_measure();
809INLINE
void TextNode::
810set_text_color(
const LColor &text_color) {
812 TextProperties::set_text_color(text_color);
813 invalidate_no_measure();
819INLINE
void TextNode::
820set_text_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
821 set_text_color(LColor(r, g, b, a));
832 invalidate_no_measure();
838INLINE
void TextNode::
839set_shadow_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a) {
840 set_shadow_color(LColor(r, g, b, a));
846INLINE
void TextNode::
847set_shadow_color(
const LColor &shadow_color) {
849 TextProperties::set_shadow_color(shadow_color);
850 invalidate_no_measure();
856INLINE
void TextNode::
857clear_shadow_color() {
860 invalidate_with_measure();
868set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset) {
880 invalidate_no_measure();
890 invalidate_no_measure();
903set_bin(
const std::string &bin) {
906 invalidate_no_measure();
917 invalidate_no_measure();
934 invalidate_no_measure();
941INLINE
void TextNode::
944 TextProperties::clear_draw_order();
945 invalidate_with_measure();
956 invalidate_with_measure();
962INLINE
void TextNode::
965 TextProperties::clear_tab_width();
966 invalidate_with_measure();
978 invalidate_with_measure();
984INLINE
void TextNode::
987 TextProperties::clear_glyph_scale();
988 invalidate_with_measure();
1000 invalidate_with_measure();
1006INLINE
void TextNode::
1007clear_glyph_shift() {
1009 TextProperties::clear_glyph_shift();
1010 invalidate_with_measure();
1045 return _wordwrapped_wtext;
1099 return _text_ul[1] - _text_lr[1];
1109 return _text_lr[0] - _text_ul[0];
1153 return do_generate();
1176 mark_internal_bounds_stale();
1186INLINE
void TextNode::
1187invalidate_no_measure() {
1188 _flags |= F_needs_rebuild;
1197INLINE
void TextNode::
1198invalidate_with_measure() {
1199 _flags |= (F_needs_rebuild | F_needs_measure);
1200 mark_internal_bounds_stale();
1207INLINE
void TextNode::
1208check_rebuild()
const {
1209 if ((_flags & F_needs_rebuild) != 0) {
1218INLINE
void TextNode::
1219check_measure()
const {
1220 if ((_flags & F_needs_measure) != 0) {
A lightweight C++ object whose constructor calls acquire() and whose destructor calls release() on a ...
A basic node of the scene graph or data graph.
std::wstring decode_text(const std::string &text) const
Returns the given wstring decoded to a single-byte string, via the current encoding system.
std::string encode_wtext(const std::wstring &wtext) const
Encodes a wide-text string into a single-char string, according to the current encoding.
An encapsulation of a font; i.e.
get_line_height
Returns the number of units high each line of text is.
The primary interface to this module.
set_glyph_scale
Specifies the factor by which to scale each letter of the text as it is placed.
PN_stdfloat calc_width(wchar_t character) const
Returns the width of a single character of the font, or 0.0 if the character is not known.
void clear_card()
Specifies that a card will not be drawn behind the text.
clear_wordwrap
Removes the wordwrap setting from the TextNode.
LVecBase4 get_frame_actual() const
Returns the actual dimensions of the frame around the text.
LVecBase4 get_frame_as_set() const
Returns the dimensions of the frame as set by set_frame_as_margin() or set_frame_actual().
PN_stdfloat get_bottom() const
Returns the bottommost extent of the text in local 2-d coordinates, unmodified by the set_transform()...
PN_stdfloat get_left() const
Returns the leftmost extent of the text in local 2-d coordinates, unmodified by the set_transform() m...
void set_card_actual(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Similar to set_card_as_margin, except the card is specified in actual coordinate units (relative to t...
get_usage_hint
Returns the UsageHint that will be applied to generated geometry.
LVecBase4 get_card_as_set() const
Returns the dimensions of the card as set by set_card_as_margin() or set_card_actual().
PN_stdfloat get_line_height() const
Returns the number of units high each line of text is.
set_max_rows
Sets the maximum number of rows that may be formatted by the TextNode.
std::string get_wordwrapped_text() const
Returns a string that represents the contents of the text, as it has been formatted by wordwrap rules...
set_indent
Specifies the amount of extra space that is inserted before the first character of each line.
void set_frame_as_margin(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Specifies that a border will be drawn around the text when it is next created.
clear_text_color
Removes the text color specification; the text will be colored whatever it was in the source font fil...
int get_num_rows() const
Returns the number of rows of text that were generated.
set_frame_corners
Enables or disables the drawing of corners for the frame.
set_shadow
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
set_wordwrap
Sets the text up to automatically wordwrap when it exceeds the indicated width.
void clear_max_rows()
Resets the TextNode's default behavior of not limiting the number of rows of text.
clear_font
Resets the font to the default font.
void set_frame_actual(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Similar to set_frame_as_margin, except the frame is specified in actual coordinate units (relative to...
set_tab_width
Sets the width of each tab stop, in screen units.
get_frame_line_width
Returns the thickness of the lines that will be used to draw the frame.
void update()
Can be called after the TextNode has been fully configured, to force the node to recompute its text i...
PN_stdfloat get_top() const
Returns the topmost extent of the text in local 2-d coordinates, unmodified by the set_transform() ma...
get_max_rows
Returns the limit on the height of the TextNode specified by set_max_rows().
set_usage_hint
Specifies the UsageHint that will be applied to generated geometry.
clear_shadow
Specifies that a shadow will not be drawn behind the text.
void set_card_decal(bool card_decal)
Sets the card_decal flag.
bool is_frame_as_margin() const
If this is true, the frame was set via a call to set_frame_as_margin(), and the dimension of the fram...
LVecBase4 get_card_transformed() const
Returns the actual card dimensions, transformed by the matrix set by set_transform().
bool has_max_rows() const
Returns true if a limit on the height of the TextNode has been set via set_max_rows(),...
void set_card_as_margin(PN_stdfloat left, PN_stdfloat right, PN_stdfloat bottom, PN_stdfloat top)
Specifies that a (possibly opaque or semitransparent) card will be held behind the text when it is ne...
set_draw_order
Sets the drawing order of text created by the TextMaker.
set_small_caps_scale
Sets the scale factor applied to lowercase letters from their uppercase equivalents,...
get_flatten_flags
Returns the flatten flags.
bool is_card_as_margin() const
If this is true, the card was set via a call to set_card_as_margin(), and the dimension of the card a...
LVecBase4 get_card_actual() const
Returns the actual dimensions of the card around the text.
PN_stdfloat get_height() const
Returns the net height of the text in local 2-d coordinates.
bool has_overflow() const
Returns true if the last text set on the text node exceeded the max_rows constraint,...
set_frame_line_width
Specifies the thickness of the lines that will be used to draw the frame.
PN_stdfloat get_width() const
Returns the net width of the text in local 2-d coordinates.
set_flatten_flags
Sets the flatten flags.
set_coordinate_system
Specifies the coordinate system in which the text will be generated.
void force_update()
Forces the TextNode to recompute itself now, even if it believes nothing has changed.
set_small_caps
Sets the small_caps flag.
PN_stdfloat get_right() const
Returns the rightmost extent of the text in local 2-d coordinates, unmodified by the set_transform() ...
void clear_frame()
Specifies that a border will not be drawn around the text.
set_bin
Names the GeomBin that the TextNode geometry should be assigned to.
LPoint3 get_upper_left_3d() const
Returns the upper-left extent of the text object, after it has been transformed into 3-d space by app...
set_transform
Sets an additional transform that is applied to the entire text paragraph.
LPoint3 get_lower_right_3d() const
Returns the lower-right extent of the text object, after it has been transformed into 3-d space by ap...
clear_bin
Removes the effect of a previous call to set_bin().
set_glyph_shift
Specifies a vertical amount to shift each letter of the text as it is placed.
std::wstring get_wordwrapped_wtext() const
Returns a wstring that represents the contents of the text, as it has been formatted by wordwrap rule...
bool get_card_decal() const
Returns the card_decal flag.
set_font
Sets the font that will be used when making text.
set_glyph_shift
Specifies a vertical amount to shift each letter of the text as it is placed.
set_shadow
Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offs...
set_align
Specifies the alignment of the text within its margins.
clear_bin
Removes the effect of a previous call to set_bin().
clear_font
Restores the default font to the text.
clear_shadow
Specifies that a shadow will not be drawn behind the text.
set_draw_order
Sets the drawing order of text created by the TextNode.
set_wordwrap
Sets the text up to automatically wordwrap when it exceeds the indicated width.
clear_indent
Removes the indent setting from the text.
clear_shadow_color
Removes the shadow color specification.
set_font
Sets the font that will be used when making text.
set_small_caps_scale
Sets the scale factor applied to lowercase letters from their uppercase equivalents,...
set_tab_width
Sets the width of each tab stop, in screen units.
clear_text_color
Removes the text color specification; the text will be colored whatever it was in the source font fil...
set_glyph_scale
Specifies the factor by which to scale each letter of the text as it is placed, in addition to any sc...
clear_wordwrap
Removes the wordwrap setting from the text.
set_indent
Specifies the amount of extra space that is inserted before the first character of each line.
clear_align
Restores the default alignment of the text.
set_small_caps
Sets the small_caps flag.
set_slant
Specifies the factor by which the text slants to the right.
set_bin
Names the CullBin that the text geometry should be assigned to.
Represents a texture object, which is typically a single 2-d image but may also represent a 1-d or 3-...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.