8.1 Figure Items

As described above, the responsibility for the contents of an instance of window relies on the programmer. To aid the programmer in making graphics, Guienv defines a number of patterns for drawing lines, rectangles (with sharp or round corners), ovals, wedges and polygons.

[2kb 212x102 GIF]

FigureItem is a subpattern of windowItem and inherits as such all its functionality (including the event handling possibilities) and defines the basic properties that are shared by all figure items. A figure item have a pen to be used for drawing the item. The pen defines attributes for defining the drawing pattern, the foreground and background colors, and the size of the pen (a rectangle).

Line is a straight line and defines the attributes start and end for accessing and changing the end-points of the line.

Shape is used as superpattern to all figure items that are defined by means of a rectangle and can be filled. Shape contains a fill attribute which defines the facilities for filling the shape (i.e. the tile pattern and the foreground and background colors to be used for the fill).

Rect is a real figure item in the sense that it is extending all figureItem procedures such that an instance of rect can be properly drawn in a window.

[1kb 176x95 GIF]

RoundRect is like rect, except that it also defines roundness to takes two integers, defining the round corners by defining the width and height of the oval in the corners. If R is an instance of roundRect, then

(OW, OH) -> R.roundness

defines the rectangle seen here.

[1kb 174x94 GIF]

Oval is also like rect except that an oval is drawn.

[1kb 176x93 GIF]

Wedge is like oval, except that it also defines startAngle and endAngle which takes one integers, defining the start and end angles of the arc. If A is an instance of wedge, then

SW -> A.startAngle
EW -> A.endAngle

defines the wedge seen here.

[2kb 175x93 GIF]

Polygon is a figure item that consists of a collection of connected line segments. The points defining the polygon is specified by:

p: [6] ^point
do &point[]->p[1][]; (3,3)  ->p[1];
   &point[]->p[2][]; (5,7)  ->p[2];
   &point[]->p[3][]; (4,45) ->p[3];
   &point[]->p[4][]; (30,45)->p[4];
   &point[]->p[5][]; (44,3) ->p[5];
   &point[]->p[6][]; (1,55) ->p[6];
   go.open;
   p[]->go.points
[2kb 176x93 GIF]

Drawing using figure items is as simple as:

Program 11: oval.bet

ORIGIN '~beta/guienv/guienv';
INCLUDE '~beta/guienv/figureitems' 
--- program: descriptor ---
guienv
(# aWindow: @window
     (# go: @oval
          (# open::
               (# 
               do (100, 100)->position;
                  (50, 100)->size;
                  7->pen.size
               #)
          #);
        eventhandler::
          (# onAboutToClose:: (# do terminate #) #);
        open:: 
          (# 
          do (100, 100)->position;
             (300, 300)->size;
             'oval'->title;
             go.open
          #)
     #)
do aWindow.open
#)

This creates a window with an oval, positioned in (100, 100) and with the oval drawn using a 7x7 sized pen.

Program 12: Screendump
(Windows NT)

[4kb 89x119 GIF]


Lidskjalv: User Interface Framework - Tutorial
© 1995-2004 Mjølner Informatics
[Modified: Friday October 27th 2000 at 14:56]