Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve how menus are displayed with invisible > indicators #5

Merged
merged 2 commits into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion glk/osglk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
52 changes: 49 additions & 3 deletions glk/osglkban.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
* *
*****************************************************************************/

/* osansi4.c -- glk banner interface */
/* osglkban.c -- glk banner interface */

#include <stdbool.h>

#include "os.h"
#include "glk.h"
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 */

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down