Graphics

Graphics in ABC is provided through a framework of types called Shapes. Each type of graphic entity (e.g. rectangle, arc, text) is a subtype of Type Shape. In addition, images, fonts and points are available to support these graphics types.

A typical method to draw a rectangle in a window called theWindow would be:

	aMethod
          { aRec -> Rectangle new.
            aRec movex 100 movey 150.
            !! it is assumed that aMethod has access to the
            !! variable theWindow which points to a Window widget
            aRec drawIn theWindow.
          }

All shapes can be moved and resized. In addition, their foreground and background colors can be set as well as their writing mode.

The shapes you can draw include: line, arc, polygon, rectangle, button, editor, icon, named icon, axis, backpage, painting and table.

Shape

Type Shape is an abstract type which provides default behavior for many of the functions required of shapes. For additional functionality, refer to Type PartsList.

Parts

origin:Point (location of upper left corner of shape)
width:Integer (width of extent rectangle)
height:Integer (height of extent rectangle)
decor:String (storage for color, modes and other decorations)

Type Methods

This section lists methods available when Type Shape is receiver.

new

Create a new shape and initialize the origin, height, width and decor.

Instance Methods

This section lists methods which are available to all instances of Shape.

selectEmbedsIn aWidget:Widget

Selects (i.e. highlights) any embedded figures in Shape. Type Text uses this method to select embedded figures in text.

animateTo aPoint:Point in aWindow:Window every msec:Integer

Moves me from my current position to aPoint in aWindow. The shape is moved using incremental, linear motion and pauses msec milliseconds each increment. Set msec to 0 for the fastest speed.

computeExtent

Recompute the width and height of me.

drop aFigure:Figure in aWidget:Widget with aMode:Shapemode

Embeds aFigure in me. AWidget and aMode are used to redisplay the shape.

hasText aString:String
REPLY Boolean

Reply TRUE if aString is contained in the shape.

unmanaged anEvent:Event

Handle anEvent which was not handled by any other object.

enterIn aWidget:Widget

Change the display of me because the user has clicked on the shape for the purpose of editing.

leaveIn aWidget:Widget

Change the display of me because the user has indicated that editing is no longer in effect for this shape.

motion anEvent:Event

Process a motion event for this shape.

buttonPress anEvent:Event

Process a buttonPress event for this shape.

buttonRelease anEvent:Event

Process a buttonRelease event for this shape.

keyPress anEvent:Event

Process a keyPress event for this shape.

keyRelease anEvent:Event

Process a keyRelease event for this shape.

isEmpty
REPLY Boolean

Reply TRUE if width and height are 0. This will be the case for objects like text which don't initially have text in them.

reset

Revert the shape back to some known state.

movex newx:Integer movey newy:Integer

Move the shape to newx@newy. Note that this does not change the display of the shape. Typically, you will erase the shape in a window, move it and then redisplay it in the new location.

shiftx dx:Integer shifty dy:Integer

Shift the origin by dx and dy. Note that this does not change the display of the shape.

resizeWidth aWidth:Integer resizeHeight aHeight:Integer

Change the width and height of the shape. Note that this does not change the display of the shape.

drawIn aWidget:Widget

Draw me in widget aWidget, typically a window.

eraseIn aWidget:Widget

This will set the foreground to the window background, draw the shape and then reset the foreground. This may not be the best way to erase it in cases when the shape overlays a colored background because it will leave a shadow.

contains pt:Point
REPLY Boolean

Reply TRUE if pt lies within the shape. By default, pt must lie within the extent rectangle. The minimum size of the rectangle is 10 by 10.

extentIn aRec:Rectangle

Set aRec to the extent rectangle of the shape.

foreground aColor:Integer

Set the foreground color of the shape to aColor. The value of aColor can be 0-black, 1-white, 2-red, 3-green, 4-blue, 5-yellow, 6-cyan, 7-magenta or a shade from 8-132.

background aColor:Integer

