mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
pgui refinements
This commit is contained in:
parent
51ef307c21
commit
b247c9d913
@ -58,6 +58,7 @@ PGEntry(const string &name) :
|
|||||||
_accept_enabled = true;
|
_accept_enabled = true;
|
||||||
_last_text_def = (TextNode *)NULL;
|
_last_text_def = (TextNode *)NULL;
|
||||||
_text_geom_stale = true;
|
_text_geom_stale = true;
|
||||||
|
_text_geom_flattened = true;
|
||||||
_blink_start = 0.0f;
|
_blink_start = 0.0f;
|
||||||
_blink_rate = 1.0f;
|
_blink_rate = 1.0f;
|
||||||
|
|
||||||
@ -110,6 +111,7 @@ PGEntry(const PGEntry ©) :
|
|||||||
_cursor_stale = true;
|
_cursor_stale = true;
|
||||||
_last_text_def = (TextNode *)NULL;
|
_last_text_def = (TextNode *)NULL;
|
||||||
_text_geom_stale = true;
|
_text_geom_stale = true;
|
||||||
|
_text_geom_flattened = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -684,17 +686,26 @@ update_text() {
|
|||||||
TextProperties inactive = tp_mgr->get_properties(_candidate_inactive);
|
TextProperties inactive = tp_mgr->get_properties(_candidate_inactive);
|
||||||
TextProperties active = tp_mgr->get_properties(_candidate_active);
|
TextProperties active = tp_mgr->get_properties(_candidate_active);
|
||||||
|
|
||||||
// Create a special TextAssembler to insert the candidate string
|
// Insert the complex sequence of characters required to show
|
||||||
// in its own special colors.
|
// the candidate string in a different color. This gets
|
||||||
|
// inserted at the current cursor position.
|
||||||
|
wstring cseq;
|
||||||
|
cseq += wstring(1, (wchar_t)text_push_properties_key);
|
||||||
|
cseq += node->decode_text(_candidate_inactive);
|
||||||
|
cseq += wstring(1, (wchar_t)text_push_properties_key);
|
||||||
|
cseq += _candidate_wtext.substr(0, _candidate_highlight_start);
|
||||||
|
cseq += wstring(1, (wchar_t)text_push_properties_key);
|
||||||
|
cseq += node->decode_text(_candidate_active);
|
||||||
|
cseq += wstring(1, (wchar_t)text_push_properties_key);
|
||||||
|
cseq += _candidate_wtext.substr(_candidate_highlight_start,
|
||||||
|
_candidate_highlight_end - _candidate_highlight_start);
|
||||||
|
cseq += wstring(1, (wchar_t)text_pop_properties_key);
|
||||||
|
cseq += _candidate_wtext.substr(_candidate_highlight_end);
|
||||||
|
cseq += wstring(1, (wchar_t)text_pop_properties_key);
|
||||||
|
|
||||||
|
// Create a special TextAssembler to insert the candidate string.
|
||||||
TextAssembler ctext(_text);
|
TextAssembler ctext(_text);
|
||||||
ctext.set_wsubstr(_candidate_wtext.substr(_candidate_highlight_end),
|
ctext.set_wsubstr(cseq, _cursor_position, 0);
|
||||||
_cursor_position, 0, inactive);
|
|
||||||
ctext.set_wsubstr(_candidate_wtext.substr(_candidate_highlight_start,
|
|
||||||
_candidate_highlight_end - _candidate_highlight_start),
|
|
||||||
_cursor_position, 0, active);
|
|
||||||
ctext.set_wsubstr(_candidate_wtext.substr(0, _candidate_highlight_start),
|
|
||||||
_cursor_position, 0, inactive);
|
|
||||||
assembled = ctext.assemble_text();
|
assembled = ctext.assemble_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -705,8 +716,16 @@ update_text() {
|
|||||||
_current_text =
|
_current_text =
|
||||||
_text_render_root.attach_new_node(assembled);
|
_text_render_root.attach_new_node(assembled);
|
||||||
_text_geom_stale = false;
|
_text_geom_stale = false;
|
||||||
|
_text_geom_flattened = false;
|
||||||
_cursor_stale = true;
|
_cursor_stale = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We'll flatten the text geometry only if we don't have focus.
|
||||||
|
// Otherwise, we assume the user may be changing it frequently.
|
||||||
|
if (!get_focus() && !_text_geom_flattened) {
|
||||||
|
_current_text.flatten_strong();
|
||||||
|
_text_geom_flattened = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
@ -172,6 +172,7 @@ private:
|
|||||||
NodePath _current_text;
|
NodePath _current_text;
|
||||||
TextNode *_last_text_def;
|
TextNode *_last_text_def;
|
||||||
bool _text_geom_stale;
|
bool _text_geom_stale;
|
||||||
|
bool _text_geom_flattened;
|
||||||
|
|
||||||
// This is the node that represents the cursor geometry. It is also
|
// This is the node that represents the cursor geometry. It is also
|
||||||
// attached to the above node, and is transformed around and/or
|
// attached to the above node, and is transformed around and/or
|
||||||
|
@ -193,38 +193,27 @@ set_wtext(const wstring &wtext) {
|
|||||||
//
|
//
|
||||||
// The substring may include nested formatting
|
// The substring may include nested formatting
|
||||||
// characters, but they must be self-contained and
|
// characters, but they must be self-contained and
|
||||||
// self-closed. The indicated TextProperties specifies
|
// self-closed. The formatting characters are not
|
||||||
// the default TextProperties to apply to the substring;
|
// literally saved in the internal string; they are
|
||||||
// it layers on top of the default TextProperties for
|
// parsed at the time of the set_wsubstr() call.
|
||||||
// the overall string specified via set_properties().
|
|
||||||
//
|
//
|
||||||
// The return value is true if all the text is accepted,
|
// The return value is true if all the text is accepted,
|
||||||
// or false if some was truncated (see set_max_rows()).
|
// or false if some was truncated (see set_max_rows()).
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
bool TextAssembler::
|
bool TextAssembler::
|
||||||
set_wsubstr(const wstring &wtext, int start, int count,
|
set_wsubstr(const wstring &wtext, int start, int count) {
|
||||||
const TextProperties &properties) {
|
|
||||||
nassertr(start >= 0 && start <= (int)_text_string.size(), false);
|
nassertr(start >= 0 && start <= (int)_text_string.size(), false);
|
||||||
nassertr(count >= 0 && start + count <= (int)_text_string.size(), false);
|
nassertr(count >= 0 && start + count <= (int)_text_string.size(), false);
|
||||||
|
|
||||||
PT(ComputedProperties) substr_cprops = _initial_cprops;
|
|
||||||
if (properties.is_any_specified()) {
|
|
||||||
TextProperties new_properties = get_properties();
|
|
||||||
new_properties.add_properties(properties);
|
|
||||||
if (substr_cprops->_properties != new_properties) {
|
|
||||||
substr_cprops = new ComputedProperties(new_properties);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use scan_wtext to unroll the substring we wish to insert, as in
|
// Use scan_wtext to unroll the substring we wish to insert, as in
|
||||||
// set_wtext(), above.
|
// set_wtext(), above.
|
||||||
TextString substr;
|
TextString substr;
|
||||||
wstring::const_iterator si = wtext.begin();
|
wstring::const_iterator si = wtext.begin();
|
||||||
scan_wtext(substr, si, wtext.end(), substr_cprops);
|
scan_wtext(substr, si, wtext.end(), _initial_cprops);
|
||||||
while (si != wtext.end()) {
|
while (si != wtext.end()) {
|
||||||
text_cat.warning()
|
text_cat.warning()
|
||||||
<< "pop_properties encountered without preceding push_properties.\n";
|
<< "pop_properties encountered without preceding push_properties.\n";
|
||||||
scan_wtext(substr, si, wtext.end(), substr_cprops);
|
scan_wtext(substr, si, wtext.end(), _initial_cprops);
|
||||||
}
|
}
|
||||||
|
|
||||||
_text_string.erase(_text_string.begin() + start, _text_string.begin() + start + count);
|
_text_string.erase(_text_string.begin() + start, _text_string.begin() + start + count);
|
||||||
|
@ -62,8 +62,7 @@ PUBLISHED:
|
|||||||
INLINE const TextProperties &get_properties() const;
|
INLINE const TextProperties &get_properties() const;
|
||||||
|
|
||||||
bool set_wtext(const wstring &wtext);
|
bool set_wtext(const wstring &wtext);
|
||||||
bool set_wsubstr(const wstring &wtext, int start, int count,
|
bool set_wsubstr(const wstring &wtext, int start, int count);
|
||||||
const TextProperties &properties = TextProperties());
|
|
||||||
|
|
||||||
wstring get_plain_wtext() const;
|
wstring get_plain_wtext() const;
|
||||||
wstring get_wordwrapped_plain_wtext() const;
|
wstring get_wordwrapped_plain_wtext() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user