Vorple has a feature apply (Vorple style) style to the entire page that AFAIK is impossible in Glk or Z-Machine, even with garglk_set_zcolors().
It’s used in games like The Van der Nagel Papyrus, where the background color changes as you navigate from room to room. For example, launch the Vorple version, then go n. e. s. e. e. n.
As you go north into “perhaps underground”, the background changes to a lavender color (which is an important hint). As you return south to “Zodiac”, the background changes back to white. As the background changes, the transcript is preserved; that’s the part that’s impossible in Glk today. @Afterward uses this technique a lot in Vorple games; it would be really nice if standard interpreters could support this.
It is nearly possible to implement something like this effect with garglk_set_zcolors(), but, oddly, you have to call glk_window_clear() to implement it. If you garglk_set_zcolors to set the background to lavender, the window background will remain unchanged; only spans of printed text will have lavender color. But if you glk_window_clear() after garglk_set_zcolors(), the window’s background changes, taking on the zcolor background color you specified. (This behavior isn’t documented in the specification of garglk_set_zcolors() at https://curiousdannii.github.io/if/gargoyle.html.)
Examples of zcoloring with and without clearing the transcript
In this first example, we use garglk_set_zcolors to set the background to pink, without clearing the transcript.
In this second example, we garglk_set_zcolors and then immediately glk_window_clear. You can no longer read “You move east,” because that was cleared from the transcript. But now, the whole window is pink, instead of just the spans.
Even the upcoming Glk CSS proposal is designed to only set styles on windows before you open them. Once a window is opened, you can’t set new CSS to apply immediately.
I’m interested in this because it only just recently dawned on me that ADRIFT supports changing the window’s background color without clearing the screen. In order for Spatterlight/Scarier to implement something like this in Glk interpreters, there would have to be an API for it.
So! Here’s my idea for a Glk extension.
void glk_window_set_background_color_immediate(winid_t win, glui32 color);
It would work just like glk_window_set_background_color(), but it would work on graphics windows, text-buffer windows, and text-grid windows, and it would update the background color immediately, rather than waiting for the next clear/resize.
It would get its own custom gestalt ID, too, gestalt_WindowBackgroundImmediate.
Alternatives
Alternate names
glk_window_set_background_color_now(): It’s shorter, and less formal, but I don’t expect authors will actually need to type it. I’m imagining that “Basic Screen Effects” will use it, and then authors will type something liketurn the background black immediately.glk_window_set_background_color_sync(): I didn’t pick this one, becauseglk_window_set_background_color()isn’t asynchronous. If you call it and then immediatelyglk_window_clear(), that will take effect immediately.glk_window_fill_background(): This mirrors other graphics-windowfillcalls which act immediately, but I didn’t pick this becausefillis about drawing pixels. It’s a strange API to use on a text-buffer window.
We could change the behavior of glk_window_set_background_color()
Currently, glk_window_set_background_color() can only be used on graphics windows, and the Glk specification says:
It does not change what is currently displayed; it only affects subsequent clears and resizes.
In principle, we could update it to support text-buffer windows, and, while we’re at it, we could make it take effect immediately/synchronously.
But I think it would be wrong to change that function’s behavior on graphics windows, and it would be confusing to have it take immediate effect on text buffers and delayed effect on graphics windows.
Changing the live foreground color would make this a lot more complicated, and may be unnecessary
Suppose your game uses black text on a white background, and you’d like to switch to white text on a black background as the player enters a dark room (a cave).
If we only have glk_window_set_background_color_immediate(), the transcript text that was printed while the player was outside the cave would still be black, which would be illegible on a black background. So, I can see why you might want glk_window_set_foreground_color_immediate() too, so all of the transcript text would change to white-on-black as you enter the cave.
But, I think that makes the scope of this proposal very confusing. What text color would glk_window_set_foreground_color_immediate() update? Normal styled text? What about User1? What if Normal had a TextColor stylehint on it? What if zcolors or CSS had been applied? Is there a precedence ordering for how other styles would apply?
Changing the window background color is very clear. Stylehints, zcolors, and CSS styles would always apply to spans and blocks on top of whatever the window background color is.
I think the normal use case for “updating the color scheme without clearing the screen” is to apply subtle background-color changes, like white to lavender in The Van der Nagel Papyrus. In subtle cases like those, changing the foreground color is unnecessary.
If you want to change colore schemes entirely, you can (and probably should) just clear the screen, so all of the new text is in a legible color.
Changing other styles on open windows seems simpler, but is even more complicated, and even more unnecessary
You could imagine changing all of the styling of the transcript text, e.g. changing it all from proportional to monospace.
But I don’t think there’s a common use case for that. You can just leave the old printed proportional text as it is.
I mention it because you could imagine a parallel API to stylehints or Glk CSS that sets arbitrary styles live. It has a certain ideological purity to it!
But that would incorporate all of the complexity of defining precedence orders for foreground colors, and apply that problem to all styles that the parallel API would touch. It seems easy at first, but it’s actually biting off the largest possible scope for this API, when all we really needed was a way to change the background color to lavender.
WDYT?












