History

Factor out qnav drawing

cancel committed 6 years ago

Commit dee15491 parent 285196d3 files · +48 −44Browse files

Unified · Split

3 files
  1. term_util.c +44 −2
  2. term_util.h +2 −1
  3. tui_main.c +2 −41
term_util.c+44−2
@@ -115,7 +115,7 @@ static ORCA_NOINLINE void qnav_stack_push(Qblock *qb, int height, int width) { · 114 unmodified lines
115115 qb->content_window = subpad(qb->outer_window, height, width, 1, 1);
116116 qb->y = top;
117117 qb->x = left;
118− qnav_stack.stack_changed = true;
118+ qnav_stack.occlusion_dirty = true;
119119 }
120120
121121 Qblock *qnav_top_block() {
@@ -164,7 +164,49 @@ void qnav_stack_pop(void) { · 42 unmodified lines
164164 delwin(outer_window);
165165 --qnav_stack.count;
166166 qnav_stack.blocks[qnav_stack.count] = NULL;
167− qnav_stack.stack_changed = true;
167+ qnav_stack.occlusion_dirty = true;
168+}
169+
170+bool qnav_draw(void) {
171+ bool drew_any = false;
172+ if (qnav_stack.count < 1)
173+ goto done;
174+ int term_h, term_w;
175+ getmaxyx(stdscr, term_h, term_w);
176+ for (Usz i = 0; i < qnav_stack.count; ++i) {
177+ Qblock *qb = qnav_stack.blocks[i];
178+ if (qnav_stack.occlusion_dirty) {
179+ bool is_frontmost = i == qnav_stack.count - 1;
180+ qblock_print_frame(qb, is_frontmost);
181+ switch (qb->tag) {
182+ case Qblock_type_qmsg:
183+ break;
184+ case Qblock_type_qmenu:
185+ qmenu_set_displayed_active(qmenu_of(qb), is_frontmost);
186+ break;
187+ case Qblock_type_qform:
188+ break;
189+ }
190+ }
191+ touchwin(qb->outer_window); // here? or after continue?
192+ if (term_h < 1 || term_w < 1)
193+ continue;
194+ int qbwin_h, qbwin_w;
195+ getmaxyx(qb->outer_window, qbwin_h, qbwin_w);
196+ int qbwin_endy = qb->y + qbwin_h;
197+ int qbwin_endx = qb->x + qbwin_w;
198+ if (qbwin_endy >= term_h)
199+ qbwin_endy = term_h - 1;
200+ if (qbwin_endx >= term_w)
201+ qbwin_endx = term_w - 1;
202+ if (qb->y >= qbwin_endy || qb->x >= qbwin_endx)
203+ continue;
204+ pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy, qbwin_endx);
205+ drew_any = true;
206+ }
207+done:
208+ qnav_stack.occlusion_dirty = false;
209+ return drew_any;
168210 }
169211
170212 void qblock_print_border(Qblock *qb, unsigned int attr) {
term_util.h+2−1
@@ -66,7 +66,7 @@ typedef struct { · 65 unmodified lines
6666 typedef struct {
6767 Qblock *blocks[16];
6868 Usz count;
69− bool stack_changed;
69+ bool occlusion_dirty;
7070 } Qnav_stack;
7171
7272 typedef struct Qmsg Qmsg;
@@ -119,6 +119,7 @@ void qnav_init(void); · 46 unmodified lines
119119 void qnav_deinit(void);
120120 Qblock *qnav_top_block(void);
121121 void qnav_stack_pop(void);
122+bool qnav_draw(void); // also clear qnav_stack.occlusion_dirty
122123
123124 void qblock_print_frame(Qblock *qb, bool active);
124125 void qblock_set_title(Qblock *qb, char const *title);
tui_main.c+2−41
@@ -3524,53 +3524,14 @@ event_loop:; · 3523 unmodified lines
35243524 case ERR: { // ERR indicates no more events.
35253525 ged_do_stuff(&t.ged);
35263526 bool drew_any = false;
3527− if (qnav_stack.stack_changed)
3528− drew_any = true;
3529− if (ged_is_draw_dirty(&t.ged) || drew_any) {
3527+ if (ged_is_draw_dirty(&t.ged) || qnav_stack.occlusion_dirty) {
35303528 werase(cont_window);
35313529 ged_draw(&t.ged, cont_window, osoc(t.file_name), t.fancy_grid_dots,
35323530 t.fancy_grid_rulers);
35333531 wnoutrefresh(cont_window);
35343532 drew_any = true;
35353533 }
3536− if (qnav_stack.count < 1)
3537− goto done_qnav_stack_update;
3538− int term_h, term_w;
3539− getmaxyx(stdscr, term_h, term_w);
3540− for (Usz i = 0; i < qnav_stack.count; ++i) {
3541− Qblock *qb = qnav_stack.blocks[i];
3542− if (qnav_stack.stack_changed) {
3543− bool is_frontmost = i == qnav_stack.count - 1;
3544− qblock_print_frame(qb, is_frontmost);
3545− switch (qb->tag) {
3546− case Qblock_type_qmsg:
3547− break;
3548− case Qblock_type_qmenu:
3549− qmenu_set_displayed_active(qmenu_of(qb), is_frontmost);
3550− break;
3551− case Qblock_type_qform:
3552− break;
3553− }
3554− }
3555− touchwin(qb->outer_window); // here? or after continue?
3556− if (term_h < 1 || term_w < 1)
3557− continue;
3558− int qbwin_h, qbwin_w;
3559− getmaxyx(qb->outer_window, qbwin_h, qbwin_w);
3560− int qbwin_endy = qb->y + qbwin_h;
3561− int qbwin_endx = qb->x + qbwin_w;
3562− if (qbwin_endy >= term_h)
3563− qbwin_endy = term_h - 1;
3564− if (qbwin_endx >= term_w)
3565− qbwin_endx = term_w - 1;
3566− if (qb->y >= qbwin_endy || qb->x >= qbwin_endx)
3567− continue;
3568− pnoutrefresh(qb->outer_window, 0, 0, qb->y, qb->x, qbwin_endy,
3569− qbwin_endx);
3570− drew_any = true;
3571− }
3572− done_qnav_stack_update:
3573− qnav_stack.stack_changed = false;
3534+ drew_any |= qnav_draw(); // clears qnav_stack.occlusion_dirty
35743535 if (drew_any)
35753536 doupdate();
35763537 double secs_to_d = ged_secs_to_deadline(&t.ged);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t