From dd52766c7be893a6a5db31bc396ccef8d758af45 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 23 Oct 2011 19:25:55 +0000 Subject: Rework textscreen focus handling so that input boxes will stop editing when they lose their focus (thanks Twelve). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2460 --- textscreen/txt_widget.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'textscreen/txt_widget.c') diff --git a/textscreen/txt_widget.c b/textscreen/txt_widget.c index d47a7507..7d31ad68 100644 --- a/textscreen/txt_widget.c +++ b/textscreen/txt_widget.c @@ -86,6 +86,10 @@ void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class) widget->callback_table = TXT_NewCallbackTable(); widget->parent = NULL; + // Not focused until we hear otherwise. + + widget->focused = 0; + // Visible by default. widget->visible = 1; @@ -155,7 +159,7 @@ void TXT_CalcWidgetSize(TXT_UNCAST_ARG(widget)) widget->widget_class->size_calc(widget); } -void TXT_DrawWidget(TXT_UNCAST_ARG(widget), int selected) +void TXT_DrawWidget(TXT_UNCAST_ARG(widget)) { TXT_CAST_ARG(txt_widget_t, widget); @@ -165,7 +169,7 @@ void TXT_DrawWidget(TXT_UNCAST_ARG(widget), int selected) // Call drawer method - widget->widget_class->drawer(widget, selected); + widget->widget_class->drawer(widget); } void TXT_DestroyWidget(TXT_UNCAST_ARG(widget)) @@ -189,6 +193,26 @@ int TXT_WidgetKeyPress(TXT_UNCAST_ARG(widget), int key) return 0; } +void TXT_SetWidgetFocus(TXT_UNCAST_ARG(widget), int focused) +{ + TXT_CAST_ARG(txt_widget_t, widget); + + if (widget == NULL) + { + return; + } + + if (widget->focused != focused) + { + widget->focused = focused; + + if (widget->widget_class->focus_change != NULL) + { + widget->widget_class->focus_change(widget, focused); + } + } +} + void TXT_SetWidgetAlign(TXT_UNCAST_ARG(widget), txt_horiz_align_t horiz_align) { TXT_CAST_ARG(txt_widget_t, widget); @@ -281,11 +305,11 @@ int TXT_HoveringOverWidget(TXT_UNCAST_ARG(widget)) && y >= widget->y && y < widget->y + widget->h); } -void TXT_SetWidgetBG(TXT_UNCAST_ARG(widget), int selected) +void TXT_SetWidgetBG(TXT_UNCAST_ARG(widget)) { TXT_CAST_ARG(txt_widget_t, widget); - if (selected) + if (widget->focused) { TXT_BGColor(TXT_COLOR_GREY, 0); } -- cgit v1.2.3