Flexible Windows problem

I was hoping somebody familiar with Flexible Windows extension can show me how to make an image display in a bottom window. Using this code, the bottom window opens, but I can’t get it to display any image?

I tried to adapt the only example I could find of making an image display, but so far with no luck…

Thanks for any help in figuring this out!

[code]Include Flexible Windows by Jon Ingold.

Figure 10 is the file “pic10.jpg”.

The Study is a room. In the study is an old oak desk. On the desk is a Parker pen, a letter, an envelope and twenty dollars.

The Study is north of the Library.

The Library is a room.

The Library is south of the Study.

The bottom-window is a graphics g-window spawned by the main-window. The position of the bottom-window is g-placebelow.

The bottom-window has back-colour g-black.


The measurement of the bottom-window is 30.

When play begins:
open up the bottom-window.

The current image is a figure-name that varies.

To depict (f - a figure-name):
    change the current image to f;
    follow the window-drawing rules for the bottom-window.

Window-drawing rule for the bottom-window (this is the construct inventory rule):
move focus to bottom-window, clearing the window;
depict Figure 10;
return to main screen.

Window-drawing rule for the bottom-window (this is the draw scaled image rule):
if bottom-window is g-unpresent, rule fails;
clear the bottom-window;
draw scaled copy of current image in bottom-window.

To draw scaled copy of (f - a figure-name) in (g - a g-window):
    (- DrawScaled({f}, {g}); -).

Include (-

    ! Doing scaling calculations in I6 lets us handle bigger numbers

    [ GetImageSize curimg index result;
        result = glk_image_get_info( ResourceIDsOfFigures-->curimg, gg_arguments, gg_arguments+WORDSIZE);
        return gg_arguments-->index;
    ];

    [ DrawScaled figure g w_total h_total graph_height graph_width w_offset h_offset;
    graph_height = WindowSize(g, 1);
    graph_width = gg_arguments-->0;
    w_total = GetImageSize(figure, 0);
    h_total = gg_arguments-->1;

    if (graph_height - h_total < 0) ! if the image won't fit, find the scaling factor
    {
        w_total = (graph_height * w_total)/h_total;
        h_total = graph_height;

    }

    if (graph_width - w_total < 0)
    {
        h_total = (graph_width * h_total)/w_total;
        w_total = graph_width;
    }

    w_offset = (graph_width - w_total)/2; if (w_offset < 0) w_offset = 0;
    h_offset = (graph_height - h_total)/2; if (h_offset < 0) h_offset = 0;

    glk_image_draw_scaled(g.ref_number, ResourceIDsOfFigures-->figure, w_offset, h_offset, w_total, h_total);
    ];

-).

[/code]

I don’t know if your source ever evokes the window-drawing rules for the bottom-window?

You tell the game to open the bottom-window up when play begins; but (in the code you posted) it seems you only tell it to follow the window-drawing rules in the “depict” phrase, which in turn is only used inside one of the window-drawing rules.

So at the moment you can’t get the game to depict anything unless it follows the construct inventory rule; and that rule won’t fire unless you get the game to depict something.

I guess you need to put a phrase like “depict Figure 10” or “follow the window-drawing rules for the bottom-window” inside a rule that fires for some other reason (like an every turn rule or a before taking inventory rule or whatever).

Also, if you get the “depict Figure 10”-phrase to execute as it is, (by sticking it at the end of the when play begins rule, say), won’t it lead to a bad loop? It will run the window-drawing rules for the bottom-window, of which the first is the construct inventory rule, which itself invokes the depict phrase, which will run the window-drawing rules, which will invoke the depict phrase etc., won’t it?

I know too little about this extension, but I’m also somewhat suspicious about the interplay between the two window-drawing rules. Actually, the documentation suggests that the ‘move focus’ and ‘return to main screen’ phrases are only needed for text windows, not for graphic ones (I don’t think Jon Ingold uses them for the graphics window in the example game). So, it might be that you should drop the construct inventory rule altogether.

(Unless, of course, I am – as we put it in Sweden – “helt ute och cyklar”.)

Thanks Felix, a lot of times I try to use the examples included in the extensions to get them to do what I need. Sometimes it works. But I don’t do so well with programming logic, horrible at it.

