Panda3D
 All Classes Functions Variables Enumerations
pgEntry.h
1 // Filename: pgEntry.h
2 // Created by: drose (13Mar02)
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 PGENTRY_H
16 #define PGENTRY_H
17 
18 #include "pandabase.h"
19 
20 #include "pgItem.h"
21 
22 #include "textNode.h"
23 #include "pointerTo.h"
24 #include "pvector.h"
25 #include "clockObject.h"
26 #include "textAssembler.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : PGEntry
30 // Description : This is a particular kind of PGItem that handles
31 // simple one-line or short multi-line text entries, of
32 // the sort where the user can type any string.
33 //
34 // A PGEntry does all of its internal manipulation on a
35 // wide string, so it can store the full Unicode
36 // character set. The interface can support either the
37 // wide string getters and setters, or the normal 8-bit
38 // string getters and setters, which use whatever
39 // encoding method is specified by the associated
40 // TextNode.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_PANDA_PGUI PGEntry : public PGItem {
43 PUBLISHED:
44  PGEntry(const string &name);
45  virtual ~PGEntry();
46 
47 protected:
48  PGEntry(const PGEntry &copy);
49 
50 public:
51  virtual PandaNode *make_copy() const;
52  virtual void xform(const LMatrix4 &mat);
53  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
54 
55  virtual void press(const MouseWatcherParameter &param, bool background);
56  virtual void keystroke(const MouseWatcherParameter &param, bool background);
57  virtual void candidate(const MouseWatcherParameter &param, bool background);
58 
59  virtual void accept(const MouseWatcherParameter &param);
60  virtual void accept_failed(const MouseWatcherParameter &param);
61  virtual void overflow(const MouseWatcherParameter &param);
62  virtual void type(const MouseWatcherParameter &param);
63  virtual void erase(const MouseWatcherParameter &param);
64  virtual void cursormove();
65 
66 PUBLISHED:
67  enum State {
68  S_focus = 0,
69  S_no_focus,
70  S_inactive
71  };
72 
73  void setup(PN_stdfloat width, int num_lines);
74  void setup_minimal(PN_stdfloat width, int num_lines);
75 
76  INLINE bool set_text(const string &text);
77  INLINE string get_plain_text() const;
78  INLINE string get_text() const;
79 
80  INLINE int get_num_characters() const;
81  INLINE wchar_t get_character(int n) const;
82  INLINE const TextGraphic *get_graphic(int n) const;
83  INLINE const TextProperties &get_properties(int n) const;
84 
85  INLINE void set_cursor_position(int position);
86  INLINE int get_cursor_position() const;
87 
88  INLINE PN_stdfloat get_cursor_X() const;
89  INLINE PN_stdfloat get_cursor_Y() const;
90 
91  INLINE void set_max_chars(int max_chars);
92  INLINE int get_max_chars() const;
93  INLINE void set_max_width(PN_stdfloat max_width);
94  INLINE PN_stdfloat get_max_width() const;
95  INLINE void set_num_lines(int num_lines);
96  INLINE int get_num_lines() const;
97 
98  INLINE void set_blink_rate(PN_stdfloat blink_rate);
99  INLINE PN_stdfloat get_blink_rate() const;
100 
101  INLINE NodePath get_cursor_def();
102  INLINE void clear_cursor_def();
103 
104  INLINE void set_cursor_keys_active(bool flag);
105  INLINE bool get_cursor_keys_active() const;
106 
107  INLINE void set_obscure_mode(bool flag);
108  INLINE bool get_obscure_mode() const;
109 
110  INLINE void set_overflow_mode(bool flag);
111  INLINE bool get_overflow_mode() const;
112 
113  INLINE void set_candidate_active(const string &candidate_active);
114  INLINE const string &get_candidate_active() const;
115 
116  INLINE void set_candidate_inactive(const string &candidate_inactive);
117  INLINE const string &get_candidate_inactive() const;
118 
119  void set_text_def(int state, TextNode *node);
120  TextNode *get_text_def(int state) const;
121 
122  virtual void set_active(bool active);
123  virtual void set_focus(bool focus);
124 
125  INLINE static string get_accept_prefix();
126  INLINE static string get_accept_failed_prefix();
127  INLINE static string get_overflow_prefix();
128  INLINE static string get_type_prefix();
129  INLINE static string get_erase_prefix();
130  INLINE static string get_cursormove_prefix();
131 
132  INLINE string get_accept_event(const ButtonHandle &button) const;
133  INLINE string get_accept_failed_event(const ButtonHandle &button) const;
134  INLINE string get_overflow_event() const;
135  INLINE string get_type_event() const;
136  INLINE string get_erase_event() const;
137  INLINE string get_cursormove_event() const;
138 
139 
140  INLINE bool set_wtext(const wstring &wtext);
141  INLINE wstring get_plain_wtext() const;
142  INLINE wstring get_wtext() const;
143  INLINE void set_accept_enabled(bool enabled);
144  bool is_wtext() const;
145 
146 
147 private:
148  void slot_text_def(int state);
149  void update_text();
150  void update_cursor();
151  void show_hide_cursor(bool visible);
152  void update_state();
153 
154  TextAssembler _text;
155  TextAssembler _obscure_text;
156  int _cursor_position;
157  bool _cursor_stale;
158  bool _cursor_visible;
159 
160  wstring _candidate_wtext;
161  size_t _candidate_highlight_start;
162  size_t _candidate_highlight_end;
163  size_t _candidate_cursor_pos;
164 
165  int _max_chars;
166  PN_stdfloat _max_width;
167  int _num_lines;
168 
169  bool _accept_enabled;
170 
171  string _candidate_active;
172  string _candidate_inactive;
173 
175  TextDefs _text_defs;
176 
177  // This is the subgraph that renders both the text and the cursor.
178  NodePath _text_render_root;
179 
180  // This is the node for rendering the actual text that is parented
181  // to the above node when the text is generated.
182  NodePath _current_text;
183  TextNode *_last_text_def;
184  bool _text_geom_stale;
185  bool _text_geom_flattened;
186 
187  // This is the node that represents the cursor geometry. It is also
188  // attached to the above node, and is transformed around and/or
189  // hidden according to the cursor's position and blink state.
190  NodePath _cursor_scale;
191  NodePath _cursor_def;
192 
193  double _blink_start;
194  double _blink_rate;
195 
196  bool _cursor_keys_active;
197  bool _obscure_mode;
198  bool _overflow_mode;
199 
200  PN_stdfloat _current_padding;
201 
202 public:
203  static TypeHandle get_class_type() {
204  return _type_handle;
205  }
206  static void init_type() {
207  PGItem::init_type();
208  register_type(_type_handle, "PGEntry",
209  PGItem::get_class_type());
210  }
211  virtual TypeHandle get_type() const {
212  return get_class_type();
213  }
214  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
215 
216 private:
217  static TypeHandle _type_handle;
218 };
219 
220 #include "pgEntry.I"
221 
222 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
virtual void xform(const LMatrix4 &mat)
Transforms the contents of this node by the indicated matrix, if it means anything to do so...
Definition: pgItem.cxx:386
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:58
This is a particular kind of PGItem that handles simple one-line or short multi-line text entries...
Definition: pgEntry.h:42
This collects together the pieces of data that are accumulated for each node while walking the scene ...
A ButtonHandle represents a single button from any device, including keyboard buttons and mouse butto...
Definition: buttonHandle.h:28
virtual void set_focus(bool focus)
Sets whether the PGItem currently has keyboard focus.
Definition: pgItem.cxx:917
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This class is not normally used directly by user code, but is used by the TextNode to lay out a block...
Definition: textAssembler.h:46
The primary interface to this module.
Definition: textNode.h:52
This defines the set of visual properties that may be assigned to the individual characters of the te...
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:778
virtual void keystroke(const MouseWatcherParameter &param, bool background)
This is a callback hook function, called whenever the user presses a key.
Definition: pgItem.cxx:752
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is sent along as a parameter to most events generated for a region to indicate the mouse and but...
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
This defines a special model that has been constructed for the purposes of embedding an arbitrary gra...
Definition: textGraphic.h:43
virtual void set_active(bool active)
Sets whether the PGItem is active for mouse watching.
Definition: pgItem.cxx:890
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:694