Simple Graphical Window

version 8 by Emily Short

  • Home page
  • Beginning
  • Next

  • Documentation

    Simple Graphical Window creates one graphics window, and provides some different methods of drawing images in that window. The window may be placed above, below, or beside the main text window (left or right), and may be sized or proportioned as we like, but there may be only one; this extension does not allow for drawing multiple graphics windows or creating a more complex window layout.

    **** Rules for drawing in windows ****

    Whenever Inform needs to re-fill the window -- at the start of the game, or when a saved game is restored, or when the player resizes the window manually -- Simple Graphical Window will follow a rule that varies, the "current graphics drawing rule". The author may set this to any of the following:

        (1) (The default.) The standard placement rule. The standard placement rule fills the window with a background color, then draws the currently shown picture (a figure-name that varies, and which the author can reset during the game). The picture is centered in the available screen space, unless it is too large, in which case it is scaled down proportionally to fit. A picture is never scaled up, on the grounds that upscaling images usually produces unattractively fuzzy results. Note that this and rules 2-4 will all behave incorrectly if we don't have at least one figure defined in our game source. In that case, see rule 5.

        (2) The fully scaled image rule. Fills the window completely with the currently shown picture, regardless of proportion. This is unlikely to look good with images of any complexity, but is included for completeness.

        (3) The tiled drawing rule. Tiles the currently shown picture to fill the available space horizontally and vertically.

        (4) The centered scaled drawing rule. Same as the standard placement rule, except that it does not fill the window with a background color first. This means that if there is something previously printed in the graphics window, this may overlap it.

        (5) The bland graphics drawing rule. Blanks the window to the background color and does nothing else.

    To set this rule at the outset of play, we would write, for instance

        Rule for starting the virtual machine:
            now the current graphics drawing rule is the bland graphics drawing rule.

    It is important to use the "starting the virtual machine" activity because this occurs before the first window-drawing happens; where as "when play begins" happens after the windows have already been set in place, when it is too late to give instructions about constructing them.

    If we need to redraw the image in the window, we write

        follow the current graphics drawing rule.

    For instance if we were adding an image to the screen every time the player moved, we might write something like

        Carry out looking:
            change currently shown picture to the room illustration of the location;
            follow the current graphics drawing rule.

    ...where the room illustration is defined for each room in the game. (The extension "Location Images" implements this idea in full.)

    The author may also create other drawing rules of his own devising and make any of these the current graphics drawing rule, as needed. It will probably be necessary to specify graphics drawing rules in Inform 6 unless the author intends a fairly simple combination of the rules already provided here; for more information about graphics drawing in Glulx, see

    In writing these rules, it's worth bearing in mind that the rule should be able to reconstruct the entire contents of the graphics window every time it is called, rather than relying on things drawn there during previous moves; otherwise, the graphics window will not redraw properly when the game is reloaded or a turn is undone.

    **** Window alignment ****

    By default, the graphics window is drawn above the main text window and below the status line. There are three other options, however: left of the main text window, right of the main text window, and below the main text window. The alignment depends on "graphics window position", which can have any of the values g-left, g-above, g-right, and g-below. So for instance we might write

        Graphics window position is g-right.

    to produce a window along the right side of the screen.

    Note that window alignment and dimensions should be set at the outset; changing them after the start of play will not redraw the window in a new size.

    **** Window dimensions ****

    Graphics windows in Glulx can be of two kinds: fixed and proportional. A fixed window has a height (or width, if drawn left/right rather than above/below) of a set number of pixels regardless of the total screen area devoted to the game; a proportional window has a height (or width) relative to that of the main window, which may be between 1 and 99 percent.

    If we prefer a proportional window, we set the "graphics window proportion" to some number between 1 and 99, thus:

        The graphics window proportion is 25.

    If we prefer a fixed window, we set "graphics window pixel count", which should be a number reflecting the desired height of our graphics window in pixels. We can set this by adding a line to our source such as

        The graphics window pixel count is 150.

    If both a graphics window pixel count and a graphics window proportion are given and the graphics window proportion is a valid number between 1 and 99, the proportion is obeyed and graphics window pixel count is simply ignored.

    If no information is provided, the graphics window defaults to a fixed-count window of 240 pixels.

    **** Glulx colors ****

    The background color used by the standard placement rule depends on the "graphics background color". The graphics background color can be set to any value of the kind "glulx color value". This extension, relying on Glulx Text Effects, provides a table of glulx color values to start from, as follows:

        Table of Common Color Values
      glulx color value  assigned number  
      g-black  0  [== $000000]  
      g-dark-grey  4473924  [== $444444]  
      g-medium-grey  8947848  [== $888888]  
      g-light-grey  14540253  [== $DDDDDD]  
      g-white  16777215  [== $FFFFFF]  

    where the assigned number of each value is the decimal representation of a hex color code. To use any of the preset values, we might write

        The graphics background color is g-black.

    Moreover, the phrase "blank window to..." allows us to fill the graphics window with one of these preset colors, as in
        blank window to g-white;
        blank window to g-black;
        blank window to graphics background color;

    It is likely that we'll want to use other colors besides those provided by this extension. We may do this by continuing the table thus:

        Table of Common Color Values (continued)
      glulx color value  assigned number  
      g-yellow-orange  39423  [== $0099FF]  
      g-ice-blue  15645627  [== $EEBBBB]   

    These numbers are conversions of hex color numbers. The principle is that the hex number represents the amount of blue in the first two digits (from 00 to FF); the amount of green in the next two digits; and the amount of red in the last two digits. Thus $0000FF has no blue or green in it, but the maximum possible amount of red. Where each pair of digits is equal (as in $444444 or $A0A0A0), we will have equal components of each color and the result will be some shade of grey. The number for g-ice-blue was selected by formulating a hex color number with a large amount of blue and a moderate amount of red and green ($EEBBBB). Similarly, the number for g-yellow-orange is the conversion of ($0099FF), with the maximum amount of red, a fair amount of green, and no blue.

    Converting a hex number to a decimal one can be performed with a scientific calculator or with a hexadecimal conversion application found online; if we're at a loss, googling "hexadecimal conversion calculator" will likely turn up an appropriate application.