Glimmr Canvas-Based Drawing
version 2/101030 by Erik Temple
- Chapter: Concepts
- Chapter: Including Glimmr Canvas-Based Drawing in a project
- Chapter: Basic Usage
- Section: Define a graphics window
- Section: Define the canvas
- Section: Create elements and assign them to the canvas
- Section: Activate elements for display
- Chapter: Kinds of element
- Chapter: Settings and options for scaling
- Chapter: Elements and mouse input
- Chapter: Intermediate and advanced topics
- Section: The default canvas-based drawing rule
- Section: Using canvases to manage display
- Section: Framing the canvas
- Section: Creating new kinds of elements
- Section: Customizing element display
- Section: Elements as objects in the world model
- Chapter: Debugging
- Chapter: Troubleshooting
- Chapter: Producing images for use with Glimmr
- Chapter: A reference to elements and their properties
- Section: Summary of sprite properties
- Section: Summary of the primitive base class's properties
- Section: Summary of the properties of the box, stroked rectangle, line, and point primitives
- Section: Summary of the properties of the stroked rectangle primitive
- Section: Summary of the properties of bitmaps
- Section: Summary of the properties of image-maps
- Section: Summary of the properties of tileset image-maps
- Section: Summary of the properties of direct image-maps
- Section: Summary of the properties of rendered strings
- Section: Summary of the properties of bitmap-rendered strings
- Section: Summary of the properties of image-rendered strings
- Chapter: Contact info
- Chapter: Change Log
- Chapter: Examples
- Example: * Simple Buttons - In this example, we show how to create a simple set of buttons that the player can press to issue commands. (We use the most important meta-commands: undo, save, restore, and transcript.) The example requires the Glimmr Image Font extension, and you will need to copy the images associated with that extension to your project's Materials folder before building this example. The example also requires Glimmr Graphic Hyperlinks, which enables the buttons to accept mouse input.
- Example: * Simpler Buttons - This example is a simple refinement of the previous example (Simple Buttons). In Simple Buttons, we had to supply what really was redundant information: the text of the label was the same as the linked replacement-command of its button, while the origin coordinate of the label is easily deducible from the placement and size of the button outline (the label is centered on the button). This example lets us define the labels minimally and auto-generate their text-strings and origin coordinates from their associated buttons. (One could go even farther with this approach, really.)
- Example: *** Basic Floorplan - Given IF's overwhelming focus on movement through physical space, one of the most likely uses for graphics is maps. At the same time, it is not often that we want to include a static map in the game, since getting the complete map all at once will usually spoil things for the player.
- Example: ** Wandering Rhodes - We want to show the player's location on a map, but the full map is so large that it leaves us unable to see details. This example explores one solution to this problem, displaying the full map in one graphics window, and showing a detail view, an inset, in a second window.
- Example: ** Roguelike-like - This example uses image-maps and some sprites to create something that looks a lot like a roguelike dungeon-crawler. None of the actual game mechanics one would want in such a game are included, of course, but the basic techniques for display are provided.
- Example: *** Deal Me In - This example illustrates a number of different techniques. We show how to change the contents of a graphics window at a stroke by changing canvases. We also construct a custom graphic element with rather complex behavior: rather than simply drawing a single entity, the element acts as a manager, interpreting and drawing game information using varied techniques, as needed.
Glimmr Canvas-Based Drawing (GCBD) takes an object-oriented approach to drawing in graphics windows. The central concept is the "canvas" (called the "g-canvas" to avoid namespace conflicts). A canvas is similar to the HTML5 <canvas> element: it is a defined area within which graphic elements of various sorts can be displayed. The canvas is basically nothing more than a coordinate system, a blank page which is given certain dimensions. To display a canvas, we assign it to a graphics window (created using the Flexible Windows extension). When the window is opened, the composition we have defined will be displayed, and the canvas--along with all of the graphic elements displayed in it--will automatically be scaled to fit in the window.
The graphic elements displayed in the canvas are called "g-elements" (again, to avoid namespace clashes with your code or with other extensions). These are declared as individual objects. GCBD provides four basic types of element:
sprite - displays an image from a file (a "figure" in Inform's terminology).
primitive - a simple shape such as a filled rectangle, an outlined box, or an arbitrary line.
bitmap - a complex element declared by specifying a grid of on/off or colored "bits"; similar to programming an LED sign.
image-map - a complex element declared by specifying a grid of image tiles.
rendered string - a complex element in which either image files or bitmaps are used to render arbitrary text strings.
The element types are discussed in more detail below. Authors can also create their own g-element types if desired; some examples are given in this documentation.
Elements are assigned to a canvas, and they can also be set either active or inactive; inactive elements will not be displayed. They can also be scaled relative to the canvas and given z-values (called "display-layer") to control the way in which objects overlap each other. If we include the Glimmr Graphic Hyperlinks extension, elements can also be made to respond in various ways to mouse input from the player.