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