diff --git a/glk/osglk.c b/glk/osglk.c index b44e46b..80193f0 100644 --- a/glk/osglk.c +++ b/glk/osglk.c @@ -151,7 +151,7 @@ int os_init(int *argc, char *argv[], const char *prompt, mainfg = 0; if (!glk_style_measure(mainwin, style_Normal, stylehint_BackColor, &mainbg)) - mainbg = 0; + mainbg = 0xFFFFFFFF; /* get default colors for status window */ statuswin = glk_window_open(mainwin, diff --git a/glk/osglkban.c b/glk/osglkban.c index d8be530..854cc02 100644 --- a/glk/osglkban.c +++ b/glk/osglkban.c @@ -21,7 +21,9 @@ * * *****************************************************************************/ -/* osansi4.c -- glk banner interface */ +/* osglkban.c -- glk banner interface */ + +#include #include "os.h" #include "glk.h" @@ -57,6 +59,7 @@ typedef struct os_banner_s glui32 fgcustom; /* custom colors */ glui32 bgcustom; glui32 bgtrans; + bool invisible; contentid_t contents; /* window contents */ glui32 style; /* active Glk style value */ @@ -130,6 +133,8 @@ osbanid_t os_banner_init(void) instance->cheight = 0; instance->cwidth = 0; + instance->invisible = FALSE; + instance->contents = 0; instance->style = style_Normal; instance->newline = 0; @@ -257,6 +262,12 @@ void os_banner_styles_apply (osbanid_t banner) glk_stylehint_set(banner->type, style_User1, stylehint_BackColor, banner->fgcolor); glk_stylehint_set(banner->type, style_User2, stylehint_BackColor, bgcustom); + // Use blockquote for invisible text - set both to the banner background + if (mainbg != 0xFFFFFFFF) { + glk_stylehint_set(banner->type, style_BlockQuote, stylehint_Proportional, propval); + glk_stylehint_set(banner->type, style_BlockQuote, stylehint_TextColor, banner->bgcolor); + glk_stylehint_set(banner->type, style_BlockQuote, stylehint_BackColor, banner->bgcolor); + } } void os_banner_styles_reset (void) @@ -282,6 +293,12 @@ void os_banner_styles_reset (void) glk_stylehint_clear(wintype_AllTypes, style_User1, stylehint_BackColor); glk_stylehint_clear(wintype_AllTypes, style_User2, stylehint_BackColor); + if (mainbg != 0xFFFFFFFF) { + glk_stylehint_clear(wintype_AllTypes, style_BlockQuote, stylehint_Proportional); + glk_stylehint_clear(wintype_AllTypes, style_BlockQuote, stylehint_TextColor); + glk_stylehint_clear(wintype_AllTypes, style_BlockQuote, stylehint_BackColor); + } + #ifdef GARGLK /* reset our default colors with a superfluous hint */ glk_stylehint_set(wintype_AllTypes, style_Normal, stylehint_TextColor, mainfg); @@ -679,7 +696,20 @@ void os_banner_disp(void *banner_handle, const char *txt, size_t len) update->x = banner->x; update->y = banner->y; - banner_contents_insert(update, txt, len); + // If invisible, overwrite with spaces + if (banner->invisible) { + char *spaces = malloc(sizeof(char) * (len)); + if (!spaces) { + return; + } + memset(spaces, ' ', len); + banner_contents_insert(update, spaces, len); + free(spaces); + } + else { + banner_contents_insert(update, txt, len); + } + banner_contents_display(update); } @@ -722,6 +752,8 @@ void os_banner_set_color(void *banner_handle, os_color_t fg, os_color_t bg) glui32 reversed = 0; glui32 normal = 0; glui32 transparent = 0; + bool invisible = FALSE; + banner->invisible = FALSE; /* evaluate parameters */ @@ -730,6 +762,10 @@ void os_banner_set_color(void *banner_handle, os_color_t fg, os_color_t bg) switch(fg) { case OS_COLOR_P_TEXTBG: + if (bg == OS_COLOR_P_TRANSPARENT) { + invisible = TRUE; + break; + } case OS_COLOR_P_STATUSBG: reversed = 1; break; @@ -760,7 +796,17 @@ void os_banner_set_color(void *banner_handle, os_color_t fg, os_color_t bg) /* choose a style */ - if (normal && transparent) + if (invisible) { + // If we can't measure the background colour, then use the replace-with-spaces method + if (mainbg == 0xFFFFFFFF) { + banner->style = style_Preformatted; + banner->invisible = TRUE; + } + else { + banner->style = style_BlockQuote; + } + } + else if (normal && transparent) banner->style = style_Normal; else if (reversed) banner->style = style_User1;