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
115 qb->content_window = subpad(qb->outer_window, height, width, 1, 1);115 qb->content_window = subpad(qb->outer_window, height, width, 1, 1);
116 qb->y = top;116 qb->y = top;
117 qb->x = left;117 qb->x = left;
118 qnav_stack.stack_changed = true;118 qnav_stack.occlusion_dirty = true;
119}119}
120 120
121Qblock *qnav_top_block() {121Qblock *qnav_top_block() {
@@ -164,7 +164,49 @@ void qnav_stack_pop(void) { · 42 unmodified lines
164 delwin(outer_window);164 delwin(outer_window);
165 --qnav_stack.count;165 --qnav_stack.count;
166 qnav_stack.blocks[qnav_stack.count] = NULL;166 qnav_stack.blocks[qnav_stack.count] = NULL;
167 qnav_stack.stack_changed = true;167 qnav_stack.occlusion_dirty = true;
168}
169
170bool 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 }
207done:
208 qnav_stack.occlusion_dirty = false;
209 return drew_any;
168}210}
169 211
170void qblock_print_border(Qblock *qb, unsigned int attr) {212void qblock_print_border(Qblock *qb, unsigned int attr) {
term_util.h+2−1
@@ -66,7 +66,7 @@ typedef struct { · 65 unmodified lines
66typedef struct {66typedef struct {
67 Qblock *blocks[16];67 Qblock *blocks[16];
68 Usz count;68 Usz count;
69 bool stack_changed;69 bool occlusion_dirty;
70} Qnav_stack;70} Qnav_stack;
71 71
72typedef struct Qmsg Qmsg;72typedef struct Qmsg Qmsg;
@@ -119,6 +119,7 @@ void qnav_init(void); · 46 unmodified lines
119void qnav_deinit(void);119void qnav_deinit(void);
120Qblock *qnav_top_block(void);120Qblock *qnav_top_block(void);
121void qnav_stack_pop(void);121void qnav_stack_pop(void);
122bool qnav_draw(void); // also clear qnav_stack.occlusion_dirty
122 123
123void qblock_print_frame(Qblock *qb, bool active);124void qblock_print_frame(Qblock *qb, bool active);
124void qblock_set_title(Qblock *qb, char const *title);125void qblock_set_title(Qblock *qb, char const *title);
tui_main.c+2−41
@@ -3524,53 +3524,14 @@ event_loop:; · 3523 unmodified lines
3524 case ERR: { // ERR indicates no more events.3524 case ERR: { // ERR indicates no more events.
3525 ged_do_stuff(&t.ged);3525 ged_do_stuff(&t.ged);
3526 bool drew_any = false;3526 bool drew_any = false;
3527 if (qnav_stack.stack_changed)3527 if (ged_is_draw_dirty(&t.ged) || qnav_stack.occlusion_dirty) {
3528 drew_any = true;
3529 if (ged_is_draw_dirty(&t.ged) || drew_any) {
3530 werase(cont_window);3528 werase(cont_window);
3531 ged_draw(&t.ged, cont_window, osoc(t.file_name), t.fancy_grid_dots,3529 ged_draw(&t.ged, cont_window, osoc(t.file_name), t.fancy_grid_dots,
3532 t.fancy_grid_rulers);3530 t.fancy_grid_rulers);
3533 wnoutrefresh(cont_window);3531 wnoutrefresh(cont_window);
3534 drew_any = true;3532 drew_any = true;
3535 }3533 }
3536 if (qnav_stack.count < 1)3534 drew_any |= qnav_draw(); // clears qnav_stack.occlusion_dirty
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;
3574 if (drew_any)3535 if (drew_any)
3575 doupdate();3536 doupdate();
3576 double secs_to_d = ged_secs_to_deadline(&t.ged);3537 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