diff options
author | Simon Howard | 2006-05-23 00:07:02 +0000 |
---|---|---|
committer | Simon Howard | 2006-05-23 00:07:02 +0000 |
commit | 1de18c1397bfb069771c02336e47b89e098b6f43 (patch) | |
tree | 6fc8d843e31110213543daae8edb145c9f045e05 /textscreen/txt_window_action.c | |
parent | 7666630775f51fe991005ff8219cb4cc0cb70327 (diff) | |
download | chocolate-doom-1de18c1397bfb069771c02336e47b89e098b6f43.tar.gz chocolate-doom-1de18c1397bfb069771c02336e47b89e098b6f43.tar.bz2 chocolate-doom-1de18c1397bfb069771c02336e47b89e098b6f43.zip |
Add window action class for action area labels at the bottom of windows.
Adjust txt_table_t to expand tables to their maximum width when they
only have one column (ensures separators reach the window edges).
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 515
Diffstat (limited to 'textscreen/txt_window_action.c')
-rw-r--r-- | textscreen/txt_window_action.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c new file mode 100644 index 00000000..072a87c5 --- /dev/null +++ b/textscreen/txt_window_action.c @@ -0,0 +1,81 @@ + +#include <string.h> + +#include "doomkeys.h" + +#include "txt_window_action.h" +#include "txt_io.h" +#include "txt_main.h" +#include "txt_window.h" + +static void TXT_WindowActionSizeCalc(TXT_UNCAST_ARG(action), + int *w, int *h) +{ + TXT_CAST_ARG(txt_window_action_t, action); + char buf[10]; + + TXT_GetKeyDescription(action->key, buf); + + // Minimum width is the string length + two spaces for padding + + *w = strlen(action->label) + strlen(buf) + 1; + *h = 1; +} + +static void TXT_WindowActionDrawer(TXT_UNCAST_ARG(action), int w, int selected) +{ + TXT_CAST_ARG(txt_window_action_t, action); + int i; + char buf[10]; + + TXT_GetKeyDescription(action->key, buf); + + 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); +} + +static void TXT_WindowActionDestructor(TXT_UNCAST_ARG(action)) +{ + TXT_CAST_ARG(txt_window_action_t, action); + + free(action->label); +} + +static int TXT_WindowActionKeyPress(TXT_UNCAST_ARG(action), int key) +{ + TXT_CAST_ARG(txt_window_action_t, action); + + if (key == action->key) + { + TXT_EmitSignal(action, "pressed"); + return 1; + } + + return 0; +} + +txt_widget_class_t txt_window_action_class = +{ + TXT_WindowActionSizeCalc, + TXT_WindowActionDrawer, + TXT_WindowActionKeyPress, + TXT_WindowActionDestructor, +}; + +txt_window_action_t *TXT_NewWindowAction(int key, char *label) +{ + txt_window_action_t *action; + + action = malloc(sizeof(txt_window_action_t)); + + TXT_InitWidget(action, &txt_window_action_class); + action->key = key; + action->label = strdup(label); + + return action; +} + |