From: Christian Heller Date: Tue, 30 Jul 2013 03:01:01 +0000 (+0200) Subject: Made the hierarchy between terminal screen, virtual screen, "pad", its frame etc... X-Git-Tag: tce~1106 X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/balance?a=commitdiff_plain;h=349ca3893498469b4e002829d9a35da514d8b55d;p=plomrogue Made the hierarchy between terminal screen, virtual screen, "pad", its frame etc. more logic by renamings and comments. --- diff --git a/src/main.c b/src/main.c index b430925..2b16733 100644 --- a/src/main.c +++ b/src/main.c @@ -138,10 +138,11 @@ int main(int argc, char *argv[]) struct Win win_info = init_win(&win_meta, "Info", &world, draw_info_win); struct Win win_log = init_win(&win_meta, "Log", &world, draw_log_win); win_keys.frame.size.x = 29; - win_map.frame.size.x = win_meta.pad.size.x - win_keys.frame.size.x + win_map.frame.size.x = win_meta.padframe.size.x - win_keys.frame.size.x - win_log.frame.size.x - 2; win_info.frame.size.y = 2; - win_log.frame.size.y = win_meta.pad.size.y - (2 + win_info.frame.size.y); + win_log.frame.size.y = win_meta.padframe.size.y + - (2 + win_info.frame.size.y); toggle_window(&win_meta, &win_keys); toggle_window(&win_meta, &win_map); toggle_window(&win_meta, &win_info); diff --git a/src/windows.c b/src/windows.c index 501f787..86cf1fe 100644 --- a/src/windows.c +++ b/src/windows.c @@ -68,10 +68,10 @@ static void refit_pad(struct WinMeta * wmeta) } /* Only resize the pad if the rightmost window column has changed. */ - if (getmaxx(wmeta->pad.curses_win) != lastwincol) + if (getmaxx(wmeta->padframe.curses_win) != lastwincol) { - wresize(wmeta->pad.curses_win, - getmaxy(wmeta->pad.curses_win), lastwincol + 2); + wresize(wmeta->padframe.curses_win, + getmaxy(wmeta->padframe.curses_win), lastwincol + 2); } } @@ -85,7 +85,7 @@ static void update_wins (struct WinMeta * wmeta, struct Win * w) } place_win(wmeta, w); refit_pad(wmeta); - w->frame.curses_win = subpad(wmeta->pad.curses_win, + w->frame.curses_win = subpad(wmeta->padframe.curses_win, w->frame.size.y, w->frame.size.x, w->start.y, w->start.x); if (0 != w->next) @@ -118,7 +118,7 @@ static void place_win (struct WinMeta * wmeta, struct Win * w) uint16_t w_prev_maxy = w->prev->start.y + getmaxy(w->prev->frame.curses_win); if ( w->frame.size.x <= w->prev->frame.size.x - && w->frame.size.y < wmeta->pad.size.y - w_prev_maxy) + && w->frame.size.y < wmeta->padframe.size.y - w_prev_maxy) { w->start.x = w->prev->start.x; w->start.y = w_prev_maxy + 1; @@ -147,7 +147,7 @@ static void place_win (struct WinMeta * wmeta, struct Win * w) + getmaxy(w_upup->frame.curses_win); widthdiff = (w_upup->start.x + w_upup->frame.size.x) - (w_up->start.x + w_up->frame.size.x); - if ( w->frame.size.y < wmeta->pad.size.y - w_prev_maxy + if ( w->frame.size.y < wmeta->padframe.size.y - w_prev_maxy && w->frame.size.x < widthdiff) { w->start.x = w_up->start.x + w_up->frame.size.x + 1 ; @@ -256,14 +256,14 @@ static void draw_wins_bordercorners(struct Win * w, WINDOW * pad) extern struct WinMeta init_win_meta(WINDOW * screen) { struct WinMeta wmeta; - wmeta.screen = screen; - wmeta.pad.size.y = getmaxy(screen); - wmeta.pad.size.x = getmaxx(screen); - wmeta.chain_start = 0; - wmeta.chain_end = 0; - wmeta.pad_offset = 0; - wmeta.pad.curses_win = newpad(wmeta.pad.size.y, 1); - wmeta.active = 0; + wmeta.screen = screen; + wmeta.padframe.size.y = getmaxy(screen); + wmeta.padframe.size.x = getmaxx(screen); + wmeta.chain_start = 0; + wmeta.chain_end = 0; + wmeta.pad_offset = 0; + wmeta.padframe.curses_win = newpad(wmeta.padframe.size.y, 1); + wmeta.active = 0; return wmeta; } @@ -278,7 +278,7 @@ extern struct Win init_win(struct WinMeta * wmeta, char * title, w.frame.curses_win = 0; w.title = title; w.frame.size.x = 20; - w.frame.size.y = wmeta->pad.size.y - 1; + w.frame.size.y = wmeta->padframe.size.y - 1; w.data = data; w.draw = func; return w; @@ -351,7 +351,8 @@ extern void reset_pad_offset(struct WinMeta * wmeta, uint16_t new_offset) { if (new_offset >= 0 && (new_offset < wmeta->pad_offset - || new_offset + wmeta->pad.size.x < getmaxx(wmeta->pad.curses_win))) + || new_offset + wmeta->padframe.size.x + < getmaxx(wmeta->padframe.curses_win))) { wmeta->pad_offset = new_offset; } @@ -363,7 +364,7 @@ extern void resize_active_win(struct WinMeta * wmeta, struct yx_uint16 size) { if (0 != wmeta->active && size.x > 0 && size.y > 0 - && size.y < wmeta->pad.size.y) + && size.y < wmeta->padframe.size.y) { wmeta->active->frame.size = size; update_wins(wmeta, wmeta->chain_start); /* Positioning of successor */ @@ -488,35 +489,36 @@ extern void draw_all_wins(struct WinMeta * wmeta) /* Empty everything before filling it a-new. */ erase(); wnoutrefresh(wmeta->screen); - werase(wmeta->pad.curses_win); + werase(wmeta->padframe.curses_win); if (wmeta->chain_start) { /* Draw windows' contents first, then their borders. */ draw_wins(wmeta->chain_start); draw_wins_borderlines(wmeta->chain_start, wmeta->active, - wmeta->pad.curses_win); - draw_wins_bordercorners(wmeta->chain_start, wmeta->pad.curses_win); + wmeta->padframe.curses_win); + draw_wins_bordercorners(wmeta->chain_start, wmeta->padframe.curses_win); /* Draw virtual screen scroll hints. */ if (wmeta->pad_offset > 0) { - draw_scroll_hint(&wmeta->pad, + draw_scroll_hint(&wmeta->padframe, wmeta->pad_offset, wmeta->pad_offset + 1, '<'); } - if (wmeta->pad_offset + wmeta->pad.size.x - < getmaxx(wmeta->pad.curses_win) - 1) + if (wmeta->pad_offset + wmeta->padframe.size.x + < getmaxx(wmeta->padframe.curses_win) - 1) { - draw_scroll_hint(&wmeta->pad, - wmeta->pad_offset + wmeta->pad.size.x - 1, - getmaxx(wmeta->pad.curses_win) - - (wmeta->pad_offset + wmeta->pad.size.x), '>'); + draw_scroll_hint(&wmeta->padframe, + wmeta->pad_offset + wmeta->padframe.size.x - 1, + getmaxx(wmeta->padframe.curses_win) + - (wmeta->pad_offset + wmeta->padframe.size.x), + '>'); } /* Write virtual screen segment to be shown on physical screen into */ /* ncurses screen buffer. */ - pnoutrefresh(wmeta->pad.curses_win, 0, wmeta->pad_offset, 0, 0, - wmeta->pad.size.y, wmeta->pad.size.x-1); + pnoutrefresh(wmeta->padframe.curses_win, 0, wmeta->pad_offset, 0, 0, + wmeta->padframe.size.y, wmeta->padframe.size.x-1); } /* Only at the end write accumulated changes to the physical screen. */ diff --git a/src/windows.h b/src/windows.h index 03d44b6..7c9860d 100644 --- a/src/windows.h +++ b/src/windows.h @@ -47,8 +47,8 @@ struct Frame { WINDOW * curses_win; - struct yx_uint16 size; /* designated size of curses_win */ -}; + struct yx_uint16 size; /* the size curses_win fits into; for the virtual */ +}; /* screen padframe: the terminal screen size */ struct Win { @@ -71,7 +71,7 @@ struct WinMeta { WINDOW * screen; /* terminal screen */ uint16_t pad_offset; /* number of cells view is moved to the right */ - struct Frame pad; /* virtual screen */ + struct Frame padframe; /* virtual screen fitted into terminal screen */ struct Win * chain_start; /* first Win, whose .prev shall point to 0 */ struct Win * chain_end; /* last Win, whose .next shall point to 0 */ struct Win * active; /* window highlighted/selected for manipulation */ @@ -79,11 +79,10 @@ struct WinMeta -/* Create on the terminal "screen" an empty WinMeta whose virtual screen at the - * beginning is sized just like the terminal screen. Note that emptiness is - * marked by WinMeta.chain_start=0. Other struct values are also initialized 0. - * - * TODO: Why is an *empty* virtual screen's size that of the terminal screen? +/* Create on the terminal "screen" an empty WinMeta. Note that emptiness is + * marked by WinMeta.chain_start=0. Other struct values are also initialized 0, + * except for the virtual screen (terminal screen height, width = 1) and its + * terminal-sized frame. */ extern struct WinMeta init_win_meta(WINDOW * screen);