00001 // Filename: pgEntry.I 00002 // Created by: drose (13Mar02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: PGEntry::set_text 00022 // Access: Published 00023 // Description: Changes the text currently displayed within the 00024 // entry. This uses the Unicode encoding currently 00025 // specified for the "focus" TextNode; therefore, the 00026 // TextNode must exist before calling set_text(). 00027 //////////////////////////////////////////////////////////////////// 00028 INLINE void PGEntry:: 00029 set_text(const string &text) { 00030 TextNode *text_node = get_text_def(S_focus); 00031 nassertv(text_node != (TextNode *)NULL); 00032 set_wtext(text_node->decode_text(text)); 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: PGEntry::get_text 00037 // Access: Published 00038 // Description: Returns the text currently displayed within the 00039 // entry. This uses the Unicode encoding currently 00040 // specified for the "focus" TextNode; therefore, the 00041 // TextNode must exist before calling get_text(). 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE string PGEntry:: 00044 get_text() const { 00045 TextNode *text_node = get_text_def(S_focus); 00046 nassertr(text_node != (TextNode *)NULL, string()); 00047 return text_node->encode_wtext(get_wtext()); 00048 } 00049 00050 //////////////////////////////////////////////////////////////////// 00051 // Function: PGEntry::set_cursor_position 00052 // Access: Published 00053 // Description: Sets the current position of the cursor. This is the 00054 // position within the text at which the next letter 00055 // typed by the user will be inserted; normally it is 00056 // the same as the length of the text. 00057 //////////////////////////////////////////////////////////////////// 00058 INLINE void PGEntry:: 00059 set_cursor_position(int position) { 00060 if (_cursor_position != position) { 00061 _cursor_position = position; 00062 _cursor_stale = true; 00063 _blink_start = ClockObject::get_global_clock()->get_frame_time(); 00064 } 00065 } 00066 00067 //////////////////////////////////////////////////////////////////// 00068 // Function: PGEntry::get_cursor_position 00069 // Access: Published 00070 // Description: Returns the current position of the cursor. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE int PGEntry:: 00073 get_cursor_position() const { 00074 return _cursor_position; 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: PGEntry::set_max_chars 00079 // Access: Published 00080 // Description: Sets the maximum number of characters that may be 00081 // typed into the entry. This is a limit on the number 00082 // of characters, as opposed to the width of the entry; 00083 // see also set_max_width(). 00084 // 00085 // If this is 0, there is no limit. 00086 //////////////////////////////////////////////////////////////////// 00087 INLINE void PGEntry:: 00088 set_max_chars(int max_chars) { 00089 _max_chars = max_chars; 00090 } 00091 00092 //////////////////////////////////////////////////////////////////// 00093 // Function: PGEntry::get_max_chars 00094 // Access: Published 00095 // Description: Returns the current maximum number of characters that 00096 // may be typed into the entry, or 0 if there is no 00097 // limit. See set_max_chars(). 00098 //////////////////////////////////////////////////////////////////// 00099 INLINE int PGEntry:: 00100 get_max_chars() const { 00101 return _max_chars; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: PGEntry::set_max_width 00106 // Access: Published 00107 // Description: Sets the maximum width of all characters that may be 00108 // typed into the entry. This is a limit on the width 00109 // of the formatted text, not a fixed limit on the 00110 // number of characters; also set_max_chars(). 00111 // 00112 // If this is 0, there is no limit. 00113 // 00114 // If _num_lines is more than 1, rather than being a 00115 // fixed width on the whole entry, this becomes instead 00116 // the wordwrap width (and the width limit on the entry 00117 // is essentially _max_width * _num_lines). 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE void PGEntry:: 00120 set_max_width(float max_width) { 00121 _max_width = max_width; 00122 _text_geom_stale = true; 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: PGEntry::get_max_width 00127 // Access: Published 00128 // Description: Returns the current maximum width of the characters 00129 // that may be typed into the entry, or 0 if there is no 00130 // limit. See set_max_width(). 00131 //////////////////////////////////////////////////////////////////// 00132 INLINE float PGEntry:: 00133 get_max_width() const { 00134 return _max_width; 00135 } 00136 00137 //////////////////////////////////////////////////////////////////// 00138 // Function: PGEntry::set_num_lines 00139 // Access: Published 00140 // Description: Sets the number of lines of text the PGEntry will 00141 // use. This only has meaning if _max_width is not 0; 00142 // _max_width indicates the wordwrap width of each line. 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE void PGEntry:: 00145 set_num_lines(int num_lines) { 00146 nassertv(num_lines >= 1); 00147 _num_lines = num_lines; 00148 _text_geom_stale = true; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: PGEntry::get_num_lines 00153 // Access: Published 00154 // Description: Returns the number of lines of text the PGEntry will 00155 // use, if _max_width is not 0. See set_num_lines(). 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE int PGEntry:: 00158 get_num_lines() const { 00159 return _num_lines; 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: PGEntry::set_blink_rate 00164 // Access: Published 00165 // Description: Sets the number of times per second the cursor will 00166 // blink while the entry has keyboard focus. 00167 // 00168 // If this is 0, the cursor does not blink, but is held 00169 // steady. 00170 //////////////////////////////////////////////////////////////////// 00171 INLINE void PGEntry:: 00172 set_blink_rate(float blink_rate) { 00173 _blink_rate = blink_rate; 00174 } 00175 00176 //////////////////////////////////////////////////////////////////// 00177 // Function: PGEntry::get_blink_rate 00178 // Access: Published 00179 // Description: Returns the number of times per second the cursor 00180 // will blink, or 0 if the cursor is not to blink. 00181 //////////////////////////////////////////////////////////////////// 00182 INLINE float PGEntry:: 00183 get_blink_rate() const { 00184 return _blink_rate; 00185 } 00186 00187 //////////////////////////////////////////////////////////////////// 00188 // Function: PGEntry::get_cursor_def 00189 // Access: Published 00190 // Description: Returns the Node that will be rendered to represent 00191 // the cursor. You can attach suitable cursor geometry 00192 // to this node. 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE const NodePath &PGEntry:: 00195 get_cursor_def() { 00196 return _cursor_def; 00197 } 00198 00199 //////////////////////////////////////////////////////////////////// 00200 // Function: PGEntry::clear_cursor_def 00201 // Access: Published 00202 // Description: Removes all the children from the cursor_def node, in 00203 // preparation for adding a new definition. 00204 //////////////////////////////////////////////////////////////////// 00205 INLINE void PGEntry:: 00206 clear_cursor_def() { 00207 _cursor_def.remove_node(); 00208 _cursor_def = _text_render_root.attach_new_node("cursor"); 00209 } 00210 00211 //////////////////////////////////////////////////////////////////// 00212 // Function: PGEntry::set_cursor_keys_active 00213 // Access: Published 00214 // Description: Sets whether the arrow keys (and home/end) control 00215 // movement of the cursor. If true, they are active; if 00216 // false, they are ignored. 00217 //////////////////////////////////////////////////////////////////// 00218 INLINE void PGEntry:: 00219 set_cursor_keys_active(bool flag) { 00220 _cursor_keys_active = flag; 00221 } 00222 00223 //////////////////////////////////////////////////////////////////// 00224 // Function: PGEntry::get_cursor_keys_active 00225 // Access: Published 00226 // Description: Returns whether the arrow keys are currently set to 00227 // control movement of the cursor; see 00228 // set_cursor_keys_active(). 00229 //////////////////////////////////////////////////////////////////// 00230 INLINE bool PGEntry:: 00231 get_cursor_keys_active() const { 00232 return _cursor_keys_active; 00233 } 00234 00235 //////////////////////////////////////////////////////////////////// 00236 // Function: PGEntry::set_obscure_mode 00237 // Access: Published 00238 // Description: Specifies whether obscure mode should be enabled. In 00239 // obscure mode, a string of asterisks is displayed 00240 // instead of the literal text, e.g. for entering 00241 // passwords. 00242 // 00243 // In obscure mode, the width of the text is computed 00244 // based on the width of the string of asterisks, not on 00245 // the width of the actual text. This has implications 00246 // on the maximum length of text that may be entered if 00247 // max_width is in effect. 00248 //////////////////////////////////////////////////////////////////// 00249 INLINE void PGEntry:: 00250 set_obscure_mode(bool flag) { 00251 if (_obscure_mode != flag) { 00252 _obscure_mode = flag; 00253 _text_geom_stale = true; 00254 } 00255 } 00256 00257 //////////////////////////////////////////////////////////////////// 00258 // Function: PGEntry::get_obscure_mode 00259 // Access: Published 00260 // Description: Specifies whether obscure mode is enabled. See 00261 // set_obscure_mode(). 00262 //////////////////////////////////////////////////////////////////// 00263 INLINE bool PGEntry:: 00264 get_obscure_mode() const { 00265 return _obscure_mode; 00266 } 00267 00268 //////////////////////////////////////////////////////////////////// 00269 // Function: PGEntry::get_accept_prefix 00270 // Access: Published, Static 00271 // Description: Returns the prefix that is used to define the accept 00272 // event for all PGEntries. The accept event is the 00273 // concatenation of this string followed by get_id(). 00274 //////////////////////////////////////////////////////////////////// 00275 INLINE string PGEntry:: 00276 get_accept_prefix() { 00277 return "accept-"; 00278 } 00279 00280 //////////////////////////////////////////////////////////////////// 00281 // Function: PGEntry::get_overflow_prefix 00282 // Access: Published, Static 00283 // Description: Returns the prefix that is used to define the overflow 00284 // event for all PGEntries. The overflow event is the 00285 // concatenation of this string followed by get_id(). 00286 //////////////////////////////////////////////////////////////////// 00287 INLINE string PGEntry:: 00288 get_overflow_prefix() { 00289 return "overflow-"; 00290 } 00291 00292 //////////////////////////////////////////////////////////////////// 00293 // Function: PGEntry::get_type_prefix 00294 // Access: Published, Static 00295 // Description: Returns the prefix that is used to define the type 00296 // event for all PGEntries. The type event is the 00297 // concatenation of this string followed by get_id(). 00298 //////////////////////////////////////////////////////////////////// 00299 INLINE string PGEntry:: 00300 get_type_prefix() { 00301 return "type-"; 00302 } 00303 00304 //////////////////////////////////////////////////////////////////// 00305 // Function: PGEntry::get_erase_prefix 00306 // Access: Published, Static 00307 // Description: Returns the prefix that is used to define the erase 00308 // event for all PGEntries. The erase event is the 00309 // concatenation of this string followed by get_id(). 00310 //////////////////////////////////////////////////////////////////// 00311 INLINE string PGEntry:: 00312 get_erase_prefix() { 00313 return "erase-"; 00314 } 00315 00316 //////////////////////////////////////////////////////////////////// 00317 // Function: PGEntry::get_accept_event 00318 // Access: Published 00319 // Description: Returns the event name that will be thrown when the 00320 // entry is accepted normally. 00321 //////////////////////////////////////////////////////////////////// 00322 INLINE string PGEntry:: 00323 get_accept_event(const ButtonHandle &button) const { 00324 return "accept-" + button.get_name() + "-" + get_id(); 00325 } 00326 00327 //////////////////////////////////////////////////////////////////// 00328 // Function: PGEntry::get_overflow_event 00329 // Access: Published 00330 // Description: Returns the event name that will be thrown when too 00331 // much text is attempted to be entered into the 00332 // PGEntry, exceeding either the limit set via 00333 // set_max_chars() or via set_max_width(). 00334 //////////////////////////////////////////////////////////////////// 00335 INLINE string PGEntry:: 00336 get_overflow_event() const { 00337 return "overflow-" + get_id(); 00338 } 00339 00340 //////////////////////////////////////////////////////////////////// 00341 // Function: PGEntry::get_type_event 00342 // Access: Published 00343 // Description: Returns the event name that will be thrown whenever 00344 // the user extends the text by typing. 00345 //////////////////////////////////////////////////////////////////// 00346 INLINE string PGEntry:: 00347 get_type_event() const { 00348 return "type-" + get_id(); 00349 } 00350 00351 //////////////////////////////////////////////////////////////////// 00352 // Function: PGEntry::get_erase_event 00353 // Access: Published 00354 // Description: Returns the event name that will be thrown whenever 00355 // the user erases characters in the text. 00356 //////////////////////////////////////////////////////////////////// 00357 INLINE string PGEntry:: 00358 get_erase_event() const { 00359 return "erase-" + get_id(); 00360 } 00361 00362 //////////////////////////////////////////////////////////////////// 00363 // Function: PGEntry::set_wtext 00364 // Access: Public 00365 // Description: Changes the text currently displayed within the 00366 // entry. 00367 //////////////////////////////////////////////////////////////////// 00368 INLINE void PGEntry:: 00369 set_wtext(const wstring &wtext) { 00370 _wtext = wtext; 00371 _text_geom_stale = true; 00372 _cursor_stale = true; 00373 _blink_start = ClockObject::get_global_clock()->get_frame_time(); 00374 } 00375 00376 //////////////////////////////////////////////////////////////////// 00377 // Function: PGEntry::get_wtext 00378 // Access: Public 00379 // Description: Returns the text currently displayed within the 00380 // entry. 00381 //////////////////////////////////////////////////////////////////// 00382 INLINE const wstring &PGEntry:: 00383 get_wtext() const { 00384 return _wtext; 00385 }