2 The Program Skeleton

As described in [MIA 91-13] every program using Bifrost must have ORIGIN in or INCLUDE the fragment called Bifrost, and execute an instance of the pattern called bifrost. The following program skeleton subway1.bet will be the starting point:

Program 1: subway1.bet

ORIGIN '~beta/bifrost/Bifrost';
-- PROGRAM: descriptor --

bifrost
(# 
   (* The program skelleton *)
   
   theWindow: @window
     (# myCanvas: @BifrostCanvas
          (# open:: 
               (# do (300, 300)->Size->theWindow.size #);
             eventhandler:: 
               (# onOpen:: (# (* ... *) #);
                  onMouseDown:: (# (* ... *) #);
                  onKeyDown:: 
                    (# 
                    do (if ch
                        ='Q' then Terminate
                       if)
                    #);
               #);
          #);
        open:: 
          (# 
          do myCanvas.open
          #)
     #) (* theWindow *)
do theWindow.open;
   1->Arguments->theWindow.title;
#)

The ORIGIN ~beta/bifrost/Bifrost contains the bifrost fragment. Bifrost includes the graphical user interface environment Lidskjalv, see [MIA 94-27], so we can start by declaring an ordinary Lidskjalv window to contain the graphics.

In the window a static Canvas [1] is declared, in which further binding of various virtuals have been prepared.

In init, so far, the Canvas is given an arbitrary size.

The onOpen virtual is called when the open procedure pattern has completed, e.g., when the window containing the Canvas has become visible in the window system. From within this virtual pattern, the drawing operations on the Canvas should be performed.

The virtual pattern onMouseDown is called when a button on the pointing device, if any, has been pressed. So far the actions to perform in this case are unspecified.

The virtual pattern onKeyDown is called when a keyboard key has been pressed. In this case, it is checked whether the user types 'Q' within the Canvas, and if so the application is stopped.

After theWindow has been opened, it is given the name of the program as title.


[1] In the current Bifrost version the pattern name BifrostCanvas is used when declaring canvasses. This is because of an overlap in names in Lidskjalv and Bifrost. The naming conflict will probably be solved in a later version of Bifrost and Lidskjalv. In the rest of this tutorial we will use the original Bifrost term 'Canvas' as a synonym for 'BifrostCanvas', but in the coding the latter has to be used for the moment


The Bifrost Graphics System - Tutorial
© 1991-2004 Mjølner Informatics
[Modified: Monday October 23rd 2000 at 22:18]