summaryrefslogtreecommitdiff
path: root/textscreen/txt_desktop.c
diff options
context:
space:
mode:
authorSimon Howard2015-04-04 21:29:33 -0400
committerSimon Howard2015-04-04 21:29:33 -0400
commit356554c22998264769a5c516697cbfbd43847ce4 (patch)
tree69e510a287f629685eaa543fbd2677dd165e628a /textscreen/txt_desktop.c
parent535b4edd143ceeae870e9c13cdac65ce17e2be48 (diff)
downloadchocolate-doom-356554c22998264769a5c516697cbfbd43847ce4.tar.gz
chocolate-doom-356554c22998264769a5c516697cbfbd43847ce4.tar.bz2
chocolate-doom-356554c22998264769a5c516697cbfbd43847ce4.zip
textscreen: Add help URL functionality for windows.
This adds the ability to associate a URL with a window that gives some extra information about it and the configuration options found in it.
Diffstat (limited to 'textscreen/txt_desktop.c')
-rw-r--r--textscreen/txt_desktop.c85
1 files changed, 80 insertions, 5 deletions
diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c
index 4c9cf5c1..e56a5ee4 100644
--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -25,6 +25,7 @@
#include "txt_separator.h"
#include "txt_window.h"
+#define HELP_KEY KEY_F1
#define MAXWINDOWS 128
static char *desktop_title;
@@ -188,6 +189,37 @@ static void DrawDesktopBackground(const char *title)
TXT_Puts(title);
}
+static void DrawHelpIndicator(void)
+{
+ char keybuf[10];
+ int fgcolor;
+ int x, y;
+
+ TXT_GetKeyDescription(HELP_KEY, keybuf, sizeof(keybuf));
+
+ TXT_GetMousePosition(&x, &y);
+
+ if (y == 0 && x >= TXT_SCREEN_W - 9)
+ {
+ fgcolor = TXT_COLOR_GREY;
+ TXT_BGColor(TXT_COLOR_BLACK, 0);
+ }
+ else
+ {
+ fgcolor = TXT_COLOR_BLACK;
+ TXT_BGColor(TXT_COLOR_GREY, 0);
+ }
+
+ TXT_GotoXY(TXT_SCREEN_W - 9, 0);
+
+ TXT_FGColor(TXT_COLOR_BRIGHT_WHITE);
+ TXT_DrawString(" ");
+ TXT_DrawString(keybuf);
+
+ TXT_FGColor(fgcolor);
+ TXT_DrawString("=Help ");
+}
+
void TXT_SetDesktopTitle(char *title)
{
free(desktop_title);
@@ -197,8 +229,9 @@ void TXT_SetDesktopTitle(char *title)
void TXT_DrawDesktop(void)
{
- int i;
+ txt_window_t *active_window;
const char *title;
+ int i;
TXT_InitClipArea();
@@ -209,6 +242,12 @@ void TXT_DrawDesktop(void)
DrawDesktopBackground(title);
+ active_window = TXT_GetActiveWindow();
+ if (active_window != NULL && active_window->help_url != NULL)
+ {
+ DrawHelpIndicator();
+ }
+
for (i=0; i<num_windows; ++i)
{
TXT_DrawWindow(all_windows[i]);
@@ -217,17 +256,53 @@ void TXT_DrawDesktop(void)
TXT_UpdateScreen();
}
+// Fallback function to handle key/mouse events that are not handled by
+// the active window.
+static void DesktopInputEvent(int c)
+{
+ txt_window_t *active_window;
+ int x, y;
+
+ switch (c)
+ {
+ case TXT_MOUSE_LEFT:
+ TXT_GetMousePosition(&x, &y);
+
+ // Clicking the top-right of the screen is equivalent
+ // to pressing the help key.
+ if (y == 0 && x >= TXT_SCREEN_W - 9)
+ {
+ DesktopInputEvent(HELP_KEY);
+ }
+ break;
+
+ case HELP_KEY:
+ active_window = TXT_GetActiveWindow();
+ if (active_window != NULL)
+ {
+ TXT_OpenWindowHelpURL(active_window);
+ }
+ break;
+
+ default:
+ break;
+ }
+
+
+}
+
void TXT_DispatchEvents(void)
{
+ txt_window_t *active_window;
int c;
while ((c = TXT_GetChar()) > 0)
{
- if (num_windows > 0)
- {
- // Send the keypress to the top window
+ active_window = TXT_GetActiveWindow();
- TXT_WindowKeyPress(all_windows[num_windows - 1], c);
+ if (active_window != NULL && !TXT_WindowKeyPress(active_window, c))
+ {
+ DesktopInputEvent(c);
}
}
}