Set the background color of the shape to aColor. The value of aColor can be 0-black, 1-white, 2-red, 3-green, 4-blue, 5-yellow, 6-cyan, 7-magenta or a shade from 8-132.

writeMode aMode:Integer

Set the writing mode to aMode. The value of aMode can be #replace or #overlay. Normally the writing mode should be #replace. Mode #overlay is used for dragging or animation when you don't want to disturb the background. The first time you draw a shape in #overlay mode it will appear. If you draw it again in the same position it will disappear without changing the background.

foreground
REPLY Integer

Reply with the foreground color.

background
REPLY Integer

Reply with the background color.

writeMode
REPLY Integer

Reply with the writing mode.

drawHandlesIn aWidget:Widget with aMode:ShapeMode

Draw the handles (i.e. small black squares) in aWidget using aMode. AWidget is usually a window and aMode contains the rectangles to draw. By default, draw the handles in the upper left and lower right corners of the extent rectangle.

selectIn aWidget:Widget

Highlight the shape to indicate that it is selected. By default, the shape is the extent rectangle.

motion anEvent:Event with aMode:ShapeMode

Process the motion event generated during editing. AMode will contain the information on the current status of the editing operation.

buttonPress anEvent:Event with aMode:ShapeMode

Process the buttonPress event generated during editing. AMode will contain the information on the current status of the editing operation.

buttonRelease anEvent:Event with aMode:ShapeMode

Process the buttonRelease event generated during editing. AMode will contain the information on the current status of the editing operation.

keyPress anEvent:Event with aMode:ShapeMode

Process the keyPress event generated during editing. AMode will contain the information on the current status of the editing operation.

keyRelease anEvent:Event with aMode:ShapeMode

Process the keyRelease event generated during editing. AMode will contain the information on the current status of the editing operation.

getValues db:Dialogbox

Set the dialogbox db to the current settings of me. The db may vary depending on the actual type of shape to set the various attributes of the shape.

setValues db:Dialogbox
Update the settings of me based on the dialogbox db.

Line

Type Line provides functionality like line width, line style and fill style which are used by all line drawing shapes. It is also used to draw single line shapes. For additional functionality, refer to Type Shape.

Parts

pattern:Bitmap (Bitmap pattern used for filling)

Instance Methods

This section lists methods which are available to all instances of Line.

from start:Point to end:Point

Set the line so that the origin is at start and the end point is at the lower right corner of the extent rectangle.

lineWidth
REPLY Integer

Reply with the line width.

lineStyle
REPLY Integer

Reply with the line style.

fillStyle
REPLY Integer

Reply with the fill style.

lineWidth aWidth:Integer

Set the line width to aWidth. It should be a number greater than 0.

lineStyle aStyle:Integer

Set the line style to aStyle. Valid values include #solid, #dot, #dash or #dotdash.

fillStyle aStyle:Integer

Set the line style to aStyle. The style is 0-none, 1-solid or 2 to 37 for other filling patterns.

Arc

Type Arc provides the functionality to draw circles, ellipses and arcs. For circles and ellipses, the beginAngle is set to 0 and the degreesOfArc to 360. Ellipses will have unequal width and height while circles will have them equal. For additional functionality, refer to Type Line.

Parts

beginAngle:Integer (Angle to begin drawing)
degreesOfArc:Integer (Degrees of sweep)

Type Methods

This section lists methods available when Type Arc is receiver. method{width w:Integer height h:Integer from newstart:Integer to newdegrees:Integer}

Reply with an arc of width w, height h, starting angle of newstart and a degreesOfArc of newdegrees.

ellipseWithWidth w:Integer height h:Integer

Reply with an ellipse of the specified dimensions.

circleWithRadius r:Integer

Reply with a circle of the given radius.

new

Reply with a circle of radius 50.

Instance Methods

This section lists methods which are available to instances of Arc.

contains pt:Point
REPLY Boolean

Reply TRUE if the arc contains pt, no matter whether the arc is filled or not.

