Generic functions to handle scrolling windows created
This commit is contained in:
parent
efd782699b
commit
f0d4409151
@ -1,3 +1,6 @@
|
|||||||
|
18 Apr 2008:
|
||||||
|
Generic functions to handle scrolling windows created
|
||||||
|
|
||||||
12 Apr 2008:
|
12 Apr 2008:
|
||||||
Yet another style for source code. GNU style now used (I am fed up
|
Yet another style for source code. GNU style now used (I am fed up
|
||||||
with tabs...)
|
with tabs...)
|
||||||
|
76
src/help.c
76
src/help.c
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: help.c,v 1.22 2008/04/12 21:14:03 culot Exp $ */
|
/* $calcurse: help.c,v 1.23 2008/04/18 17:53:31 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -256,15 +256,12 @@ wanted_page (int ch)
|
|||||||
void
|
void
|
||||||
help_screen (void)
|
help_screen (void)
|
||||||
{
|
{
|
||||||
window_t hwin;
|
scrollwin_t hwin;
|
||||||
window_t hpad;
|
|
||||||
const int PADOFFSET = 4;
|
const int PADOFFSET = 4;
|
||||||
const int TITLELINES = 3;
|
const int TITLELINES = 3;
|
||||||
int ch = '?';
|
|
||||||
int text_lines;
|
|
||||||
int first_line = 0, nl = 0;
|
|
||||||
int page, oldpage;
|
|
||||||
int need_resize;
|
int need_resize;
|
||||||
|
int ch = '?';
|
||||||
|
int page, oldpage;
|
||||||
help_page_t hscr[HELPSCREENS];
|
help_page_t hscr[HELPSCREENS];
|
||||||
|
|
||||||
hscr[HELP_MAIN].title =
|
hscr[HELP_MAIN].title =
|
||||||
@ -560,71 +557,62 @@ help_screen (void)
|
|||||||
"Send your feedback or comments to : calcurse@culot.org\n"
|
"Send your feedback or comments to : calcurse@culot.org\n"
|
||||||
"Calcurse home page : http://culot.org/calcurse");
|
"Calcurse home page : http://culot.org/calcurse");
|
||||||
|
|
||||||
need_resize = 0;
|
hwin.win.x = 0;
|
||||||
|
hwin.win.y = 0;
|
||||||
|
hwin.win.h = (notify_bar ()) ? row - 3 : row - 2;
|
||||||
|
hwin.win.w = col;
|
||||||
|
|
||||||
|
hwin.pad.x = PADOFFSET;
|
||||||
|
hwin.pad.y = TITLELINES;
|
||||||
|
hwin.pad.h = BUFSIZ;
|
||||||
|
hwin.pad.w = col - 2 * PADOFFSET + 1;
|
||||||
|
|
||||||
|
snprintf (hwin.label, BUFSIZ, _("Calcurse %s | help"), VERSION);
|
||||||
|
wins_scrollwin_init (&hwin);
|
||||||
|
wins_show (hwin.win.p, hwin.label);
|
||||||
page = oldpage = HELP_MAIN;
|
page = oldpage = HELP_MAIN;
|
||||||
help_wins_init (&hwin, &hpad, PADOFFSET);
|
need_resize = 0;
|
||||||
|
|
||||||
/* Display the help screen related to user input. */
|
/* Display the help screen related to user input. */
|
||||||
while (ch != 'q')
|
while (ch != 'q')
|
||||||
{
|
{
|
||||||
erase_window_part (hwin.p, 1, TITLELINES, col - 2, hwin.h - 2);
|
erase_window_part (hwin.win.p, 1, TITLELINES, col - 2,
|
||||||
|
hwin.win.h - 2);
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
help_wins_reset (&hwin, &hpad, PADOFFSET);
|
help_wins_reset (&hwin.win, &hwin.pad, PADOFFSET);
|
||||||
first_line = 0;
|
hwin.first_visible_line = 0;
|
||||||
nl = write_help_pad (&hpad, &hscr[oldpage]);
|
hwin.total_lines = write_help_pad (&hwin.pad, &hscr[oldpage]);
|
||||||
need_resize = 1;
|
need_resize = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTRL ('n'):
|
case CTRL ('n'):
|
||||||
if (nl > (first_line + hwin.h - (PADOFFSET + 1)))
|
if (hwin.total_lines
|
||||||
first_line++;
|
> (hwin.first_visible_line + hwin.win.h - hwin.pad.x))
|
||||||
|
hwin.first_visible_line++;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTRL ('p'):
|
case CTRL ('p'):
|
||||||
if (first_line > 0)
|
if (hwin.first_visible_line > 0)
|
||||||
first_line--;
|
hwin.first_visible_line--;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
page = wanted_page (ch);
|
page = wanted_page (ch);
|
||||||
if (page != NOPAGE)
|
if (page != NOPAGE)
|
||||||
{
|
{
|
||||||
first_line = 0;
|
hwin.first_visible_line = 0;
|
||||||
nl = write_help_pad (&hpad, &hscr[page]);
|
hwin.total_lines = write_help_pad (&hwin.pad, &hscr[page]);
|
||||||
oldpage = page;
|
oldpage = page;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
wins_scrollwin_display (&hwin);
|
||||||
/* Draw the scrollbar if necessary. */
|
|
||||||
text_lines = hwin.h - (PADOFFSET + 1);
|
|
||||||
if (nl > text_lines)
|
|
||||||
{
|
|
||||||
float ratio = ((float) text_lines + 1) / ((float) nl);
|
|
||||||
int sbar_length = (int) (ratio * text_lines);
|
|
||||||
int highend = (int) (ratio * first_line);
|
|
||||||
int sbar_top = highend + TITLELINES + 1;
|
|
||||||
|
|
||||||
if ((sbar_top + sbar_length) > hwin.h - 1)
|
|
||||||
sbar_length = hwin.h - 1 - sbar_top;
|
|
||||||
draw_scrollbar (hwin.p, sbar_top, col - 2,
|
|
||||||
sbar_length, TITLELINES + 1, hwin.h - 1, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
wmove (win[STA].p, 0, 0);
|
|
||||||
wnoutrefresh (hwin.p);
|
|
||||||
pnoutrefresh (hpad.p, first_line, 0, PADOFFSET, PADOFFSET,
|
|
||||||
hwin.h - 2, col - PADOFFSET);
|
|
||||||
doupdate ();
|
|
||||||
ch = wgetch (win[STA].p);
|
ch = wgetch (win[STA].p);
|
||||||
ch = tolower (ch);
|
ch = tolower (ch);
|
||||||
}
|
}
|
||||||
|
wins_scrollwin_delete (&hwin);
|
||||||
delwin (hpad.p);
|
|
||||||
delwin (hwin.p);
|
|
||||||
if (need_resize)
|
if (need_resize)
|
||||||
wins_reset ();
|
wins_reset ();
|
||||||
}
|
}
|
||||||
|
50
src/wins.c
50
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
|
* Calcurse - text-based organizer
|
||||||
@ -118,6 +118,54 @@ wins_init (void)
|
|||||||
keypad (win[STA].p, TRUE);
|
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
|
* Delete the existing windows and recreate them with their new
|
||||||
* size and placement.
|
* size and placement.
|
||||||
|
20
src/wins.h
20
src/wins.h
@ -1,4 +1,4 @@
|
|||||||
/* $calcurse: wins.h,v 1.7 2008/04/12 21:14:03 culot Exp $ */
|
/* $calcurse: wins.h,v 1.8 2008/04/18 17:53:31 culot Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calcurse - text-based organizer
|
* Calcurse - text-based organizer
|
||||||
@ -40,7 +40,7 @@ typedef enum
|
|||||||
}
|
}
|
||||||
window_e;
|
window_e;
|
||||||
|
|
||||||
/* Window properties */
|
/* Generic window structure. */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
WINDOW *p; /* pointer to window */
|
WINDOW *p; /* pointer to window */
|
||||||
@ -48,8 +48,17 @@ typedef struct
|
|||||||
unsigned h; /* height */
|
unsigned h; /* height */
|
||||||
int x; /* x position */
|
int x; /* x position */
|
||||||
int y; /* y position */
|
int y; /* y position */
|
||||||
}
|
} window_t;
|
||||||
window_t;
|
|
||||||
|
/* Generic scrolling window structure. */
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
window_t win;
|
||||||
|
window_t pad;
|
||||||
|
unsigned first_visible_line;
|
||||||
|
unsigned total_lines;
|
||||||
|
char label[BUFSIZ];
|
||||||
|
} scrollwin_t;
|
||||||
|
|
||||||
extern window_t win[NBWINS];
|
extern window_t win[NBWINS];
|
||||||
|
|
||||||
@ -60,6 +69,9 @@ window_e wins_slctd (void);
|
|||||||
void wins_slctd_set (window_e);
|
void wins_slctd_set (window_e);
|
||||||
void wins_slctd_next (void);
|
void wins_slctd_next (void);
|
||||||
void wins_init (void);
|
void wins_init (void);
|
||||||
|
void wins_scrollwin_init (scrollwin_t *);
|
||||||
|
void wins_scrollwin_delete (scrollwin_t *);
|
||||||
|
void wins_scrollwin_display (scrollwin_t *);
|
||||||
void wins_reinit (void);
|
void wins_reinit (void);
|
||||||
void wins_show (WINDOW *, char *);
|
void wins_show (WINDOW *, char *);
|
||||||
void wins_get_config (void);
|
void wins_get_config (void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user