[ENH]StarMorph
Karl Ramberg
karl.ramberg at chello.se
Sun Sep 24 15:57:17 UTC 2000
I enhanced the StarMorph by adding a menu option to let you
specify how many points the star should have.
Karl
-------------- next part --------------
'From Squeak2.9alpha of 13 June 2000 [latest update: #2657] on 24 September 2000 at 5:52:40 pm'!
PolygonMorph subclass: #StarMorph
instanceVariableNames: 'points pt '
classVariableNames: ''
poolDictionaries: ''
category: 'Morphic-Widgets'!
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:51'!
addCustomMenuItems: aMenu hand: aHandMorph
super addCustomMenuItems: aMenu hand: aHandMorph.
aMenu add: 'Points' action: #inputPoints.
! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:49'!
dragVertex: evt fromHandle: handle vertIndex: label
| ext oldR strokeOrigin offset |
label == #center
ifTrue: [offset _ evt cursorPoint - (handles at: 1) bounds center.
self position: self position + offset].
label == #outside
ifTrue: [strokeOrigin _ (handles at: 1) bounds center.
pt _ strokeOrigin - evt cursorPoint - ((handles at: 2) extent // 2).
ext _ pt r.
oldR _ ext.
vertices _ (0 to: 359 by: 360 // vertices size)
collect: [:angle | (Point r: (oldR _ oldR = ext
ifTrue: [ext * 5 // 12]
ifFalse: [ext]) degrees: angle + pt degrees)
+ strokeOrigin].
(handles at: 2)
position: evt cursorPoint].
self computeBounds! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:49'!
handlesMouseDown
^true! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:49'!
initialize
super initialize.
borderWidth _ 1.
borderColor _ Color black.
pt _ 10 @ 10.
points _ 5.
self updateDrawing! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:48'!
inputPoints
points _ FillInTheBlank request: 'Number of Points on the star:'.
self updateDrawing! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 16:47'!
mouseDown: evt
^ evt shiftPressed
ifTrue: [((owner isKindOf: PolygonMorph) and: [owner includesHandle: self])
ifTrue: ["Prevent insertion handles from getting edited"
^ super mouseDown: evt].
self toggleHandles.
handles ifNil: [^ self].
]
ifFalse: [super mouseDown: evt]! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:47'!
points: aInteger
^ points _ aInteger! !
!StarMorph methodsFor: 'as yet unclassified' stamp: 'kfr 9/24/2000 17:47'!
updateDrawing
| strokeOrigin ext oldR |
strokeOrigin _ self bounds center.
ext _ pt r.
oldR _ ext.
vertices _ (0 to: 359 by: 360 // points // 2)
collect: [:angle | (Point r: (oldR _ oldR = ext
ifTrue: [ext * 5 // 12]
ifFalse: [ext]) degrees: angle + pt degrees)
+ strokeOrigin].
self position: self position.
self computeBounds! !
More information about the Squeak-dev
mailing list
|