forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpgEntry.h
More file actions
222 lines (175 loc) · 6.61 KB
/
pgEntry.h
File metadata and controls
222 lines (175 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
// Filename: pgEntry.h
// Created by: drose (13Mar02)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) Carnegie Mellon University. All rights reserved.
//
// All use of this software is subject to the terms of the revised BSD
// license. You should have received a copy of this license along
// with this source code in a file named "LICENSE."
//
////////////////////////////////////////////////////////////////////
#ifndef PGENTRY_H
#define PGENTRY_H
#include "pandabase.h"
#include "pgItem.h"
#include "textNode.h"
#include "pointerTo.h"
#include "pvector.h"
#include "clockObject.h"
#include "textAssembler.h"
////////////////////////////////////////////////////////////////////
// Class : PGEntry
// Description : This is a particular kind of PGItem that handles
// simple one-line or short multi-line text entries, of
// the sort where the user can type any string.
//
// A PGEntry does all of its internal manipulation on a
// wide string, so it can store the full Unicode
// character set. The interface can support either the
// wide string getters and setters, or the normal 8-bit
// string getters and setters, which use whatever
// encoding method is specified by the associated
// TextNode.
////////////////////////////////////////////////////////////////////
class EXPCL_PANDA_PGUI PGEntry : public PGItem {
PUBLISHED:
PGEntry(const string &name);
virtual ~PGEntry();
protected:
PGEntry(const PGEntry ©);
public:
virtual PandaNode *make_copy() const;
virtual void xform(const LMatrix4 &mat);
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
virtual void press(const MouseWatcherParameter ¶m, bool background);
virtual void keystroke(const MouseWatcherParameter ¶m, bool background);
virtual void candidate(const MouseWatcherParameter ¶m, bool background);
virtual void accept(const MouseWatcherParameter ¶m);
virtual void accept_failed(const MouseWatcherParameter ¶m);
virtual void overflow(const MouseWatcherParameter ¶m);
virtual void type(const MouseWatcherParameter ¶m);
virtual void erase(const MouseWatcherParameter ¶m);
virtual void cursormove();
PUBLISHED:
enum State {
S_focus = 0,
S_no_focus,
S_inactive
};
void setup(PN_stdfloat width, int num_lines);
void setup_minimal(PN_stdfloat width, int num_lines);
INLINE bool set_text(const string &text);
INLINE string get_plain_text() const;
INLINE string get_text() const;
INLINE int get_num_characters() const;
INLINE wchar_t get_character(int n) const;
INLINE const TextGraphic *get_graphic(int n) const;
INLINE const TextProperties &get_properties(int n) const;
INLINE void set_cursor_position(int position);
INLINE int get_cursor_position() const;
INLINE PN_stdfloat get_cursor_X() const;
INLINE PN_stdfloat get_cursor_Y() const;
INLINE void set_max_chars(int max_chars);
INLINE int get_max_chars() const;
INLINE void set_max_width(PN_stdfloat max_width);
INLINE PN_stdfloat get_max_width() const;
INLINE void set_num_lines(int num_lines);
INLINE int get_num_lines() const;
INLINE void set_blink_rate(PN_stdfloat blink_rate);
INLINE PN_stdfloat get_blink_rate() const;
INLINE NodePath get_cursor_def();
INLINE void clear_cursor_def();
INLINE void set_cursor_keys_active(bool flag);
INLINE bool get_cursor_keys_active() const;
INLINE void set_obscure_mode(bool flag);
INLINE bool get_obscure_mode() const;
INLINE void set_overflow_mode(bool flag);
INLINE bool get_overflow_mode() const;
INLINE void set_candidate_active(const string &candidate_active);
INLINE const string &get_candidate_active() const;
INLINE void set_candidate_inactive(const string &candidate_inactive);
INLINE const string &get_candidate_inactive() const;
void set_text_def(int state, TextNode *node);
TextNode *get_text_def(int state) const;
virtual void set_active(bool active);
virtual void set_focus(bool focus);
INLINE static string get_accept_prefix();
INLINE static string get_accept_failed_prefix();
INLINE static string get_overflow_prefix();
INLINE static string get_type_prefix();
INLINE static string get_erase_prefix();
INLINE static string get_cursormove_prefix();
INLINE string get_accept_event(const ButtonHandle &button) const;
INLINE string get_accept_failed_event(const ButtonHandle &button) const;
INLINE string get_overflow_event() const;
INLINE string get_type_event() const;
INLINE string get_erase_event() const;
INLINE string get_cursormove_event() const;
INLINE bool set_wtext(const wstring &wtext);
INLINE wstring get_plain_wtext() const;
INLINE wstring get_wtext() const;
INLINE void set_accept_enabled(bool enabled);
bool is_wtext() const;
private:
void slot_text_def(int state);
void update_text();
void update_cursor();
void show_hide_cursor(bool visible);
void update_state();
TextAssembler _text;
TextAssembler _obscure_text;
int _cursor_position;
bool _cursor_stale;
bool _cursor_visible;
wstring _candidate_wtext;
size_t _candidate_highlight_start;
size_t _candidate_highlight_end;
size_t _candidate_cursor_pos;
int _max_chars;
PN_stdfloat _max_width;
int _num_lines;
bool _accept_enabled;
string _candidate_active;
string _candidate_inactive;
typedef pvector< PT(TextNode) > TextDefs;
TextDefs _text_defs;
// This is the subgraph that renders both the text and the cursor.
NodePath _text_render_root;
// This is the node for rendering the actual text that is parented
// to the above node when the text is generated.
NodePath _current_text;
TextNode *_last_text_def;
bool _text_geom_stale;
bool _text_geom_flattened;
// This is the node that represents the cursor geometry. It is also
// attached to the above node, and is transformed around and/or
// hidden according to the cursor's position and blink state.
NodePath _cursor_scale;
NodePath _cursor_def;
double _blink_start;
double _blink_rate;
bool _cursor_keys_active;
bool _obscure_mode;
bool _overflow_mode;
PN_stdfloat _current_padding;
public:
static TypeHandle get_class_type() {
return _type_handle;
}
static void init_type() {
PGItem::init_type();
register_type(_type_handle, "PGEntry",
PGItem::get_class_type());
}
virtual TypeHandle get_type() const {
return get_class_type();
}
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
private:
static TypeHandle _type_handle;
};
#include "pgEntry.I"
#endif