demo: only move fpsgraph when grabbed #595

This commit is contained in:
nick black 2020-05-10 20:41:48 -04:00
parent 454806d53a
commit ea3ca7d503
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
3 changed files with 27 additions and 10 deletions

View File

@ -137,8 +137,8 @@ timespec_mul(const struct timespec* ts, unsigned multiplier, struct timespec* pr
/*---------------------------------FPS plot-------------------------------*/
int fpsgraph_init(struct notcurses* nc);
int fpsgraph_stop(struct notcurses* nc);
int plot_grab(int y);
int plot_release(void);
int fpsplot_grab(int y);
int fpsplot_release(void);
/*----------------------------------HUD----------------------------------*/
extern struct ncplane* hud;
struct ncplane* hud_create(struct notcurses* nc);

View File

@ -108,11 +108,11 @@ about_toggle(struct notcurses* nc){
ncplane_set_bg(n, 0);
ncplane_set_bg_alpha(n, CELL_ALPHA_BLEND);
ncplane_printf_aligned(n, 1, NCALIGN_CENTER, "notcurses-demo %s", notcurses_version());
ncplane_printf_aligned(n, 3, NCALIGN_LEFT, " q quit");
ncplane_printf_aligned(n, 3, NCALIGN_RIGHT, "restart Ctrl+R ");
ncplane_printf_aligned(n, 3, NCALIGN_LEFT, " P toggle plot");
ncplane_printf_aligned(n, 3, NCALIGN_RIGHT, "toggle help Ctrl+U ");
ncplane_printf_aligned(n, 4, NCALIGN_LEFT, " H toggle HUD");
ncplane_printf_aligned(n, 4, NCALIGN_RIGHT, "toggle help Ctrl+U ");
ncplane_printf_aligned(n, 5, NCALIGN_LEFT, " P toggle plot");
ncplane_printf_aligned(n, 4, NCALIGN_RIGHT, "restart Ctrl+R ");
ncplane_printf_aligned(n, 5, NCALIGN_CENTER, "q quit");
ncplane_putstr_aligned(n, 7, NCALIGN_CENTER, "\u00a9 nick black <nickblack@linux.com>");
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
cell lr = CELL_TRIVIAL_INITIALIZER, ll = CELL_TRIVIAL_INITIALIZER;
@ -370,11 +370,25 @@ int hud_release(void){
if(hud == NULL){
return -1;
}
if(hud_grab_x < 0 && hud_grab_y < 0){
return -1;
}
hud_grab_x = -1;
hud_grab_y = -1;
return hud_standard_bg(hud);
}
int fpsplot_release(void){
if(plot == NULL){
return -1;
}
if(plot_grab_y < 0){
return -1;
}
plot_grab_y = -1;
return hud_standard_bg(hud);
}
// currently running demo is always at y = HUD_ROWS-2
int hud_completion_notify(const demoresult* result){
if(running){
@ -530,10 +544,10 @@ int fpsgraph_init(struct notcurses* nc){
memset(&opts, 0, sizeof(opts));
opts.flags = NCPLOT_OPTIONS_LABELTICKSD | NCPLOT_OPTIONS_EXPONENTIALD;
opts.gridtype = NCPLOT_8x1;
channels_set_fg_rgb(&opts.minchannel, 0x40, 0x50, 0x40);
channels_set_fg_rgb(&opts.minchannel, 0xff, 0x00, 0xff);
channels_set_bg(&opts.minchannel, 0x201020);
channels_set_bg_alpha(&opts.minchannel, CELL_ALPHA_BLEND);
channels_set_fg_rgb(&opts.maxchannel, 0xd0, 0xff, 0xd0);
channels_set_fg_rgb(&opts.maxchannel, 0x00, 0xff, 0x00);
channels_set_bg(&opts.maxchannel, 0x201020);
channels_set_bg_alpha(&opts.maxchannel, CELL_ALPHA_BLEND);
struct ncuplot* fpsplot = ncuplot_create(newp, &opts, 0, 0);
@ -561,7 +575,7 @@ int fpsgraph_stop(struct notcurses* nc){
}
// mouse has maybe pressed on the plot. the caller is responsible for rerendering.
int plot_grab(int y){
int fpsplot_grab(int y){
int ret;
if(plot == NULL || plot_hidden){
return -1;

View File

@ -27,10 +27,13 @@ handle_mouse(const ncinput* ni){
int ret;
if(ni->id == NCKEY_RELEASE){
ret = hud_release();
if(ret < 0){
ret = fpsplot_release();
}
}else{
ret = hud_grab(ni->y, ni->x);
if(ret < 0){
ret = plot_grab(ni->y);
ret = fpsplot_grab(ni->y);
}
}
// do not render here. the demos, if coded properly, will be regularly