Panda3D
|
00001 // Filename: textProperties.h 00002 // Created by: drose (06Apr04) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef TEXTPROPERTIES_H 00016 #define TEXTPROPERTIES_H 00017 00018 #include "pandabase.h" 00019 00020 #include "config_text.h" 00021 #include "luse.h" 00022 #include "textFont.h" 00023 #include "pointerTo.h" 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Class : TextProperties 00027 // Description : This defines the set of visual properties that may be 00028 // assigned to the individual characters of the text. 00029 // (Properties which affect the overall block of text 00030 // can only be specified on the TextNode directly). 00031 // 00032 // Typically, there is just one set of properties on a 00033 // given block of text, which is set directly on the 00034 // TextNode (TextNode inherits from TextProperties). 00035 // That makes all of the text within a particular block 00036 // have the same appearance. 00037 // 00038 // This separate class exists in order to implement 00039 // multiple different kinds of text appearing within one 00040 // block. The text string itself may reference a 00041 // TextProperties structure by name using the \1 and \2 00042 // tokens embedded within the string; each nested 00043 // TextProperties structure modifies the appearance of 00044 // subsequent text within the block. 00045 //////////////////////////////////////////////////////////////////// 00046 class EXPCL_PANDA_TEXT TextProperties { 00047 PUBLISHED: 00048 enum Alignment { 00049 A_left, 00050 A_right, 00051 A_center, 00052 A_boxed_left, 00053 A_boxed_right, 00054 A_boxed_center 00055 }; 00056 00057 TextProperties(); 00058 TextProperties(const TextProperties ©); 00059 void operator = (const TextProperties ©); 00060 00061 bool operator == (const TextProperties &other) const; 00062 INLINE bool operator != (const TextProperties &other) const; 00063 00064 void clear(); 00065 INLINE bool is_any_specified() const; 00066 00067 INLINE static void set_default_font(TextFont *); 00068 INLINE static TextFont *get_default_font(); 00069 00070 INLINE void set_font(TextFont *font); 00071 INLINE void clear_font(); 00072 INLINE bool has_font() const; 00073 INLINE TextFont *get_font() const; 00074 00075 INLINE void set_small_caps(bool small_caps); 00076 INLINE void clear_small_caps(); 00077 INLINE bool has_small_caps() const; 00078 INLINE bool get_small_caps() const; 00079 00080 INLINE void set_small_caps_scale(PN_stdfloat small_caps_scale); 00081 INLINE void clear_small_caps_scale(); 00082 INLINE bool has_small_caps_scale() const; 00083 INLINE PN_stdfloat get_small_caps_scale() const; 00084 00085 INLINE void set_slant(PN_stdfloat slant); 00086 INLINE void clear_slant(); 00087 INLINE bool has_slant() const; 00088 INLINE PN_stdfloat get_slant() const; 00089 00090 INLINE void set_underscore(bool underscore); 00091 INLINE void clear_underscore(); 00092 INLINE bool has_underscore() const; 00093 INLINE bool get_underscore() const; 00094 00095 INLINE void set_underscore_height(PN_stdfloat underscore_height); 00096 INLINE void clear_underscore_height(); 00097 INLINE bool has_underscore_height() const; 00098 INLINE PN_stdfloat get_underscore_height() const; 00099 00100 INLINE void set_align(Alignment align_type); 00101 INLINE void clear_align(); 00102 INLINE bool has_align() const; 00103 INLINE Alignment get_align() const; 00104 00105 INLINE void set_indent(PN_stdfloat indent); 00106 INLINE void clear_indent(); 00107 INLINE bool has_indent() const; 00108 INLINE PN_stdfloat get_indent() const; 00109 00110 INLINE void set_wordwrap(PN_stdfloat wordwrap); 00111 INLINE void clear_wordwrap(); 00112 INLINE bool has_wordwrap() const; 00113 INLINE PN_stdfloat get_wordwrap() const; 00114 00115 INLINE void set_preserve_trailing_whitespace(bool preserve_trailing_whitespace); 00116 INLINE void clear_preserve_trailing_whitespace(); 00117 INLINE bool has_preserve_trailing_whitespace() const; 00118 INLINE bool get_preserve_trailing_whitespace() const; 00119 00120 INLINE void set_text_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a); 00121 INLINE void set_text_color(const LColor &text_color); 00122 INLINE void clear_text_color(); 00123 INLINE bool has_text_color() const; 00124 INLINE LColor get_text_color() const; 00125 00126 INLINE void set_shadow_color(PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a); 00127 INLINE void set_shadow_color(const LColor &shadow_color); 00128 INLINE void clear_shadow_color(); 00129 INLINE bool has_shadow_color() const; 00130 INLINE LColor get_shadow_color() const; 00131 00132 INLINE void set_shadow(PN_stdfloat xoffset, PN_stdfloat yoffset); 00133 INLINE void set_shadow(const LVecBase2 &shadow_offset); 00134 INLINE void clear_shadow(); 00135 INLINE bool has_shadow() const; 00136 INLINE LVector2 get_shadow() const; 00137 00138 INLINE void set_bin(const string &bin); 00139 INLINE void clear_bin(); 00140 INLINE bool has_bin() const; 00141 INLINE const string &get_bin() const; 00142 00143 INLINE int set_draw_order(int draw_order); 00144 INLINE void clear_draw_order(); 00145 INLINE bool has_draw_order() const; 00146 INLINE int get_draw_order() const; 00147 00148 INLINE void set_tab_width(PN_stdfloat tab_width); 00149 INLINE void clear_tab_width(); 00150 INLINE bool has_tab_width() const; 00151 INLINE PN_stdfloat get_tab_width() const; 00152 00153 INLINE void set_glyph_scale(PN_stdfloat glyph_scale); 00154 INLINE void clear_glyph_scale(); 00155 INLINE bool has_glyph_scale() const; 00156 INLINE PN_stdfloat get_glyph_scale() const; 00157 00158 INLINE void set_glyph_shift(PN_stdfloat glyph_shift); 00159 INLINE void clear_glyph_shift(); 00160 INLINE bool has_glyph_shift() const; 00161 INLINE PN_stdfloat get_glyph_shift() const; 00162 00163 INLINE void set_text_scale(PN_stdfloat text_scale); 00164 INLINE void clear_text_scale(); 00165 INLINE bool has_text_scale() const; 00166 INLINE PN_stdfloat get_text_scale() const; 00167 00168 void add_properties(const TextProperties &other); 00169 00170 void write(ostream &out, int indent_level = 0) const; 00171 00172 private: 00173 static void load_default_font(); 00174 00175 enum Flags { 00176 F_has_font = 0x00000001, 00177 F_has_small_caps = 0x00000002, 00178 F_has_small_caps_scale = 0x00000004, 00179 F_has_slant = 0x00000008, 00180 F_has_align = 0x00000010, 00181 F_has_indent = 0x00000020, 00182 F_has_wordwrap = 0x00000040, 00183 F_has_preserve_trailing_whitespace = 0x00000080, 00184 F_has_text_color = 0x00000100, 00185 F_has_shadow_color = 0x00000200, 00186 F_has_shadow = 0x00000400, 00187 F_has_bin = 0x00000800, 00188 F_has_draw_order = 0x00001000, 00189 F_has_tab_width = 0x00002000, 00190 F_has_glyph_scale = 0x00004000, 00191 F_has_glyph_shift = 0x00008000, 00192 F_has_underscore = 0x00010000, 00193 F_has_underscore_height = 0x00020000, 00194 F_has_text_scale = 0x00040000, 00195 }; 00196 00197 int _specified; 00198 00199 PT(TextFont) _font; 00200 bool _small_caps; 00201 PN_stdfloat _small_caps_scale; 00202 PN_stdfloat _slant; 00203 bool _underscore; 00204 PN_stdfloat _underscore_height; 00205 Alignment _align; 00206 PN_stdfloat _indent_width; 00207 PN_stdfloat _wordwrap_width; 00208 bool _preserve_trailing_whitespace; 00209 LColor _text_color; 00210 LColor _shadow_color; 00211 LVector2 _shadow_offset; 00212 string _bin; 00213 int _draw_order; 00214 PN_stdfloat _tab_width; 00215 PN_stdfloat _glyph_scale; 00216 PN_stdfloat _glyph_shift; 00217 PN_stdfloat _text_scale; 00218 00219 static PT(TextFont) _default_font; 00220 static bool _loaded_default_font; 00221 00222 public: 00223 static TypeHandle get_class_type() { 00224 return _type_handle; 00225 } 00226 static void init_type() { 00227 register_type(_type_handle, "TextProperties"); 00228 } 00229 00230 private: 00231 static TypeHandle _type_handle; 00232 }; 00233 00234 #include "textProperties.I" 00235 00236 #endif