Glk provides standard ways to check the size of an image (glk_image_get_info
), and to draw it either at that size (glk_image_draw
) or at a different size (glk_image_draw_scaled
). You can also check the size of a graphics window (glk_window_get_size
), allowing you to customize your graphics for any type of device or screen.
But there’s one thing missing. There’s no way to check the size of a text buffer window in pixels (glk_window_get_size
returns the size in characters, and the size of a character in pixels is entirely up to the library). Which makes it nigh-impossible for the author to choose an appropriate size, either for the image itself, or to have Glk scale it.
One solution is to let the interpreter handle it. This is what I’ve generally done: trusting the interpreter to draw my images at an appropriate size (at the library author’s discretion), like how I trust the interpreter to draw my text with an appropriate line height, appropriate font, and so on. Unfortunately, this does not seem to be a reliable solution.
Dannii has suggested another option: a way to query the size of the screen (or of a text buffer window) in pixels. Then the author can be responsible for deciding exactly how they want it to look on different window sizes. I suggest a different solution, though.
I’m not a graphic designer, and someone writing a mobile Glk library probably knows much more than I do about how images should be scaled on mobile. There’s also one argument to the image-drawing functions that’s currently entirely unused in text buffer windows (it exists to provide coordinates in graphics windows).
I propose that this argument (val2
in the specification) be used to suggest how the image should be scaled. In particular, it can take the values:
- imagescale_Raw (0): the current behavior. If scale parameters are provided, interpret them as a size in pixels. If no scale parameters are provided, the behavior is unspecified (or could mean “always draw at full size” if we want to specify it fully and change the existing behavior).
- imagescale_Proportional (1): if scale parameters are provided, interpret them as a fraction of the window width and height (probably as fixed-point values but could also be floats I suppose). If not, scale the image down proportionally so it fits the current window in both dimensions.
- imagescale_Good (2): use a “good” scaling, whatever that means to the author of the library. We trust library authors to decide what is good typography; this option trusts them also to decide what’s good image placement.
Any thoughts on this? If we go with Dannii’s proposal, these options could also be handled on the game side, with e.g. an Inform extension that measures the size of the window, decides whether it’s mobile or desktop, and applies some design principles based on that. But I think letting the authors of individual Glk libraries have a say based on the devices they’re targetting can give better results overall.