summaryrefslogtreecommitdiffstats
path: root/screen-write.c
diff options
context:
space:
mode:
authornicm <nicm>2019-05-10 14:12:47 +0000
committernicm <nicm>2019-05-10 14:12:47 +0000
commit004a9b52f0389700194d2789674a1fda90409438 (patch)
tree4c2771ae062e5b14221cb600377b873e3963f67a /screen-write.c
parentcb10bfb8effff694460af6927c30d8f805f8b9c0 (diff)
Add a function to draw a simple menu onto a screen.
Diffstat (limited to 'screen-write.c')
-rw-r--r--screen-write.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/screen-write.c b/screen-write.c
index 237b6359..ad3808ae 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -403,6 +403,44 @@ screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
screen_write_set_cursor(ctx, cx, cy);
}
+/* Draw a menu on screen. */
+void
+screen_write_menu(struct screen_write_ctx *ctx, struct menu *menu, int choice)
+{
+ struct screen *s = ctx->s;
+ struct grid_cell gc;
+ u_int cx, cy, i, j;
+
+ cx = s->cx;
+ cy = s->cy;
+
+ memcpy(&gc, &grid_default_cell, sizeof gc);
+
+ screen_write_box(ctx, menu->width + 4, menu->count + 2);
+ screen_write_cursormove(ctx, cx + 2, cy, 0);
+ format_draw(ctx, &gc, menu->width, menu->title, NULL);
+
+ for (i = 0; i < menu->count; i++) {
+ if (menu->items[i].name == NULL) {
+ screen_write_cursormove(ctx, cx, cy + 1 + i, 0);
+ screen_write_hline(ctx, menu->width + 4, 1, 1);
+ } else {
+ if (choice >= 0 && i == (u_int)choice)
+ gc.attr |= GRID_ATTR_REVERSE;
+ screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
+ for (j = 0; j < menu->width; j++)
+ screen_write_putc(ctx, &gc, ' ');
+ screen_write_cursormove(ctx, cx + 2, cy + 1 + i, 0);
+ format_draw(ctx, &gc, menu->width, menu->items[i].name,
+ NULL);
+ if (choice >= 0 && i == (u_int)choice)
+ gc.attr &= ~GRID_ATTR_REVERSE;
+ }
+ }
+
+ screen_write_set_cursor(ctx, cx, cy);
+}
+
/* Draw a box on screen. */
void
screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny)