Add blinking text cursor to focused textbox

Unlike the previous implementation, the blinking cursor now only applies
to the focused (frontmost) window.
This commit is contained in:
Celtic Minstrel 2017-05-12 15:11:27 -04:00
parent 0e7866db2d
commit cbc4af1a20
3 changed files with 8 additions and 5 deletions

View file

@ -125,6 +125,7 @@ Version 1.13.7+dev:
* Improve layout of MP Create at low resolutions.
* Game Load screen now lists the gold and total number of units for each
side.
* Textboxes now have a blinking cursor when focused.
* WML Engine:
* Add base_income key to [store_side]
* Fix issues with alpha animations on hidden units (#14503)

View file

@ -65,9 +65,7 @@
y1 = "(text_y_offset + 2)"
x2 = "(cursor_offset + {X_OFFSET})"
y2 = "(text_y_offset + text_font_height - 2)"
color = "255, 255, 255, 255"
# TODO: disabled until there's a way to deal with textboxes on multiple windows
#color = "([255, 255, 255, cursor_alpha])"
color = "([255, 255, 255, cursor_alpha])"
thickness = 1
[/line]
#enddef

View file

@ -40,7 +40,7 @@ text_box_base::text_box_base()
, selection_length_(0)
, cursor_timer_(0)
, cursor_alpha_(0)
, cursor_blink_rate_ms_(0) // TODO: disabled until there's a way to deal with textboxes on multiple windows
, cursor_blink_rate_ms_(750)
, text_changed_callback_()
{
#ifdef __unix__
@ -277,7 +277,11 @@ void text_box_base::cursor_timer_callback()
cursor_alpha_ = 255;
return;
default:
cursor_alpha_ = (~cursor_alpha_) & 0xFF;
if(get_window() != open_window_stack.back()) {
cursor_alpha_ = 0;
} else {
cursor_alpha_ = (~cursor_alpha_) & 0xFF;
}
}
for(auto& tmp : get_canvases()) {