mirror of
https://git.zap.org.au/git/trader.git
synced 2025-06-30 22:19:26 -04:00
Add a "y" parameter to center(); add the COL_CENTER macro
This commit is contained in:
parent
c0943b9f7d
commit
10c4cb2a22
25
src/intf.c
25
src/intf.c
@ -106,11 +106,10 @@ void init_screen (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
move(0, 0);
|
|
||||||
|
|
||||||
attrset(has_colors() ? COLOR_PAIR(YELLOW_ON_CYAN) | A_BOLD :
|
attrset(has_colors() ? COLOR_PAIR(YELLOW_ON_CYAN) | A_BOLD :
|
||||||
A_REVERSE | A_BOLD);
|
A_REVERSE | A_BOLD);
|
||||||
center(stdscr, true, PACKAGE_NAME);
|
center(stdscr, 0, true, PACKAGE_NAME);
|
||||||
attrset(A_NORMAL);
|
attrset(A_NORMAL);
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
@ -281,25 +280,26 @@ int txrefresh (void)
|
|||||||
/*-----------------------------------------------------------------------
|
/*-----------------------------------------------------------------------
|
||||||
Function: center - Centre a string on the current line
|
Function: center - Centre a string on the current line
|
||||||
Arguments: win - Window to use
|
Arguments: win - Window to use
|
||||||
|
y - Line on which to centre the string
|
||||||
clrline - True to print spaces on both sides of line
|
clrline - True to print spaces on both sides of line
|
||||||
format - printf()-like format string
|
format - printf()-like format string
|
||||||
... - printf()-like arguments
|
... - printf()-like arguments
|
||||||
Returns: int - Return code from wprintw()
|
Returns: int - Return code from wprintw()
|
||||||
|
|
||||||
This function prints a string (formated with wprintw(format, ...)) in
|
This function prints a string (formated with wprintw(format, ...)) in
|
||||||
the centre of the current line in the window win. If clrline is TRUE,
|
the centre of line y in the window win. If clrline is TRUE, spaces are
|
||||||
spaces are printed before and after the line to make sure the current
|
printed before and after the line to make sure the current attributes
|
||||||
attributes are set. The cursor is then moved to the start of the next
|
are set; in this case, the cursor is also moved to the start of the
|
||||||
line, or the start of the current line (if already on the last line of
|
next line (or the start of the current line if already on the last line
|
||||||
the screen). Please note that wrefresh() is NOT called.
|
of the window). Please note that wrefresh() is NOT called.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int center (WINDOW *win, const bool clrline, const char *format, ...)
|
int center (WINDOW *win, int y, const bool clrline, const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
int len, ret;
|
int len, ret;
|
||||||
int y, x, maxy, maxx;
|
int maxy, maxx;
|
||||||
int fill;
|
int fill;
|
||||||
|
|
||||||
char *buf = malloc(OUTBUFSIZE);
|
char *buf = malloc(OUTBUFSIZE);
|
||||||
@ -313,13 +313,12 @@ int center (WINDOW *win, const bool clrline, const char *format, ...)
|
|||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
getyx(win, y, x);
|
|
||||||
getmaxyx(win, maxy, maxx);
|
getmaxyx(win, maxy, maxx);
|
||||||
|
|
||||||
fill = (maxx - len) / 2;
|
fill = (maxx - len) / 2;
|
||||||
|
|
||||||
if (clrline) {
|
if (clrline) {
|
||||||
wmove(win, y, 0);
|
wmove(win, y, 0);
|
||||||
|
|
||||||
if (fill > 0) {
|
if (fill > 0) {
|
||||||
wprintw(win, "%*c", fill, ' ');
|
wprintw(win, "%*c", fill, ' ');
|
||||||
}
|
}
|
||||||
@ -327,12 +326,12 @@ int center (WINDOW *win, const bool clrline, const char *format, ...)
|
|||||||
if (maxx - len - fill > 0) {
|
if (maxx - len - fill > 0) {
|
||||||
wprintw(win, "%*c", maxx - len - fill, ' ');
|
wprintw(win, "%*c", maxx - len - fill, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wmove(win, (y + 1 >= maxy ? y : y + 1), 0);
|
||||||
} else {
|
} else {
|
||||||
ret = mvwprintw(win, y, fill > 0 ? fill : 0, "%s", buf);
|
ret = mvwprintw(win, y, fill > 0 ? fill : 0, "%s", buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
wmove(win, (y + 1 >= maxy ? y : y + 1), 0);
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
14
src/intf.h
14
src/intf.h
@ -39,8 +39,8 @@
|
|||||||
* Constants and type declarations *
|
* Constants and type declarations *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
#define MIN_COLS (80) /* Minimum number of columns in terminal */
|
|
||||||
#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 */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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
|
||||||
@ -48,11 +48,12 @@
|
|||||||
be added to each newwin() call to position the window correctly.
|
be added to each newwin() call to position the window correctly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WIN_COLS MIN_COLS /* Number of columns in main windows */
|
|
||||||
#define WIN_LINES MIN_LINES /* Number of lines in main windows */
|
#define WIN_LINES MIN_LINES /* Number of lines in main windows */
|
||||||
|
#define WIN_COLS MIN_COLS /* Number of columns in main windows */
|
||||||
|
|
||||||
#define COL_OFFSET ((COLS - MIN_COLS) / 2) /* Window offsets */
|
#define LINE_OFFSET (0) /* Window offsets */
|
||||||
#define LINE_OFFSET (0)
|
#define COL_OFFSET ((COLS - WIN_COLS) / 2)
|
||||||
|
#define COL_CENTER(x) ((COLS - (x)) / 2)
|
||||||
|
|
||||||
|
|
||||||
// Colour pairs used in Star Traders
|
// Colour pairs used in Star Traders
|
||||||
@ -86,8 +87,9 @@ extern int deltxwin (void);
|
|||||||
extern int delalltxwin (void);
|
extern int delalltxwin (void);
|
||||||
extern int txrefresh (void);
|
extern int txrefresh (void);
|
||||||
|
|
||||||
extern int center (WINDOW *win, const bool clrline, const char *format, ...)
|
extern int center (WINDOW *win, int y, const bool clrline,
|
||||||
__attribute__((format (printf, 3, 4)));
|
const char *format, ...)
|
||||||
|
__attribute__((format (printf, 4, 5)));
|
||||||
|
|
||||||
|
|
||||||
#endif /* included_INTF_H */
|
#endif /* included_INTF_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user