home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP25.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
4KB
|
170 lines
'Smalltalk Textbook Appendix 25'!
EngiGeometric subclass: #EngiVertex
instanceVariableNames: 'vertexPoint vertexExtent vertexState '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Graph'!
EngiVertex comment:
'
Engi 0.07 (24 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiVertex methodsFor: 'initialize-release'!
initialize
super initialize.
vertexPoint := Point zero.
vertexExtent := 16 @ 16.
^self! !
!EngiVertex methodsFor: 'testing'!
containsPoint: aPoint
^self bounds containsPoint: aPoint!
isBranch
^false!
isVertex
^true! !
!EngiVertex methodsFor: 'bounds accessing'!
computeBounds
| bounds margin expand |
bounds := self vertexPoint extent: self vertexExtent.
margin := (self lineWidth / 2) asInteger.
expand := margin @ margin corner: margin + 1 @ (margin + 1).
bounds := bounds rounded expandedBy: expand.
^bounds! !
!EngiVertex methodsFor: 'point accessing'!
vertexPoint
^vertexPoint!
vertexPoint: aPoint
vertexPoint := aPoint.
self flushBounds! !
!EngiVertex methodsFor: 'extent accessing'!
vertexExtent
^vertexExtent!
vertexExtent: sizePoint
vertexExtent := sizePoint.
self flushBounds! !
!EngiVertex methodsFor: 'state accessing'!
vertexState
^vertexState!
vertexState: aState
vertexState := aState! !
!EngiVertex methodsFor: 'transforming'!
rotatedBy: angleDegree
self vertexPoint: (self class rotate: self vertexPoint by: angleDegree).
self flushBounds!
scaledBy: scalePoint
self vertexPoint: (self class scale: self vertexPoint by: scalePoint).
self flushBounds!
translatedBy: amountPoint
self vertexPoint: (self class translate: self vertexPoint by: amountPoint).
self flushBounds! !
!EngiVertex methodsFor: 'displaying'!
displayFilledOn: graphicsContext at: aPoint
| aRectangle |
self fillColor isNil ifFalse: [((self bounds translatedBy: aPoint)
intersects: graphicsContext clippingBounds)
ifTrue:
[aRectangle := self vertexPoint extent: self vertexExtent.
aRectangle := (aRectangle translatedBy: aPoint) rounded.
graphicsContext paint: self fillColor.
graphicsContext lineWidth: self lineWidth.
graphicsContext
displayWedgeBoundedBy: (aRectangle insetBy: (1 @ 1 corner: 1 @ 1))
startAngle: 0
sweepAngle: 360]]!
displayStrokedOn: graphicsContext at: aPoint
| aRectangle |
self strokeColor isNil ifFalse: [((self bounds translatedBy: aPoint)
intersects: graphicsContext clippingBounds)
ifTrue:
[aRectangle := self vertexPoint extent: self vertexExtent.
aRectangle := (aRectangle translatedBy: aPoint) rounded.
graphicsContext paint: self strokeColor.
graphicsContext lineWidth: self lineWidth.
graphicsContext
displayArcBoundedBy: (aRectangle insetBy: (1 @ 1 corner: 2 @ 2))
startAngle: 0
sweepAngle: 360]]! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiVertex class
instanceVariableNames: ''!
!EngiVertex class methodsFor: 'instance creation'!
new
^super new initialize! !
!EngiVertex class methodsFor: 'examples'!
example1
"EngiVertex example1."
| aVertex activeWindow activeSensor previousPoint currentPoint |
aVertex := EngiVertex new.
activeWindow := aVertex class activeWindow.
activeWindow clear.
activeSensor := activeWindow sensor.
previousPoint := nil.
[activeSensor anyButtonPressed]
whileFalse:
[currentPoint := activeSensor cursorPoint.
previousPoint = currentPoint
ifFalse:
[previousPoint := currentPoint.
aVertex vertexPoint: currentPoint.
aVertex strokeColor: aVertex class sampleColor.
aVertex fillColor: aVertex class sampleColor.
aVertex display]].
activeWindow display.
^aVertex!
example2
"EngiVertex example2."
| aVertex visualTransporter |
aVertex := EngiVertex new.
aVertex strokeColor: ColorValue red.
aVertex fillColor: ColorValue green.
aVertex lineWidth: 3.
aVertex vertexPoint: 100 @ 100.
visualTransporter := EngiVisualTransporter load: aVertex.
visualTransporter
follow: [self activeSensor cursorPoint]
while: [self activeSensor noButtonPressed]
on: self activeGraphicsContext.
^aVertex! !