Displaying Figure Inside Spawned Graphics Window

I’m not entirely sure how to do what I want. I’ve found plenty of examples but they all refer to statements like “The drawing rule of the graphics window is …” and that doesn’t work for me.

So, context. I’m using Flexible Windows. I have the following:

[code]Figure of TesterStories is the file “TesterStories.png”.

The side window is a text buffer g-window.
The side window is spawned by the main window.

The position of the side window is g-placeleft.
The measurement of the side window is 30.
The scale method of the side window is g-fixed-size.

The graphics window is a graphics g-window.
The graphics window is spawned by the side window.

The position of the graphics window is g-placeabove.
The measurement of the graphics window is 120.
The scale method of the graphics window is g-fixed-size.

Rule for refreshing the side window:
try taking inventory.

When play begins:
open the side window;
open the graphics window.

Every turn:
refresh the side window.[/code]
Everything shows up perfectly fine, as far as structure goes: a main window and then off to the left my side window; above that my graphic window.

The image itself can be displayed. But what I can’t figure out how to do is get the image into the graphics window. I tried:

Rule for refreshing the graphics window: display Figure of TesterStories.
That, however, does not work as intended. (Essentially displaying the image multiple times in the main window.)

I tried this:

[code]
Rule for refreshing the graphics window:
follow the draw the title rule.

This is the draw the title rule:
clear the graphics window;
display the Figure of TesterStories.[/code]
Same problem, though.

Actually, think I got it. I had to borrow from Simple Graphical Window. (I couldn’t use it directly because it presumed a graphics window spawned from main.)

For anyone who stumbles upon this, here’s what I ended up doing and the minimum I needed to creatively borrow:

[code]This is the draw the title rule:
clear the graphics window;
draw the Figure of TesterStories in the graphics window.

To decide what number is the height of (image - a figure-name):
(- SGW_ImageSize( {image}, 1 ) -).

To decide what number is the width of (image - a figure-name):
(- SGW_ImageSize( {image}, 0 ) -).

Include (-
[ SGW_ImageSize image index;
glk_image_get_info( ResourceIDsOfFigures–>image, gg_arguments, gg_arguments + WORDSIZE );
return gg_arguments–>index;
];
-).

To draw (image - a figure-name) in (win - a graphics g-window) at x (x - a number) and y (y - a number) scaled to width (width - a number) and height (height - a number):
(- glk_image_draw_scaled( {win}.(+ ref number +), ResourceIDsOfFigures–>( {image} ), {x}, {y}, {width}, {height} ); -).

To draw (image - a figure-name) in (win - a graphics g-window):
let image height be the height of image;
let image width be the width of image;
let window height be the height of win;
let window width be the width of win;
let x offset be 0;
let y offset be 0;
let final height be window height;
let final width be window width;
draw image in win at x x offset and y y offset scaled to width final width and height final height.[/code]
I’m not sure if that’s the most effective way, but it does have the benefit of working!

If you get the update to SGW here: github.com/i7/extensions/blob/m … Window.i7x

Then it gives you these phrases:

To draw (image - a figure-name) in (win - a graphics g-window), fully scaled:
To tile (image - a figure-name) in (win - a graphics g-window):
To draw (image - a figure-name) in (win - a graphics g-window) at x (x - a number) and y (y - a number):
To draw (image - a figure-name) in (win - a graphics g-window) at x (x - a number) and y (y - a number) scaled to width (width - a number) and height (height - a number):

You can use the phrases for any graphics window, not just the one which SGW defines. Also, you can easily change how the window SGW defines is spawned. I’m not sure if simply defining it as spawning it from something else will work, or else just put that in a before starting the virtual machine rule.

And feel free to copy them and use them without SGW too if you like.