summaryrefslogtreecommitdiff
path: root/textscreen
diff options
context:
space:
mode:
authorSimon Howard2009-11-21 16:36:46 +0000
committerSimon Howard2009-11-21 16:36:46 +0000
commitafa0c4c7979c1508605d0e79487f299cd03adda6 (patch)
tree7df1745badf169e4490e3a56a89a28ac37977c14 /textscreen
parent095bc1110b3c11fbf2e17bfd51bf78909fe34662 (diff)
parent2c6e7b2f10c32ca0406ca6753e7701d83e6dea8f (diff)
downloadchocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.tar.gz
chocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.tar.bz2
chocolate-doom-afa0c4c7979c1508605d0e79487f299cd03adda6.zip
Merge from trunk.
Subversion-branch: /branches/raven-branch Subversion-revision: 1737
Diffstat (limited to 'textscreen')
-rw-r--r--textscreen/txt_desktop.c4
-rw-r--r--textscreen/txt_dropdown.c2
-rw-r--r--textscreen/txt_gui.c9
-rw-r--r--textscreen/txt_gui.h6
-rw-r--r--textscreen/txt_inputbox.c2
-rw-r--r--textscreen/txt_io.c6
-rw-r--r--textscreen/txt_io.h2
-rw-r--r--textscreen/txt_main.h2
-rw-r--r--textscreen/txt_scrollpane.c76
-rw-r--r--textscreen/txt_sdl.c49
-rw-r--r--textscreen/txt_table.c82
-rw-r--r--textscreen/txt_table.h13
-rw-r--r--textscreen/txt_widget.c4
-rw-r--r--textscreen/txt_widget.h4
-rw-r--r--textscreen/txt_window_action.c2
-rw-r--r--textscreen/txt_window_action.h2
16 files changed, 233 insertions, 32 deletions
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 e7f0472e..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,17 +224,16 @@ 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);
if (VALID_Y(y))
{
- p = s;
x1 = x;
for (p = s; *p != '\0'; ++p)
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_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_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_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_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_sdl.c b/textscreen/txt_sdl.c
index cfeaf0b0..71736720 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
//
@@ -221,7 +221,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];
@@ -267,19 +267,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; y1<y+h; ++y1)
+ for (y1=y; y1<y_end; ++y1)
{
- for (x1=x; x1<x+w; ++x1)
+ for (x1=x; x1<x_end; ++x1)
{
UpdateCharacter(x1, y1);
}
}
- SDL_UpdateRect(screen, x * font->w, 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)
@@ -289,7 +314,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;
@@ -328,7 +357,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:
@@ -339,9 +370,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;
@@ -462,7 +495,7 @@ signed int TXT_GetChar(void)
return -1;
}
-static char *SpecialKeyName(int key)
+static const char *SpecialKeyName(int key)
{
switch (key)
{
@@ -528,7 +561,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_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 */
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