Squeak Class Documentation category index | class index  
 
PolygonMorph
  category: Morphic-Basic
  superclass: BorderedMorph
  subclasses: StarMorph WireMorph EnvelopeLineMorph LineMorph BlobMorph LipsMorph CurveMorph BalloonMorph

This class combines the old Polygon and Curve classes.

The 1-bit fillForm to make display and containment tests reasonably fast. However, this functionality is in the process of being supplanted by balloon capabilities, which should eventually provide anti-aliasing as well.

instance methods
  access
  borderColor:
borderWidth:
isClosed
isCurve
isOpen
makeOpenOrClosed
openOrClosePhrase
vertices

  dashes
  borderDashOffset
dashedBorder:
step
stepTime
wantsSteps

  drawing
  areasRemainingToFill:
drawArrowOn:at:from:
drawArrowsOn:
drawBorderOn:
drawBorderOn:usingEnds:
drawClippedBorderOn:usingEnds:
drawDashedBorderOn:
drawDashedBorderOn:usingEnds:
drawOn:
drawOnFormCanvas:
drawPostscriptOn:

  editing
  addHandles
dragVertex:event:fromHandle:
dragVertex:fromHandle:vertIndex:
dropVertex:event:fromHandle:
dropVertex:fromHandle:vertIndex:
fillStyle
fillStyle:
handlesMouseDown:
justDroppedInto:event:
mouseDown:
newVertex:event:fromHandle:
newVertex:fromHandle:afterVert:
updateHandles
verticesAt:put:

  geometry
  closestPointTo:
containsPoint:
couldHaveRoundedCorners
extent:
flipHAroundX:
flipVAroundY:
inset:
merge:
mergeDropThird:in:from:

  halo control
  addFlexShellIfNecessary
heading:
referencePosition
rotationCenter
rotationCenter:
rotationDegrees
rotationDegrees:
setRotationCenterFrom:
transformedBy:

  initialization
  beSmoothCurve
beStraightSegments
initialize
initializeToStandAlone
installModelIn:
vertices:color:borderWidth:borderColor:

  menu
  addCustomMenuItems:hand:
arrowSpec:
customizeArrows:
handlesShowingPhrase
makeBackArrow
makeBothArrows
makeClosed
makeForwardArrow
makeNoArrows
makeOpen
quickFill:
removeHandles
showOrHideHandles
showingHandles
specifyDashedLine
standardArrows
toggleHandles
toggleSmoothing

  object fileIn
  convertToCurrentVersion:refStream:

  private
  arrowBoundsAt:from:
arrowForms
borderForm
computeArrowFormAt:from:
computeBounds
curveBounds
filledForm
getVertices
includesHandle:
lineSegments
loadCachedState
privateMoveBy:
releaseCachedState
setVertices:

  smoothing
  coefficients
computeNextToEndPoints
derivs:first:second:third:
lineSegmentsDo:
nextToFirstPoint
nextToLastPoint

  visual properties
  canHaveFillStyles
defaultColor

class methods
  instance creation
  arrowPrototype
fromHand:
fromHandFreehand:
shapeFromPen:color:borderWidth:borderColor:
supplementaryPartsDescriptions
vertices:color:borderWidth:borderColor:

  parts bin
  descriptionForPartsBin

instance methods
  access top  
 

borderColor:


 

borderWidth:


 

isClosed


 

isCurve


 

isOpen


 

makeOpenOrClosed

toggle the open/closed status of the receiver


 

openOrClosePhrase


 

vertices


  dashes top  
 

borderDashOffset


 

dashedBorder:

A dash spec is a 3- or 5-element array with
{ length of normal border color.
length of alternate border color.
alternate border color.
starting offset.
amount to add to offset at each step }
Starting offset is usually = 0, but changing it moves the dashes along the curve.


 

step

Do some periodic activity. Use startStepping/stopStepping to start and stop getting sent this message. The time between steps is specified by this morph's answer to the stepTime message. The generic version dispatches control to the player, if any. The nasty circumlocation about owner's transformation is necessitated by the flexing problem that the player remains in the properties dictionary both of the flex and the real morph. In the current architecture, only the top renderer's pointer to the player should actually be honored for the purpose of firing.


 

stepTime

Answer the desired time between steps in milliseconds. This default implementation requests that the 'step' method be called once every second.


 

