diff options
author | Simon Howard | 2006-05-23 19:33:35 +0000 |
---|---|---|
committer | Simon Howard | 2006-05-23 19:33:35 +0000 |
commit | 240a1cfcca8f53a114a4302e93af793be21809d0 (patch) | |
tree | f9f92c2454d274902f2e1edf36c4f7300404bbb5 | |
parent | 59864df095516a0e6a1fecb5a6abfeedc1e56188 (diff) | |
download | chocolate-doom-240a1cfcca8f53a114a4302e93af793be21809d0.tar.gz chocolate-doom-240a1cfcca8f53a114a4302e93af793be21809d0.tar.bz2 chocolate-doom-240a1cfcca8f53a114a4302e93af793be21809d0.zip |
Add a default action to close windows when escape is pressed. Do not
make escape quit the program unless there are no open windows. Add
TXT_ExitMainLoop().
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 518
-rw-r--r-- | textscreen/txt_desktop.c | 24 | ||||
-rw-r--r-- | textscreen/txt_desktop.h | 2 | ||||
-rw-r--r-- | textscreen/txt_window.c | 8 |
3 files changed, 30 insertions, 4 deletions
diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c index 4cfe30a0..72bda28a 100644 --- a/textscreen/txt_desktop.c +++ b/textscreen/txt_desktop.c @@ -25,6 +25,8 @@ #include <stdlib.h> #include <string.h> +#include "doomkeys.h" + #include "txt_desktop.h" #include "txt_gui.h" #include "txt_main.h" @@ -36,6 +38,7 @@ static char *desktop_title; static txt_window_t *all_windows[MAXWINDOWS]; static int num_windows = 0; +static int main_loop_running = 0; void TXT_AddDesktopWindow(txt_window_t *win) { @@ -137,21 +140,34 @@ void TXT_DispatchEvents(void) while ((c = TXT_GetChar()) > 0) { - if (c == 27) - exit(0); - if (num_windows > 0) { // Send the keypress to the top window TXT_WindowKeyPress(all_windows[num_windows - 1], c); } + else + { + // No windows + + if (c == KEY_ESCAPE) + { + TXT_ExitMainLoop(); + } + } } } +void TXT_ExitMainLoop(void) +{ + main_loop_running = 0; +} + void TXT_GUIMainLoop(void) { - for (;;) + main_loop_running = 1; + + while (main_loop_running) { TXT_DispatchEvents(); TXT_DrawDesktop(); diff --git a/textscreen/txt_desktop.h b/textscreen/txt_desktop.h index 79597039..37da146a 100644 --- a/textscreen/txt_desktop.h +++ b/textscreen/txt_desktop.h @@ -31,6 +31,8 @@ void TXT_AddDesktopWindow(txt_window_t *win); void TXT_RemoveDesktopWindow(txt_window_t *win); void TXT_SetDesktopTitle(char *title); void TXT_DrawDesktop(void); +void TXT_GUIMainLoop(void); +void TXT_ExitMainLoop(void); #endif /* #ifndef TXT_DESKTOP_T */ diff --git a/textscreen/txt_window.c b/textscreen/txt_window.c index b66995d7..9c1f0257 100644 --- a/textscreen/txt_window.c +++ b/textscreen/txt_window.c @@ -45,6 +45,13 @@ void TXT_SetWindowAction(txt_window_t *window, window->actions[position] = action; } +static void DefaultCancelAction(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(window)) +{ + TXT_CAST_ARG(txt_window_t, window); + + TXT_CloseWindow(window); +} + txt_window_t *TXT_NewWindow(char *title) { int i; @@ -74,6 +81,7 @@ txt_window_t *TXT_NewWindow(char *title) cancel_action = TXT_NewWindowAction(KEY_ESCAPE, "Abort"); TXT_SetWindowAction(win, TXT_HORIZ_LEFT, cancel_action); + TXT_SignalConnect(cancel_action, "pressed", DefaultCancelAction, win); accept_action = TXT_NewWindowAction(KEY_ENTER, "Accept"); TXT_SetWindowAction(win, TXT_HORIZ_RIGHT, accept_action); |