asString
REPLY String

Reply with the string representation of the arc in the form ``x@y w:h:begin:degree''.

arcmode
REPLY Integer

Reply with the arc mode.

arcmode aMode:Integer

Set the arc mode. Valid values for aMode include #pieslice or #chord. Arc mode is used in drawing filled arcs which have degreesOfArc less than 360. With #pieslice, the filled area is bounded by a line from the center to the beginning of the arc and a line from the center to the end of the arc. With #chord, the area is bounded by the arc and a line drawn from the beginning to the end of the arc.

Polygon

Type Polygon supports the functionality of a shape consisting of many edges. Straight/curved and opened/closed polygons are supported. Arrow heads may be positioned on the line segments as well. For additional functionality, refer to Type Line.

Parts

endpoints:Array (list of endpoints)
arrowMode:Integer (arrow head mode)
polyMode:Integer (straight/curved,opened/closed)
selectpt:Point (used during editing)

Type Methods

This section lists methods available when Type Polygon is receiver.

origin orgPt:Point points anArray:Array

Reply with polygon with origin at orgPt and endpoint in anArray.

new

Reply with new line from 0@0 to 100@0.

Instance Methods

This section lists methods which are available to instances of Polygon.

asString
REPLY String

Reply with a string of the form ``[(x1@y1)(x2@y2)...(xn@yn)]''.

arrowStyle
REPLY Integer

Reply with arrow style.

arrowStyle aMode:Integer

Set arrow style to aMode. Valid values for aMode include #none, #all, #beginall, #endall, #beginend, #begin and #end. The 'all' in #all, #beginall and #endall refers to all line segments. For example, #beginall would place arrow heads at the beginning of each line segment. Since ABC draws curves as very short line segments, it is recommended that you use an arrowStyle of #none for curves.

polyStyle
REPLY Integer

Reply with polygon style.

polyStyle aMode:Integer

Set the polygon style to aMode. Valid values for aMode include #openline, #closedline, #opencurve and #closedcurve.

Rectangle

Type rectangle is used to draw squares and rectangles. For additional functionality, refer to Type Line.

Type Methods

This section lists methods available when Type Rectangle is receiver.

x newx:Integer y newy:Integer width w:Integer height h:Integer

Reply with a rectangle of the given position and dimensions.

Instance Methods

This section lists methods which are available to instances of Rectangle.

pixelsToMm

Convert the rectangle of the given width and height in pixels to a similar rectangle measured in millimeters.

recStyle aStyle:Integer

Set the rectangle style to aStyle. Values values for aStyle include #squared and #rounded.

recStyle
REPLY Integer

Reply with the rectangle style.

corner
REPLY Point

Reply with the corner point.

surrounds rec:Rectangle
REPLY Boolean

Reply TRUE if rec is fully contained in me.

intersects aRec:Rectangle
REPLY Boolean

Reply TRUE if me and aRec overlap.

asString
REPLY String

Reply with a string of the form ``x@y;w:h''.

Text

Type Text supports the display of text in a window. Text may be multiline text with embedded figures. For additional functionality, refer to Type Shape.

Parts

lines:Array (array of lines, one string per line)
theFont:Font (font of text)
row:Integer (row of editing cursor)
col:Integer (column of editing cursor)
bullet:Icon (type of bullet)
embeds:Array (array of embedded figures)

Type Methods

This section lists methods available when Type Text is receiver.

new

Reply with an empty Text item.

newText anArray:Array

Reply a text item as specified in anArray.

Instance Methods

This section lists methods which are available to instances of Text.

selectEmbedsIn aWidget:Widget

Highlight any embedded figures which have behaviors associated with them.

embeddedFigureAt aName:String
REPLY Figure

Reply with the embedded figure named aName. Otherwise reply NIL.

reset

Reset any embedded figures.

embedCount
REPLY Integer

Reply with the number of embedded objects on row row.

