From 1715116ef17946f1c77fb2da220384e7889f1329 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 20 Jul 2009 22:27:59 +0000 Subject: Remove redundant variable assignment (thanks Quasar/Yagisan) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1630 --- textscreen/txt_gui.c | 1 - 1 file changed, 1 deletion(-) (limited to 'textscreen') diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index e7f0472e..276176ec 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -234,7 +234,6 @@ void TXT_DrawString(char *s) if (VALID_Y(y)) { - p = s; x1 = x; for (p = s; *p != '\0'; ++p) -- cgit v1.2.3 From ec81c27ef5af20761afb2295cdd7c92b213a5807 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 27 Aug 2009 23:27:47 +0000 Subject: Allow PGUP/PGDN to scroll up and down in scroll panes (thanks LionsPhil). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1631 --- textscreen/txt_scrollpane.c | 76 ++++++++++++++++++++++++++++++++++++++++- textscreen/txt_table.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ textscreen/txt_table.h | 13 +++++++ 3 files changed, 170 insertions(+), 1 deletion(-) (limited to 'textscreen') diff --git a/textscreen/txt_scrollpane.c b/textscreen/txt_scrollpane.c index ef6e4fb3..d81cce4b 100644 --- a/textscreen/txt_scrollpane.c +++ b/textscreen/txt_scrollpane.c @@ -254,10 +254,53 @@ static void ShowSelectedWidget(txt_scrollpane_t *scrollpane) } } +// Another hack for tables - when scrolling in 'pages', the normal key press +// event does not provide children with enough information to know how far +// to move their selection to reach a new page. This function does so. +// Note that it *only* affects scrolling in pages, not with arrows! +// A side-effect of this, rather than 'pulling' the selection to fit within +// the new page, is that we will jump straight over ranges of unselectable +// items longer than a page, but that is also true of arrow-key scrolling. +// The other unfortunate effect of doing things this way is that page keys +// have no effect on tables _not_ in scrollpanes: not even home/end. + +static int PageSelectedWidget(txt_scrollpane_t *scrollpane, int key) +{ + int pagex = 0; // No page left/right yet, but some keyboards have them + int pagey = 0; + + // Subtract one from the absolute page distance as this is slightly more + // intuitive: a page down first jumps to the bottom of the current page, + // then proceeds to scroll onwards. + + switch (key) + { + case KEY_PGUP: + pagey = 1 - scrollpane->h; + break; + + case KEY_PGDN: + pagey = scrollpane->h - 1; + break; + + default: // We shouldn't even be in this function + return 0; + } + + if (scrollpane->child->widget_class == &txt_table_class) + { + return TXT_PageTable(scrollpane->child, pagex, pagey); + } + + return 0; +} + // Interpret arrow key presses as scroll commands static int InterpretScrollKey(txt_scrollpane_t *scrollpane, int key) { + int maxy; + switch (key) { case KEY_UPARROW: @@ -292,6 +335,31 @@ static int InterpretScrollKey(txt_scrollpane_t *scrollpane, int key) } break; + case KEY_PGUP: + if (scrollpane->y > 0) + { + scrollpane->y -= scrollpane->h; + if (scrollpane->y < 0) + { + scrollpane->y = 0; + } + return 1; + } + break; + + case KEY_PGDN: + maxy = FullHeight(scrollpane) - scrollpane->h; + if (scrollpane->y < maxy) + { + scrollpane->y += scrollpane->h; + if (scrollpane->y > maxy) + { + scrollpane->y = maxy; + } + return 1; + } + break; + default: break; } @@ -316,8 +384,14 @@ static int TXT_ScrollPaneKeyPress(TXT_UNCAST_ARG(scrollpane), int key) if (scrollpane->child->widget_class == &txt_table_class && (key == KEY_UPARROW || key == KEY_DOWNARROW - || key == KEY_LEFTARROW || key == KEY_RIGHTARROW)) + || key == KEY_LEFTARROW || key == KEY_RIGHTARROW + || key == KEY_PGUP || key == KEY_PGDN)) { + if (PageSelectedWidget(scrollpane, key)) + { + result = 1; + } + ShowSelectedWidget(scrollpane); } diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c index 0d4d1e35..1b432681 100644 --- a/textscreen/txt_table.c +++ b/textscreen/txt_table.c @@ -770,3 +770,85 @@ void TXT_SetColumnWidths(TXT_UNCAST_ARG(table), ...) va_end(args); } +// Moves the select by at least the given number of characters. +// Currently quietly ignores pagex, as we don't use it. + +int TXT_PageTable(TXT_UNCAST_ARG(table), int pagex, int pagey) +{ + TXT_CAST_ARG(txt_table_t, table); + unsigned int *column_widths; + unsigned int *row_heights; + int rows; + int changed = 0; + + rows = TableRows(table); + + row_heights = malloc(sizeof(int) * rows); + column_widths = malloc(sizeof(int) * table->columns); + + CalcRowColSizes(table, row_heights, column_widths); + + if (pagex) + { + // @todo Jump selection to the left or right as needed + } + + if (pagey) + { + int new_x, new_y; + int distance = 0; + int dir; + + // What direction are we moving? + + if (pagey > 0) + { + dir = 1; + } + else + { + dir = -1; + } + + // Move the cursor until the desired distance is reached. + + new_y = table->selected_y; + + while (new_y >= 0 && new_y < rows) + { + // We are about to travel a distance equal to the height of the row + // we are about to leave. + + distance += row_heights[new_y]; + + // *Now* increment the loop. + + new_y += dir; + + new_x = FindSelectableColumn(table, new_y, table->selected_x); + + if (new_x >= 0) + { + // Found a selectable widget in this column! + // Select it anyway in case we don't find something better. + + table->selected_x = new_x; + table->selected_y = new_y; + changed = 1; + + // ...but is it far enough away? + + if (distance >= abs(pagey)) + { + break; + } + } + } + } + + free(row_heights); + free(column_widths); + + return changed; +} + diff --git a/textscreen/txt_table.h b/textscreen/txt_table.h index 0e7fbe94..0166abee 100644 --- a/textscreen/txt_table.h +++ b/textscreen/txt_table.h @@ -178,6 +178,19 @@ void TXT_SetColumnWidths(TXT_UNCAST_ARG(table), ...); void TXT_ClearTable(TXT_UNCAST_ARG(table)); +/** + * Hack to move the selection in a table by a 'page', triggered by the + * scrollpane. This acts as per the keyboard events for the arrows, but moves + * the selection by at least the specified number of characters. + * + * @param table The table. + * @param pagex Minimum distance to move the selection horizontally. + * @param pagey Minimum distance to move the selection vertically. + * @return Non-zero if the selection has been changed. + */ + +int TXT_PageTable(TXT_UNCAST_ARG(table), int pagex, int pagey); + #endif /* #ifndef TXT_TABLE_T */ -- cgit v1.2.3 From 42f7a9b8a27ae1192b49005f5be3eba32f740d05 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sun, 20 Sep 2009 15:27:40 +0000 Subject: Use "const char" in libtextscreen where appropriate (thanks entryway). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1679 --- textscreen/txt_desktop.c | 4 ++-- textscreen/txt_dropdown.c | 2 +- textscreen/txt_gui.c | 8 ++++---- textscreen/txt_gui.h | 6 +++--- textscreen/txt_io.c | 6 +++--- textscreen/txt_io.h | 2 +- textscreen/txt_sdl.c | 6 +++--- textscreen/txt_widget.c | 4 ++-- textscreen/txt_widget.h | 4 ++-- textscreen/txt_window_action.c | 2 +- textscreen/txt_window_action.h | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) (limited to 'textscreen') diff --git a/textscreen/txt_desktop.c b/textscreen/txt_desktop.c index 99a5062d..f833441f 100644 --- a/textscreen/txt_desktop.c +++ b/textscreen/txt_desktop.c @@ -61,7 +61,7 @@ void TXT_RemoveDesktopWindow(txt_window_t *win) num_windows = to; } -static void DrawDesktopBackground(char *title) +static void DrawDesktopBackground(const char *title) { int i; unsigned char *screendata; @@ -117,7 +117,7 @@ void TXT_SetDesktopTitle(char *title) void TXT_DrawDesktop(void) { int i; - char *title; + const char *title; TXT_InitClipArea(); diff --git a/textscreen/txt_dropdown.c b/textscreen/txt_dropdown.c index c5c4f99f..efed8d67 100644 --- a/textscreen/txt_dropdown.c +++ b/textscreen/txt_dropdown.c @@ -193,7 +193,7 @@ static void TXT_DropdownListDrawer(TXT_UNCAST_ARG(list), int selected) { TXT_CAST_ARG(txt_dropdown_list_t, list); unsigned int i; - char *str; + const char *str; // Set bg/fg text colors. diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c index 276176ec..ec166415 100644 --- a/textscreen/txt_gui.c +++ b/textscreen/txt_gui.c @@ -55,7 +55,7 @@ static txt_cliparea_t *cliparea = NULL; #define VALID_X(x) ((x) >= cliparea->x1 && (x) < cliparea->x2) #define VALID_Y(y) ((y) >= cliparea->y1 && (y) < cliparea->y2) -void TXT_DrawDesktopBackground(char *title) +void TXT_DrawDesktopBackground(const char *title) { int i; unsigned char *screendata; @@ -125,7 +125,7 @@ void TXT_DrawShadow(int x, int y, int w, int h) } } -void TXT_DrawWindowFrame(char *title, int x, int y, int w, int h) +void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h) { int x1, y1; int bx, by; @@ -224,11 +224,11 @@ void TXT_DrawSeparator(int x, int y, int w) } } -void TXT_DrawString(char *s) +void TXT_DrawString(const char *s) { int x, y; int x1; - char *p; + const char *p; TXT_GetXY(&x, &y); diff --git a/textscreen/txt_gui.h b/textscreen/txt_gui.h index 3795c65a..ad7ae428 100644 --- a/textscreen/txt_gui.h +++ b/textscreen/txt_gui.h @@ -27,10 +27,10 @@ #ifndef TXT_GUI_H #define TXT_GUI_H -void TXT_DrawDesktopBackground(char *title); -void TXT_DrawWindowFrame(char *title, int x, int y, int w, int h); +void TXT_DrawDesktopBackground(const char *title); +void TXT_DrawWindowFrame(const char *title, int x, int y, int w, int h); void TXT_DrawSeparator(int x, int y, int w); -void TXT_DrawString(char *s); +void TXT_DrawString(const char *s); void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range); void TXT_DrawVertScrollbar(int x, int y, int h, int cursor, int range); diff --git a/textscreen/txt_io.c b/textscreen/txt_io.c index 1e8106e7..1ecc7bd6 100644 --- a/textscreen/txt_io.c +++ b/textscreen/txt_io.c @@ -33,7 +33,7 @@ static struct { txt_color_t color; - char *name; + const char *name; } colors[] = { {TXT_COLOR_BLACK, "black"}, {TXT_COLOR_BLUE, "blue"}, @@ -147,11 +147,11 @@ void TXT_PutChar(int c) PutChar(screen, c); } -void TXT_Puts(char *s) +void TXT_Puts(const char *s) { int previous_color = TXT_COLOR_BLACK; unsigned char *screen; - char *p; + const char *p; char colorname_buf[20]; char *ending; int col; diff --git a/textscreen/txt_io.h b/textscreen/txt_io.h index 78c68f46..dc25aa93 100644 --- a/textscreen/txt_io.h +++ b/textscreen/txt_io.h @@ -30,7 +30,7 @@ #include "txt_main.h" void TXT_PutChar(int c); -void TXT_Puts(char *s); +void TXT_Puts(const char *s); void TXT_GotoXY(int x, int y); void TXT_GetXY(int *x, int *y); void TXT_FGColor(txt_color_t color); diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 367ed095..bc98a51b 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -217,7 +217,7 @@ static inline void UpdateCharacter(int x, int y) unsigned char *p; unsigned char *s, *s1; int bg, fg; - int x1, y1; + unsigned int x1, y1; p = &screendata[(y * TXT_SCREEN_W + x) * 2]; character = p[0]; @@ -458,7 +458,7 @@ signed int TXT_GetChar(void) return -1; } -static char *SpecialKeyName(int key) +static const char *SpecialKeyName(int key) { switch (key) { @@ -524,7 +524,7 @@ static char *SpecialKeyName(int key) void TXT_GetKeyDescription(int key, char *buf) { - char *keyname; + const char *keyname; keyname = SpecialKeyName(key); diff --git a/textscreen/txt_widget.c b/textscreen/txt_widget.c index 2f019c94..2300b32c 100644 --- a/textscreen/txt_widget.c +++ b/textscreen/txt_widget.c @@ -94,7 +94,7 @@ void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class) } void TXT_SignalConnect(TXT_UNCAST_ARG(widget), - char *signal_name, + const char *signal_name, TxtWidgetSignalFunc func, void *user_data) { @@ -117,7 +117,7 @@ void TXT_SignalConnect(TXT_UNCAST_ARG(widget), callback->user_data = user_data; } -void TXT_EmitSignal(TXT_UNCAST_ARG(widget), char *signal_name) +void TXT_EmitSignal(TXT_UNCAST_ARG(widget), const char *signal_name) { TXT_CAST_ARG(txt_widget_t, widget); txt_callback_table_t *table; diff --git a/textscreen/txt_widget.h b/textscreen/txt_widget.h index 63cc5f35..9688829d 100644 --- a/textscreen/txt_widget.h +++ b/textscreen/txt_widget.h @@ -106,7 +106,7 @@ struct txt_widget_s void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class); void TXT_CalcWidgetSize(TXT_UNCAST_ARG(widget)); void TXT_DrawWidget(TXT_UNCAST_ARG(widget), int selected); -void TXT_EmitSignal(TXT_UNCAST_ARG(widget), char *signal_name); +void TXT_EmitSignal(TXT_UNCAST_ARG(widget), const char *signal_name); int TXT_WidgetKeyPress(TXT_UNCAST_ARG(widget), int key); void TXT_WidgetMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b); void TXT_DestroyWidget(TXT_UNCAST_ARG(widget)); @@ -121,7 +121,7 @@ void TXT_LayoutWidget(TXT_UNCAST_ARG(widget)); * @param user_data User-specified pointer to pass to the callback function. */ -void TXT_SignalConnect(TXT_UNCAST_ARG(widget), char *signal_name, +void TXT_SignalConnect(TXT_UNCAST_ARG(widget), const char *signal_name, TxtWidgetSignalFunc func, void *user_data); /** diff --git a/textscreen/txt_window_action.c b/textscreen/txt_window_action.c index 45a2482c..a326a5ed 100644 --- a/textscreen/txt_window_action.c +++ b/textscreen/txt_window_action.c @@ -101,7 +101,7 @@ txt_widget_class_t txt_window_action_class = NULL, }; -txt_window_action_t *TXT_NewWindowAction(int key, char *label) +txt_window_action_t *TXT_NewWindowAction(int key, const char *label) { txt_window_action_t *action; diff --git a/textscreen/txt_window_action.h b/textscreen/txt_window_action.h index ab87f72c..7f93dd48 100644 --- a/textscreen/txt_window_action.h +++ b/textscreen/txt_window_action.h @@ -59,7 +59,7 @@ struct txt_window_action_s * @return Pointer to the new window action widget. */ -txt_window_action_t *TXT_NewWindowAction(int key, char *label); +txt_window_action_t *TXT_NewWindowAction(int key, const char *label); /** * Create a new window action that closes the window when the -- cgit v1.2.3 From 410579ec66f7df8757cb980c0a78e3161b7f20d5 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Wed, 30 Sep 2009 23:07:03 +0000 Subject: Change British English spellings to American English, for consistency. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1699 --- textscreen/txt_inputbox.c | 2 +- textscreen/txt_main.h | 2 +- textscreen/txt_sdl.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'textscreen') diff --git a/textscreen/txt_inputbox.c b/textscreen/txt_inputbox.c index 9151d431..3e52bae9 100644 --- a/textscreen/txt_inputbox.c +++ b/textscreen/txt_inputbox.c @@ -53,7 +53,7 @@ static void TXT_InputBoxDrawer(TXT_UNCAST_ARG(inputbox), int selected) w = inputbox->widget.w; - // Select the background colour based on whether we are currently + // Select the background color based on whether we are currently // editing, and if not, whether the widget is selected. if (inputbox->editing && selected) diff --git a/textscreen/txt_main.h b/textscreen/txt_main.h index 4357d656..add30fa3 100644 --- a/textscreen/txt_main.h +++ b/textscreen/txt_main.h @@ -67,7 +67,7 @@ typedef enum TXT_COLOR_BRIGHT_WHITE, } txt_color_t; -// Initialise the screen +// Initialize the screen // Returns 1 if successful, 0 if failed. int TXT_Init(void); diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index bc98a51b..0b11aeab 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -162,7 +162,7 @@ static void ChooseFont(void) } // -// Initialise text mode screen +// Initialize text mode screen // // Returns 1 if successful, 0 if an error occurred // -- cgit v1.2.3 From 3771126689527293eb4ad658b338d7910bf79012 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Mon, 26 Oct 2009 19:28:12 +0000 Subject: Initial hacks for compiling under SDL 1.3. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1726 --- textscreen/txt_sdl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'textscreen') diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 0b11aeab..4f8bc2a8 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -285,7 +285,11 @@ void TXT_UpdateScreen(void) void TXT_GetMousePosition(int *x, int *y) { +#if SDL_VERSION_ATLEAST(1, 3, 0) + SDL_GetMouseState(0, x, y); +#else SDL_GetMouseState(x, y); +#endif *x /= font->w; *y /= font->h; @@ -324,7 +328,9 @@ static int TranslateKey(SDL_keysym *sym) case SDLK_PAUSE: return KEY_PAUSE; +#if !SDL_VERSION_ATLEAST(1, 3, 0) case SDLK_EQUALS: return KEY_EQUALS; +#endif case SDLK_LSHIFT: case SDLK_RSHIFT: @@ -335,9 +341,11 @@ static int TranslateKey(SDL_keysym *sym) return KEY_RCTRL; case SDLK_LALT: - case SDLK_LMETA: case SDLK_RALT: +#if !SDL_VERSION_ATLEAST(1, 3, 0) + case SDLK_LMETA: case SDLK_RMETA: +#endif return KEY_RALT; case SDLK_CAPSLOCK: return KEY_CAPSLOCK; -- cgit v1.2.3 From 9ea3cb62c94b2f293cc5dbc95518b8312434e093 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 5 Nov 2009 19:57:55 +0000 Subject: Perform bounds checking on values passed to TXT_UpdateScreenArea() to avoid crashes. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 1728 --- textscreen/txt_sdl.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'textscreen') diff --git a/textscreen/txt_sdl.c b/textscreen/txt_sdl.c index 4f8bc2a8..cd7dd77d 100644 --- a/textscreen/txt_sdl.c +++ b/textscreen/txt_sdl.c @@ -263,19 +263,44 @@ static inline void UpdateCharacter(int x, int y) } } +static int LimitToRange(int val, int min, int max) +{ + if (val < min) + { + return min; + } + else if (val > max) + { + return max; + } + else + { + return val; + } +} + void TXT_UpdateScreenArea(int x, int y, int w, int h) { int x1, y1; + int x_end; + int y_end; + + x_end = LimitToRange(x + w, 0, TXT_SCREEN_W - 1); + y_end = LimitToRange(y + h, 0, TXT_SCREEN_H - 1); + x = LimitToRange(x, 0, TXT_SCREEN_W - 1); + y = LimitToRange(y, 0, TXT_SCREEN_H - 1); - for (y1=y; y1w, y * font->h, w * font->w, h * font->h); + SDL_UpdateRect(screen, + x * font->w, y * font->h, + (x_end - x) * font->w, (y_end - y) * font->h); } void TXT_UpdateScreen(void) -- cgit v1.2.3