Drawing Statements

A drawing statement is a statement that invokes one of the Shape routines - either a system one or a user defined one. These statements are the core of the system and are quite complex.

Drawing statements may only occur within a Shape routine - including the Program routine.

drawstmt ::= shapeexpr ( [ paramlist ] ) [ => grcontextlist ] ;

The shapeexpr is any expression that yields a Shape value. This will be either a name of a Shape routine or an expression that yields a datum containing a Shape.

The paramlist is the same as for calling routines in general and are covered elsewhere. Even if there are no parameters the brackets still need to be present.

The grcontextlist is a comma separated list of graphics context values to be used for this call. If any context object is not specified then the value will be inherited from the current graphics context. If all the context elements are to be inherited then the '=>' must be omitted.

The Graphics Context

The graphics context controls how and where the shape will be drawn. Not all the elements need to be specified, however no type may occur more than once. The system will be able to detect the data type of the expressions so the graphics elements can be listed in any order.

The Origin

The origin expressions should yield a result of type Point. The origin is the one context element that can be written directly as a structure within a pair of braces. Thus any such structure will automatically be assumed to be a Point.

The origin specifies where the shape should be drawn. This is always specified relative to the current context. So if the current context has an origin at {100, 100} and an origin is specified in the current drawing statement as {10, 20} then the working origin for the invoked shape will be {110, 120} on the actual final image.

Other Graphics Context Elements

The other four contexts elements are the pen, brush, font and canvas. None of these can be written as a literal structure and so should be a datum identifier or an expression that yields a value of the correct type. The datums containing the current defaults for these can be accessed by the identifiers Pen, Brush, Font and Canvas. These can be used in conjunction with the brace operator '{' to generate new objects.

Circle(10) => {10, 20}, Pen { colour -> {100, 0, 0} };

In the example above the circle will be draw at 10 pixels left and 20 pixels down relative to the current origin. The statement will also generate a temporary pen that has all the characteristics of the current pen but with the colour set explicitly to red.