diff options
Diffstat (limited to 'textscreen')
-rw-r--r-- | textscreen/Makefile.am | 2 | ||||
-rw-r--r-- | textscreen/examples/Makefile.am | 2 | ||||
-rw-r--r-- | textscreen/txt_desktop.c | 27 | ||||
-rw-r--r-- | textscreen/txt_desktop.h | 19 | ||||
-rw-r--r-- | textscreen/txt_dropdown.c | 19 | ||||
-rw-r--r-- | textscreen/txt_scrollpane.c | 18 | ||||
-rw-r--r-- | textscreen/txt_sdl.c | 7 | ||||
-rw-r--r-- | textscreen/txt_window.c | 23 | ||||
-rw-r--r-- | textscreen/txt_window.h | 10 |
9 files changed, 116 insertions, 11 deletions
diff --git a/textscreen/Makefile.am b/textscreen/Makefile.am index 6fb1724a..4fd87868 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..09589688 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: @@ -219,6 +223,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 +246,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..9e2a42c7 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,21 @@ 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); +#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..29f8de4c 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -215,15 +215,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 +253,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 e183cf6d..bfae2a9a 100644 --- a/textscreen/txt_window.h +++ b/textscreen/txt_window.h @@ -176,6 +176,16 @@ void TXT_SetMouseListener(txt_window_t *window, TxtWindowMousePress mouse_listener, void *user_data); +/** + * 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_T */ |