findFigureAt aPoint:Point
REPLY Figure

Reply with the figure which contains aPoint. Otherwise reply NIL.

addFont aStyle:Integer in aWidget:Widget

Change or add an embedded font at row and col. If the font at row and col is #bold or #italics and aStyle is #italics or #bold, respectively, then change the embedded font to #bolditalics.

addEmbed anObject:PartsList

Add the embedded object at row and col. AnObject should be either a font or a Figure or a signal will be generated.
SIGNAL "Bad text embed object"

WidthOf aRow:Integer to aCol:Integer
REPLY Integer

Reply with the width of the characters on aRow from 1 to aCol. This measurement account for variable sized fonts and embedded figures.

heightOf aRow:Integer
REPLY Integer

Reply with the maximum height of aRow. This measurement includes any embedded figures.

hasText aString:String
REPLY Boolean

Reply TRUE if any of the text in the text object includes aString (case-insensitive).

drawCursorIn aWidget:Widget with aMode:ShapeMode

Draw the text cursor at row and col. AMode contains the triangle used for the text cursor.

isEmpty
REPLY Boolean

Reply TRUE if there is not text in me.

drawHandlesIn aWidget:Widget with aMode:ShapeMode

The resize handle for text is display at the lower left corner rather than the lower right. Clicking on it in edit mode will cycle between the font sizes.

setTextTo anArray:Array

Change the text to that stored in anArray.

drawIn aWidget:Widget from start:Integer to finish:Integer

Draw the text from row start to row finish.

setFontTo aFont:Font

Change the font to aFont.

asString
REPLY String

Reply with a string of the text with lines separated by newline characters. Also note that embedded figures will not be included but that ASCII values of 1 and 2 will be present in the string where these figures were found.

Button

Type Button provides the ability to display text with a border and optional shadow. For additional functionality, refer to Type Text.

Parts

border:Rectangle (used to display border)
shadow:Boolean (TRUE if shadow is desired)

Type Methods

This section lists methods available when Type Button is receiver.

new

Reply with a rounded and shadowed button.

newText anArray:Array

Reply with a button of the specified text in anArray.

Instance Methods

This section lists methods which are available to instances of Button.

drawBorderIn aWidget:Widget

Draw the border rectangle.

drawShadowIn aWidget:Widget

Draw the shadow if shadow is TRUE.

Editor

Type Editor is a button which can be edited by users. You can specify the minimum size of the editor and whether it can be expanded. The width is based on the number of allowable characters and is computed using the width of W in the current font. There may be some additional space if the entered characters are not as wide as W. For additional functionality, refer to Type Button.

Parts

textWidth:Integer
textHeight:Integer
numLines:Integer
numChars:Integer
expand:Boolean
smode:Shapemode
viewing:Boolean

Type Methods

This section lists methods available when Type Editor is receiver.

new

Reply with an editor of 1 line and 10 characters which cannot expand.

Instance Methods

This section lists methods which are available to instances of Editor.

reset

Clear the text from the editor.

enterIn aWidget:Widget

Display the text cursor.

leaveIn aWidget:Widget

Remove the text cursor.

Icon

Type Icon is used to display bitmaps in a window. For additional functionality, refer to Type Shape.

Parts

mapName:String (bitmap name)
map:Bitmap (actual bitmap)

Type Methods

This section lists methods available when Type Icon is receiver.

new

Reply with the Bitmap icon which looks like a tree.

Instance Methods

This section lists methods which are available to instances of Icon.

bitmap aName:String

Set the bitmap to aName.

drawHandlesIn aWidget:Widget with aMode:ShapeMode

Draw only the drag handle since a bitmap cannot be resized.

NamedIcon

Type NamedIcon draws a bitmap in a window with text centered below it. For additional functionality, refer to Type Icon.

Parts

title:Text (text used for the title)

Type Methods

This section lists methods available when Type NamedIcon is receiver.

new

Reply with a new icon named ``New Icon''.

Instance Methods

