diff options
author | Frederic Culot <calcurse@culot.org> | 2008-04-18 17:53:31 +0000 |
---|---|---|
committer | Frederic Culot <calcurse@culot.org> | 2008-04-18 17:53:31 +0000 |
commit | f0d44091519e26b160ce12bc7366d02f196ac852 (patch) | |
tree | bcce6810ef6435d44ba3e2ca3d59912cf8f65dfe /src/wins.c | |
parent | efd782699b63038a36bf68eaa1230d2d10bd9b38 (diff) | |
download | calcurse-f0d44091519e26b160ce12bc7366d02f196ac852.zip |
Generic functions to handle scrolling windows created
Diffstat (limited to 'src/wins.c')
-rwxr-xr-x | src/wins.c | 50 |
1 files changed, 49 insertions, 1 deletions
@@ -1,4 +1,4 @@ -/* $calcurse: wins.c,v 1.13 2008/04/12 21:14:03 culot Exp $ */ +/* $calcurse: wins.c,v 1.14 2008/04/18 17:53:31 culot Exp $ */ /* * Calcurse - text-based organizer @@ -119,6 +119,54 @@ wins_init (void) } /* + * Create a new window and its associated pad, which is used to make the + * scrolling faster. + */ +void +wins_scrollwin_init (scrollwin_t *sw) +{ + ASSERT (sw != NULL); + sw->win.p = newwin (sw->win.h, sw->win.w, sw->win.y, sw->win.x); + sw->pad.p = newpad (sw->pad.h, sw->pad.w); + sw->first_visible_line = 0; + sw->total_lines = 0; +} + +/* Free an already created scrollwin. */ +void +wins_scrollwin_delete (scrollwin_t *sw) +{ + ASSERT (sw != NULL); + delwin(sw->win.p); + delwin(sw->pad.p); +} + +/* Display a scrolling window. */ +void +wins_scrollwin_display (scrollwin_t *sw) +{ + const int visible_lines = sw->win.h - sw->pad.x; + + if (sw->total_lines > visible_lines) + { + float ratio = ((float) visible_lines) / ((float) sw->total_lines); + int sbar_length = (int) (ratio * visible_lines); + int highend = (int) (ratio * sw->first_visible_line); + int sbar_top = highend + sw->pad.y + 1; + + if ((sbar_top + sbar_length) > sw->win.h - 1) + sbar_length = sw->win.h - sbar_top; + draw_scrollbar (sw->win.p, sbar_top, sw->win.w + sw->win.x - 2, + sbar_length, sw->pad.y + 1, sw->win.h - 1, true); + } + wmove (win[STA].p, 0, 0); + wnoutrefresh (sw->win.p); + pnoutrefresh (sw->pad.p, sw->first_visible_line, 0, sw->pad.y, sw->pad.x, + sw->win.h - sw->pad.y + 1, sw->win.w - sw->win.x); + doupdate (); +} + +/* * Delete the existing windows and recreate them with their new * size and placement. */ |