Skip to content

Commit bfa27c5

Browse files
committed
fix issues with text_scale, text_color, text_align
1 parent 3611b35 commit bfa27c5

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

direct/src/gui/DirectEntry.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,30 @@ def enterText(self, text):
166166
def getBounds(self, state = 0):
167167
# Compute the width and height for the entry itself, ignoring
168168
# geometry etc.
169-
lineHeight = self.onscreenText.textNode.getLineHeight()
169+
tn = self.onscreenText.textNode
170+
mat = tn.getTransform()
171+
align = tn.getAlign()
172+
lineHeight = tn.getLineHeight()
170173
numLines = self['numLines']
171174
width = self['width']
172-
self.ll.set(0.0, 0.0, -0.3 * lineHeight - (lineHeight * (numLines - 1)))
173-
self.ur.set(width, 0.0, lineHeight * 1.3)
175+
176+
if align == TextNode.ALeft:
177+
left = 0.0
178+
right = width
179+
elif align == TextNode.ACenter:
180+
left = -width / 2.0
181+
right = width / 2.0
182+
elif align == TextNode.ARight:
183+
left = -width
184+
right = 0.0
185+
186+
bottom = -0.3 * lineHeight - (lineHeight * (numLines - 1))
187+
top = lineHeight
188+
189+
self.ll.set(left, 0.0, bottom)
190+
self.ur.set(right, 0.0, top)
191+
self.ll = mat.xformPoint(self.ll)
192+
self.ur = mat.xformPoint(self.ur)
174193

175194
# Scale bounds to give a pad around graphics. We also want to
176195
# scale around the border width.

panda/src/pgui/pgEntry.I

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ get_cursor_def() {
205205
INLINE void PGEntry::
206206
clear_cursor_def() {
207207
_cursor_def.remove_node();
208-
_cursor_def = _text_render_root.attach_new_node("cursor");
208+
_cursor_def = _cursor_scale.attach_new_node("cursor");
209209
}
210210

211211
////////////////////////////////////////////////////////////////////
@@ -435,6 +435,7 @@ set_wtext(const wstring &wtext) {
435435
_text_geom_stale = true;
436436
_cursor_stale = true;
437437
_blink_start = ClockObject::get_global_clock()->get_frame_time();
438+
set_cursor_position(_wtext.size());
438439
}
439440

440441
////////////////////////////////////////////////////////////////////

panda/src/pgui/pgEntry.cxx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ PGEntry(const string &name) :
5757
_blink_rate = 1.0f;
5858

5959
_text_render_root = NodePath("text_root");
60-
_cursor_def = _text_render_root.attach_new_node("cursor");
60+
_cursor_scale = _text_render_root.attach_new_node("cursor_scale");
61+
_cursor_def = _cursor_def.attach_new_node("cursor");
6162
_cursor_visible = true;
6263

6364
// These strings are used to specify the TextProperties to apply to
@@ -580,7 +581,7 @@ setup(float width, int num_lines) {
580581
LineSegs ls;
581582
ls.set_color(0.0f, 0.0f, 0.0f, 1.0f);
582583
ls.move_to(0.0f, 0.0f, -0.15f * line_height);
583-
ls.draw_to(0.0f, 0.0f, 0.85f * line_height);
584+
ls.draw_to(0.0f, 0.0f, 0.70f * line_height);
584585
get_cursor_def().attach_new_node(ls.create());
585586

586587
/*
@@ -761,6 +762,10 @@ update_text() {
761762
// Get the left edge of the text at this line.
762763
line._left = 0.0f;
763764
if (_last_text_def->get_align() != TextNode::A_left) {
765+
// Temporarily set this line's text in the TextNode, just so
766+
// we can measure the left margin. (If align is A_left, we
767+
// know that the left margin is 0.0, so we don't need to do
768+
// this.)
764769
_last_text_def->set_wtext(line._str);
765770
line._left = _last_text_def->get_left();
766771
}
@@ -782,6 +787,10 @@ update_text() {
782787
if (!_current_text.is_empty()) {
783788
_current_text.remove_node();
784789
}
790+
791+
// We need to reset the text, since we might have changed it
792+
// temporarily in the above when align is not A_left.
793+
_last_text_def->set_wtext(display_wtext);
785794
_current_text =
786795
_text_render_root.attach_new_node(_last_text_def->generate());
787796
_text_geom_stale = false;
@@ -798,6 +807,8 @@ void PGEntry::
798807
update_cursor() {
799808
TextNode *node = get_text_def(get_state());
800809
nassertv(node != (TextNode *)NULL);
810+
_cursor_scale.set_mat(node->get_transform());
811+
_cursor_scale.set_color(node->get_text_color());
801812

802813
if (_cursor_stale || node != _last_text_def) {
803814
update_text();
@@ -853,9 +864,9 @@ void PGEntry::
853864
show_hide_cursor(bool visible) {
854865
if (visible != _cursor_visible) {
855866
if (visible) {
856-
_cursor_def.show();
867+
_cursor_scale.show();
857868
} else {
858-
_cursor_def.hide();
869+
_cursor_scale.hide();
859870
}
860871
_cursor_visible = visible;
861872
}

panda/src/pgui/pgEntry.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class EXPCL_PANDA PGEntry : public PGItem {
176176
// This is the node that represents the cursor geometry. It is also
177177
// attached to the above node, and is transformed around and/or
178178
// hidden according to the cursor's position and blink state.
179+
NodePath _cursor_scale;
179180
NodePath _cursor_def;
180181

181182
double _blink_start;

0 commit comments

Comments
 (0)