An ABC manual consists of hyperlinked pages, each page of which consists of a collection of figures. The figures can have both a shape and behavior. Examples of shapes include polygons, arcs, rectangles and axes. Examples of behaviors include click, drag, and link. The shapes and behaviors in the default version of ABC provide many of the capabilities designers want in the development of a hypermedia manual.
However, there will be many applications which could make use of specialized shapes or behaviors. For example, the regular polygon shape was not originally in ABC but was designed by a student for use in a lesson. In addition to providing needed capabilities, creating a new shape saves development time and provides a consistent interface. In this chapter I will discuss how to develop a new shape and behavior. Be sure to review Graphics if you have not already done so.
Note: Since RegPoly already exists in your version, don't attempt to create it again. However, you can review the code which is referenced below or edit it in ABC.
Suggestion: A good way to develop a new type is to edit a method of a similar, existing type, use Method/New in the Type Manager to create the new method and copy the code from the old to the new method.The responsibilities of a shape is to draw itself, get and retrieve user input data from its dialogbox (which you will create later), to resize itself on request and perform any other functions which are unique to the shape.
The primary role of the RegPoly shape is to compute a regular closed polygon with n sides which can be circumscribed in a square. This recomputation is done in resizeWidth:resizeHeight:. The width and height of the square is chosen to be the minimum of the supplied width and height. Then the vertices of the regular polygon are computed and put into the endpoints array. Drawing is done using drawIn: of Polygon.
To keep the user from being able to move or edit the vertices, drawHandlesIn:with: is overridden to display only the move and resize handles. Also, computeExtent is overridden since there is no reason to recompute the width and height. For polygons, computeExtent determines the maximum width and height of the polygon based on all its endpoints.
When a regular polygon is added to a page, the Page Manager will issue a "RegPoly new" message to create a new polygon. The new method is supplied to make the default polygon a closed pentagon.
When creating a new shape, you will need to create a new dialogbox in the Widgets folder and give it the proper name as described above.
Suggestion: Copy a dialogbox for a similar shape and then edit the copy, adding and deleting widgets as necessary.See the section on Editing a View in Designing an Application to learn how to modify a dialogbox. Remember to name all of your widgets and use those names in getValues: and setValues:. Also be sure to click on the dialogbox and name it with the same name as you used to refer to it in the widgets folder.
To create a bitmap use the Bitmap Manager. Make it a 16x16 bitmap which is the default size. Make sure you store it in the Bitmaps folder.
It will become available the next time you use the Page Manager.