From 51e90ca7e9f684afb6d99a672ad675303f95997d Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 7 Nov 2021 07:02:38 -0500 Subject: [PATCH] [hud] use ncmetric for elapsed time --- src/demo/hud.c | 19 ++++++++++++++----- src/demo/outro.c | 6 +++--- src/demo/reel.c | 2 +- src/demo/unicodeblocks.c | 9 +++++---- src/info/main.c | 2 +- src/lib/visual-details.h | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/demo/hud.c b/src/demo/hud.c index 39a4ec0ab..b7ac2980e 100644 --- a/src/demo/hud.c +++ b/src/demo/hud.c @@ -392,9 +392,13 @@ hud_print_finished(elem* list){ if(ncplane_printf_yx(hud, line, 1, "%d", e->frames) < 0){ return -1; } - if(ncplane_printf_yx(hud, line, 7, "%"PRIu64".%03"PRIu64"s", - e->totalns / NANOSECS_IN_SEC, - (e->totalns % NANOSECS_IN_SEC) / 1000000) < 0){ + char buf[PREFIXCOLUMNS]; + ncmetric(e->totalns, NANOSECS_IN_SEC, buf, 0, 1000, '\0'); + for(size_t x = 6 ; x < 14 - strlen(buf) ; ++x){ + nccell ci = CELL_TRIVIAL_INITIALIZER; + ncplane_putc_yx(hud, 1, x, &ci); + } + if(ncplane_printf_yx(hud, line, 14 - strlen(buf), "%ss", buf) < 0){ return -1; } if(ncplane_putstr_yx(hud, line, 16, e->name) < 0){ @@ -608,8 +612,13 @@ int demo_render(struct notcurses* nc){ if(ncplane_printf_yx(hud, 1, 1, "%d", elems->frames) < 0){ return -1; } - if(ncplane_printf_yx(hud, 1, 7, "%"PRIu64".%03"PRIu64"s", ns / NANOSECS_IN_SEC, - (ns % NANOSECS_IN_SEC) / 1000000) < 0){ + char buf[PREFIXCOLUMNS]; + ncmetric(ns, NANOSECS_IN_SEC, buf, 0, 1000, '\0'); + for(size_t x = 6 ; x < 14 - strlen(buf) ; ++x){ + nccell ci = CELL_TRIVIAL_INITIALIZER; + ncplane_putc_yx(hud, 1, x, &ci); + } + if(ncplane_printf_yx(hud, 1, 14 - strlen(buf), "%ss", buf) < 0){ return -1; } if(ncplane_putstr_yx(hud, 1, 16, elems->name) < 0){ diff --git a/src/demo/outro.c b/src/demo/outro.c index 0ed0770be..68e448330 100644 --- a/src/demo/outro.c +++ b/src/demo/outro.c @@ -3,7 +3,7 @@ static int y; static int targy; -static int xstart; +static unsigned xstart; static struct ncplane* on; struct ncvisual_options vopts; @@ -114,7 +114,7 @@ videothread(void* vnc){ } static struct ncplane* -outro_message(struct notcurses* nc, int* rows, int* cols){ +outro_message(struct notcurses* nc, unsigned* rows, unsigned* cols){ const char str0[] = " ATL, baby! ATL! "; const char str1[] = " throw your hands in the air "; const char* str2 = notcurses_canutf8(nc) ? " hack on! —dank❤ " : " hack on! --dank "; @@ -207,7 +207,7 @@ int outro(struct notcurses* nc){ ncplane_set_name(vopts.n, "bnnr"); } xstart = cols; - int ystart = rows; + unsigned ystart = rows; on = outro_message(nc, &ystart, &xstart); if(on == NULL){ return -1; diff --git a/src/demo/reel.c b/src/demo/reel.c index c496cdd7c..ac172f683 100644 --- a/src/demo/reel.c +++ b/src/demo/reel.c @@ -192,7 +192,7 @@ ncreel_demo_core(struct notcurses* nc){ tabletctx* tctxs = NULL; bool aborted = false; int x = 8, y = 4; - int dimy, dimx; + unsigned dimy, dimx; struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx); struct ncplane_options nopts = { .y = y, diff --git a/src/demo/unicodeblocks.c b/src/demo/unicodeblocks.c index 2d50e1300..0f3b70198 100644 --- a/src/demo/unicodeblocks.c +++ b/src/demo/unicodeblocks.c @@ -25,7 +25,7 @@ fade_block(struct notcurses* nc, struct ncplane* nn, const struct timespec* subd // negative row will result in vertical pbar on the left side static struct ncprogbar* pbar_make(struct notcurses* nc, int row){ - int dimx, dimy; + unsigned dimx, dimy; struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx); struct ncplane_options nopts = { .y = row < 0 ? 4 : row, @@ -42,8 +42,9 @@ pbar_make(struct notcurses* nc, int row){ uint64_t channels = 0; ncchannels_set_bg_rgb(&channels, 0); ncplane_set_base(pbar, "", 0, channels); - int posy, posx, pdimy, pdimx; + int posy, posx; ncplane_yx(pbar, &posy, &posx); + unsigned pdimy, pdimx; ncplane_dim_yx(pbar, &pdimy, &pdimx); ncplane_cursor_move_yx(std, posy - 1, posx - 1); channels = 0; @@ -66,7 +67,7 @@ pbar_make(struct notcurses* nc, int row){ static int draw_block(struct ncplane* nn, uint32_t blockstart){ - int dimx, dimy; + unsigned dimx, dimy; ncplane_dim_yx(nn, &dimy, &dimx); nccell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER; nccell ll = CELL_TRIVIAL_INITIALIZER, lr = CELL_TRIVIAL_INITIALIZER; @@ -207,7 +208,7 @@ int unicodeblocks_demo(struct notcurses* nc){ return 0; } ncplane_greyscale(notcurses_stdplane(nc)); - int pbarrow = 4 + BLOCKSIZE / CHUNKSIZE + 4; + unsigned pbarrow = 4 + BLOCKSIZE / CHUNKSIZE + 4; if(pbarrow > maxy - 2){ pbarrow = -1; } diff --git a/src/info/main.c b/src/info/main.c index 4eb6e13e8..bc7ad5ee7 100644 --- a/src/info/main.c +++ b/src/info/main.c @@ -319,7 +319,7 @@ unicodedumper(struct ncplane* n, const char* indent){ uint64_t ul = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70); uint64_t ll = NCCHANNELS_INITIALIZER(0xff, 0xff, 0xff, 0x19, 0x19, 0x70); ncplane_cursor_move_yx(n, y - 15, 0); - ncplane_stain(n, -1, -1, y - 1, 79, ul, ur, ll, lr); + ncplane_stain(n, -1, -1, 15, 80, ul, ur, ll, lr); ncplane_set_styles(n, NCSTYLE_BOLD | NCSTYLE_ITALIC); ncplane_cursor_move_yx(n, y - 12, 54); wviz(n, L"🯁🯂🯃https://notcurses.com"); diff --git a/src/lib/visual-details.h b/src/lib/visual-details.h index 78b4562ec..e9347e39a 100644 --- a/src/lib/visual-details.h +++ b/src/lib/visual-details.h @@ -24,7 +24,7 @@ typedef struct ncvisual { uint32_t* data; // (scaled) RGBA image data, rowstride bytes per row unsigned pixx, pixy; // pixel geometry, *not* cell geometry // lines are sometimes padded. this many true bytes per row in data. - int rowstride; + unsigned rowstride; bool owndata; // we own data iff owndata == true } ncvisual;