demo: translucent menu, always display HUD close button

pull/344/head
nick black 4 years ago
parent 0d9b4f1aa1
commit 8249bac3e9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -166,7 +166,7 @@ const demoresult* demoresult_lookup(int idx);
/*----------------------------------HUD----------------------------------*/ /*----------------------------------HUD----------------------------------*/
// returns true if the input was handled by the menu/HUD // returns true if the input was handled by the menu/HUD
bool menu_or_hud_key(const struct ncinput *ni); bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni);
// returns 2 if we've successfully passed the deadline, 1 if we've been aborted // returns 2 if we've successfully passed the deadline, 1 if we've been aborted
// (as returned by demo_render(), 0 if we ought keep going, or -1 if there was // (as returned by demo_render(), 0 if we ought keep going, or -1 if there was

@ -266,7 +266,7 @@ int grid_demo(struct notcurses* nc){
y = 1; y = 1;
ret |= ccell_set_bg_rgb(&ul, i, x * rs, y * bs); ret |= ccell_set_bg_rgb(&ul, i, x * rs, y * bs);
ret |= ccell_set_fg_rgb(&ul, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y); ret |= ccell_set_fg_rgb(&ul, 255 - rs * x, 255 - gs * (x + y), 255 - bs * y);
if(ncplane_putc_yx(n, 0, 0, &ul) <= 0){ if(ncplane_putc_yx(n, y, 0, &ul) <= 0){
return -1; return -1;
} }
for(x = 1 ; x < maxx - 1 ; ++x){ for(x = 1 ; x < maxx - 1 ; ++x){

@ -17,6 +17,7 @@ static int hud_pos_y;
static const int NSLEN = 9; static const int NSLEN = 9;
static const int HUD_ROWS = 3; static const int HUD_ROWS = 3;
static const int HUD_COLS = 30; static const int HUD_COLS = 30;
static const int PLEN = HUD_COLS - 9 - NSLEN;
typedef struct elem { typedef struct elem {
char* name; char* name;
@ -61,7 +62,19 @@ hud_grabbed_bg(struct ncplane* n){
} }
// returns true if the input was handled by the menu/HUD // returns true if the input was handled by the menu/HUD
bool menu_or_hud_key(const struct ncinput *ni){ bool menu_or_hud_key(struct notcurses *nc, const struct ncinput *ni){
// toggle the HUD
if(ni->id == 'H' && !ni->alt && !ni->ctrl){
if(menu){
ncmenu_rollup(menu);
}
if(hud){
hud_destroy();
}else{
hud_create(nc);
}
return true;
}
if(!menu){ if(!menu){
return false; return false;
} }
@ -89,7 +102,7 @@ bool menu_or_hud_key(const struct ncinput *ni){
struct ncmenu* menu_create(struct notcurses* nc){ struct ncmenu* menu_create(struct notcurses* nc){
struct ncmenu_item demo_items[] = { struct ncmenu_item demo_items[] = {
{ .desc = "Toggle HUD", .shortcut = { .id = 'H', .ctrl = true, }, }, { .desc = "Toggle HUD", .shortcut = { .id = 'H', }, },
{ .desc = NULL, }, { .desc = NULL, },
{ .desc = "Restart", .shortcut = { .id = 'r', .ctrl = true, }, }, { .desc = "Restart", .shortcut = { .id = 'r', .ctrl = true, }, },
}; };
@ -108,7 +121,8 @@ struct ncmenu* menu_create(struct notcurses* nc){
uint64_t headerchannels = 0; uint64_t headerchannels = 0;
uint64_t sectionchannels = 0; uint64_t sectionchannels = 0;
channels_set_fg(&headerchannels, 0xffffff); channels_set_fg(&headerchannels, 0xffffff);
channels_set_bg(&headerchannels, 0xaf64af); channels_set_bg(&headerchannels, 0x7f347f);
channels_set_bg_alpha(&headerchannels, CELL_ALPHA_BLEND);
const ncmenu_options mopts = { const ncmenu_options mopts = {
.bottom = false, .bottom = false,
.hiding = false, .hiding = false,
@ -121,7 +135,36 @@ struct ncmenu* menu_create(struct notcurses* nc){
return menu; return menu;
} }
static elem**
hud_print_finished(int* line){
elem** hook = &elems;
elem* e = elems;
while(e){
hook = &e->next;
if(hud){
cell c = CELL_TRIVIAL_INITIALIZER;
ncplane_base(hud, &c);
ncplane_set_bg(hud, cell_bg(&c));
ncplane_set_bg_alpha(hud, CELL_ALPHA_BLEND);
ncplane_set_fg(hud, 0);
cell_release(hud, &c);
if(ncplane_printf_yx(hud, *line, 0, "%-6d %*ju.%02jus %-*.*s", e->frames,
NSLEN - 3, e->totalns / GIG,
(e->totalns % GIG) / (GIG / 100),
PLEN, PLEN, e->name) < 0){
return NULL;
}
}
++*line;
e = e->next;
}
return hook;
}
struct ncplane* hud_create(struct notcurses* nc){ struct ncplane* hud_create(struct notcurses* nc){
if(hud){
return NULL;
}
int dimx, dimy; int dimx, dimy;
notcurses_term_dim_yx(nc, &dimy, &dimx); notcurses_term_dim_yx(nc, &dimy, &dimx);
int yoffset = dimy - HUD_ROWS - 1; int yoffset = dimy - HUD_ROWS - 1;
@ -132,10 +175,6 @@ struct ncplane* hud_create(struct notcurses* nc){
hud_standard_bg(n); hud_standard_bg(n);
ncplane_set_fg(n, 0xffffff); ncplane_set_fg(n, 0xffffff);
ncplane_set_bg(n, 0x409040); ncplane_set_bg(n, 0x409040);
if(ncplane_putegc_yx(n, 0, HUD_COLS - 1, "\u2612", NULL) < 0){
ncplane_destroy(n);
return NULL;
}
return (hud = n); return (hud = n);
} }
@ -194,16 +233,7 @@ int hud_completion_notify(const demoresult* result){
// inform the HUD of an upcoming demo // inform the HUD of an upcoming demo
int hud_schedule(const char* demoname){ int hud_schedule(const char* demoname){
if(hud == NULL){
return -1;
}
cell c = CELL_TRIVIAL_INITIALIZER;
ncplane_base(hud, &c);
ncplane_set_bg(hud, cell_bg(&c));
ncplane_set_bg_alpha(hud, CELL_ALPHA_BLEND);
ncplane_set_fg(hud, 0);
elem* cure; elem* cure;
elem** hook = &elems;
int line = writeline; int line = writeline;
// once we pass through this conditional: // once we pass through this conditional:
// * cure is ready to write to, and print at y = HUD_ROWS - 1 // * cure is ready to write to, and print at y = HUD_ROWS - 1
@ -218,18 +248,9 @@ int hud_schedule(const char* demoname){
--writeline; --writeline;
cure = malloc(sizeof(*cure)); cure = malloc(sizeof(*cure));
} }
elem* e = elems; elem** hook = hud_print_finished(&line);
int plen = HUD_COLS - 10 - NSLEN; if(hook == NULL){
while(e){ return -1;
hook = &e->next;
if(ncplane_printf_yx(hud, line, 0, "%-6d %*ju.%02jus %-*.*s", e->frames,
NSLEN - 3, e->totalns / GIG,
(e->totalns % GIG) / (GIG / 100),
plen, plen, e->name) < 0){
return -1;
}
++line;
e = e->next;
} }
*hook = cure; *hook = cure;
cure->name = strdup(demoname); cure->name = strdup(demoname);
@ -240,11 +261,13 @@ int hud_schedule(const char* demoname){
clock_gettime(CLOCK_MONOTONIC, &cur); clock_gettime(CLOCK_MONOTONIC, &cur);
cure->startns = timespec_to_ns(&cur); cure->startns = timespec_to_ns(&cur);
running = cure; running = cure;
if(ncplane_printf_yx(hud, line, 0, "%-6d %*ju.%02jus %-*.*s", cure->frames, if(hud){
if(ncplane_printf_yx(hud, line, 0, "%-6d %*ju.%02jus %-*.*s", cure->frames,
NSLEN - 3, cure->totalns / GIG, NSLEN - 3, cure->totalns / GIG,
(cure->totalns % GIG) / (GIG / 100), (cure->totalns % GIG) / (GIG / 100),
plen, plen, cure->name) < 0){ PLEN, PLEN, cure->name) < 0){
return -1; return -1;
}
} }
return 0; return 0;
} }
@ -278,6 +301,9 @@ int demo_render(struct notcurses* nc){
if(interrupted){ if(interrupted){
return 1; return 1;
} }
if(menu){
ncplane_move_top(ncmenu_plane(menu));
}
if(hud){ if(hud){
int plen = HUD_COLS - 4 - NSLEN; int plen = HUD_COLS - 4 - NSLEN;
ncplane_move_top(hud); ncplane_move_top(hud);
@ -285,15 +311,21 @@ int demo_render(struct notcurses* nc){
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
uint64_t ns = timespec_to_ns(&ts) - running->startns; uint64_t ns = timespec_to_ns(&ts) - running->startns;
++running->frames; ++running->frames;
cell c = CELL_TRIVIAL_INITIALIZER;
ncplane_base(hud, &c);
ncplane_set_bg(hud, cell_bg(&c));
ncplane_set_bg_alpha(hud, CELL_ALPHA_BLEND);
ncplane_set_fg(hud, 0);
cell_release(hud, &c);
if(ncplane_printf_yx(hud, HUD_ROWS - 1, 0, "%-6d %*ju.%02jus %-*.*s", if(ncplane_printf_yx(hud, HUD_ROWS - 1, 0, "%-6d %*ju.%02jus %-*.*s",
running->frames, running->frames,
NSLEN - 3, ns / GIG, (ns % GIG) / (GIG / 100), NSLEN - 3, ns / GIG, (ns % GIG) / (GIG / 100),
plen, plen, running->name) < 0){ plen, plen, running->name) < 0){
return -1; return -1;
} }
} if(ncplane_putegc_yx(hud, 0, HUD_COLS - 1, "\u2a02", NULL) < 0){
if(menu){ return -1;
ncplane_move_top(ncmenu_plane(menu)); }
} }
return notcurses_render(nc); return notcurses_render(nc);
} }

@ -95,7 +95,7 @@ ultramegaok_demo(void* vnc){
handle_mouse(&ni); handle_mouse(&ni);
}else{ }else{
// if this was about the menu or HUD, pass to them, and continue // if this was about the menu or HUD, pass to them, and continue
if(menu_or_hud_key(&ni)){ if(menu_or_hud_key(nc, &ni)){
continue; continue;
} }
if(ni.id == 'q'){ if(ni.id == 'q'){

Loading…
Cancel
Save