mirror of
https://git.zap.org.au/git/trader.git
synced 2024-12-04 14:46:45 -05:00
Handle KEY_RESIZE events (where defined) in a simple manner
Unfortunately, the implementation of Curses (even Ncurses) requires that to truely handle resizing, one must destroy and recreate every window (and, of course, repaint it)--a lot of work that is not done at this time.
This commit is contained in:
parent
738ffcd69a
commit
3984468894
112
src/intf.c
112
src/intf.c
@ -119,6 +119,19 @@ static void init_title (void);
|
|||||||
static void sigterm_handler (int sig);
|
static void sigterm_handler (int sig);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: txresize - Handle a terminal resize event
|
||||||
|
Parameters: (none)
|
||||||
|
Returns: (nothing)
|
||||||
|
|
||||||
|
This function handles a SIGWINCH (terminal window size changed) event
|
||||||
|
by refreshing Curses windows as appropriate.
|
||||||
|
*/
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
|
static void txresize (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: txinput_fixup - Copy strings with fixup
|
Function: txinput_fixup - Copy strings with fixup
|
||||||
Parameters: dest - Destination buffer of size BUFSIZE
|
Parameters: dest - Destination buffer of size BUFSIZE
|
||||||
@ -464,6 +477,26 @@ int txrefresh (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************/
|
||||||
|
// txresize: Handle a terminal resize event
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
void txresize (void)
|
||||||
|
{
|
||||||
|
/* The current implementation cannot resize windows per se: a given
|
||||||
|
window would have to be destroyed and recreated in the new
|
||||||
|
location, then redrawn, most likely via a call-back function.
|
||||||
|
We just redraw the game title, refresh all windows and hope for
|
||||||
|
the best! */
|
||||||
|
|
||||||
|
init_title();
|
||||||
|
txrefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************/
|
/***********************************************************************/
|
||||||
// attrpr: Print a string with a particular character rendition
|
// attrpr: Print a string with a particular character rendition
|
||||||
|
|
||||||
@ -654,11 +687,34 @@ int center3 (WINDOW *win, int y, chtype attr1, chtype attr3, chtype attr2,
|
|||||||
|
|
||||||
int gettxchar (WINDOW *win)
|
int gettxchar (WINDOW *win)
|
||||||
{
|
{
|
||||||
|
int key;
|
||||||
|
bool done;
|
||||||
|
|
||||||
|
|
||||||
keypad(win, true);
|
keypad(win, true);
|
||||||
meta(win, true);
|
meta(win, true);
|
||||||
wtimeout(win, -1);
|
wtimeout(win, -1);
|
||||||
|
|
||||||
return wgetch(win);
|
done = false;
|
||||||
|
while (! done) {
|
||||||
|
key = wgetch(win);
|
||||||
|
switch (key) {
|
||||||
|
case ERR:
|
||||||
|
beep();
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
|
case KEY_RESIZE:
|
||||||
|
txresize();
|
||||||
|
break;
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
default:
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1265,11 +1321,11 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
|
|||||||
|
|
||||||
// Miscellaneous keys and events
|
// Miscellaneous keys and events
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
case KEY_EVENT:
|
txresize();
|
||||||
ret = key;
|
|
||||||
done = true;
|
|
||||||
break;
|
break;
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
default:
|
default:
|
||||||
beep();
|
beep();
|
||||||
@ -1279,11 +1335,11 @@ int gettxline (WINDOW *win, char *buf, int bufsize, bool *restrict modified,
|
|||||||
wtimeout(win, -1);
|
wtimeout(win, -1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
case KEY_EVENT:
|
txresize();
|
||||||
ret = key;
|
|
||||||
done = true;
|
|
||||||
break;
|
break;
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
default:
|
default:
|
||||||
beep();
|
beep();
|
||||||
@ -1553,11 +1609,24 @@ bool answer_yesno (WINDOW *win, chtype attr_keys)
|
|||||||
|
|
||||||
done = false;
|
done = false;
|
||||||
while (! done) {
|
while (! done) {
|
||||||
key = toupper(wgetch(win));
|
key = wgetch(win);
|
||||||
|
|
||||||
if (key == 'Y' || key == 'N') {
|
switch (key) {
|
||||||
|
case 'Y':
|
||||||
|
case 'y':
|
||||||
|
case 'N':
|
||||||
|
case 'n':
|
||||||
|
key = toupper(key);
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
break;
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
|
case KEY_RESIZE:
|
||||||
|
txresize();
|
||||||
|
break;
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
default:
|
||||||
beep();
|
beep();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1584,6 +1653,10 @@ bool answer_yesno (WINDOW *win, chtype attr_keys)
|
|||||||
|
|
||||||
void wait_for_key (WINDOW *win, int y, chtype attr)
|
void wait_for_key (WINDOW *win, int y, chtype attr)
|
||||||
{
|
{
|
||||||
|
int key;
|
||||||
|
bool done;
|
||||||
|
|
||||||
|
|
||||||
keypad(win, true);
|
keypad(win, true);
|
||||||
meta(win, true);
|
meta(win, true);
|
||||||
wtimeout(win, -1);
|
wtimeout(win, -1);
|
||||||
@ -1591,7 +1664,24 @@ void wait_for_key (WINDOW *win, int y, chtype attr)
|
|||||||
center(win, y, attr, "[ Press <SPACE> to continue ] ");
|
center(win, y, attr, "[ Press <SPACE> to continue ] ");
|
||||||
wrefresh(win);
|
wrefresh(win);
|
||||||
|
|
||||||
(void) wgetch(win);
|
done = false;
|
||||||
|
while (! done) {
|
||||||
|
key = wgetch(win);
|
||||||
|
switch (key) {
|
||||||
|
case ERR:
|
||||||
|
beep();
|
||||||
|
break;
|
||||||
|
|
||||||
|
#ifdef HANDLE_RESIZE_EVENTS
|
||||||
|
case KEY_RESIZE:
|
||||||
|
txresize();
|
||||||
|
break;
|
||||||
|
#endif // HANDLE_RESIZE_EVENTS
|
||||||
|
|
||||||
|
default:
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
30
src/intf.h
30
src/intf.h
@ -43,20 +43,27 @@
|
|||||||
/*
|
/*
|
||||||
This version of Star Traders only utilises WIN_COLS x WIN_LINES of a
|
This version of Star Traders only utilises WIN_COLS x WIN_LINES of a
|
||||||
terminal screen; this terminal must be at least MIN_COLS x MIN_LINES in
|
terminal screen; this terminal must be at least MIN_COLS x MIN_LINES in
|
||||||
size; the newtxwin() function automatically places a new window in the
|
size. The newtxwin() function automatically places a new window in the
|
||||||
centre-top of the terminal screen. The program does not yet handle
|
centre-top of the terminal screen.
|
||||||
terminal resizing events.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define MIN_LINES 24 // Minimum number of lines in terminal
|
#define MIN_LINES 24 // Minimum number of lines in terminal
|
||||||
#define MIN_COLS 80 // Minimum number of columns in terminal
|
#define MIN_COLS 80 // Minimum number of columns in terminal
|
||||||
|
|
||||||
#define WIN_LINES MIN_LINES // Number of lines in main window
|
#define WIN_LINES MIN_LINES // Number of lines used in main window
|
||||||
#define WIN_COLS MIN_COLS // Number of columns in main window
|
#define WIN_COLS MIN_COLS // Number of columns used in main window
|
||||||
|
|
||||||
#define WCENTER -1 // Centre the new window
|
#define WCENTER -1 // Centre the new window
|
||||||
|
|
||||||
|
|
||||||
|
// Check if resizing events are supported
|
||||||
|
#ifdef KEY_RESIZE
|
||||||
|
# define HANDLE_RESIZE_EVENTS 1
|
||||||
|
#else
|
||||||
|
# undef HANDLE_RESIZE_EVENTS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Visibility of the cursor in Curses (for curs_set())
|
// Visibility of the cursor in Curses (for curs_set())
|
||||||
typedef enum curs_type {
|
typedef enum curs_type {
|
||||||
CURS_INVISIBLE = 0,
|
CURS_INVISIBLE = 0,
|
||||||
@ -77,8 +84,6 @@ typedef enum curs_type {
|
|||||||
|
|
||||||
#define KEY_CTRL(x) ((x) - 0100) // ASCII control character
|
#define KEY_CTRL(x) ((x) - 0100) // ASCII control character
|
||||||
|
|
||||||
#define KEY_ILLEGAL 077777 // No key should ever return this!
|
|
||||||
|
|
||||||
// Keycodes for inserting the default value in input routines
|
// Keycodes for inserting the default value in input routines
|
||||||
#define KEY_DEFAULTVAL1 '='
|
#define KEY_DEFAULTVAL1 '='
|
||||||
#define KEY_DEFAULTVAL2 ';'
|
#define KEY_DEFAULTVAL2 ';'
|
||||||
@ -91,17 +96,6 @@ typedef enum curs_type {
|
|||||||
# define KEY_CRIGHT 01052 // CTRL + Right Arrow
|
# define KEY_CRIGHT 01052 // CTRL + Right Arrow
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Keycodes only defined by NCurses
|
|
||||||
#ifndef KEY_RESIZE
|
|
||||||
# define KEY_RESIZE KEY_ILLEGAL
|
|
||||||
#endif
|
|
||||||
#ifndef KEY_EVENT
|
|
||||||
# define KEY_EVENT KEY_ILLEGAL
|
|
||||||
#endif
|
|
||||||
#ifndef KEY_MOUSE
|
|
||||||
# define KEY_MOUSE KEY_ILLEGAL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Timeout value (in ms) for Meta-X-style keyboard input
|
// Timeout value (in ms) for Meta-X-style keyboard input
|
||||||
#ifdef NCURSES_VERSION
|
#ifdef NCURSES_VERSION
|
||||||
# define META_TIMEOUT ESCDELAY
|
# define META_TIMEOUT ESCDELAY
|
||||||
|
Loading…
Reference in New Issue
Block a user