wantsSteps

Return true if the receiver overrides the default Morph step method.


  drawing top  
 

areasRemainingToFill:

Could be improved by quick check of inner rectangle


 

drawArrowOn:at:from:

Draw a triangle oriented along the line from priorPoint to
endPoint. Answer the wingBase.


 

drawArrowsOn:

Answer (possibly modified) endpoints for border drawing


 

drawBorderOn:


 

drawBorderOn:usingEnds:

Display my border on the canvas.


 

drawClippedBorderOn:usingEnds:


 

drawDashedBorderOn:


 

drawDashedBorderOn:usingEnds:

Display my border on the canvas. NOTE: mostly copied from
drawBorderOn:


 

drawOn:

Display the receiver, a spline curve, approximated by straight
line segments.


 

drawOnFormCanvas:

Display the receiver, a spline curve, approximated by straight line segments.


 

drawPostscriptOn:

Display the receiver, a spline curve, approximated by straight
line segments.


  editing top  
 

addHandles


 

dragVertex:event:fromHandle:


 

dragVertex:fromHandle:vertIndex:

Reorder the arguments for existing event handlers


 

dropVertex:event:fromHandle:


 

dropVertex:fromHandle:vertIndex:

Reorder the arguments for existing event handlers


 

fillStyle

Return the current fillStyle of the receiver.


 

fillStyle:

Set the current fillStyle of the receiver.


 

handlesMouseDown:

Do I want to receive mouseDown events (mouseDown:, mouseMove:, mouseUp:)?


 

justDroppedInto:event:

This message is sent to a dropped morph after it has been dropped on -- and been accepted by -- a drop-sensitive morph


 

mouseDown:

Handle a mouse down event. The default response is to let my eventHandler, if any, handle it.


 

newVertex:event:fromHandle:

Insert a new vertex and fix everything up! Install the drag-handle of the new vertex as recipient of further mouse events.


 

newVertex:fromHandle:afterVert:

Reorder the arguments for existing event handlers


 

updateHandles


 

verticesAt:put:


  geometry top  
 

closestPointTo:


 

containsPoint:


 

couldHaveRoundedCorners

subclases unhappy with rounded corners reimplement


 

extent:

Not really advisable, but we can preserve most of the geometry if we don't
shrink things too small.


 

flipHAroundX:

Flip me horizontally around the center. If centerX is nil, compute my center of gravity.


 

flipVAroundY:

Flip me vertically around the center. If centerY is nil, compute my center of gravity.


 

inset:

Only works if I am made of rectangles (every segment of me is horizontal or vertical). Inset each vertex by amt. Uses containsPoint.


 

merge:

Expand myself to enclose the other polygon. (Later merge overlapping or disjoint in a smart way.) For now, the two polygons must share at least two vertices. Shared vertices must come one after the other in each polygon. Polygons must not overlap.


 

mergeDropThird:in:from:

We are merging two polygons. In this case, they have at least three identical shared vertices. Make sure they are sequential in each, and drop the middle one from vertex lists mv, hv, and shared. First vertices on lists are identical already.


  halo control top  
 

addFlexShellIfNecessary

When scaling or rotating from a halo, I can do this without a flex shell


 

heading:

Set the receiver's heading (in eToy terms).
Note that polygons never use flex shells.


 

referencePosition

Return the current reference position of the receiver


 

rotationCenter

Return the rotation center of the receiver. The rotation center defines the relative offset inside the receiver's bounds for locating the reference position.


 

rotationCenter:

Set the new rotation center of the receiver. The rotation center defines the relative offset inside the receiver's bounds for locating the reference position.


 

rotationDegrees

Default implementation.


 

rotationDegrees:


 

setRotationCenterFrom:

Polygons store their referencePosition.


 

transformedBy:


  initialization top  
 

beSmoothCurve


 

beStraightSegments


 

initialize


 

initializeToStandAlone

Set up the receiver, created by a #basicNew and now ready to be initialized, as a fully-formed morph suitable for providing a graphic for a parts bin surrogate, and, when such a parts-bin surrogate is clicked on, for attaching to the hand as a viable stand-alone morph. Because of historical precedent, #initialize has been expected to handle this burden, though a great number of morphs actually cannot stand alone. In any case, by default we call the historical #initialize, though unhappily, so that all existing morphs will work no worse than before when using this protocol.


 

