diff options
author | Simon Howard | 2011-10-23 19:25:55 +0000 |
---|---|---|
committer | Simon Howard | 2011-10-23 19:25:55 +0000 |
commit | dd52766c7be893a6a5db31bc396ccef8d758af45 (patch) | |
tree | 0ece2688a18f5f8f3d893047973d1c6ab4c82df1 /textscreen/txt_widget.c | |
parent | 71d316afb2ae7191a4ef6fac2d757238ae3616e1 (diff) | |
download | chocolate-doom-dd52766c7be893a6a5db31bc396ccef8d758af45.tar.gz chocolate-doom-dd52766c7be893a6a5db31bc396ccef8d758af45.tar.bz2 chocolate-doom-dd52766c7be893a6a5db31bc396ccef8d758af45.zip |
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
Diffstat (limited to 'textscreen/txt_widget.c')
-rw-r--r-- | textscreen/txt_widget.c | 32 |
1 files changed, 28 insertions, 4 deletions
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); } |