Panda3D
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  */
38 class EXPCL_PANDA_PGUI PGEntry : public PGItem {
39 PUBLISHED:
40  explicit PGEntry(const std::string &name);
41  virtual ~PGEntry();
42 
43 protected:
44  PGEntry(const PGEntry &copy);
45 
46 public:
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 
62 PUBLISHED:
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 
143 private:
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 
198 public:
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 
212 private:
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...
Definition: buttonHandle.h:26
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling,...
Definition: cullTraverser.h:45
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:159
This is a particular kind of PGItem that handles simple one-line or short multi-line text entries,...
Definition: pgEntry.h:38
This is the base class for all the various kinds of gui widget objects.
Definition: pgItem.h:53
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:860
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:837
A basic node of the scene graph or data graph.
Definition: pandaNode.h:65
This class is not normally used directly by user code, but is used by the TextNode to lay out a block...
Definition: textAssembler.h:43
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
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
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(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.