# Glimmr Canvas-Based Drawing

## version 2/101030 by Erik Temple

**Chapter - Calculating the scaling factors**

Scaling something is an activity.

Last for scaling a graphics g-window (called the window) (this is the default window-scaling rule):

#if utilizing Glimmr debugging;

say "[>console][CBD]Window [i][window][/i] is [width of the window] by [height of the window] pixels.[<]";

#end if;

let panel be the associated canvas of the window;

if panel is nothing:

say "*** Scaling error: No canvas defined for [italic type][window][roman type].";

rule fails;

if the canvas-width of panel is 0 or the canvas-height of panel is 0:

if the background image of panel is Figure of Null:

#if utilizing Glimmr debugging;

say "[>console][CBD]*** Scaling error: Dimensions of canvas [i][panel][/i] not specified. Either define the canvas using a background image, or assign numerical dimensions.[<]";

#end if;

rule fails;

[doubling up of variables necessary due to an apparent bug in Inform]

let canvas-x be the image-width of the background image of panel;

let canvas-y be the image-height of the background image of panel;

now the canvas-width of panel is canvas-x;

now the canvas-height of panel is canvas-y;

#if utilizing Glimmr debugging;

say "[>console][CBD]Canvas [i][panel][/i] is [canvas-width of panel] by [canvas-height of panel] pixels.[<]";

#end if;

if the arbitrary scaling factor of the window is real greater than 0.0000:

now the scaling factor of the window is the arbitrary scaling factor of the window;

#if utilizing Glimmr debugging;

say "[>console][CBD]Scaling factor of [i][window][/i] set to [scaling factor of the window] based on arbitrary scaling factor.[<]";

#end if;

otherwise:

let x-win be the width of the window as a fixed point number;

let y-win be the height of the window as a fixed point number;

now the x-scaling factor of the window is x-win real divided by the canvas-width of panel;

now the y-scaling factor of the window is y-win real divided by the canvas-height of panel;

if the x-scaling factor of the window is real greater than the y-scaling factor of the window:

now the scaling factor of the window is the y-scaling factor of the window;

#if utilizing Glimmr debugging;

say "[>console][CBD][i][window][/i] scaling factor set to the vertical scaling factor: [y-scaling factor of the window].[<]";

#end if;

otherwise:

now the scaling factor of the window is the x-scaling factor of the window;

#if utilizing Glimmr debugging;

say "[>console][CBD][i][window][/i] scaling factor set to the horizontal scaling factor: [i][x-scaling factor of the window][/i].[<]";

#end if;

if the scaling factor of the window is greater than 1.0000:

unless the oversize scaling of the window is true:

now the scaling factor of the window is 1.0000;

#if utilizing Glimmr debugging;

say "[>console][CBD][i][window][/i] scaling factor set to [scaling factor of the window]. To allow for a higher scaling factor, set the window's oversize scaling property to true.[<]";

#end if;

now the scaled width of panel is the scaling factor of the window real times the canvas-width of panel as an integer;

now the scaled height of panel is the scaling factor of the window real times the canvas-height of panel as an integer;

#if utilizing Glimmr debugging;

say "[>console][CBD]Scaled size for canvas [i][panel][/i] is [scaled width of panel] by [scaled height of panel].[<]";

#end if;