summaryrefslogtreecommitdiffstats
path: root/grid.c
diff options
context:
space:
mode:
authornicm <nicm>2017-02-13 16:05:30 +0000
committernicm <nicm>2017-02-13 16:05:30 +0000
commit4c2a78029d0cb307899be42d94d3c255b97fb15f (patch)
tree8aa3cf637c8555114378b4565623ff210d04031b /grid.c
parent921880e00beb052d2c59fbeba75d0a0aaa8888ea (diff)
Collected cells may still need to be extended for RGB colours.
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/grid.c b/grid.c
index 388a2c1b..3beaf0f1 100644
--- a/grid.c
+++ b/grid.c
@@ -78,6 +78,20 @@ grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc,
gce->data.data = c;
}
+/* Check if a cell should be extended. */
+static int
+grid_need_extended_cell(const struct grid_cell_entry *gce,
+ const struct grid_cell *gc)
+{
+ if (gce->flags & GRID_FLAG_EXTENDED)
+ return (1);
+ if (gc->data.size != 1 || gc->data.width != 1)
+ return (1);
+ if ((gc->fg & COLOUR_FLAG_RGB) ||(gc->bg & COLOUR_FLAG_RGB))
+ return (1);
+ return (0);
+}
+
/* Set cell as extended. */
static struct grid_cell *
grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce,
@@ -382,7 +396,6 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
{
struct grid_line *gl;
struct grid_cell_entry *gce;
- int extended;
if (grid_check_y(gd, py) != 0)
return;
@@ -394,14 +407,7 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc)
gl->cellused = px + 1;
gce = &gl->celldata[px];
- extended = (gce->flags & GRID_FLAG_EXTENDED);
- if (!extended && (gc->data.size != 1 || gc->data.width != 1))
- extended = 1;
- if (!extended && (gc->fg & COLOUR_FLAG_RGB))
- extended = 1;
- if (!extended && (gc->bg & COLOUR_FLAG_RGB))
- extended = 1;
- if (extended)
+ if (grid_need_extended_cell(gce, gc))
grid_extended_cell(gl, gce, gc);
else
grid_store_cell(gce, gc, gc->data.data[0]);
@@ -428,9 +434,8 @@ grid_set_cells(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc,
for (i = 0; i < slen; i++) {
gce = &gl->celldata[px + i];
- if (gce->flags & GRID_FLAG_EXTENDED) {
- gcp = &gl->extddata[gce->offset];
- memcpy(gcp, gc, sizeof *gcp);
+ if (grid_need_extended_cell(gce, gc)) {
+ gcp = grid_extended_cell(gl, gce, gc);
utf8_set(&gcp->data, s[i]);
} else
grid_store_cell(gce, gc, s[i]);