Added SP->termattrs and PDC_set_bold(). termattrs() is actually useful

now. The main goal here is to allow A_BOLD to select *either* high
intensity color (the old behavior) *or* a genuine bold font (the new
option for SDL-TTF and X11), but not both at once; and also to
facilitate similar choice with A_BLINK in the future. (High-intensity
color can still be combined with bold fonts by directly selecting one of
the 8-15 colors.) A_ITALIC is also half-covered, but since A_INVIS is
kind of useless, I've omitted PDC_set_italic(). To Do: Test everywhere;
more docs.
This commit is contained in:
William McBrine
2018-01-01 09:36:58 -05:00
parent d2feec20da
commit 06f3d4e702
17 changed files with 176 additions and 39 deletions

View File

@@ -325,4 +325,5 @@ pdcsetsc.c:
-----------
### int PDC_set_blink(bool blinkon);
### int PDC_set_bold(bool boldon);
### void PDC_set_title(const char *title);

View File

@@ -321,6 +321,7 @@ typedef struct
int sb_cur_x;
#endif
short line_color; /* color of line attributes - default -1 */
attr_t termattrs; /* attribute capabilities */
} SCREEN;
/*----------------------------------------------------------------------
@@ -1318,6 +1319,7 @@ PDCEX wchar_t *slk_wlabel(int);
PDCEX void PDC_debug(const char *, ...);
PDCEX int PDC_ungetch(int);
PDCEX int PDC_set_blink(bool);
PDCEX int PDC_set_bold(bool);
PDCEX int PDC_set_line_color(short);
PDCEX void PDC_set_title(const char *);

View File

@@ -541,6 +541,8 @@ int PDC_scr_open(int argc, char **argv)
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = TRUE;
SP->termattrs = (SP->mono ? A_UNDERLINE : A_COLOR) | A_REVERSE | A_BLINK;
/* If the environment variable PDCURSES_BIOS is set, the DOS int10()
BIOS calls are used in place of direct video memory access. */

View File

@@ -10,6 +10,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -18,9 +19,13 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise. On DOS, this function also
adjusts the value of COLORS -- 16 for FALSE, and 8 for TRUE.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -97,5 +102,15 @@ int PDC_set_blink(bool blinkon)
COLORS = 8;
}
if (blinkon && (COLORS == 8))
SP->termattrs |= A_BLINK;
else if (!blinkon && (COLORS == 16))
SP->termattrs &= ~A_BLINK;
return (COLORS - (blinkon * 8) != 8) ? OK : ERR;
}
int PDC_set_bold(bool boldon)
{
return boldon ? ERR : OK;
}

View File

@@ -169,6 +169,8 @@ int PDC_scr_open(int argc, char **argv)
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = TRUE;
SP->termattrs = (SP->mono ? A_UNDERLINE : A_COLOR) | A_REVERSE | A_BLINK;
/* This code for preserving the current screen */
if (getenv("PDC_RESTORE_SCREEN"))

View File

@@ -10,6 +10,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -18,9 +19,13 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise. On OS/2, this function also
adjusts the value of COLORS -- 16 for FALSE, and 8 for TRUE.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -99,14 +104,25 @@ int PDC_set_blink(bool blinkon)
result = VioSetState(&statebuf, 0);
VioGetState(&statebuf, 0); /* needed? */
if (statebuf[2])
SP->termattrs &= ~A_BLINK;
else
SP->termattrs |= A_BLINK;
if (pdc_color_started)
COLORS = statebuf[2] ? 16 : 8;
return (result == 0) ? OK : ERR;
#else
SP->termattrs &= ~A_BLINK;
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
#endif
}
int PDC_set_bold(bool boldon)
{
return boldon ? ERR : OK;
}

View File

@@ -117,24 +117,16 @@ char *longname(void)
chtype termattrs(void)
{
chtype temp = A_BLINK | A_BOLD | A_INVIS | A_REVERSE | A_UNDERLINE;
/* note: blink is bold background on some platforms */
PDC_LOG(("termattrs() - called\n"));
if (!SP->mono)
temp |= A_COLOR;
return temp;
return SP->termattrs;
}
attr_t term_attrs(void)
{
PDC_LOG(("term_attrs() - called\n"));
return WA_BLINK | WA_BOLD | WA_INVIS | WA_LEFT | WA_REVERSE |
WA_RIGHT | WA_UNDERLINE;
return SP->termattrs;
}
char *termname(void)

View File

