summaryrefslogtreecommitdiff
path: root/textscreen/txt_table.c
diff options
context:
space:
mode:
authorSimon Howard2006-05-29 21:39:12 +0000
committerSimon Howard2006-05-29 21:39:12 +0000
commitb3e5170bbba1c3048da86a5291cd45524abfeac2 (patch)
treecc272ff689b826eac099e3cb7d53070c7da50c44 /textscreen/txt_table.c
parent64b2890756bc7f48fdf2fd0ef8c25dd8f0fd1c22 (diff)
downloadchocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.tar.gz
chocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.tar.bz2
chocolate-doom-b3e5170bbba1c3048da86a5291cd45524abfeac2.zip
Add ability to make widgets right aligned or centered within tables.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 546
Diffstat (limited to 'textscreen/txt_table.c')
-rw-r--r--textscreen/txt_table.c61
1 files changed, 51 insertions, 10 deletions
diff --git a/textscreen/txt_table.c b/textscreen/txt_table.c
index 20c74b53..e410d4df 100644
--- a/textscreen/txt_table.c
+++ b/textscreen/txt_table.c
@@ -354,15 +354,59 @@ static void CheckValidSelection(txt_table_t *table)
}
}
+static void DrawCell(txt_table_t *table, int x, int y,
+ int draw_x, int draw_y, int w, int selected)
+{
+ txt_widget_t *widget;
+ int cw, ch;
+
+ widget = table->widgets[y * table->columns + x];
+
+ switch (widget->align)
+ {
+ case TXT_HORIZ_LEFT:
+ break;
+
+ case TXT_HORIZ_CENTER:
+ TXT_CalcWidgetSize(widget, &cw, &ch);
+
+ // Separators are always drawn left-aligned.
+
+ if (widget->widget_class != &txt_separator_class)
+ {
+ draw_x += (w - cw) / 2;
+ w = cw;
+ }
+
+ break;
+
+ case TXT_HORIZ_RIGHT:
+ TXT_CalcWidgetSize(widget, &cw, &ch);
+
+ if (widget->widget_class != &txt_separator_class)
+ {
+ draw_x += w - cw;
+ w = cw;
+ }
+
+ break;
+ }
+
+ TXT_GotoXY(draw_x, draw_y);
+
+ TXT_DrawWidget(widget, w, selected && x == table->selected_x
+ && y == table->selected_y);
+}
+
static void TXT_TableDrawer(TXT_UNCAST_ARG(table), int w, int selected)
{
TXT_CAST_ARG(txt_table_t, table);
- txt_widget_t *widget;
int *column_widths;
int *row_heights;
int origin_x, origin_y;
int draw_x, draw_y;
int x, y;
+ int i;
int rows;
// Check the table's current selection points at something valid before
@@ -400,18 +444,15 @@ static void TXT_TableDrawer(TXT_UNCAST_ARG(table), int w, int selected)
for (x=0; x<table->columns; ++x)
{
- if (y * table->columns + x >= table->num_widgets)
- break;
-
- TXT_GotoXY(draw_x, draw_y);
+ i = y * table->columns + x;
- widget = table->widgets[y * table->columns + x];
+ if (i >= table->num_widgets)
+ break;
- if (widget != NULL)
+ if (table->widgets[i] != NULL)
{
- TXT_DrawWidget(widget, column_widths[x],
- selected && x == table->selected_x
- && y == table->selected_y);
+ DrawCell(table, x, y, draw_x, draw_y,
+ column_widths[x], selected);
}
draw_x += column_widths[x];