From 71a127463aeceb7906a6a6a1980dcde179834cc9 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 27 Nov 2019 21:29:28 -0500 Subject: [PATCH] ncplane_create() --- src/demo/widecolor.c | 4 ++-- src/lib/notcurses.c | 35 ++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/demo/widecolor.c b/src/demo/widecolor.c index 1d869219e..24a022ace 100644 --- a/src/demo/widecolor.c +++ b/src/demo/widecolor.c @@ -11,7 +11,7 @@ int widecolor_demo(struct notcurses* nc){ "Война и мир", "Бра́тья Карама́зовы", "Час сэканд-хэнд", - "ஸீரோ டிகிரி", + //"ஸீரோ டிகிரி", "Tonio Kröger", /*"بين القصرين", "قصر الشوق", @@ -259,7 +259,7 @@ int widecolor_demo(struct notcurses* nc){ } }while(y < maxy && x < maxx); ncplane_fg_rgb8(n, 255, 255, 255); - // ncplane_set_style(n, WA_BOLD); + ncplane_set_style(n, WA_BOLD); ncplane_cursor_move_yx(n, 2, 2); ncplane_printf(n, " %dx%d (%d/%d) ", maxx, maxy, i, sizeof(steps) / sizeof(*steps)); ncplane_cursor_move_yx(n, 3, 2); diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 50063d796..40b4b6b61 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -42,6 +42,7 @@ typedef struct ncplane { egcpool pool; // attached storage pool for UTF-8 EGCs uint64_t channels; // works the same way as cells uint32_t attrword; // same deal as in a cell + void* userptr; // slot for the user to stick some opaque pointer } ncplane; typedef struct ncstats { @@ -253,14 +254,8 @@ term_emit(const char* seq, FILE* out, bool flush){ return 0; } -// create an ncplane of the specified dimensions, but do not yet place it in -// the z-buffer. clear out all cells. this is for a wholly new context. static ncplane* -create_initial_ncplane(notcurses* nc){ - int rows, cols; - if(update_term_dimensions(nc, &rows, &cols)){ - return NULL; - } +ncplane_create(notcurses* nc, int rows, int cols){ ncplane* p = malloc(sizeof(*p)); size_t fbsize = sizeof(*p->fb) * (rows * cols); if((p->fb = malloc(fbsize)) == NULL){ @@ -278,6 +273,17 @@ create_initial_ncplane(notcurses* nc){ return p; } +// create an ncplane of the specified dimensions, but do not yet place it in +// the z-buffer. clear out all cells. this is for a wholly new context. +static ncplane* +create_initial_ncplane(notcurses* nc){ + int rows, cols; + if(update_term_dimensions(nc, &rows, &cols)){ + return NULL; + } + return ncplane_create(nc, rows, cols); +} + // Call this when the screen size changes. Takes a flat // array of *rows * *cols cells (may be NULL if *rows == *cols == 0). Gets the // new size, and copies what can be copied from the old stdscr. Assumes that @@ -327,6 +333,21 @@ const ncplane* notcurses_stdplane_const(const notcurses* nc){ return nc->stdscr; } +ncplane* notcurses_newplane(notcurses* nc, int rows, int cols, + int yoff, int xoff, void* opaque){ + if(rows <= 0 || cols <= 0){ + return NULL; + } + ncplane* n = create_initial_ncplane(nc); + if(n == NULL){ + return n; + } + n->absx = xoff; + n->absy = yoff; + n->userptr = opaque; + return n; +} + int ncplane_destroy(notcurses* nc, ncplane* ncp){ if(ncp){ if(nc->stdscr == ncp){