installModelIn:

Simple morphs have no model


 

vertices:color:borderWidth:borderColor:


  menu top  
 

addCustomMenuItems:hand:

Add morph-specific items to the given menu which was invoked by the given hand. This method provides is invoked both from the halo-menu and from the control-menu regimes.


 

arrowSpec:

Specify a custom arrow for this line.
specPt x abs gives the length of the arrow (point to base) in terms of borderWidth.
If specPt x is negative, then the base of the arrow will be concave.
specPt y abs gives the width of the arrow.
The standard arrow is equivalent to arrowSpec: 5@4.
See arrowBoundsAt:From: for details.


 

customizeArrows:


 

handlesShowingPhrase


 

makeBackArrow


 

makeBothArrows


 

makeClosed


 

makeForwardArrow


 

makeNoArrows


 

makeOpen


 

quickFill:


 

removeHandles

tk 9/2/97 allow it to be called twice (when nil already)


 

showOrHideHandles


 

showingHandles


 

specifyDashedLine


 

standardArrows


 

toggleHandles


 

toggleSmoothing


  object fileIn top  
 

convertToCurrentVersion:refStream:

subclasses should implement if they wish to convert old instances to modern ones


  private top  
 

arrowBoundsAt:from:

Answer a triangle oriented along the line from priorPoint to endPoint.


 

arrowForms

ArrowForms are computed only upon demand


 

borderForm

A form must be created for drawing the border whenever the borderColor is translucent.


 

computeArrowFormAt:from:

Compute a triangle oriented along the line from priorPoint to
endPoint. Then draw those lines in a form and return that
form, with appropriate offset


 

computeBounds


 

curveBounds


 

filledForm

Note: The filled form is actually 2 pixels bigger than bounds, and the point corresponding to this morphs' position is at 1@1 in the form. This is due to the details of the fillig routines, at least one of which requires an extra 1-pixel margin around the outside. Computation of the filled form is done only on demand.


 

getVertices


 

includesHandle:


 

lineSegments


 

loadCachedState

Prepare for fast response -- next page of a book?


 

privateMoveBy:

Private! Use 'position:' instead.


 

releaseCachedState

Release any state that can be recomputed on demand, such as the pixel values for a color gradient or the editor state for a TextMorph. This method may be called to save space when a morph becomes inaccessible. Implementations of this method should do 'super releaseCachedState'.


 

setVertices:


  smoothing top  
 

coefficients

Compute an array for the coefficients. This is copied from Flegal's old
code in the Spline class.


 

computeNextToEndPoints


 

derivs:first:second:third:

Compute the first, second and third derivitives (in coeffs) from
the Points in this Path (coeffs at: 1 and coeffs at: 5).


 

lineSegmentsDo:

Emit a sequence of segment endpoints into endPointsBlock.


 

nextToFirstPoint

For arrow direction


 

nextToLastPoint

For arrow direction


  visual properties top  
 

canHaveFillStyles

Return true if the receiver can have general fill styles; not just colors.
This method is for gradually converting old morphs.


 

defaultColor

Return the default fill style for the receiver


class methods
  instance creation top  
 

arrowPrototype


 

fromHand:

Let the user draw a polygon, clicking at each vertex, and ending
by clicking within 5 of the first point...


 

fromHandFreehand:

Let the user draw a polygon, holding the mouse down, and ending
by clicking within 5 of the first point...


 

shapeFromPen:color:borderWidth:borderColor:

World addMorph: (PolygonMorph
shapeFromPen: [:p | p hilbert: 4 side: 5. p go: 5.
p hilbert: 4 side: 5. p go: 5]
color: Color red borderWidth: 1 borderColor: Color black)


 

supplementaryPartsDescriptions

Answer a list of DescriptionForPartsBin objects that characterize objects that this class wishes to contribute to Stationery bins *other* than by the standard default #newStandAlone protocol


 

vertices:color:borderWidth:borderColor:


  parts bin top  
 

descriptionForPartsBin

If the receiver is a member of a class that would like to be represented in a parts bin, answer the name by which it should be known, and a documentation string to be provided, for example, as balloon help. When the 'nativitySelector' is sent to the 'globalReceiver', it is expected that some kind of Morph will result. The parameters used in the implementation below are for documentation purposes only!