diff --git a/panda/src/pgui/pgEntry.cxx b/panda/src/pgui/pgEntry.cxx index 2bc9aa4d85..0fe6dae3e2 100644 --- a/panda/src/pgui/pgEntry.cxx +++ b/panda/src/pgui/pgEntry.cxx @@ -58,6 +58,7 @@ PGEntry(const string &name) : _accept_enabled = true; _last_text_def = (TextNode *)NULL; _text_geom_stale = true; + _text_geom_flattened = true; _blink_start = 0.0f; _blink_rate = 1.0f; @@ -110,6 +111,7 @@ PGEntry(const PGEntry ©) : _cursor_stale = true; _last_text_def = (TextNode *)NULL; _text_geom_stale = true; + _text_geom_flattened = true; } //////////////////////////////////////////////////////////////////// @@ -684,17 +686,26 @@ update_text() { TextProperties inactive = tp_mgr->get_properties(_candidate_inactive); TextProperties active = tp_mgr->get_properties(_candidate_active); - // Create a special TextAssembler to insert the candidate string - // in its own special colors. + // Insert the complex sequence of characters required to show + // 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); - ctext.set_wsubstr(_candidate_wtext.substr(_candidate_highlight_end), - _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); + ctext.set_wsubstr(cseq, _cursor_position, 0); assembled = ctext.assemble_text(); } @@ -705,8 +716,16 @@ update_text() { _current_text = _text_render_root.attach_new_node(assembled); _text_geom_stale = false; + _text_geom_flattened = false; _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; + } } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pgui/pgEntry.h b/panda/src/pgui/pgEntry.h index f9dc40e7b4..76d0305606 100644 --- a/panda/src/pgui/pgEntry.h +++ b/panda/src/pgui/pgEntry.h @@ -172,6 +172,7 @@ private: 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 diff --git a/panda/src/text/textAssembler.cxx b/panda/src/text/textAssembler.cxx index 8ad48e1481..2ee1b6359f 100644 --- a/panda/src/text/textAssembler.cxx +++ b/panda/src/text/textAssembler.cxx @@ -193,38 +193,27 @@ set_wtext(const wstring &wtext) { // // The substring may include nested formatting // characters, but they must be self-contained and -// self-closed. The indicated TextProperties specifies -// the default TextProperties to apply to the substring; -// it layers on top of the default TextProperties for -// the overall string specified via set_properties(). +// self-closed. The formatting characters are not +// literally saved in the internal string; they are +// parsed at the time of the set_wsubstr() call. // // The return value is true if all the text is accepted, // or false if some was truncated (see set_max_rows()). //////////////////////////////////////////////////////////////////// bool TextAssembler:: -set_wsubstr(const wstring &wtext, int start, int count, - const TextProperties &properties) { +set_wsubstr(const wstring &wtext, int start, int count) { nassertr(start >= 0 && start <= (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 // set_wtext(), above. TextString substr; 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()) { text_cat.warning() << "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); diff --git a/panda/src/text/textAssembler.h b/panda/src/text/textAssembler.h index 51b0e3ed52..597df6a84c 100644 --- a/panda/src/text/textAssembler.h +++ b/panda/src/text/textAssembler.h @@ -62,8 +62,7 @@ PUBLISHED: INLINE const TextProperties &get_properties() const; bool set_wtext(const wstring &wtext); - bool set_wsubstr(const wstring &wtext, int start, int count, - const TextProperties &properties = TextProperties()); + bool set_wsubstr(const wstring &wtext, int start, int count); wstring get_plain_wtext() const; wstring get_wordwrapped_plain_wtext() const;