@@ -96,6 +96,8 @@ void PDC_update_rects(void)
static void _set_attr(chtype ch)
{
attr_t sysattrs = SP->termattrs;
ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE);
if (oldch != ch)
@@ -107,8 +109,10 @@ static void _set_attr(chtype ch)
PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg);
newfg |= (ch & A_BOLD) ? 8 : 0;
newbg |= (ch & A_BLINK) ? 8 : 0;
if ((ch & A_BOLD) && !(sysattrs & A_BOLD))
newfg |= 8;
if ((ch & A_BLINK) && !(sysattrs & A_BLINK))
newbg |= 8;
if (ch & A_REVERSE)
{
@@ -309,6 +313,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
#ifdef PDC_WIDE
Uint16 chstr[2] = {0, 0};
#endif
attr_t sysattrs = SP->termattrs;
PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno));
@@ -364,8 +369,12 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
#ifdef PDC_WIDE
chstr[0] = ch & A_CHARTEXT;
TTF_SetFontStyle(pdc_ttffont, (ch & A_BOLD ? TTF_STYLE_BOLD : 0) |
(ch & A_ITALIC ? TTF_STYLE_ITALIC : 0));
TTF_SetFontStyle(pdc_ttffont,
( ((ch & A_BOLD) && (sysattrs & A_BOLD)) ?
TTF_STYLE_BOLD : 0) |
( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ?
TTF_STYLE_ITALIC : 0) );
pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr,
pdc_color[foregr]);

View File

@@ -273,6 +273,12 @@ int PDC_scr_open(int argc, char **argv)
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = FALSE;
#ifdef PDC_WIDE
SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE;
#else
SP->termattrs = A_COLOR | A_PROTECT | A_REVERSE;
#endif
PDC_reset_prog_mode();
return OK;

View File

@@ -10,6 +10,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -18,9 +19,12 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -57,8 +61,23 @@ void PDC_set_title(const char *title)
int PDC_set_blink(bool blinkon)
{
SP->termattrs &= ~A_BLINK;
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
}
int PDC_set_bold(bool boldon)
{
#ifdef PDC_WIDE
if (boldon)
SP->termattrs |= A_BOLD;
else
SP->termattrs &= ~A_BOLD;
return OK;
#else
return boldon ? ERR : OK;
#endif
}

View File

