summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--setup/txt_joybinput.c10
-rw-r--r--setup/txt_keyinput.c10
-rw-r--r--setup/txt_mouseinput.c10
-rw-r--r--textscreen/txt_button.c8
-rw-r--r--textscreen/txt_checkbox.c8
-rw-r--r--textscreen/txt_desktop.c10
-rw-r--r--textscreen/txt_desktop.h9
-rw-r--r--textscreen/txt_dropdown.c10
-rw-r--r--textscreen/txt_gui.c4
-rw-r--r--textscreen/txt_gui.h4
-rw-r--r--textscreen/txt_inputbox.c8
-rw-r--r--textscreen/txt_label.c2
-rw-r--r--textscreen/txt_radiobutton.c8
-rw-r--r--textscreen/txt_scrollpane.c4
-rw-r--r--textscreen/txt_sdl.c26
-rw-r--r--textscreen/txt_separator.c2
-rw-r--r--textscreen/txt_spinctrl.c10
-rw-r--r--textscreen/txt_table.c4
-rw-r--r--textscreen/txt_widget.c62
-rw-r--r--textscreen/txt_widget.h34
-rw-r--r--textscreen/txt_window.c8
-rw-r--r--textscreen/txt_window_action.c17
23 files changed, 192 insertions, 78 deletions
diff --git a/NEWS b/NEWS
index 73206691..d37ee185 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,8 @@
match the game default (thanks Alexandre Xavier).
libtextscreen:
+ * The background on GUI controls now lights up when hovering over
+ them, so that it is more obvious what you are selecting.
* It is now possible to type a '+' in input boxes (thanks
Alexandre Xavier).
* It is possible to use the mouse wheel to scroll through scroll
diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c
index cde3d2c2..861414f7 100644
--- a/setup/txt_joybinput.c
+++ b/setup/txt_joybinput.c
@@ -153,15 +153,7 @@ static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input), int selected
GetJoystickButtonDescription(*joystick_input->variable, buf);
}
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
- else
- {
- TXT_BGColor(TXT_COLOR_BLUE, 0);
- }
-
+ TXT_SetWidgetBG(joystick_input, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(buf);
diff --git a/setup/txt_keyinput.c b/setup/txt_keyinput.c
index 08eb9d8c..dfa6ede2 100644
--- a/setup/txt_keyinput.c
+++ b/setup/txt_keyinput.c
@@ -118,15 +118,7 @@ static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input), int selected)
TXT_GetKeyDescription(*key_input->variable, buf);
}
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
- else
- {
- TXT_BGColor(TXT_COLOR_BLUE, 0);
- }
-
+ TXT_SetWidgetBG(key_input, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(buf);
diff --git a/setup/txt_mouseinput.c b/setup/txt_mouseinput.c
index 4f454c8c..2c14a010 100644
--- a/setup/txt_mouseinput.c
+++ b/setup/txt_mouseinput.c
@@ -111,15 +111,7 @@ static void TXT_MouseInputDrawer(TXT_UNCAST_ARG(mouse_input), int selected)
GetMouseButtonDescription(*mouse_input->variable, buf);
}
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
- else
- {
- TXT_BGColor(TXT_COLOR_BLUE, 0);
- }
-
+ TXT_SetWidgetBG(mouse_input, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(buf);
diff --git a/textscreen/txt_button.c b/textscreen/txt_button.c
index 85517b3d..536e5f56 100644
--- a/textscreen/txt_button.c
+++ b/textscreen/txt_button.c
@@ -46,16 +46,12 @@ static void TXT_ButtonDrawer(TXT_UNCAST_ARG(button), int selected)
w = button->widget.w;
- TXT_BGColor(TXT_COLOR_BLUE, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
+ TXT_SetWidgetBG(button, selected);
TXT_DrawString(button->label);
-
+
for (i=strlen(button->label); i < w; ++i)
{
TXT_DrawString(" ");
diff --git a/textscreen/txt_checkbox.c b/textscreen/txt_checkbox.c
index 35c5739d..f2183b7c 100644
--- a/textscreen/txt_checkbox.c
+++ b/textscreen/txt_checkbox.c
@@ -48,7 +48,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox), int selected)
w = checkbox->widget.w;
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
@@ -67,11 +67,7 @@ static void TXT_CheckBoxDrawer(TXT_UNCAST_ARG(checkbox), int selected)
TXT_DrawString(") ");
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
-
+ TXT_SetWidgetBG(checkbox, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(checkbox->label);
diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c
index f833441f..c497f0e3 100644
--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -61,6 +61,16 @@ void TXT_RemoveDesktopWindow(txt_window_t *win)
num_windows = to;
}
+txt_window_t *TXT_GetActiveWindow(void)
+{
+ if (num_windows == 0)
+ {
+ return NULL;
+ }
+
+ return all_windows[num_windows - 1];
+}
+
static void DrawDesktopBackground(const char *title)
{
int i;
diff --git a/textscreen/txt_desktop.h b/textscreen/txt_desktop.h
index 95343977..42a011e7 100644
--- a/textscreen/txt_desktop.h
+++ b/textscreen/txt_desktop.h
@@ -63,6 +63,15 @@ void TXT_ExitMainLoop(void);
void TXT_GUIMainLoop(void);
+/**
+ * Get the top window on the desktop that is currently receiving
+ * inputs.
+ *
+ * @return The active window, or NULL if no windows are present.
+ */
+
+txt_window_t *TXT_GetActiveWindow(void);
+
#endif /* #ifndef TXT_DESKTOP_H */
diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c
index c8103302..01cf830d 100644
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -197,15 +197,7 @@ static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list), int selected)
// Set bg/fg text colors.
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
- else
- {
- TXT_BGColor(TXT_COLOR_BLUE, 0);
- }
-
+ TXT_SetWidgetBG(list, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
// Select a string to draw from the list, if the current value is
diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c
index ec166415..d00e3a65 100644
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -131,7 +131,7 @@ void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h)
int bx, by;
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
for (y1=y; y1<y+h; ++y1)
{
@@ -191,7 +191,7 @@ void TXT_DrawSeparator(int x, int y, int w)
data = TXT_GetScreenData();
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
if (!VALID_Y(y))
{
diff --git a/textscreen/txt_gui.h b/textscreen/txt_gui.h
index ad7ae428..06fc7a36 100644
--- a/textscreen/txt_gui.h
+++ b/textscreen/txt_gui.h
@@ -27,6 +27,9 @@
#ifndef TXT_GUI_H
#define TXT_GUI_H
+#define TXT_WINDOW_BACKGROUND TXT_COLOR_BLUE
+#define TXT_HOVER_BACKGROUND TXT_COLOR_CYAN
+
void TXT_DrawDesktopBackground(const char *title);
void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h);
void TXT_DrawSeparator(int x, int y, int w);
@@ -35,6 +38,7 @@ void TXT_DrawString(const char *s);
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range);
void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range);
+
void TXT_InitClipArea(void);
void TXT_PushClipArea(int x1, int x2, int y1, int y2);
void TXT_PopClipArea(void);
diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c
index 852346f3..a28c342c 100644
--- a/textscreen/txt_inputbox.c
+++ b/textscreen/txt_inputbox.c
@@ -60,15 +60,9 @@ static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox), int selected)
{
TXT_BGColor(TXT_COLOR_BLACK, 0);
}
- else if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
else
{
- // Not even selected
-
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_SetWidgetBG(inputbox, selected);
}
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
diff --git a/textscreen/txt_label.c b/textscreen/txt_label.c
index 0deea803..c973bce2 100644
--- a/textscreen/txt_label.c
+++ b/textscreen/txt_label.c
@@ -176,7 +176,7 @@ txt_label_t *TXT_NewLabel(char *text)
// Default colors
- label->bgcolor = TXT_COLOR_BLUE;
+ label->bgcolor = TXT_WINDOW_BACKGROUND;
label->fgcolor = TXT_COLOR_BRIGHT_WHITE;
TXT_SetLabel(label, text);
diff --git a/textscreen/txt_radiobutton.c b/textscreen/txt_radiobutton.c
index 00c2c4fc..0755562d 100644
--- a/textscreen/txt_radiobutton.c
+++ b/textscreen/txt_radiobutton.c
@@ -48,7 +48,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton), int selected)
w = radiobutton->widget.w;
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("(");
@@ -67,11 +67,7 @@ static void TXT_RadioButtonDrawer(TXT_UNCAST_ARG(radiobutton), int selected)
TXT_DrawString(") ");
- if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
-
+ TXT_SetWidgetBG(radiobutton, selected);
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(radiobutton->label);
diff --git a/textscreen/txt_scrollpane.c b/textscreen/txt_scrollpane.c
index 856f6b8a..2fd45c55 100644
--- a/textscreen/txt_scrollpane.c
+++ b/textscreen/txt_scrollpane.c
@@ -557,6 +557,10 @@ txt_scrollpane_t *TXT_NewScrollPane(int w, int h, TXT_UNCAST_ARG(target))
scrollpane->expand_w = w <= 0;
scrollpane->expand_h = h <= 0;
+ // Set parent pointer for inner widget.
+
+ target->parent = &scrollpane->widget;
+
return scrollpane;
}
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index 365e6bf0..5ae151e9 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -221,7 +221,7 @@ int TXT_Init(void)
// Ignore all mouse motion events
- SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+// SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
// Repeat key presses so we can hold down arrows to scroll down the
// menu, for example. This is what setup.exe does.
@@ -475,6 +475,24 @@ static int SDLButtonToTXTButton(int button)
}
}
+static int MouseHasMoved(void)
+{
+ static int last_x = 0, last_y = 0;
+ int x, y;
+
+ TXT_GetMousePosition(&x, &y);
+
+ if (x != last_x || y != last_y)
+ {
+ last_x = x; last_y = y;
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
signed int TXT_GetChar(void)
{
SDL_Event ev;
@@ -510,6 +528,12 @@ signed int TXT_GetChar(void)
// Quit = escape
return 27;
+ case SDL_MOUSEMOTION:
+ if (MouseHasMoved())
+ {
+ return 0;
+ }
+
default:
break;
}
diff --git a/textscreen/txt_separator.c b/textscreen/txt_separator.c
index 563d0c62..89db0b03 100644
--- a/textscreen/txt_separator.c
+++ b/textscreen/txt_separator.c
@@ -65,7 +65,7 @@ static void TXT_SeparatorDrawer(TXT_UNCAST_ARG(separator), int selected)
{
TXT_GotoXY(x, y);
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
TXT_DrawString(" ");
TXT_DrawString(separator->label);
diff --git a/textscreen/txt_spinctrl.c b/textscreen/txt_spinctrl.c
index d775aecf..2b2d4d09 100644
--- a/textscreen/txt_spinctrl.c
+++ b/textscreen/txt_spinctrl.c
@@ -149,7 +149,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol), int selected)
unsigned int padding;
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_DrawString("\x1b ");
@@ -161,13 +161,9 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol), int selected)
{
TXT_BGColor(TXT_COLOR_BLACK, 0);
}
- else if (selected)
- {
- TXT_BGColor(TXT_COLOR_GREY, 0);
- }
else
{
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_SetWidgetBG(spincontrol, selected);
}
if (!spincontrol->editing)
@@ -195,7 +191,7 @@ static void TXT_SpinControlDrawer(TXT_UNCAST_ARG(spincontrol), int selected)
}
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
- TXT_BGColor(TXT_COLOR_BLUE, 0);
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
TXT_DrawString(" \x1a");
}
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index ffe6fd14..b9d727a3 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -173,6 +173,10 @@ void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget))
sizeof(txt_widget_t *) * (table->num_widgets + 1));
table->widgets[table->num_widgets] = widget;
++table->num_widgets;
+
+ // Maintain parent pointer.
+
+ widget->parent = &table->widget;
}
// Add multiple widgets to a table.
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);
+ }
+}
+
diff --git a/textscreen/txt_widget.h b/textscreen/txt_widget.h
index bb895f92..ebb5a292 100644
--- a/textscreen/txt_widget.h
+++ b/textscreen/txt_widget.h
@@ -102,6 +102,10 @@ struct txt_widget_s
int x, y;
unsigned int w, h;
+
+ // Pointer up to parent widget that contains this widget.
+
+ txt_widget_t *parent;
};
void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class);
@@ -146,6 +150,34 @@ void TXT_SetWidgetAlign(TXT_UNCAST_ARG(widget), txt_horiz_align_t horiz_align);
int TXT_SelectableWidget(TXT_UNCAST_ARG(widget));
-#endif /* #ifndef TXT_WIDGET_H */
+/**
+ * Query whether the mouse is hovering over the specified widget.
+ *
+ * @param widget The widget.
+ * @return Non-zero if the mouse cursor is over the widget.
+ */
+
+int TXT_HoveringOverWidget(TXT_UNCAST_ARG(widget));
+
+/**
+ * Set the background to draw the specified widget, depending on
+ * whether it is selected and the mouse is hovering over it.
+ *
+ * @param widget The widget.
+ * @param selected Whether the widget is selected.
+ */
+
+void TXT_SetWidgetBG(TXT_UNCAST_ARG(widget), int selected);
+
+/**
+ * Query whether the specified widget is contained within another
+ * widget.
+ *
+ * @param haystack The widget that might contain needle.
+ * @param needle The widget being queried.
+ */
+int TXT_ContainsWidget(TXT_UNCAST_ARG(haystack), TXT_UNCAST_ARG(needle));
+
+#endif /* #ifndef TXT_WIDGET_H */
diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c
index 46e71d3a..7ba11778 100644
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -40,6 +40,10 @@ void TXT_SetWindowAction(txt_window_t *window,
}
window->actions[position] = action;
+
+ // Maintain parent pointer.
+
+ action->widget.parent = &window->table.widget;
}
txt_window_t *TXT_NewWindow(char *title)
@@ -158,7 +162,7 @@ static void LayoutActionArea(txt_window_t *window)
TXT_CalcWidgetSize(widget);
- widget->x = window->window_x + 2;
+ widget->x = window->window_x + 1;
widget->y = window->window_y + window->window_h - widget->h - 1;
// Adjust available space:
@@ -175,7 +179,7 @@ static void LayoutActionArea(txt_window_t *window)
TXT_CalcWidgetSize(widget);
- widget->x = window->window_x + window->window_w - 2 - widget->w;
+ widget->x = window->window_x + window->window_w - 1 - widget->w;
widget->y = window->window_y + window->window_h - widget->h - 1;
// Adjust available space:
diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c
index e593b7b6..81d3e94d 100644
--- a/textscreen/txt_window_action.c
+++ b/textscreen/txt_window_action.c
@@ -37,9 +37,10 @@ static void TXT_WindowActionSizeCalc(TXT_UNCAST_ARG(action))
TXT_GetKeyDescription(action->key, buf);
- // Minimum width is the string length + two spaces for padding
+ // Width is label length, plus key description length, plus '='
+ // and two surrounding spaces.
- action->widget.w = strlen(action->label) + strlen(buf) + 1;
+ action->widget.w = strlen(action->label) + strlen(buf) + 3;
action->widget.h = 1;
}
@@ -50,12 +51,24 @@ static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action), int selected)
TXT_GetKeyDescription(action->key, buf);
+ if (TXT_HoveringOverWidget(action))
+ {
+ TXT_BGColor(TXT_COLOR_BLACK, 0);
+ }
+ else
+ {
+ TXT_BGColor(TXT_WINDOW_BACKGROUND, 0);
+ }
+
+ TXT_DrawString(" ");
TXT_FGColor(TXT_COLOR_BRIGHT_GREEN);
TXT_DrawString(buf);
TXT_FGColor(TXT_COLOR_BRIGHT_CYAN);
TXT_DrawString("=");
+
TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
TXT_DrawString(action->label);
+ TXT_DrawString(" ");
}
static void TXT_WindowActionDestructor(TXT_UNCAST_ARG(action))