Panda3D
 All Classes Functions Variables Enumerations
textProperties.h
1 // Filename: textProperties.h
2 // Created by: drose (06Apr04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TEXTPROPERTIES_H
16 #define TEXTPROPERTIES_H
17 
18 #include "pandabase.h"
19 
20 #include "config_text.h"
21 #include "luse.h"
22 #include "textFont.h"
23 #include "pointerTo.h"
24 
25 ////////////////////////////////////////////////////////////////////
26 // Class : TextProperties
27 // Description : This defines the set of visual properties that may be
28 // assigned to the individual characters of the text.
29 // (Properties which affect the overall block of text
30 // can only be specified on the TextNode directly).
31 //
32 // Typically, there is just one set of properties on a
33 // given block of text, which is set directly on the
34 // TextNode (TextNode inherits from TextProperties).
35 // That makes all of the text within a particular block
36 // have the same appearance.
37 //
38 // This separate class exists in order to implement
39 // multiple different kinds of text appearing within one
40 // block. The text string itself may reference a
41 // TextProperties structure by name using the \1 and \2
42 // tokens embedded within the string; each nested
43 // TextProperties structure modifies the appearance of
44 // subsequent text within the block.
45 ////////////////////////////////////////////////////////////////////
46 class EXPCL_PANDA_TEXT TextProperties {
47 PUBLISHED:
48  enum Alignment {
49  A_left,
50  A_right,
51  A_center,
52  A_boxed_left,
53  A_boxed_right,
54  A_boxed_center
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 string &bin);
139  INLINE void clear_bin();
140  INLINE bool has_bin() const;
141  INLINE const 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  void add_properties(const TextProperties &other);
169 
170  void write(ostream &out, int indent_level = 0) const;
171 
172 private:
173  static void load_default_font();
174 
175  enum Flags {
176  F_has_font = 0x00000001,
177  F_has_small_caps = 0x00000002,
178  F_has_small_caps_scale = 0x00000004,
179  F_has_slant = 0x00000008,
180  F_has_align = 0x00000010,
181  F_has_indent = 0x00000020,
182  F_has_wordwrap = 0x00000040,
183  F_has_preserve_trailing_whitespace = 0x00000080,
184  F_has_text_color = 0x00000100,
185  F_has_shadow_color = 0x00000200,
186  F_has_shadow = 0x00000400,
187  F_has_bin = 0x00000800,
188  F_has_draw_order = 0x00001000,
189  F_has_tab_width = 0x00002000,
190  F_has_glyph_scale = 0x00004000,
191  F_has_glyph_shift = 0x00008000,
192  F_has_underscore = 0x00010000,
193  F_has_underscore_height = 0x00020000,
194  F_has_text_scale = 0x00040000,
195  };
196 
197  int _specified;
198 
199  PT(TextFont) _font;
200  bool _small_caps;
201  PN_stdfloat _small_caps_scale;
202  PN_stdfloat _slant;
203  bool _underscore;
204  PN_stdfloat _underscore_height;
205  Alignment _align;
206  PN_stdfloat _indent_width;
207  PN_stdfloat _wordwrap_width;
208  bool _preserve_trailing_whitespace;
209  LColor _text_color;
210  LColor _shadow_color;
211  LVector2 _shadow_offset;
212  string _bin;
213  int _draw_order;
214  PN_stdfloat _tab_width;
215  PN_stdfloat _glyph_scale;
216  PN_stdfloat _glyph_shift;
217  PN_stdfloat _text_scale;
218 
219  static PT(TextFont) _default_font;
220  static bool _loaded_default_font;
221 
222 public:
223  static TypeHandle get_class_type() {
224  return _type_handle;
225  }
226  static void init_type() {
227  register_type(_type_handle, "TextProperties");
228  }
229 
230 private:
231  static TypeHandle _type_handle;
232 };
233 
234 #include "textProperties.I"
235 
236 #endif
An encapsulation of a font; i.e.
Definition: textFont.h:36
This is the base class for all two-component vectors and points.
Definition: lvecBase2.h:105
This is the base class for all three-component vectors and points.
Definition: lvecBase4.h:111
This is a two-component vector offset.
Definition: lvector2.h:91
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:85