This section lists methods which are available to instances of NamedIcon.

centerTitle

Recompute location of title and center it.

named name:String

Rename icon with name.

Axis

Type Axis provides the functionality to display a vertical or horizontal axis with tic marks and labels. Graphs can be constructed by creating a vertical and horizontal axis.

Options are available for numbering on the #left or #right of a vertical axis (for horizontal axes, use #left for top and #right for bottom) by setting numPlacement to these values. Similarly, tic marks are positioned using #left, #middle or #right by setting ticPlacement.

The format of the number labels are controlled by specifying labelFormat. This is a string which uses a format string like ``%5.1f'' or ``X = %f'' to display the number. For integer values use a format like ``%5.0f'' to eliminate the decimal point.

The major tic marks are drawn by specifying the number of divisions to break the axis into. For example, if you want 4 equal divisions for a scale from 0 to 100, specify 4. Tics will be drawn at 0,25,50,75 and 100. Similarly, the minor tic marks are drawn by specifying the number of divisions to break each major interval into.

Methods are also available for converting between millimeters and scaled units. These can be used to plot points or lines on a graph or for determining where a user clicked in scaled coordinates. For additional functionality, refer to Type Shape.

Parts

vertical:Boolean (TRUE if axis is vertical)
minimum:Real (minimum scaled value)
maximum:Real (maximum scaled value)
major:Integer (major interval for tic marks)
minor:Integer (minor integer for tic marks)
majorTic:Line (line to display major tic marks)
minorTic:Line (line to display minor tic marks)
theLabel:Text (text to display label)
labelFormat:String (format string to display label)
descending:Boolean (TRUE if numbers are descending)
numPlacement:Integer (side to display labels)
ticPlacement:Integer (side to display tic marks)
theAxis:Line (line to display axis)

Type Methods

This section lists methods available when Type Axis is receiver.

new

Reply with a horizontal axis from 0.0 to 100.0.

Instance Methods

This section lists methods which are available to instances of Axis.

scale aValue:Integer
REPLY Real

Converts aValue from millimeters to scaled units.
SIGNAL "Axis value out of bounds"

locate aValue:Real
REPLY Integer

Reply with location of aValue in millimeters.

Backpage

Type Backpage is used to provide another page as a background. This is useful when you have a number of pages which all have the same background. It simplifies design, provides consistency and saves space. If there are any active figures in the backpage, they will active in the page which uses a backpage shape. For additional functionality, refer to Type Shape.

Parts

pageName:String (name of page to display)
thePage:Page (used for display purposes)

Instance Methods

No new methods are defined for this type.

Painting

Type Painting is used to display graphics files in GIF, PBM, XBM or ABC format. For additional functionality, refer to Type Shape.

Parts

theImage:Image (the image to display)
showBorder:Boolean (TRUE if border should be drawn)
imageName:String (name of image)

Instance Methods

This section lists methods which are available to instances of Painting.

drawIn aWidget:Widget startingAt aPoint:Point

Draw a portion of the image in aWidget. The upper left portion begins at aPoint in the image and includes width by height pixels.

image aName:String

Set the image to aName. Note that the image is an ABC object which contains the file name of the actual data. The image name is an internal ABC name. Thus you can have several images which use the same file but may be of different dimensions.

Table

Type Table is essential a two dimensional texteditor. You have control over the number of rows and columns, spacing, size of each cell and whether it can be edited by the user. When editing, pressing TAB will move horizontally and pressing RETURN will move vertically. For additional functionality, refer to Type Shape.

Parts

editors:Array (list of editor cells)
nrows:Integer (rows)
ncols:Integer (columns)
row:Integer (current editing row)
col:Integer (current editing column)
colsPerEditor:Integer (width of each editor)
theEditor:Editor (current editor being edited)
spacex:Integer (horizontal space between editors)
spacey:Integer (vertical space between editors)
allowEdit:Boolean (TRUE if user can edit)

Type Methods