@@ -96,6 +96,8 @@ void PDC_update_rects(void)
static void _set_attr(chtype ch)
{
attr_t sysattrs = SP->termattrs;
ch &= (A_COLOR|A_BOLD|A_BLINK|A_REVERSE);
if (oldch != ch)
@@ -107,8 +109,10 @@ static void _set_attr(chtype ch)
PDC_pair_content(PAIR_NUMBER(ch), &newfg, &newbg);
newfg |= (ch & A_BOLD) ? 8 : 0;
newbg |= (ch & A_BLINK) ? 8 : 0;
if ((ch & A_BOLD) && !(sysattrs & A_BOLD))
newfg |= 8;
if ((ch & A_BLINK) && !(sysattrs & A_BLINK))
newbg |= 8;
if (ch & A_REVERSE)
{
@@ -311,6 +315,7 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
#ifdef PDC_WIDE
Uint16 chstr[2] = {0, 0};
#endif
attr_t sysattrs = SP->termattrs;
PDC_LOG(("PDC_transform_line() - called: lineno=%d\n", lineno));
@@ -365,8 +370,12 @@ void PDC_transform_line(int lineno, int x, int len, const chtype *srcp)
#ifdef PDC_WIDE
chstr[0] = ch & A_CHARTEXT;
TTF_SetFontStyle(pdc_ttffont, (ch & A_BOLD ? TTF_STYLE_BOLD : 0) |
(ch & A_ITALIC ? TTF_STYLE_ITALIC : 0));
TTF_SetFontStyle(pdc_ttffont,
( ((ch & A_BOLD) && (sysattrs & A_BOLD)) ?
TTF_STYLE_BOLD : 0) |
( ((ch & A_ITALIC) && (sysattrs & A_ITALIC)) ?
TTF_STYLE_ITALIC : 0) );
pdc_font = TTF_RenderUNICODE_Solid(pdc_ttffont, chstr,
pdc_color[foregr]);

View File

@@ -287,6 +287,12 @@ int PDC_scr_open(int argc, char **argv)
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = FALSE;
#ifdef PDC_WIDE
SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE;
#else
SP->termattrs = A_COLOR | A_PROTECT | A_REVERSE;
#endif
PDC_reset_prog_mode();
return OK;

View File

@@ -10,6 +10,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -18,9 +19,12 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -57,8 +61,23 @@ void PDC_set_title(const char *title)
int PDC_set_blink(bool blinkon)
{
SP->termattrs &= ~A_BLINK;
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
}
int PDC_set_bold(bool boldon)
{
#ifdef PDC_WIDE
if (boldon)
SP->termattrs |= A_BOLD;
else
SP->termattrs &= ~A_BOLD;
return OK;
#else
return boldon ? ERR : OK;
#endif
}

View File

@@ -407,6 +407,8 @@ int PDC_scr_open(int argc, char **argv)
SP->mouse_wait = PDC_CLICK_PERIOD;
SP->audible = TRUE;
SP->termattrs = A_COLOR | A_REVERSE;
if (SP->lines < 2 || SP->lines > csbi.dwMaximumWindowSize.Y)
{
fprintf(stderr, "LINES value must be >= 2 and <= %d: got %d\n",

View File

@@ -10,6 +10,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -18,9 +19,12 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -84,8 +88,14 @@ void PDC_set_title(const char *title)
int PDC_set_blink(bool blinkon)
{
SP->termattrs &= ~A_BLINK;
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
}
int PDC_set_bold(bool boldon)
{
return boldon ? ERR : OK;
}

View File

@@ -12,6 +12,7 @@ pdcsetsc
### Synopsis
int PDC_set_blink(bool blinkon);
int PDC_set_bold(bool boldon);
void PDC_set_title(const char *title);
### Description
@@ -20,9 +21,12 @@ pdcsetsc
actual blink mode (TRUE), or sets the background color to high
intensity (FALSE). The default is platform-dependent (FALSE in
most cases). It returns OK if it could set the state to match
the given parameter, ERR otherwise. Current platforms also
adjust the value of COLORS according to this function -- 16 for
FALSE, and 8 for TRUE.
the given parameter, ERR otherwise.
PDC_set_bold() toggles whether the A_BOLD attribute selects an actual
bold font (TRUE), or sets the foreground color to high intensity
(FALSE). It returns OK if it could set the state to match the given
parameter, ERR otherwise.
PDC_set_title() sets the title of the window in which the curses
program is running. This function may not do anything on some
@@ -69,8 +73,19 @@ void PDC_set_title(const char *title)
int PDC_set_blink(bool blinkon)
{
SP->termattrs &= ~A_BLINK;
if (pdc_color_started)
COLORS = 16;
return blinkon ? ERR : OK;
}
int PDC_set_bold(bool boldon)
{
if (boldon)
SP->termattrs |= A_BOLD;
else
SP->termattrs &= ~A_BOLD;
return OK;
}

View File

@@ -577,6 +577,7 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row,
GC gc;
int xpos, ypos;
short fore, back;
attr_t sysattrs;
PDC_pair_content(PAIR_NUMBER(attr), &fore, &back);
@@ -588,8 +589,12 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row,
/* Specify the color table offsets */
fore |= (attr & A_BOLD) ? 8 : 0;
back |= (attr & A_BLINK) ? 8 : 0;
sysattrs = SP->termattrs;
if ((attr & A_BOLD) && !(sysattrs & A_BOLD))
fore |= 8;
if ((attr & A_BLINK) && !(sysattrs & A_BLINK))
back |= 8;
/* Reverse flag = highlighted selection XOR A_REVERSE set */
@@ -597,7 +602,12 @@ static int _new_packet(chtype attr, bool rev, int len, int col, int row,
/* Determine which GC to use - normal, italic or bold */
gc = (attr & A_ITALIC) ? italic_gc : (attr & A_BOLD) ? bold_gc : normal_gc;
if ((attr & A_ITALIC) && (sysattrs & A_ITALIC))
gc = italic_gc;
else if ((attr & A_BOLD) && (sysattrs & A_BOLD))
gc = bold_gc;
else
gc = normal_gc;
/* Draw it */
@@ -3047,6 +3057,8 @@ int XCursesSetupX(int argc, char *argv[])
SP->mouse_wait = xc_app_data.clickPeriod;
SP->audible = TRUE;
SP->termattrs = A_COLOR | A_ITALIC | A_PROTECT | A_REVERSE;
PDC_LOG(("%s:SHM size for curscr %d\n", XCLOGMSG, SP->XcurscrSize));
if ((shmid_Xcurscr = shmget(shmkey_Xcurscr, SP->XcurscrSize +