2011-07-02 00:53:45 -04:00
|
|
|
/************************************************************************
|
|
|
|
* *
|
|
|
|
* Star Traders: A Game of Interstellar Trading *
|
|
|
|
* Copyright (C) 1990-2011, John Zaitseff *
|
|
|
|
* *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Author: John Zaitseff <J.Zaitseff@zap.org.au>
|
|
|
|
$Id$
|
|
|
|
|
2011-07-19 06:32:00 -04:00
|
|
|
This file, intf.h, contains declarations for basic text input/output
|
|
|
|
functions used in Star Traders. It uses the X/Open Curses library to
|
|
|
|
provide terminal-independent functionality.
|
2011-07-02 00:53:45 -04:00
|
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef included_INTF_H
|
|
|
|
#define included_INTF_H 1
|
|
|
|
|
|
|
|
|
2011-07-02 07:25:57 -04:00
|
|
|
#include "system.h"
|
|
|
|
|
|
|
|
|
2011-07-02 00:53:45 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Constants and type declarations *
|
|
|
|
************************************************************************/
|
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
size; the newtxwin() function automatically places a new window in the
|
|
|
|
centre-top of the terminal screen. The program does not yet handle
|
|
|
|
terminal resizing events.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MIN_LINES 24 // Minimum number of lines 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_COLS MIN_COLS // Number of columns in main window
|
|
|
|
|
|
|
|
#define WCENTER(x) ((COLS - (x)) / 2) // Centre the window
|
|
|
|
|
|
|
|
|
|
|
|
// Visibility of the cursor in Curses (for curs_set())
|
2011-07-04 05:15:38 -04:00
|
|
|
typedef enum curs_type {
|
|
|
|
CURS_INVISIBLE = 0,
|
|
|
|
CURS_NORMAL = 1,
|
|
|
|
CURS_VISIBLE = 2
|
|
|
|
} curs_type_t;
|
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
#define CURS_OFF CURS_INVISIBLE
|
|
|
|
#define CURS_ON CURS_NORMAL
|
2011-07-04 08:02:01 -04:00
|
|
|
|
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
// Keycodes not defined by Curses
|
|
|
|
#define KEY_BS 0010 // ASCII ^H backspace
|
|
|
|
#define KEY_TAB 0011 // ASCII ^I character tabulation
|
|
|
|
#define KEY_RETURN 0012 // ASCII ^J line feed
|
|
|
|
#define KEY_ESC 0033 // ASCII ^[ escape
|
|
|
|
#define KEY_DEL 0177 // ASCII delete
|
2011-07-10 20:31:19 -04:00
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
#define KEY_CTRL(x) ((x) - 0100) // ASCII control character
|
2011-07-10 20:31:19 -04:00
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
#define KEY_ILLEGAL 077777 // No key should ever return this!
|
|
|
|
|
|
|
|
// Keycode for inserting the default value in input routines
|
|
|
|
#define KEY_DEFAULTVAL '='
|
|
|
|
|
|
|
|
// Control-arrow key combinations, as returned by NCurses
|
2011-07-10 20:31:19 -04:00
|
|
|
#ifndef KEY_CDOWN
|
2011-07-20 02:12:02 -04:00
|
|
|
# define KEY_CDOWN 01007 // CTRL + Down Arrow
|
|
|
|
# define KEY_CUP 01060 // CTRL + Up Arrow
|
|
|
|
# define KEY_CLEFT 01033 // CTRL + Left Arrow
|
|
|
|
# define KEY_CRIGHT 01052 // CTRL + Right Arrow
|
2011-07-10 20:31:19 -04:00
|
|
|
#endif
|
2011-07-20 02:12:02 -04:00
|
|
|
|
|
|
|
// Keycodes only defined by NCurses
|
|
|
|
#ifndef KEY_RESIZE
|
|
|
|
# define KEY_RESIZE KEY_ILLEGAL
|
2011-07-10 20:31:19 -04:00
|
|
|
#endif
|
2011-07-20 02:12:02 -04:00
|
|
|
#ifndef KEY_EVENT
|
|
|
|
# define KEY_EVENT KEY_ILLEGAL
|
2011-07-10 20:31:19 -04:00
|
|
|
#endif
|
2011-07-20 02:12:02 -04:00
|
|
|
#ifndef KEY_MOUSE
|
|
|
|
# define KEY_MOUSE KEY_ILLEGAL
|
2011-07-10 20:31:19 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Timeout value (in ms) for Meta-X-style keyboard input
|
2011-07-20 02:12:02 -04:00
|
|
|
#ifdef NCURSES_VERSION
|
|
|
|
# define META_TIMEOUT ESCDELAY
|
|
|
|
#else
|
|
|
|
# define META_TIMEOUT 1000
|
|
|
|
#endif
|
2011-07-04 08:02:01 -04:00
|
|
|
|
2011-07-02 00:53:45 -04:00
|
|
|
|
2011-07-02 09:19:40 -04:00
|
|
|
/*
|
2011-07-20 02:12:02 -04:00
|
|
|
Colour pairs used in Star Traders. This list MUST be synchronised with
|
|
|
|
the initialisation of colour pairs in init_screen().
|
2011-07-02 09:19:40 -04:00
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
X/Open Curses only lists the following colours: black, blue, green,
|
|
|
|
cyan, red, magenta, yellow, white. Most implementations allow these
|
|
|
|
colours plus bold versions (for the foreground).
|
|
|
|
*/
|
2011-07-02 07:25:57 -04:00
|
|
|
enum color_pairs {
|
|
|
|
DEFAULT_COLORS = 0,
|
2011-07-14 01:16:04 -04:00
|
|
|
BLACK_ON_WHITE,
|
2011-07-20 02:12:02 -04:00
|
|
|
BLUE_ON_BLACK,
|
|
|
|
GREEN_ON_BLACK,
|
2011-07-14 01:16:04 -04:00
|
|
|
CYAN_ON_BLUE,
|
2011-07-20 02:12:02 -04:00
|
|
|
RED_ON_BLACK,
|
2011-07-04 08:02:01 -04:00
|
|
|
YELLOW_ON_BLACK,
|
|
|
|
YELLOW_ON_BLUE,
|
2011-07-02 07:25:57 -04:00
|
|
|
YELLOW_ON_CYAN,
|
2011-07-14 01:16:04 -04:00
|
|
|
WHITE_ON_BLACK,
|
|
|
|
WHITE_ON_BLUE,
|
2011-07-20 02:12:02 -04:00
|
|
|
WHITE_ON_RED
|
2011-07-02 07:25:57 -04:00
|
|
|
};
|
|
|
|
|
2011-07-20 02:12:02 -04:00
|
|
|
// Colour and non-colour character rendition selection
|
|
|
|
#define ATTR(color, nocolor) (use_color ? (color) : (nocolor))
|
|
|
|
|
|
|
|
// Character renditions (attributes) used in Star Traders
|
|
|
|
#define ATTR_GAME_TITLE ATTR(COLOR_PAIR(YELLOW_ON_CYAN) | A_BOLD, A_REVERSE | A_BOLD)
|
|
|
|
#define ATTR_ROOT_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_NORMAL)
|
|
|
|
#define ATTR_NORMAL_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLUE), A_NORMAL)
|
|
|
|
#define ATTR_MAP_WINDOW ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_NORMAL)
|
|
|
|
#define ATTR_STATUS_WINDOW ATTR(COLOR_PAIR(BLACK_ON_WHITE), A_REVERSE)
|
|
|
|
#define ATTR_ERROR_WINDOW ATTR(COLOR_PAIR(WHITE_ON_RED), A_REVERSE)
|
|
|
|
#define ATTR_WINDOW_TITLE ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_REVERSE)
|
|
|
|
#define ATTR_WINDOW_SUBTITLE ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_REVERSE)
|
|
|
|
#define ATTR_MAP_TITLE ATTR(COLOR_PAIR(WHITE_ON_BLUE), A_NORMAL)
|
|
|
|
#define ATTR_MAP_T_HIGHLIGHT ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD, A_BOLD)
|
2011-07-15 00:55:56 -04:00
|
|
|
#define ATTR_MAP_T_STANDOUT ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD | A_BLINK, A_BOLD | A_BLINK)
|
2011-07-20 02:12:02 -04:00
|
|
|
#define ATTR_ERROR_TITLE ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_BOLD)
|
|
|
|
#define ATTR_INPUT_FIELD ATTR(COLOR_PAIR(WHITE_ON_BLACK), A_BOLD | '_')
|
|
|
|
#define ATTR_KEYCODE_STR ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_REVERSE)
|
|
|
|
#define ATTR_HIGHLIGHT_STR ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD, A_BOLD)
|
2011-07-15 03:46:57 -04:00
|
|
|
#define ATTR_STANDOUT_STR ATTR(COLOR_PAIR(YELLOW_ON_BLUE) | A_BOLD | A_BLINK, A_BOLD | A_BLINK)
|
2011-07-20 02:12:02 -04:00
|
|
|
#define ATTR_ERROR_STR ATTR(COLOR_PAIR(WHITE_ON_RED) | A_BOLD, A_REVERSE)
|
|
|
|
#define ATTR_WAITNORMAL_STR ATTR(COLOR_PAIR(CYAN_ON_BLUE), A_NORMAL)
|
|
|
|
#define ATTR_WAITERROR_STR ATTR(COLOR_PAIR(WHITE_ON_RED), A_REVERSE)
|
|
|
|
#define ATTR_MAP_EMPTY ATTR(COLOR_PAIR(BLUE_ON_BLACK) | A_BOLD, A_NORMAL)
|
|
|
|
#define ATTR_MAP_OUTPOST ATTR(COLOR_PAIR(GREEN_ON_BLACK) | A_BOLD, A_NORMAL)
|
|
|
|
#define ATTR_MAP_STAR ATTR(COLOR_PAIR(YELLOW_ON_BLACK) | A_BOLD, A_BOLD)
|
|
|
|
#define ATTR_MAP_COMPANY ATTR(COLOR_PAIR(RED_ON_BLACK) | A_BOLD, A_BOLD)
|
|
|
|
#define ATTR_MAP_CHOICE ATTR(COLOR_PAIR(WHITE_ON_RED) | A_BOLD, A_REVERSE)
|
2011-07-10 21:40:52 -04:00
|
|
|
|
|
|
|
|
2011-07-03 22:41:30 -04:00
|
|
|
/************************************************************************
|
|
|
|
* Global variable declarations *
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
extern WINDOW *curwin; // Top-most (current) window
|
2011-07-10 21:40:52 -04:00
|
|
|
extern bool use_color; // True to use colour in Star Traders
|
2011-07-03 22:41:30 -04:00
|
|
|
|
|
|
|
|
2011-07-02 07:25:57 -04:00
|
|
|
/************************************************************************
|
2011-07-19 06:32:00 -04:00
|
|
|
* Basic text input/output function prototypes *
|
2011-07-02 07:25:57 -04:00
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
extern void init_screen (void);
|
|
|
|
extern void end_screen (void);
|
|
|
|
|
2011-07-03 22:41:30 -04:00
|
|
|
// Simplified panel-like window functions
|
2011-07-04 05:41:55 -04:00
|
|
|
|
2011-07-19 21:41:46 -04:00
|
|
|
extern WINDOW *newtxwin (int nlines, int ncols, int begin_y, int begin_x,
|
|
|
|
bool draw_bkgd_box, chtype bkgd_attr);
|
2011-07-03 22:41:30 -04:00
|
|
|
extern int deltxwin (void);
|
|
|
|
extern int delalltxwin (void);
|
|
|
|
extern int txrefresh (void);
|
|
|
|
|
2011-07-04 05:41:55 -04:00
|
|
|
// Output routines
|
|
|
|
|
2011-07-11 01:56:01 -04:00
|
|
|
extern int center (WINDOW *win, int y, int attr, const char *format, ...)
|
|
|
|
__attribute__((format (printf, 4, 5)));
|
2011-07-02 07:25:57 -04:00
|
|
|
|
2011-07-15 00:55:56 -04:00
|
|
|
extern int center2 (WINDOW *win, int y, int attr_initial, int attr_string,
|
|
|
|
const char *initial, const char *format, ...)
|
|
|
|
__attribute__((format (printf, 6, 7)));
|
|
|
|
|
2011-07-16 01:47:05 -04:00
|
|
|
extern int center3 (WINDOW *win, int y, int attr_initial, int attr_final,
|
|
|
|
int attr_string, const char *initial, const char *final,
|
|
|
|
const char *format, ...)
|
|
|
|
__attribute__((format (printf, 8, 9)));
|
|
|
|
|
2011-07-10 18:01:18 -04:00
|
|
|
extern int attrpr (WINDOW *win, int attr, const char *format, ...)
|
|
|
|
__attribute__((format (printf, 3, 4)));
|
2011-07-04 05:41:55 -04:00
|
|
|
|
2011-07-04 08:02:01 -04:00
|
|
|
// Input routines
|
|
|
|
|
|
|
|
extern int gettxchar (WINDOW *win);
|
2011-07-10 20:31:19 -04:00
|
|
|
extern int gettxline (WINDOW *win, char *buf, int bufsize, bool multifield,
|
|
|
|
int maxlen, const char *emptyval, const char *defaultval,
|
|
|
|
const char *allowed, bool stripspc, int y, int x,
|
2011-07-10 22:28:13 -04:00
|
|
|
int fieldsize, int attr, bool *modified);
|
2011-07-10 23:18:26 -04:00
|
|
|
extern int gettxstring (WINDOW *win, char **bufptr, bool multifield,
|
|
|
|
int y, int x, int fieldsize, int attr, bool *modified);
|
2011-07-18 10:37:10 -04:00
|
|
|
extern int gettxdouble (WINDOW *win, double *result, double min, double max,
|
|
|
|
double emptyval, double defaultval, int y, int x,
|
|
|
|
int fieldsize, int attr);
|
2011-07-19 00:15:33 -04:00
|
|
|
extern int gettxlong (WINDOW *win, long *result, long min, long max,
|
|
|
|
long emptyval, long defaultval, int y, int x,
|
|
|
|
int fieldsize, int attr);
|
2011-07-02 00:53:45 -04:00
|
|
|
|
2011-07-11 00:43:16 -04:00
|
|
|
extern bool answer_yesno (WINDOW *win);
|
2011-07-11 03:57:52 -04:00
|
|
|
extern void wait_for_key (WINDOW *win, int y, int attr);
|
2011-07-11 00:43:16 -04:00
|
|
|
|
|
|
|
|
2011-07-02 00:53:45 -04:00
|
|
|
#endif /* included_INTF_H */
|