From f0d44091519e26b160ce12bc7366d02f196ac852 Mon Sep 17 00:00:00 2001 From: Frederic Culot Date: Fri, 18 Apr 2008 17:53:31 +0000 Subject: Generic functions to handle scrolling windows created --- src/wins.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/wins.c') diff --git a/src/wins.c b/src/wins.c index 489c3da..189e149 100755 --- a/src/wins.c +++ b/src/wins.c @@ -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 @@ -118,6 +118,54 @@ wins_init (void) keypad (win[STA].p, TRUE); } +/* + * 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. -- cgit v1.2.3-54-g00ecf