home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP29.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-29
|
16KB
|
484 lines
'Smalltalk Textbook Appendix 29'!
EngiDisplayModel subclass: #EngiGraphModel
instanceVariableNames: 'graphSelections '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Graph'!
EngiGraphModel comment:
'
Engi 0.07 (24 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiGraphModel methodsFor: 'bounds accessing'!
areaVerticesAndBranches: aCollection at: aPoint
| vertexCollection branchCollection aRectangle |
aCollection isEmpty ifTrue: [^nil].
vertexCollection := (aCollection select: [:each | each isVertex]) asOrderedCollection.
branchCollection := (aCollection select: [:each | each isBranch]) asOrderedCollection.
self value doBranches: [:branch | ((vertexCollection includes: branch startVertex)
or: [vertexCollection includes: branch endVertex])
ifTrue: [(branchCollection includes: branch)
ifFalse: [branchCollection add: branch]]].
aRectangle := nil.
vertexCollection
do:
[:vertex |
| box |
box := vertex bounds translatedBy: aPoint + displayOrigin.
box := box expandedBy: self expandedRectangleForVertex.
aRectangle isNil
ifTrue: [aRectangle := box]
ifFalse: [aRectangle := aRectangle merge: box]].
branchCollection
do:
[:branch |
| box |
box := branch bounds translatedBy: aPoint + displayOrigin.
box := box expandedBy: self expandedRectangleForBranch.
aRectangle isNil
ifTrue: [aRectangle := box]
ifFalse: [aRectangle := aRectangle merge: box]].
^aRectangle!
expandedRectangle
^4 @ 4 corner: 4 @ 4!
expandedRectangleForBranch
^3 @ 3 corner: 3 @ 3!
expandedRectangleForVertex
^1 @ 1 corner: 1 @ 1! !
!EngiGraphModel methodsFor: 'properties accessing'!
fillColor
^self value fillColor!
fillColor: colorValue
self value fillColor: colorValue.
self changed: #value!
lineWidth
^self value lineWidth!
lineWidth: anInteger
self value lineWidth: anInteger.
self changed: #value!
strokeColor
^self value strokeColor!
strokeColor: colorValue
self value strokeColor: colorValue.
self changed: #value! !
!EngiGraphModel methodsFor: 'displaying'!
displayDeselections: aCollection on: graphicsContext at: aPoint
| aRectangle displayContext |
aRectangle := self
eraseVerticesAndBranches: aCollection
on: graphicsContext
at: aPoint.
aRectangle isNil ifTrue: [^self].
displayContext := graphicsContext copy.
displayContext clippingRectangle: (aRectangle intersect: displayContext clippingBounds).
displayContext paint: displayContext medium backgroundColor.
displayContext displayRectangle: aRectangle.
self displayOn: displayContext at: aPoint!
displayOn: graphicsContext
self displayOn: graphicsContext at: Point zero!
displayOn: graphicsContext at: aPoint
self displayAxesOn: graphicsContext at: aPoint.
self displayValueOn: graphicsContext at: aPoint.
self
displaySelections: self selections
on: graphicsContext
at: aPoint!
displaySelections: aCollection on: graphicsContext at: aPoint
| aRectangle displayContext |
aRectangle := self areaVerticesAndBranches: aCollection at: aPoint.
aRectangle isNil ifTrue: [^self].
displayContext := graphicsContext copy.
displayContext clippingRectangle: (aRectangle intersect: displayContext clippingBounds).
aCollection
do:
[:each |
each isVertex
ifTrue:
[| box |
box := each bounds translatedBy: aPoint + displayOrigin.
box := box expandedBy: self expandedRectangleForVertex.
box := box insetBy: (0 @ 0 corner: 1 @ 1).
self value fillColor isNil
ifFalse:
[displayContext paint: self value fillColor.
displayContext displayRectangle: box].
displayContext paint: self value strokeColor.
displayContext displayRectangularBorder: box.
each displayOn: displayContext at: aPoint + displayOrigin].
each isBranch
ifTrue:
[| box |
box := (each startPoint + aPoint + displayOrigin extent: 0 @ 0)
expandedBy: self expandedRectangleForBranch.
box := box insetBy: (0 @ 0 corner: 1 @ 1).
self value fillColor isNil
ifFalse:
[displayContext paint: self value fillColor.
displayContext displayRectangle: box].
displayContext paint: self value strokeColor.
displayContext displayRectangularBorder: box.
box := (each endPoint + aPoint + displayOrigin extent: 0 @ 0)
expandedBy: self expandedRectangleForBranch.
box := box insetBy: (0 @ 0 corner: 1 @ 1).
self value fillColor isNil
ifFalse:
[displayContext paint: self value fillColor.
displayContext displayRectangle: box].
displayContext paint: self value strokeColor.
displayContext displayRectangularBorder: box.
each displayOn: displayContext at: aPoint + displayOrigin]]!
eraseVerticesAndBranches: vertexCollection on: graphicsContext at: aPoint
| aRectangle displayContext |
aRectangle := self areaVerticesAndBranches: vertexCollection at: aPoint.
aRectangle isNil ifTrue: [^nil].
displayContext := graphicsContext copy.
displayContext clippingRectangle: (aRectangle intersect: displayContext clippingBounds).
displayContext paint: displayContext medium backgroundColor.
displayContext displayRectangle: aRectangle.
^aRectangle! !
!EngiGraphModel methodsFor: 'controlling'!
holdingActivity: aController
| millisecondTime timeLimit aPoint aVertex |
millisecondTime := 300.
timeLimit := Time millisecondClockValue + millisecondTime.
[Time millisecondClockValue < timeLimit]
whileTrue:
[aController sensor redButtonPressed ifFalse: [^false].
Processor yield].
aPoint := self convertToMyPoint: aController sensor cursorPoint.
aVertex := self detection: aPoint.
aVertex isNil ifTrue: [^false].
self selectedVertices detect: [:vertex | vertex = aVertex]
ifNone: [^false].
^true!
movingActivity: aController
| saveBounds selectedVertices aPoint aRectangle graphicsContext vertexCollection branchCollection |
saveBounds := self bounds.
selectedVertices := self selectedVertices.
selectedVertices isEmpty ifTrue: [^self].
Cursor crossHair showWhile: [aPoint := self
movingVertices: selectedVertices
controller: aController
isDown: true].
vertexCollection := OrderedCollection new.
selectedVertices do: [:vertex | vertexCollection add: vertex].
branchCollection := OrderedCollection new.
self value doBranches: [:branch | ((vertexCollection includes: branch startVertex)
or: [vertexCollection includes: branch endVertex])
ifTrue: [branchCollection add: branch]].
self dependentsDo: [:view | aRectangle := self
eraseVerticesAndBranches: vertexCollection
on: view graphicsContext
at: Point zero].
vertexCollection do: [:vertex | vertex translatedBy: aPoint].
branchCollection do: [:branch | branch translatedBy: aPoint].
self flushBounds.
aRectangle isNil
ifTrue: [aRectangle := self areaVerticesAndBranches: vertexCollection at: Point zero]
ifFalse: [aRectangle := aRectangle merge: (self areaVerticesAndBranches: vertexCollection at: Point zero)].
aRectangle isNil ifTrue: [^self].
self
dependentsDo:
[:view |
graphicsContext := view graphicsContext.
self bounds area = saveBounds area
ifTrue: [graphicsContext clippingRectangle: (aRectangle intersect: graphicsContext clippingBounds)]
ifFalse: [view clearInside].
self displayOn: graphicsContext]!
redButtonActivity: aController
(self holdingActivity: aController)
ifTrue: [self movingActivity: aController]
ifFalse: [self selectingActivity: aController]!
selectingActivity: aController
| aPoint oldSelections anObject newSelections removingSelections addingSelections |
aPoint := self convertToMyPoint: aController sensor cursorPoint.
oldSelections := self selections copy.
anObject := self detection: aPoint.
aController sensor shiftDown
ifTrue: [anObject isNil ifFalse: [(self selections includes: anObject)
ifTrue: [self selections remove: anObject]
ifFalse: [self selections add: anObject]]]
ifFalse: [anObject isNil