Is resizing Glk windows really a thing?

I hacked together some code to make proportional windows in glulx have a min and max size by hooking into where Glulx.i6t handles evtype_Arrange, but I got all kinds of weird behavior on different interpreters, including a crash on Lectrote. Is glk_window_set_arrangement not well supported, or am I likely doing something wrong?

You’re probably calling it wrong. What specifically are you doing and what’s the error message?

It’s a hack on Simple Graphical Window. The resizing function:

[ ResizeGraphicsWindow o2 widthptr picwidth prop;
	if (gg_picwin) {
		o2 = glk_window_get_parent(gg_picwin);
		
		picwidth = VM_ScreenWidth();
		prop = (+ Graphics window proportion +);
		if (picwidth * prop / 100 < 120) {
			glk_window_set_arrangement(o2, winmethod_Left | winmethod_Fixed, 120, gg_picwin);
		}
		else if (picwidth * prop / 100 > 240) {
			glk_window_set_arrangement(o2, winmethod_Left | winmethod_Fixed, 240, gg_picwin);
		}
		else {
			glk_window_set_arrangement(o2, winmethod_Left | winmethod_Proportional, prop, gg_picwin);
		}
		BlankWindowToColor();
		MyRedrawGraphicsWindows();
	}
];

In the IDE VM it doesn’t act quite right in terms of repainting the background, but I imagine I can fix that. In Gargoyle, Lectrote, and Spatterlight the size never changes. I tracked down the crash in Lectrote to a debug print statement I left in.

Disclaimer: my first i6 function, so be kind. :slight_smile:

ETA: All on MacOS.

At first glance that looks okay: have you got a complete example you could post to test with?

1 Like

My problem is apparently that I don’t read the docs. From Glulx.i6t:

Screen height and width are measured in characters, with respect to the
fixed-pitch font used for the status line. The main window normally contains
variable-pitch text which may even have been kerned, and character dimensions
make little sense there.

So there doesn’t seem to be a way to get the pixel width of the main window. Which makes this task a little bit harder, maybe impossible?

That’s correct; there’s no way to measure the size of a text buffer window in pixels. Dannii has proposed an extension to do this, but I think it’s generally better to avoid depending on exact pixel measurements.

Counterfeit Monkey opens a zero-height graphics window above the main text window and measures that instead in order to get the width of the text window in pixels. This is used to control the width of the map window, and seems to work fine in all interpreters I’ve tried.

5 Likes

Beautiful, thanks for the tip. Works perfectly in Inform, Spatterlight, Gargoyle and Lectrote, all on Mac.

(Not quite, I’ve been thinking of a Glk extension to expose the virtual pixel to device pixel ratio.)