intfiction.org

The Interactive Fiction Community Forum
It is currently Mon Oct 22, 2018 7:06 pm

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Jun 29, 2018 3:47 pm 
Offline

Joined: Thu Apr 24, 2014 1:55 pm
Posts: 100
I'm trying to see if I can scale an image that I'm displaying "inline" in the main window.

Based on what I've read here, it seems like there's no way to auto-scale an image to fit the main window. (If that's wrong, please advise.) However, I'd still like to be able to scale it explicitly. I can't figure out what extensions I would need, or if I can do it with a few lines of Inform 6 code.

Any help appreciated!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Jun 30, 2018 12:48 pm 
Offline
User avatar

Joined: Tue Nov 08, 2011 8:11 am
Posts: 2649
Location: US - Central
Perhaps Emily's "Simple Graphical Window" - would work, or contain source text that you could modify for your purposes.
Quote:
Simple Graphical Window
version 8 by Emily Short
Provides a graphics window in the upper part of the screen, in which the author can place images; with provision for scaling, tiling, or centering images automatically, as well as setting a background color. Extension requires Glulx Entry Points Version 7.


I'd get it from the public library within Inform 7 if possible, otherwise
http://inform7.com/extensions/Emily%20S ... rce_6.html

_________________
http://hanonondricek.wixsite.com/pyramidif
https://pyramidif.itch.io/


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Jun 30, 2018 3:40 pm 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 605
The basic approach is to make sure that at the Inform 6 level you end up calling glk_image_draw_scaled() with whatever width and height you want. For example:
Code:
To display-scaled (F - figure name):
   (- DisplayScaledFigure(ResourceIDsOfFigures-->{F}); -).

Include (-
[ DisplayScaledFigure id;
   if (glk_gestalt(gestalt_Graphics, 0)) {
      glk_image_draw_scaled(gg_mainwin, id, imagealign_InlineCenter, 0, 200, 200);
      print "^";
   }
];
-)

Figure of Example is the file "Example.png".

Nowhere-much is a room. The whatever is in Nowhere-much.

After examining the whatever:
   display-scaled the Figure of Example;
This will draw the image inline, scaled to 200x200. One unfortunate problem: image scaling in text windows isn't implemented in the interpreter built into Inform 7, at least not the Windows version. I don't think anyone has noticed before now. The result does work when you release the game and load it into a Glulx interpreter that handles scaling, e.g. Windows Git.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Sat Jun 30, 2018 4:14 pm 
Offline

Joined: Thu Apr 24, 2014 1:55 pm
Posts: 100
Thank you!


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon Aug 06, 2018 4:16 pm 
Offline

Joined: Thu Apr 24, 2014 1:55 pm
Posts: 100
This approach seems to work fine in Git, Glulxe, and Quixe, but I'm having problems with Gargoyle. After drawing a couple of images at different scales, Gargoyle shuts down (without an error message).

This example exhibits the problem for me. It uses a 500x500 JPG image.

Gargoyle shuts down if I type IMAGE / SCALE 50 / IMAGE.

Code:
Main is a room. "You are here."

the player is in Main.

Figure F is the file "Example.jpg".

imaging is an action out of world.
understand "image" as imaging.

carry out imaging:
   draw Figure F at scale current_scale;
   
current_scale is a number that varies. current_scale is 100.

scale_setting is an action out of world applying to one number.
understand "scale [a number]" as scale_setting.

carry out scale_setting:
   let N be the number understood;
   if N < 10 or N > 300:
      say "The scale must stay between 10% and 300%.";
   else:
      say "Image scaling set to [N]%.";
      now current_scale is N;


w_normal is always 500.
h_normal is always 500.

to draw (F - a figure name) at scale (N - a number):
   let width be w_normal;
   now width is width * N;
   now width is width / 100;
   let height be h_normal;
   now height is height * N;
   now height is height / 100;
   display-scaled F at width by height;
   

To display-scaled (F - figure name) at (W - a number) by (H - a number):
   (- DisplayScaledFigure(ResourceIDsOfFigures-->{F}, {W}, {H}); -).

Include (-
[ DisplayScaledFigure id width height;
   if (glk_gestalt(gestalt_Graphics, 0)) {
     glk_image_draw_scaled(gg_mainwin, id, imagealign_InlineCenter, 0, width, height);
     print "^";
   }
];
-)


Top
 Profile Send private message  
Reply with quote  
PostPosted: Mon Aug 06, 2018 4:38 pm 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 605
It's hard to say anything definite without debugging Gargoyle properly, but the most likely explanation is a bug of some sort in Gargoyle. Sorry that that isn't much help. You could try a bug report at https://github.com/garglk/garglk/issues.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Aug 07, 2018 1:26 pm 
Offline

Joined: Thu Apr 24, 2014 1:55 pm
Posts: 100
I can hard-code the pixel dimensions of each figure, but it would be nicer to call some function that gives that info. Is there a way to do that?


Top
 Profile Send private message  
Reply with quote  
PostPosted: Tue Aug 07, 2018 4:19 pm 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 605
dibianca wrote:
I can hard-code the pixel dimensions of each figure, but it would be nicer to call some function that gives that info. Is there a way to do that?
Yes, there's glk_image_get_info(), which returns the width and height of a given image resource - see https://eblong.com/zarf/glk/glk-spec-074_7.html#s.1.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 08, 2018 2:08 am 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 605
If you can't figure out how to make glk_image_get_info() work, by the way, say so and I'll have a look at modifying your example. But I probably won't have time until next week, though.


Top
 Profile Send private message  
Reply with quote  
PostPosted: Wed Aug 08, 2018 1:26 pm 
Offline

Joined: Thu Apr 24, 2014 1:55 pm
Posts: 100
glk_image_get_info() uses pointers, which I've never used before. I came up with something that seems to work, but I'm not sure it's safe. If there's a safer or better way of handling this, please tell me.

This is what I have:

Code:
Figure F is the file "Example.jpg".

infoing is an action out of world.
understand "info" as infoing.

carry out infoing:
   extract info from Figure F;
   say "width: [latest_width]; height [latest_height].";

Include (- Array i6_global_width --> 1; Array i6_global_height --> 1; -) after "Definitions.i6t".

to decide which number is latest_width:
   (- i6_global_width-->0 -).

to decide which number is latest_height:
   (- i6_global_height-->0 -).

to extract info from (F - a figure name):
   (- ExtractImageInfo(ResourceIDsOfFigures-->{F}); -).

Include (-
[ ExtractImageInfo id;
   glk_image_get_info(id, i6_global_width, i6_global_height);
];
-)


Top
 Profile Send private message  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group