This versions does what I want it to, except center the image in the window I open up. I can’t find any syntax in the extensions which tell it to center the image, there’s commands to do that in other extensions, but they don’t work here.

If anyone knows how to get an image to display and center please help. Do a need to include another extension on top of these to have the image centered?

[code]

Include Flexible Windows by Jon Ingold.
Include Glulx Entry Points by Emily Short.

Figure 0 is the file “sample.jpg”.

The banner-window is a graphics g-window spawned by the main-window.

The measurement of the banner-window is 15.The position of the banner-window is g-placebelow.

Every turn when the banner-window is g-present: follow the window-drawing rules for the banner-window.

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

When play begins:
    open up the graphics-window.

The current image is a figure-name that varies.

Carry out looking:
depict Figure 0;

To depict (f - a figure-name):
    change the current image to f;
    follow the window-drawing rules for the graphics-window.

Window-drawing rule for the graphics-window (this is the draw scaled image rule):
    if graphics-window is g-unpresent, rule fails;
    clear the graphics-window;
    draw scaled copy of current image in graphics-window.

[/code]

There are a few problems in your second code posting. The most important seems to be that you shift from referring to the “banner-window” to the “graphics-window” about halfway through. You have a call to the window-drawing rule for the banner-window, but you don’t actually have such a rule; there’s only a rule for the graphics-window, and the I6 code (from your first code posting) that you’re invoking with “draw scaled copy of current image in graphics-window” would scale and center the image in the graphics-window rather than the banner-window. Due to Flexible Windows’ defaults, the graphics-window you’ve defined will occupy the rightmost 40% of the banner-window. This will cause your image to appear off-center, on the right side of the screen. Is that what you’re seeing? If so, the solution is to eliminate the graphics-window from your code entirely.

You can also get rid of the rule that redraws the window every turn. That’s not necessary because you’re already updating the window whenever the image changes (in the carry out looking rules).

I also feel the need to point out that, if this is for the same project you’re using Glimmr Automap with, you have an easier solution that doesn’t require including a new I6 drawing rule. Glimmr Canvas-Based Drawing, which runs under the hood of Glimmr Automap, will automatically take over the window-drawing rule of any graphics window if you don’t provide your own specific rule for it. So, this is all you’d need to do to display an image centered in the window:

[code]The banner-window is a graphics g-window spawned by the main-window. The position is g-placebelow. The back-colour is g-black. The measurement is 30.

The banner-canvas is a graphics-canvas. The background image is Figure 10. The associated canvas of the banner-window is the banner-canvas.

When play begins:
open up the banner-window.[/code]

This will make the background image as large as it can and center it in the available space. All that you’d need to add is an rule (e.g. in the look command, as you have done already) to assign the background image of the banner-canvas and trigger the drawing.

–Erik

Thanks again for your help, your first suggestion worked, and now the windows no longer conflict when saving and restoring games. I also tried adding the code below, and it returned a problem when compiling:

[code]The banner-window is a graphics g-window spawned by the main-window. The position is g-placebelow. The back-colour is g-black. The measurement is 30.

The banner-canvas is a graphics-canvas. The background image is Figure 10. The associated canvas of the banner-window is the banner-canvas.

When play begins:
open up the banner-window.[/code]


Problem. The sentence ‘The banner-canvas is a graphics-canvas’ appears to say two things are the same - I am reading ‘banner-canvas’ and ‘graphics-canvas’ as two different things, and therefore it makes no sense to say that one is the other: it would be like saying that ‘Tom is Jerry’. It would be all right if the second thing were the name of a kind, perhaps with properties: for instance ‘Mouse-Hole is a lighted room’ says that something called Mouse-Hole exists and that it is a ‘room’, which is a kind I know about, combined with a property called ‘lighted’ which I also know about.


I don’t if it’s something else in my code causing the problem, or one of the extensions, but on down the road I might prefer your simpler solution, if you can tell off-hand what’s causing it.

But seems its working now, and I hope I’m done with graphics for awhile!

Ah, silly me. It should be “g-canvas”, not “graphics-canvas”…

–Erik