This section lists methods available when Type Table is receiver.

new

Reply with a table of 3 rows and 3 columns with 5 characters per editor.

Instance Methods

This section lists methods which are available to instances of Table.

positionEditors

Realign editors after resetting spacing, sizes etc.

setFontTo aFont:Font

Change the font of all the editors.

row r:Integer col c:Integer
REPLY Editor

Reply with the editor located at row r and column c. Use this when you want to get the string stored at a particular cell.

rows Rows:Integer cols Cols:Integer

Change the size of me to rows by cols.

Font

Type Font provides the font capabilities which are needed to display text. There are currently 4 fonts and 5 sizes of these fonts for use. For additional functionality, refer to Type PartsList.

Parts

typeface:String (times,roman,helvetica or symbol)
style:Integer (#normal,#bold,#italics,#bolditalics)
pointSize:Integer (10,12,14,18,24)

Type Methods

This section lists methods available when Type Font is receiver.

new

Reply with a times, normal, 14 point font.

typeface tface:String style aStyle:Integer pointSize aSize:Integer

Reply with a font of the given characteristics.

Instance Methods

This section lists methods which are available to instances of Font.

widthOf aString:String from start:Integer to end:Integer
REPLY Integer

Reply with the width of the given substring based on the characteristics of me.

widthOf aString:String
REPLY Integer

Reply with the width of aString.

ascent
REPLY Integer

Reply with the vertical distance above the base line for me.

descent
REPLY Integer

Reply with the vertical distance below the base line of me.

height
REPLY Integer

Reply with the sum of the ascent and descent.

Image

Type Image stores the information necessary to display an image stored in an external file. For additional functionality, refer to Type PartsList.

Parts

filename:String (name of data file)
width:Integer (width of external image)
height:Integer (height of external image)
dither:Boolean (TRUE if dithering is needed)

Type Methods

This section lists methods available when Type Image is receiver.

at imgname:String

Reply with the image stored in the image directory under imgname. Reply NIL if not found.

newImage aFileName:String

Reply with an image with filename aFilename.

Instance Methods

This section lists methods which are available to instances of Image.

load

Load the image file from disk into memory. Images are buffered in memory and may need to be reloaded due to storage requirements. This method is a way of explicitly loading the file.

setImageTo aName:String

Change the image name.

extentIn aRec:Rectangle

Set aRec to the size of the image.

Point

Type Point provides the functionality to maintain an x,y coordinate and manipulate it. For additional functionality, refer to Type PartsList.

Parts

x:Integer
y:Integer

Type Methods

This section lists methods available when Type Point is receiver.

x newx:Integer y newy:Integer

Reply with a point at newx@newy.

new

Reply with a point at 0@0.

Instance Methods

This section lists methods which are available to instances of Point.

movex newx:Integer movey newy:Integer

Set the point to the new position.

shiftx dx:Integer shifty dy:Integer

Shift the point by dx,dy.

belowRightOf pt:Point
REPLY Boolean

Reply TRUE if me is below (i.e. larger y) and to the right (i.e. larger x) of pt.

aboveLeftOf pt:Point
REPLY Boolean

Reply TRUE if me is above (i.e. smaller y) and to the left (i.e. smaller x) of pt.

above pt:Point
REPLY Boolean

Reply TRUE if me is above pt.

below pt:Point
REPLY Boolean

Reply TRUE if me is below pt.

leftOf pt:Point
REPLY Boolean

Reply TRUE if me is to the left of pt.

rightOf pt:Point
REPLY Boolean

Reply TRUE ifme is to the right of pt.

+ pt:Point

Add pt's x and pt's y to me.

- pt:Point

Subtract pt's xy and pt's y from me.

asString
REPLY String

Reply with a string of the form ``x@y''.

squaredDistanceFrom aPoint:Point
REPLY Integer

Reply with distance of me from aPoint squared.

distanceFrom aPoint:Point
REPLY Real

Reply with the distance of me from aPoint.