summaryrefslogtreecommitdiff
path: root/textscreen
diff options
context:
space:
mode:
Diffstat (limited to 'textscreen')
-rw-r--r--textscreen/Makefile.am2
-rw-r--r--textscreen/examples/Makefile.am2
-rw-r--r--textscreen/txt_desktop.c79
-rw-r--r--textscreen/txt_desktop.h39
-rw-r--r--textscreen/txt_dropdown.c19
-rw-r--r--textscreen/txt_scrollpane.c18
-rw-r--r--textscreen/txt_sdl.c11
-rw-r--r--textscreen/txt_window.c23
-rw-r--r--textscreen/txt_window.h11
9 files changed, 188 insertions, 16 deletions
diff --git a/textscreen/Makefile.am b/textscreen/Makefile.am
index 04039ac3..2c04ff0f 100644
--- a/textscreen/Makefile.am
+++ b/textscreen/Makefile.am
@@ -1,5 +1,5 @@
-AM_CFLAGS = -I../src
+AM_CFLAGS = -I$(top_builddir)/src
CTAGS_ARGS=-I TXT_UNCAST_ARG+
diff --git a/textscreen/examples/Makefile.am b/textscreen/examples/Makefile.am
index e314e7e8..efd17072 100644
--- a/textscreen/examples/Makefile.am
+++ b/textscreen/examples/Makefile.am
@@ -1,5 +1,5 @@
-AM_CFLAGS = -I.. -I../../src
+AM_CFLAGS = -I.. -I$(top_builddir)/src
noinst_PROGRAMS=guitest calculator
diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c
index 2c7caa27..2316145f 100644
--- a/textscreen/txt_desktop.c
+++ b/textscreen/txt_desktop.c
@@ -39,6 +39,10 @@ static txt_window_t *all_windows[MAXWINDOWS];
static int num_windows = 0;
static int main_loop_running = 0;
+static TxtIdleCallback periodic_callback = NULL;
+static void *periodic_callback_data;
+static unsigned int periodic_callback_period;
+
void TXT_AddDesktopWindow(txt_window_t *win)
{
// Previously-top window loses focus:
@@ -93,6 +97,58 @@ txt_window_t *TXT_GetActiveWindow(void)
return all_windows[num_windows - 1];
}
+int TXT_RaiseWindow(txt_window_t *window)
+{
+ int i;
+
+ for (i = 0; i < num_windows - 1; ++i)
+ {
+ if (all_windows[i] == window)
+ {
+ all_windows[i] = all_windows[i + 1];
+ all_windows[i + 1] = window;
+
+ if (i == num_windows - 2)
+ {
+ TXT_SetWindowFocus(all_windows[i], 0);
+ TXT_SetWindowFocus(window, 1);
+ }
+
+ return 1;
+ }
+ }
+
+ // Window not in the list, or at the end of the list (top) already.
+
+ return 0;
+}
+
+int TXT_LowerWindow(txt_window_t *window)
+{
+ int i;
+
+ for (i = 0; i < num_windows - 1; ++i)
+ {
+ if (all_windows[i + 1] == window)
+ {
+ all_windows[i + 1] = all_windows[i];
+ all_windows[i] = window;
+
+ if (i == num_windows - 2)
+ {
+ TXT_SetWindowFocus(window, 0);
+ TXT_SetWindowFocus(all_windows[i + 1], 1);
+ }
+
+ return 1;
+ }
+ }
+
+ // Window not in the list, or at the start of the list (bottom) already.
+
+ return 0;
+}
+
static void DrawDesktopBackground(const char *title)
{
int i;
@@ -219,6 +275,15 @@ void TXT_DrawASCIITable(void)
TXT_UpdateScreen();
}
+void TXT_SetPeriodicCallback(TxtIdleCallback callback,
+ void *user_data,
+ unsigned int period)
+{
+ periodic_callback = callback;
+ periodic_callback_data = user_data;
+ periodic_callback_period = period;
+}
+
void TXT_GUIMainLoop(void)
{
main_loop_running = 1;
@@ -233,10 +298,20 @@ void TXT_GUIMainLoop(void)
{
TXT_ExitMainLoop();
}
-
+
TXT_DrawDesktop();
// TXT_DrawASCIITable();
- TXT_Sleep(0);
+
+ if (periodic_callback == NULL)
+ {
+ TXT_Sleep(0);
+ }
+ else
+ {
+ TXT_Sleep(periodic_callback_period);
+
+ periodic_callback(periodic_callback_data);
+ }
}
}
diff --git a/textscreen/txt_desktop.h b/textscreen/txt_desktop.h
index 8d4726e5..f98d4627 100644
--- a/textscreen/txt_desktop.h
+++ b/textscreen/txt_desktop.h
@@ -30,6 +30,8 @@
#include "txt_window.h"
+typedef void (*TxtIdleCallback)(void *user_data);
+
void TXT_AddDesktopWindow(txt_window_t *win);
void TXT_RemoveDesktopWindow(txt_window_t *win);
void TXT_DrawDesktop(void);
@@ -73,6 +75,41 @@ void TXT_GUIMainLoop(void);
txt_window_t *TXT_GetActiveWindow(void);
-#endif /* #ifndef TXT_DESKTOP_H */
+/**
+ * Set a callback function to be invoked periodically by the main
+ * loop code.
+ *
+ * @param callback The callback to invoke, or NULL to cancel
+ * an existing callback.
+ * @param user_data Extra data to pass to the callback.
+ * @param period Maximum time between invoking each callback.
+ * eg. a value of 200 will cause the callback
+ * to be invoked at least once every 200ms.
+ */
+void TXT_SetPeriodicCallback(TxtIdleCallback callback,
+ void *user_data,
+ unsigned int period);
+
+/**
+ * Raise the z-position of the given window relative to other windows.
+ *
+ * @param window The window to raise.
+ * @return Non-zero if the window was raised successfully,
+ * or zero if the window could not be raised further.
+ */
+
+int TXT_RaiseWindow(txt_window_t *window);
+
+/**
+ * Lower the z-position of the given window relative to other windows.
+ *
+ * @param window The window to make inactive.
+ * @return Non-zero if the window was lowered successfully,
+ * or zero if the window could not be lowered further.
+ */
+
+int TXT_LowerWindow(txt_window_t *window);
+
+#endif /* #ifndef TXT_DESKTOP_H */
diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c
index d88716b5..652c9a36 100644
--- a/textscreen/txt_dropdown.c
+++ b/textscreen/txt_dropdown.c
@@ -49,14 +49,29 @@ static int ValidSelection(txt_dropdown_list_t *list)
static int SelectorWindowY(txt_dropdown_list_t *list)
{
+ int result;
+
if (ValidSelection(list))
{
- return list->widget.y - 1 - *list->variable;
+ result = list->widget.y - 1 - *list->variable;
}
else
{
- return list->widget.y - 1 - (list->num_values / 2);
+ result = list->widget.y - 1 - (list->num_values / 2);
+ }
+
+ // Keep dropdown inside the screen.
+
+ if (result < 1)
+ {
+ result = 1;
+ }
+ else if (result + list->num_values > (TXT_SCREEN_H - 3))
+ {
+ result = TXT_SCREEN_H - list->num_values - 3;
}
+
+ return result;
}
// Called when a button in the selector window is pressed
diff --git a/textscreen/txt_scrollpane.c b/textscreen/txt_scrollpane.c
index 4f468ffe..c53f68df 100644
--- a/textscreen/txt_scrollpane.c
+++ b/textscreen/txt_scrollpane.c
@@ -158,6 +158,18 @@ static void TXT_ScrollPaneSizeCalc(TXT_UNCAST_ARG(scrollpane))
{
++scrollpane->widget.w;
}
+
+ if (scrollpane->child != NULL)
+ {
+ if (scrollpane->child->w < scrollpane->w)
+ {
+ scrollpane->child->w = scrollpane->w;
+ }
+ if (scrollpane->child->h < scrollpane->h)
+ {
+ scrollpane->child->h = scrollpane->h;
+ }
+ }
}
static void TXT_ScrollPaneDrawer(TXT_UNCAST_ARG(scrollpane))
@@ -395,10 +407,10 @@ static int TXT_ScrollPaneKeyPress(TXT_UNCAST_ARG(scrollpane), int key)
// automatically move the scroll pane to show the new
// selected item.
- if (scrollpane->child->widget_class == &txt_table_class
- && (key == KEY_UPARROW || key == KEY_DOWNARROW
+ if ((key == KEY_UPARROW || key == KEY_DOWNARROW
|| key == KEY_LEFTARROW || key == KEY_RIGHTARROW
- || key == KEY_PGUP || key == KEY_PGDN))
+ || key == KEY_PGUP || key == KEY_PGDN)
+ && scrollpane->child->widget_class == &txt_table_class)
{
if (PageSelectedWidget(scrollpane, key))
{
diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c
index c51fcaf3..488399d3 100644
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -178,11 +178,7 @@ static void ChooseFont(void)
if (modes == NULL || modes == (SDL_Rect **) -1 || *modes == NULL)
{
-#ifdef _WIN32_WCE
- font = &small_font;
-#else
font = &main_font;
-#endif
return;
}
@@ -215,15 +211,19 @@ static void ChooseFont(void)
int TXT_Init(void)
{
+ int flags;
+
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
return 0;
}
+ flags = SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF;
+
ChooseFont();
screen = SDL_SetVideoMode(TXT_SCREEN_W * font->w,
- TXT_SCREEN_H * font->h, 8, 0);
+ TXT_SCREEN_H * font->h, 8, flags);
if (screen == NULL)
return 0;
@@ -249,6 +249,7 @@ int TXT_Init(void)
void TXT_Shutdown(void)
{
free(screendata);
+ screendata = NULL;
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c
index b08ac658..9ab6da9b 100644
--- a/textscreen/txt_window.c
+++ b/textscreen/txt_window.c
@@ -20,10 +20,12 @@
//
#include <stdlib.h>
+#include <stdarg.h>
#include <string.h>
#include "doomkeys.h"
+#include "txt_label.h"
#include "txt_desktop.h"
#include "txt_gui.h"
#include "txt_io.h"
@@ -502,3 +504,24 @@ void TXT_SetWindowFocus(txt_window_t *window, int focused)
TXT_SetWidgetFocus(window, focused);
}
+txt_window_t *TXT_MessageBox(char *title, char *message, ...)
+{
+ txt_window_t *window;
+ char buf[256];
+ va_list args;
+
+ va_start(args, message);
+ vsnprintf(buf, sizeof(buf), message, args);
+ va_end(args);
+
+ window = TXT_NewWindow(title);
+ TXT_AddWidget(window, TXT_NewLabel(buf));
+
+ TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL);
+ TXT_SetWindowAction(window, TXT_HORIZ_CENTER,
+ TXT_NewWindowEscapeAction(window));
+ TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL);
+
+ return window;
+}
+
diff --git a/textscreen/txt_window.h b/textscreen/txt_window.h
index 19440941..8b1e1fb9 100644
--- a/textscreen/txt_window.h
+++ b/textscreen/txt_window.h
@@ -191,6 +191,15 @@ void TXT_SetMouseListener(txt_window_t *window,
TxtWindowMousePress mouse_listener,
void *user_data);
-#endif /* #ifndef TXT_WINDOW_H */
+/**
+ * Open a window displaying a message.
+ *
+ * @param title Title of the window.
+ * @param message The message to display in the window.
+ * @return The new window.
+ */
+
+txt_window_t *TXT_MessageBox(char *title, char *message, ...);
+#endif /* #ifndef TXT_WINDOW_H */