Glulx Drawing Commands

version 1/090629 by Erik Temple

  • Home page
  • Beginning



  • Documentation

    Glulx Drawing Commands exposes all of the inputs to the main Glulx drawing commands at the I7 level. When used with either Simple Graphical Window or Flexible Windows, this enables authors to write their own drawing rules without any I6 inclusions. Glulx Drawing Commands also includes a couple of derivative commands, including commands to draw a "stroke" of variable weight around a rectangular area of the screen, and to draw squares using a slightly more concise syntax

    The extension implements the Glulx commands glk_image_draw, glk_image_draw_scaled, and glk_window_fill_rect. It does not include the glk_window_erase_rect command, since this is easily imitated using the "draw a rectangle" command provided together with the background color attributes provided by the Simple Graphical Window and Flexible Windows extensions it is designed to work with.

    Glulx Drawing Commands requires either Emily Short's Simple Graphical Window or Jon Ingold's Flexible Windows, and provides equivalent functions with either. Since these two extensions are incompatible, Glulx Drawing Commands cannot be used with both at the same time!

    Glulx Drawing Commands provides the following drawing phrases (as written with Simple Graphical Window; see below for Flexible Windows syntax):

        (1) draw the image Figure of Cover at coordinates 10 by 10;
        (2) draw the image Figure of Cover at coordinates 10 by 10 with dimensions 20 by 40;
        (3) draw a g-red filled rectangle at coordinates 10 by 10 to 20 by 40;
        (4) draw a g-red filled square at coordinates 10 by 10 with size 20;
        (5) draw a rectangle with g-red stroke of 2 pixels from coordinates 10 by 10 to 20 by 40, outlining;
        (6) draw a square with g-red stroke of 2 pixels from coordinates 10 by 10 with size 20, outlining;

    Command 1 draws an image file (previously defined as Figure of...) with its upper left corner at a set of given coordinates, without scaling. Command 2 scales also draws and image, but fits it to the dimensions provided. Command 3 draws a rectangle of a given color, with its upper left corner at the first provided pair of coordinates, and its lower right corner at the second pair. Colors for the drawing commands must be defined in the Table of Common Color Values, (provided by the Glulx Text Effects extension). Command 4 simplifies the drawing of a square by allowing us to provide just the coordinate of the upper left corner of the shape, followed by the length (in pixels) of its sides.

    Commands 5 and 6 draw a rectangular outline with lines ("stroke" in the parlance of graphic art) of a given width (provided in pixels). If we append the "outlining" phrase option, these lines will be drawn outside the rectangular area we've defined; otherwise, the lines will be drawn on the interior of the rectangle.

    The syntax for drawing commands is relatively forgiving, and phrases can be shortened significantly, e.g.:

        draw Figure of Cover at 10 by 10;
        draw Figure of Cover at 10 by 10 with dimensions 20 by 40;
        draw a g-red filled rectangle at 10 by 10 to 20 by 40;
        draw a square with g-red stroke of 2 pixels from 10 by 10 with size 20;

    To use these commands with Flexible Windows, we must also supply the name of the g-window we wish to draw to (we need to have set up and opened this g-window prior to drawing to it):

        draw the image Figure of Cover in the graphics-window at coordinates 10 by 10;
        (2) draw the image Figure of Cover in the graphics-window at coordinates 10 by 10 with dimensions 20 by 40;
        (3) draw a g-red filled rectangle in the graphics-window at coordinates 10 by 10 to 20 by 40;
        (4) draw a g-red filled square in the graphics-window at coordinates 10 by 10 with size 20;
        (5) draw a rectangle with g-red stroke of 2 pixels in the graphics-window from coordinates 10 by 10 to 20 by 40, outlining;
        (6) draw a square with g-red stroke of 2 pixels in the graphics-window from coordinates 10 by 10 with size 20, outlining;

    The phrase "in the (g-window)" should be placed just before the coordinates are given.

    Finally, with both Simple Graphical Window and Flexible Windows, the dimensions of a figure can be queried using these terms:

        pixel-width
        pixel-height

    This is especially useful if we want to scale an image to fit the window. Brief usage:

        let X be the pixel-width of Figure of Cover;
        let Y be the pixel-width of Figure of Cover;
        draw the image Figure of Cover in the graphics-window at coordinates 10 by 10 with dimensions X and Y;

    Simple Graphical Window provides these terms to query the size of the graphics window:

        current graphics window width
        current graphics window height

    If we are using Flexible Windows, we will want to use these terms:

        width of (a g-window)
        height of (a g-window)