diff options
author | James Haley | 2010-01-26 00:59:02 +0000 |
---|---|---|
committer | James Haley | 2010-01-26 00:59:02 +0000 |
commit | b80409202d07732ec201c9816887262b505b81d4 (patch) | |
tree | 364dcb86f2c22411a720447bfa21c4de9191ff6f /textscreen/txt_table.c | |
parent | 66e8dc63bd0b384c99f0d0ff60b3d75c42d441b1 (diff) | |
parent | 8f6edc1f7402215c5e38d1f03939ce6b5ff5e3ae (diff) | |
download | chocolate-doom-b80409202d07732ec201c9816887262b505b81d4.tar.gz chocolate-doom-b80409202d07732ec201c9816887262b505b81d4.tar.bz2 chocolate-doom-b80409202d07732ec201c9816887262b505b81d4.zip |
Merge from raven-branch
Subversion-branch: /branches/strife-branch
Subversion-revision: 1825
Diffstat (limited to 'textscreen/txt_table.c')
-rw-r--r-- | textscreen/txt_table.c | 82 |
1 files changed, 82 insertions, 0 deletions
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; +} + |