Previous | Table of Contents | Next |
6.3.4.2. VIB
VIB provides a visual interface on which tools can be placed, arranged, and configured. Mouse actions and dialogs provide the means.
The VIB window for a new interface looks like this:
The menu at the top provides various features. Below this is a toolbar with icons representing the kinds of tools and decorations that can be placed on an interface.
From left to right, these are
Below the toolbar is a rectangular area that indicates the size of the interface that is being constructed. The box at its lower-right corner can be dragged to change the size of the area.
An instance of a tool is created by pressing on its icon and dragging onto the interface area. The attributes of a newly created tool usually need to be changed. This is done by using the mouse for positioning and sizing and by dialogs for other attributes as well as setting precise locations and sizes.
A dialog for configuring a tool is produced by pressing the right mouse button with the mouse cursor on the tool. For example, the dialog for the clear button, after editing, looks like this:
The label, clear, is what appears on the face of the button. The ID is used to identify the tool; a mnemonic value, perhaps the same as the label, is useful for keeping track of tools. The callback field contains the name of an Icon procedure that is called when the user presses the button. Thus, the code for the symmetric drawing application contains a procedure clear_cb() that clears the display region so that a new drawing can be started. The other fields in this dialog relate to the buttons appearance and functionality. For example, for the lines button, toggle is checked to indicate that the button maintains a state.
The dialog for a menu provides fields for the items the menu supports:
As indicated by this dialog, there are provisions for adding and deleting items and creating submenus for items.
The dialog for a region provides four options for the visual appearance of the regions border:
The callback procedure for a dialog is called when an event occurs in the region.
The final interface for the symmetric drawing application, as seen in VIB, looks like this:
6.3.4.3. Integrating the Interface and the Program
VIB produces code to create the interface. The complete application consists of the VIB interface code, code to support user interaction, and code for the functionality of the application itself.
The code produced by VIB contains a procedure, ui(), that opens a window for the interface, draws the tools, and initializes them. This procedure also returns a table whose keys are the tool IDs and whose corresponding values are records that implement the tools.
A program that has a VIB interface typically begins in this way:
procedure main() tools := ui()
The tools are enclosed within and managed by a root tool that has the ID root. User events are handled by a procedure that takes the root as an argument:
GetEvents(tools[root])
This procedure produces callbacks for user actions on tools. GetEvent() never returns; all program activity occurs as the result of callbacks.
6.3.4.4. Callbacks
A callback procedure has two arguments: the tool that caused the callback and a value associated with that tool.
In the case of a menu, the value is a list that contains the selected items and items from successive submenus, if any. The callback procedure for the file menu is
procedure file_cb(tool, value) case value[1] of { save: save() help: help() quit: exit() } return end
Because the items on the file menu do not have submenus, the list has only one element. The procedures save() and help() save an image file for the current drawing and provide access for information on how to use the application, respectively. The function exit() simply terminates program execution.
The callback procedure for the clear button is simpler. Because no value is associated with a button without a state, no arguments are needed:
procedure clear_cb() EraseArea(pane) if \lines then drawmirrors() return end
The global variable lines is non-null if lines for the mirrors are to be drawn.
Activity related to symmetric drawing occurs within the region tool. For a region, the callback values are the events themselves, such as mouse button presses. The symmetric drawing application has several modes, including drawing points, drawing lines, and erasing. The portion of the region callback associated with drawing points illustrates the procedure:
procedure pane_cb(vidget, event) &lpress: { # freehand drawing every DrawPoint(pane, &x | (W &x), &y | (H &y)) every DrawPoint(pane, &y | (W &y), &x | (H &x)) x := &x y := &y }
Note that alternation is used to draw in symmetric positions.
Previous | Table of Contents | Next |