2019-06-17 19:33:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2019-07-01 12:23:38 +02:00
|
|
|
#include <stddef.h>
|
2019-06-17 19:33:10 +02:00
|
|
|
#include "terminal.h"
|
2019-07-01 12:23:38 +02:00
|
|
|
|
2020-05-16 23:43:05 +02:00
|
|
|
void grid_swap_row(struct grid *grid, int row_a, int row_b);
|
2019-08-22 17:33:23 +02:00
|
|
|
struct row *grid_row_alloc(int cols, bool initialize);
|
2019-07-10 16:27:55 +02:00
|
|
|
void grid_row_free(struct row *row);
|
2020-04-16 19:38:30 +02:00
|
|
|
void grid_reflow(
|
2020-02-15 22:19:08 +01:00
|
|
|
struct grid *grid, int new_rows, int new_cols,
|
2020-04-17 21:04:32 +02:00
|
|
|
int old_screen_rows, int new_screen_rows,
|
|
|
|
|
size_t tracking_points_count,
|
2020-04-17 22:17:33 +02:00
|
|
|
struct coord *const tracking_points[static tracking_points_count]);
|
2019-07-10 16:27:55 +02:00
|
|
|
|
2019-08-27 19:33:19 +02:00
|
|
|
static inline int
|
|
|
|
|
grid_row_absolute(const struct grid *grid, int row_no)
|
|
|
|
|
{
|
|
|
|
|
return (grid->offset + row_no) & (grid->num_rows - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
grid_row_absolute_in_view(const struct grid *grid, int row_no)
|
|
|
|
|
{
|
|
|
|
|
return (grid->view + row_no) & (grid->num_rows - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-08 13:57:31 +02:00
|
|
|
static inline struct row *
|
2019-08-22 17:33:23 +02:00
|
|
|
_grid_row_maybe_alloc(struct grid *grid, int row_no, bool alloc_if_null)
|
2019-07-08 13:57:31 +02:00
|
|
|
{
|
|
|
|
|
assert(grid->offset >= 0);
|
2019-07-10 16:27:55 +02:00
|
|
|
|
2019-08-27 19:33:19 +02:00
|
|
|
int real_row = grid_row_absolute(grid, row_no);
|
2019-07-10 16:27:55 +02:00
|
|
|
struct row *row = grid->rows[real_row];
|
|
|
|
|
|
2019-08-22 17:33:23 +02:00
|
|
|
if (row == NULL && alloc_if_null) {
|
|
|
|
|
row = grid_row_alloc(grid->num_cols, false);
|
2019-07-10 16:27:55 +02:00
|
|
|
grid->rows[real_row] = row;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 17:33:23 +02:00
|
|
|
assert(row != NULL);
|
2019-07-10 16:27:55 +02:00
|
|
|
return row;
|
2019-07-08 13:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-22 17:33:23 +02:00
|
|
|
static inline struct row *
|
|
|
|
|
grid_row(struct grid *grid, int row_no)
|
|
|
|
|
{
|
|
|
|
|
return _grid_row_maybe_alloc(grid, row_no, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline struct row *
|
|
|
|
|
grid_row_and_alloc(struct grid *grid, int row_no)
|
|
|
|
|
{
|
|
|
|
|
return _grid_row_maybe_alloc(grid, row_no, true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-09 16:26:36 +02:00
|
|
|
static inline struct row *
|
2019-07-10 16:27:55 +02:00
|
|
|
grid_row_in_view(struct grid *grid, int row_no)
|
2019-07-09 16:26:36 +02:00
|
|
|
{
|
|
|
|
|
assert(grid->view >= 0);
|
|
|
|
|
|
2019-08-27 19:33:19 +02:00
|
|
|
int real_row = grid_row_absolute_in_view(grid, row_no);
|
2019-07-10 16:27:55 +02:00
|
|
|
struct row *row = grid->rows[real_row];
|
|
|
|
|
|
|
|
|
|
assert(row != NULL);
|
|
|
|
|
return row;
|
|
|
|
|
}
|