Counterfeit Monkey — 6 of 292

Emily Short

Release 6

Section 2 - Local Maps

A room has a figure-name called the local map. [Actual file names and assignments are made later, after all the rooms have been defined.]

[Simple Graphical Window provides instructions for scaling an image and putting it in the middle of the screen if the aspect ratio of the window it needs to fill is slightly wrong. In this case, though, we want to put the map at the bottom of the screen and fill the background above it with black, so there is no apparent top and bottom margin at all.]

This is the bottom wide drawing rule:

draw wide image in graphics window;

To draw wide image in graphics window:

(- ScaleToBottomWide(); -)

This is the bottom scaled drawing rule:

draw bottom scaled image in graphics window.

To draw bottom scaled image in graphics window:

(- ScaleToBottom(); -)

Include (-

[ ScaleToBottom cur_pic result graph_width graph_height

img_width img_height w_offset h_offset w_total h_total;

if (FollowRulebook( (+glulx picture selection rules+) ) ) { cur_pic = ResourceIDsOfFigures-->(+ internally selected picture +); }

if (cur_pic == 0) rtrue;

if (gg_picwin) {

result = glk_window_get_size(gg_picwin, gg_arguments, gg_arguments+WORDSIZE);

graph_width = gg_arguments-->0;

graph_height = gg_arguments-->1;

result = glk_image_get_info( cur_pic, gg_arguments, gg_arguments+WORDSIZE);

img_width = gg_arguments-->0;

img_height = gg_arguments-->1;

w_total = img_width;

h_total = img_height;

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; if (h_offset < 0) h_offset = 0;

glk_image_draw_scaled(gg_picwin, cur_pic, w_offset, h_offset, w_total, h_total);

}

];

[ ScaleToBottomWide cur_pic result graph_width graph_height

img_width img_height w_offset h_offset w_total h_total;

if (FollowRulebook( (+glulx picture selection rules+) ) ) { cur_pic = ResourceIDsOfFigures-->(+ internally selected picture +); }

if (cur_pic == 0) rtrue;

if (gg_picwin) {

result = glk_window_get_size(gg_picwin, gg_arguments, gg_arguments+WORDSIZE);

graph_width = gg_arguments-->0;

graph_height = gg_arguments-->1;

result = glk_image_get_info( cur_pic, gg_arguments, gg_arguments+WORDSIZE);

img_width = gg_arguments-->0;

img_height = gg_arguments-->1;

w_total = img_width;

h_total = img_height;

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; if (h_offset < 0) h_offset = 0;

glk_image_draw_scaled(gg_picwin, cur_pic, 0, h_offset, graph_width, h_total);

}

];

-)