Panda3D
Loading...
Searching...
No Matches
pgEntry.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pgEntry.h
10 * @author drose
11 * @date 2002-03-13
12 */
13
14#ifndef PGENTRY_H
15#define PGENTRY_H
16
17#include "pandabase.h"
18
19#include "pgItem.h"
20
21#include "textNode.h"
22#include "pointerTo.h"
23#include "pvector.h"
24#include "clockObject.h"
25#include "textAssembler.h"
26#include "pipeline.h"
27
28/**
29 * This is a particular kind of PGItem that handles simple one-line or short
30 * multi-line text entries, of the sort where the user can type any string.
31 *
32 * A PGEntry does all of its internal manipulation on a wide string, so it can
33 * store the full Unicode character set. The interface can support either the
34 * wide string getters and setters, or the normal 8-bit string getters and
35 * setters, which use whatever encoding method is specified by the associated
36 * TextNode.
37 */
38class EXPCL_PANDA_PGUI PGEntry : public PGItem {
39PUBLISHED:
40 explicit PGEntry(const std::string &name);
41 virtual ~PGEntry();
42
43protected:
44 PGEntry(const PGEntry &copy);
45
46public:
47 virtual PandaNode *make_copy() const;
48 virtual void xform(const LMatrix4 &mat);
49 virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
50
51 virtual void press(const MouseWatcherParameter &param, bool background);
52 virtual void keystroke(const MouseWatcherParameter &param, bool background);
53 virtual void candidate(const MouseWatcherParameter &param, bool background);
54
55 virtual void accept(const MouseWatcherParameter &param);
56 virtual void accept_failed(const MouseWatcherParameter &param);
57 virtual void overflow(const MouseWatcherParameter &param);
58 virtual void type(const MouseWatcherParameter &param);
59 virtual void erase(const MouseWatcherParameter &param);
60 virtual void cursormove();
61
62PUBLISHED:
63 enum State {
64 S_focus = 0,
65 S_no_focus,
66 S_inactive
67 };
68
69 void setup(PN_stdfloat width, int num_lines);
70 void setup_minimal(PN_stdfloat width, int num_lines);
71
72 INLINE bool set_text(const std::string &text);
73 INLINE std::string get_plain_text() const;
74 INLINE std::string get_text() const;
75
76 INLINE int get_num_characters() const;
77 INLINE wchar_t get_character(int n) const;
78 INLINE const TextGraphic *get_graphic(int n) const;
79 INLINE const TextProperties &get_properties(int n) const;
80
81 INLINE void set_cursor_position(int position);
82 INLINE int get_cursor_position() const;
83
84 INLINE PN_stdfloat get_cursor_X() const;
85 INLINE PN_stdfloat get_cursor_Y() const;
86
87 INLINE void set_max_chars(int max_chars);
88 INLINE int get_max_chars() const;
89 INLINE void set_max_width(PN_stdfloat max_width);
90 INLINE PN_stdfloat get_max_width() const;
91 INLINE void set_num_lines(int num_lines);
92 INLINE int get_num_lines() const;
93
94 INLINE void set_blink_rate(PN_stdfloat blink_rate);
95 INLINE PN_stdfloat get_blink_rate() const;
96
97 INLINE NodePath get_cursor_def();
98 INLINE void clear_cursor_def();
99
100 INLINE void set_cursor_keys_active(bool flag);
101 INLINE bool get_cursor_keys_active() const;
102
103 INLINE void set_obscure_mode(bool flag);
104 INLINE bool get_obscure_mode() const;
105
106 INLINE void set_overflow_mode(bool flag);
107 INLINE bool get_overflow_mode() const;
108
109 INLINE void set_candidate_active(const std::string &candidate_active);
110 INLINE const std::string &get_candidate_active() const;
111
112 INLINE void set_candidate_inactive(const std::string &candidate_inactive);
113 INLINE const std::string &get_candidate_inactive() const;
114
115 void set_text_def(int state, TextNode *node);
116 TextNode *get_text_def(int state) const;
117
118 virtual void set_active(bool active);
119 virtual void set_focus(bool focus);
120
121 INLINE static std::string get_accept_prefix();
122 INLINE static std::string get_accept_failed_prefix();
123 INLINE static std::string get_overflow_prefix();
124 INLINE static std::string get_type_prefix();
125 INLINE static std::string get_erase_prefix();
126 INLINE static std::string get_cursormove_prefix();
127
128 INLINE std::string get_accept_event(const ButtonHandle &button) const;
129 INLINE std::string get_accept_failed_event(const ButtonHandle &button) const;
130 INLINE std::string get_overflow_event() const;
131 INLINE std::string get_type_event() const;
132 INLINE std::string get_erase_event() const;
133 INLINE std::string get_cursormove_event() const;
134
135
136 INLINE bool set_wtext(const std::wstring &wtext);
137 INLINE std::wstring get_plain_wtext() const;
138 INLINE std::wstring get_wtext() const;
139 INLINE void set_accept_enabled(bool enabled);
140 bool is_wtext() const;
141
142
143private:
144 void slot_text_def(int state);
145 void update_text();
146 void update_cursor();
147 void show_hide_cursor(bool visible);
148 void update_state();
149
150 TextAssembler _text;
151 TextAssembler _obscure_text;
152 int _cursor_position;
153 bool _cursor_stale;
154 bool _cursor_visible;
155
156 std::wstring _candidate_wtext;
157 size_t _candidate_highlight_start;
158 size_t _candidate_highlight_end;
159 size_t _candidate_cursor_pos;
160
161 int _max_chars;
162 PN_stdfloat _max_width;
163 int _num_lines;
164
165 bool _accept_enabled;
166
167 std::string _candidate_active;
168 std::string _candidate_inactive;
169
170 typedef pvector< PT(TextNode) > TextDefs;
171 TextDefs _text_defs;
172
173 // This is the subgraph that renders both the text and the cursor.
174 NodePath _text_render_root;
175
176 // This is the node for rendering the actual text that is parented to the
177 // above node when the text is generated.
178 NodePath _current_text;
179 TextNode *_last_text_def;
180 bool _text_geom_stale;
181 bool _text_geom_flattened;
182
183 // This is the node that represents the cursor geometry. It is also
184 // attached to the above node, and is transformed around andor hidden
185 // according to the cursor's position and blink state.
186 NodePath _cursor_scale;
187 NodePath _cursor_def;
188
189 double _blink_start;
190 double _blink_rate;
191
192 bool _cursor_keys_active;
193 bool _obscure_mode;
194 bool _overflow_mode;
195
196 PN_stdfloat _current_padding;
197
198public:
199 static TypeHandle get_class_type() {
200 return _type_handle;
201 }
202 static void init_type() {
203 PGItem::init_type();
204 register_type(_type_handle, "PGEntry",
205 PGItem::get_class_type());
206 }
207 virtual TypeHandle get_type() const {
208 return get_class_type();
209 }
210 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
211
212private:
213 static TypeHandle _type_handle;
214};
215
216#include "pgEntry.I"
217
218#endif
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
const std::string & get_candidate_active() const
See set_candidate_active().
Definition pgEntry.I:394
PN_stdfloat get_cursor_X() const
Returns the node position x of the cursor.
Definition pgEntry.I:138
std::string get_plain_text() const
Returns the text currently displayed within the entry, without any embedded properties characters.
Definition pgEntry.I:38
std::string get_overflow_event() const
Returns the event name that will be thrown when too much text is attempted to be entered into the PGE...
Definition pgEntry.I:509
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so.
Definition pgEntry.cxx:151
void set_candidate_active(const std::string &candidate_active)
Specifies the name of the TextProperties structure added to the TextPropertiesManager that will be us...
Definition pgEntry.I:385
void set_cursor_position(int position)
Sets the current position of the cursor.
Definition pgEntry.I:110
virtual void type(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the user extends the text by typing.
Definition pgEntry.cxx:521
std::wstring get_wtext() const
Returns the text currently displayed within the entry.
Definition pgEntry.I:576
const std::string & get_candidate_inactive() const
See set_candidate_inactive().
Definition pgEntry.I:421
const TextProperties & get_properties(int n) const
Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped ...
Definition pgEntry.I:99
TextNode * get_text_def(int state) const
Returns the TextNode that will be used to render the text within the entry when the entry is in the i...
Definition pgEntry.cxx:699
std::string get_type_event() const
Returns the event name that will be thrown whenever the user extends the text by typing.
Definition pgEntry.I:518
NodePath get_cursor_def()
Returns the Node that will be rendered to represent the cursor.
Definition pgEntry.I:269
void set_cursor_keys_active(bool flag)
Sets whether the arrow keys (and home/end) control movement of the cursor.
Definition pgEntry.I:290
void set_max_chars(int max_chars)
Sets the maximum number of characters that may be typed into the entry.
Definition pgEntry.I:160
bool is_wtext() const
Returns true if any of the characters in the string returned by get_wtext() are out of the range of a...
Definition pgEntry.cxx:740
void set_overflow_mode(bool flag)
Specifies whether overflow mode should be enabled.
Definition pgEntry.I:347
std::string get_accept_failed_event(const ButtonHandle &button) const
Returns the event name that will be thrown when the entry cannot accept an input.
Definition pgEntry.I:499
void set_num_lines(int num_lines)
Sets the number of lines of text the PGEntry will use.
Definition pgEntry.I:216
PN_stdfloat get_cursor_Y() const
Returns the node position y of the cursor.
Definition pgEntry.I:147
bool get_cursor_keys_active() const
Returns whether the arrow keys are currently set to control movement of the cursor; see set_cursor_ke...
Definition pgEntry.I:300
void setup_minimal(PN_stdfloat width, int num_lines)
Sets up the entry without creating any frame or other decoration.
Definition pgEntry.cxx:646
int get_num_characters() const
Returns the number of characters of text in the entry.
Definition pgEntry.I:67
virtual void erase(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the user erase characters in the text.
Definition pgEntry.cxx:534
std::string get_cursormove_event() const
Returns the event name that will be thrown whenever the cursor moves.
Definition pgEntry.I:535
virtual void cursormove()
This is a callback hook function, called whenever the cursor moves.
Definition pgEntry.cxx:546
std::string get_text() const
Returns the text currently displayed within the entry.
Definition pgEntry.I:51
static std::string get_cursormove_prefix()
Returns the prefix that is used to define the cursor event for all PGEntries.
Definition pgEntry.I:481
wchar_t get_character(int n) const
Returns the character at the indicated position in the entry.
Definition pgEntry.I:78
void set_max_width(PN_stdfloat max_width)
Sets the maximum width of all characters that may be typed into the entry.
Definition pgEntry.I:187
static std::string get_accept_failed_prefix()
Returns the prefix that is used to define the accept failed event for all PGEntries.
Definition pgEntry.I:442
virtual PandaNode * make_copy() const
Returns a newly-allocated Node that is a shallow copy of this one.
Definition pgEntry.cxx:141
void setup(PN_stdfloat width, int num_lines)
Sets up the entry for normal use.
Definition pgEntry.cxx:559
void set_candidate_inactive(const std::string &candidate_inactive)
Specifies the name of the TextProperties structure added to the TextPropertiesManager that will be us...
Definition pgEntry.I:412
virtual void accept(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the entry is accepted by the user pressing Enter no...
Definition pgEntry.cxx:479
bool set_wtext(const std::wstring &wtext)
Changes the text currently displayed within the entry.
Definition pgEntry.I:546
std::string get_erase_event() const
Returns the event name that will be thrown whenever the user erases characters in the text.
Definition pgEntry.I:527
PN_stdfloat get_max_width() const
Returns the current maximum width of the characters that may be typed into the entry,...
Definition pgEntry.I:205
bool get_overflow_mode() const
Specifies whether overflow mode is enabled.
Definition pgEntry.I:367
static std::string get_accept_prefix()
Returns the prefix that is used to define the accept event for all PGEntries.
Definition pgEntry.I:432
void set_obscure_mode(bool flag)
Specifies whether obscure mode should be enabled.
Definition pgEntry.I:316
static std::string get_overflow_prefix()
Returns the prefix that is used to define the overflow event for all PGEntries.
Definition pgEntry.I:452
int get_num_lines() const
Returns the number of lines of text the PGEntry will use, if _max_width is not 0.
Definition pgEntry.I:237
void set_blink_rate(PN_stdfloat blink_rate)
Sets the number of times per second the cursor will blink while the entry has keyboard focus.
Definition pgEntry.I:249
bool set_text(const std::string &text)
Changes the text currently displayed within the entry.
Definition pgEntry.I:23
int get_cursor_position() const
Returns the current position of the cursor.
Definition pgEntry.I:129
void set_text_def(int state, TextNode *node)
Changes the TextNode that will be used to render the text within the entry when the entry is in the i...
Definition pgEntry.cxx:682
virtual void overflow(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the entry is overflowed because the user attempts t...
Definition pgEntry.cxx:508
PN_stdfloat get_blink_rate() const
Returns the number of times per second the cursor will blink, or 0 if the cursor is not to blink.
Definition pgEntry.I:259
static std::string get_type_prefix()
Returns the prefix that is used to define the type event for all PGEntries.
Definition pgEntry.I:461
std::string get_accept_event(const ButtonHandle &button) const
Returns the event name that will be thrown when the entry is accepted normally.
Definition pgEntry.I:490
const TextGraphic * get_graphic(int n) const
Returns the graphic object at the indicated position in the pre-wordwrapped string.
Definition pgEntry.I:89
bool get_obscure_mode() const
Specifies whether obscure mode is enabled.
Definition pgEntry.I:335
static std::string get_erase_prefix()
Returns the prefix that is used to define the erase event for all PGEntries.
Definition pgEntry.I:471
int get_max_chars() const
Returns the current maximum number of characters that may be typed into the entry,...
Definition pgEntry.I:170
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition pgEntry.cxx:176
void clear_cursor_def()
Removes all the children from the cursor_def node, in preparation for adding a new definition.
Definition pgEntry.I:279
std::wstring get_plain_wtext() const
Returns the text currently displayed within the entry, without any embedded properties characters.
Definition pgEntry.I:567
void set_accept_enabled(bool enabled)
Sets whether the input may be accepted–use to disable submission by the user.
Definition pgEntry.I:586
virtual void accept_failed(const MouseWatcherParameter &param)
This is a callback hook function, called whenever the user presses Enter but we can't accept the inpu...
Definition pgEntry.cxx:493
virtual void press(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever a mouse or keyboard button is depressed while the m...
Definition pgItem.cxx:674
virtual void keystroke(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever the user presses a key.
Definition pgItem.cxx:726
virtual void set_focus(bool focus)
Sets whether the PGItem currently has keyboard focus.
Definition pgItem.cxx:874
virtual void candidate(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever the user highlights an option in the IME window.
Definition pgItem.cxx:750
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition pgItem.cxx:851
This class is not normally used directly by user code, but is used by the TextNode to lay out a block...
This defines a special model that has been constructed for the purposes of embedding an arbitrary gra...
Definition textGraphic.h:37
The primary interface to this module.
Definition textNode.h:48
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:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.