diff options
author | Simon Howard | 2011-06-13 22:21:37 +0000 |
---|---|---|
committer | Simon Howard | 2011-06-13 22:21:37 +0000 |
commit | 391e7466b1efb7cbede4a1c356a210d9e7ee616b (patch) | |
tree | 90d13346d9cd3636df44290ded13d59ae3712543 /textscreen/txt_widget.c | |
parent | fa328faf056affa216f2f3a8764ca0d56262efe9 (diff) | |
parent | 822664b4ff873d462370e9e96a9d91e6066c221d (diff) | |
download | chocolate-doom-391e7466b1efb7cbede4a1c356a210d9e7ee616b.tar.gz chocolate-doom-391e7466b1efb7cbede4a1c356a210d9e7ee616b.tar.bz2 chocolate-doom-391e7466b1efb7cbede4a1c356a210d9e7ee616b.zip |
Merge from trunk.
Subversion-branch: /branches/raven-branch
Subversion-revision: 2347
Diffstat (limited to 'textscreen/txt_widget.c')
-rw-r--r-- | textscreen/txt_widget.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/textscreen/txt_widget.c b/textscreen/txt_widget.c index 760943d5..d47a7507 100644 --- a/textscreen/txt_widget.c +++ b/textscreen/txt_widget.c @@ -24,6 +24,8 @@ #include "txt_io.h" #include "txt_widget.h" +#include "txt_gui.h" +#include "txt_desktop.h" typedef struct { @@ -82,6 +84,7 @@ void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class) widget->widget_class = widget_class; widget->callback_table = TXT_NewCallbackTable(); + widget->parent = NULL; // Visible by default. @@ -237,3 +240,62 @@ int TXT_SelectableWidget(TXT_UNCAST_ARG(widget)) } } +int TXT_ContainsWidget(TXT_UNCAST_ARG(haystack), TXT_UNCAST_ARG(needle)) +{ + TXT_CAST_ARG(txt_widget_t, haystack); + TXT_CAST_ARG(txt_widget_t, needle); + + while (needle != NULL) + { + if (needle == haystack) + { + return 1; + } + + needle = needle->parent; + } + + return 0; +} + +int TXT_HoveringOverWidget(TXT_UNCAST_ARG(widget)) +{ + TXT_CAST_ARG(txt_widget_t, widget); + txt_window_t *active_window; + int x, y; + + // We can only be hovering over widgets in the active window. + + active_window = TXT_GetActiveWindow(); + + if (active_window == NULL || !TXT_ContainsWidget(active_window, widget)) + { + return 0; + } + + // Is the mouse cursor within the bounds of the widget? + + TXT_GetMousePosition(&x, &y); + + return (x >= widget->x && x < widget->x + widget->w + && y >= widget->y && y < widget->y + widget->h); +} + +void TXT_SetWidgetBG(TXT_UNCAST_ARG(widget), int selected) +{ + TXT_CAST_ARG(txt_widget_t, widget); + + if (selected) + { + TXT_BGColor(TXT_COLOR_GREY, 0); + } + else if (TXT_HoveringOverWidget(widget)) + { + TXT_BGColor(TXT_HOVER_BACKGROUND, 0); + } + else + { + TXT_BGColor(TXT_WINDOW_BACKGROUND, 0); + } +} + |