From dee1549232dd102cc9253a2f3267e1330fdf7cde Mon Sep 17 00:00:00 2001 From: cancel Date: Mon, 27 Jan 2020 07:14:36 +0900 Subject: [PATCH] Factor out qnav drawing --- term_util.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-- term_util.h | 3 ++- tui_main.c | 43 ++----------------------------------------- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/term_util.c b/term_util.c index 198dcfe..4cc282c 100644 --- a/term_util.c +++ b/term_util.c @@ -115,7 +115,7 @@ static ORCA_NOINLINE void qnav_stack_push(Qblock *qb, int height, int width) { qb->content_window = subpad(qb->outer_window, height, width, 1, 1); qb->y = top; qb->x = left; - qnav_stack.stack_changed = true; + qnav_stack.occlusion_dirty = true; } Qblock *qnav_top_block() { @@ -164,7 +164,49 @@ void qnav_stack_pop(void) { delwin(outer_window); --qnav_stack.count; qnav_stack.blocks[qnav_stack.count] = NULL; - qnav_stack.stack_changed = true; + qnav_stack.occlusion_dirty = true; +} + +bool qnav_draw(void) { + bool drew_any = false; + if (qnav_stack.count < 1) + goto done; + int term_h, term_w; + getmaxyx(stdscr, term_h, term_w); + for (Usz i = 0; i < qnav_stack.count; ++i) { + Qblock *qb = qnav_stack.blocks[i]; + if (qnav_stack.occlusion_dirty) { + bool is_frontmost = i == qnav_stack.count - 1; + qblock_print_frame(qb, is_frontmost); + switch (qb->tag) { + case Qblock_type_qmsg: + break; + case Qblock_type_qmenu: + qmenu_set_displayed_active(qmenu_of(qb), is_frontmost); + break; + case Qblock_type_qform: + break; + } + } + touchwin(qb->outer_window); // here? or after continue? + if (term_h < 1 || term_w < 1) + continue; + int qbwin_h, qbwin_w; + getmaxyx(qb->outer_window, qbwin_h, qbwin_w); + int qbwin_endy = qb->y + qbwin_h; + int qbwin_endx = qb->x + qbwin_w; + if (qbwin_endy >= term_h) + qbwin_endy = term_h - 1; + if (qbwin_endx >= term_w) + qbwin_endx = term_w - 1; + if (qb->y >= qbwin_endy || qb->x >= qbwin_endx) + continue; + pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy, qbwin_endx); + drew_any = true; + } +done: + qnav_stack.occlusion_dirty = false; + return drew_any; } void qblock_print_border(Qblock *qb, unsigned int attr) { diff --git a/term_util.h b/term_util.h index a8e7f1a..fdcc3e0 100644 --- a/term_util.h +++ b/term_util.h @@ -66,7 +66,7 @@ typedef struct { typedef struct { Qblock *blocks[16]; Usz count; - bool stack_changed; + bool occlusion_dirty; } Qnav_stack; typedef struct Qmsg Qmsg; @@ -119,6 +119,7 @@ void qnav_init(void); void qnav_deinit(void); Qblock *qnav_top_block(void); void qnav_stack_pop(void); +bool qnav_draw(void); // also clear qnav_stack.occlusion_dirty void qblock_print_frame(Qblock *qb, bool active); void qblock_set_title(Qblock *qb, char const *title); diff --git a/tui_main.c b/tui_main.c index 25a48ee..4a2b79c 100644 --- a/tui_main.c +++ b/tui_main.c @@ -3524,53 +3524,14 @@ event_loop:; case ERR: { // ERR indicates no more events. ged_do_stuff(&t.ged); bool drew_any = false; - if (qnav_stack.stack_changed) - drew_any = true; - if (ged_is_draw_dirty(&t.ged) || drew_any) { + if (ged_is_draw_dirty(&t.ged) || qnav_stack.occlusion_dirty) { werase(cont_window); ged_draw(&t.ged, cont_window, osoc(t.file_name), t.fancy_grid_dots, t.fancy_grid_rulers); wnoutrefresh(cont_window); drew_any = true; } - if (qnav_stack.count < 1) - goto done_qnav_stack_update; - int term_h, term_w; - getmaxyx(stdscr, term_h, term_w); - for (Usz i = 0; i < qnav_stack.count; ++i) { - Qblock *qb = qnav_stack.blocks[i]; - if (qnav_stack.stack_changed) { - bool is_frontmost = i == qnav_stack.count - 1; - qblock_print_frame(qb, is_frontmost); - switch (qb->tag) { - case Qblock_type_qmsg: - break; - case Qblock_type_qmenu: - qmenu_set_displayed_active(qmenu_of(qb), is_frontmost); - break; - case Qblock_type_qform: - break; - } - } - touchwin(qb->outer_window); // here? or after continue? - if (term_h < 1 || term_w < 1) - continue; - int qbwin_h, qbwin_w; - getmaxyx(qb->outer_window, qbwin_h, qbwin_w); - int qbwin_endy = qb->y + qbwin_h; - int qbwin_endx = qb->x + qbwin_w; - if (qbwin_endy >= term_h) - qbwin_endy = term_h - 1; - if (qbwin_endx >= term_w) - qbwin_endx = term_w - 1; - if (qb->y >= qbwin_endy || qb->x >= qbwin_endx) - continue; - pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy, - qbwin_endx); - drew_any = true; - } - done_qnav_stack_update: - qnav_stack.stack_changed = false; + drew_any |= qnav_draw(); // clears qnav_stack.occlusion_dirty if (drew_any) doupdate(); double secs_to_d = ged_secs_to_deadline(&t.ged);