moved some handle stuff from DrawView to here,
to provide more framework for subclasses.
--- a/ObjView.st Sat Feb 20 12:46:36 1999 +0100
+++ b/ObjView.st Sat Feb 20 18:36:31 1999 +0100
@@ -286,6 +286,12 @@
!ObjectView class methodsFor:'defaults'!
+handleSize
+ "size of blob drawn for handles"
+
+ ^ (Display horizontalPixelPerMillimeter * 1.2) rounded asInteger
+!
+
hitDelta
"when clicking an object, allow for hitDelta pixels around object;
0 is exact; 1*pixelPerMillimeter is good for draw programs"
@@ -2474,6 +2480,114 @@
^ (device verticalPixelPerMillimeter * 20) asInteger
! !
+!ObjectView methodsFor:'selection & handles'!
+
+drawHandle:aPoint
+ |hsize halfSize|
+
+ hsize := self handleSize.
+ halfSize := hsize // 2.
+ self fillRectangleX:(aPoint x - halfSize)
+ y:(aPoint y - halfSize)
+ width:hsize
+ height:hsize
+!
+
+drawHandlesFor:anObject
+ |hsize halfSize|
+
+ hsize := self handleSize.
+ halfSize := hsize // 2.
+ anObject handlesDo:[:point |
+ self fillRectangleX:(point x - halfSize)
+ y:(point y - halfSize)
+ width:hsize
+ height:hsize
+ ]
+!
+
+findObjectHandleAt:aPoint
+ |objectFound|
+ contents do:[:object |
+ (self object:object hasHandle:aPoint) ifTrue:[
+ objectFound := object
+ ]
+ ].
+ ^ objectFound
+!
+
+handle:handlePoint isHitBy:aPoint
+ ^ (self handleFor:handlePoint) containsPoint:aPoint
+!
+
+handleFor:aPoint
+ "return the handle-rectangle for a handle at aPoint"
+
+ |hsize centerX centerY|
+
+ hsize := self handleSize.
+ centerX := aPoint x.
+ centerY := aPoint y.
+ ^ Rectangle left:(centerX - hsize)
+ top:(centerY - hsize)
+ right:(centerX + hsize)
+ bottom:(centerY + hsize)
+!
+
+handleSize
+ "return the size of the handles - sincc handles should be
+ the same size regardless of scaling, inverse-scale from
+ what the default is."
+
+ |hs|
+
+ hs := self class handleSize.
+ transformation notNil ifTrue:[
+ ^ transformation applyInverseScaleX:hs
+ ].
+ ^ hs
+!
+
+invertHandle:aHandle
+ self xoring:[self drawHandle:aHandle]
+!
+
+invertHandlesOf:aSelection
+ aSelection notNil ifTrue:[
+ self xoring:[
+ self forEach:aSelection do:[:anObject |
+ (anObject respondsTo:#handlesDo:) ifTrue:[
+ self drawHandlesFor:anObject
+ ] ifFalse:[
+ anObject drawOutlineIn:self
+ ]
+ ]
+ ]
+ ]
+!
+
+object:anObject hasHandleAt:aPoint
+ |found|
+
+ found := false.
+ anObject handlesDo:[:handlePoint |
+ (self handle:handlePoint isHitBy:aPoint) ifTrue:[
+ found := true
+ ]
+ ].
+ ^ found
+!
+
+selectionHandlesDo:aBlock
+ self forEach:selection do:[:theObject |
+ (theObject respondsTo:#handlesDo:) ifTrue:[
+ theObject handlesDo:[:theHandle |
+ aBlock value:theObject value:theHandle
+ ]
+ ]
+ ]
+! !
+
!ObjectView methodsFor:'selections'!
addToSelection:anObject
@@ -2955,5 +3069,5 @@
!ObjectView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/Attic/ObjView.st,v 1.63 1999-02-17 20:07:23 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/Attic/ObjView.st,v 1.64 1999-02-20 17:36:31 cg Exp $'
! !
--- a/ObjectView.st Sat Feb 20 12:46:36 1999 +0100
+++ b/ObjectView.st Sat Feb 20 18:36:31 1999 +0100
@@ -286,6 +286,12 @@
!ObjectView class methodsFor:'defaults'!
+handleSize
+ "size of blob drawn for handles"
+
+ ^ (Display horizontalPixelPerMillimeter * 1.2) rounded asInteger
+!
+
hitDelta
"when clicking an object, allow for hitDelta pixels around object;
0 is exact; 1*pixelPerMillimeter is good for draw programs"
@@ -2474,6 +2480,114 @@
^ (device verticalPixelPerMillimeter * 20) asInteger
! !
+!ObjectView methodsFor:'selection & handles'!
+
+drawHandle:aPoint
+ |hsize halfSize|
+
+ hsize := self handleSize.
+ halfSize := hsize // 2.
+ self fillRectangleX:(aPoint x - halfSize)
+ y:(aPoint y - halfSize)
+ width:hsize
+ height:hsize
+!
+
+drawHandlesFor:anObject
+ |hsize halfSize|
+
+ hsize := self handleSize.
+ halfSize := hsize // 2.
+ anObject handlesDo:[:point |
+ self fillRectangleX:(point x - halfSize)
+ y:(point y - halfSize)
+ width:hsize
+ height:hsize
+ ]
+!
+
+findObjectHandleAt:aPoint
+ |objectFound|
+ contents do:[:object |
+ (self object:object hasHandle:aPoint) ifTrue:[
+ objectFound := object
+ ]
+ ].
+ ^ objectFound
+!
+
+handle:handlePoint isHitBy:aPoint
+ ^ (self handleFor:handlePoint) containsPoint:aPoint
+!
+
+handleFor:aPoint
+ "return the handle-rectangle for a handle at aPoint"
+
+ |hsize centerX centerY|
+
+ hsize := self handleSize.
+ centerX := aPoint x.
+ centerY := aPoint y.
+ ^ Rectangle left:(centerX - hsize)
+ top:(centerY - hsize)
+ right:(centerX + hsize)
+ bottom:(centerY + hsize)
+!
+
+handleSize
+ "return the size of the handles - sincc handles should be
+ the same size regardless of scaling, inverse-scale from
+ what the default is."
+
+ |hs|
+
+ hs := self class handleSize.
+ transformation notNil ifTrue:[
+ ^ transformation applyInverseScaleX:hs
+ ].
+ ^ hs
+!
+
+invertHandle:aHandle
+ self xoring:[self drawHandle:aHandle]
+!
+
+invertHandlesOf:aSelection
+ aSelection notNil ifTrue:[
+ self xoring:[
+ self forEach:aSelection do:[:anObject |
+ (anObject respondsTo:#handlesDo:) ifTrue:[
+ self drawHandlesFor:anObject
+ ] ifFalse:[
+ anObject drawOutlineIn:self
+ ]
+ ]
+ ]
+ ]
+!
+
+object:anObject hasHandleAt:aPoint
+ |found|
+
+ found := false.
+ anObject handlesDo:[:handlePoint |
+ (self handle:handlePoint isHitBy:aPoint) ifTrue:[
+ found := true
+ ]
+ ].
+ ^ found
+!
+
+selectionHandlesDo:aBlock
+ self forEach:selection do:[:theObject |
+ (theObject respondsTo:#handlesDo:) ifTrue:[
+ theObject handlesDo:[:theHandle |
+ aBlock value:theObject value:theHandle
+ ]
+ ]
+ ]
+! !
+
!ObjectView methodsFor:'selections'!
addToSelection:anObject
@@ -2955,5 +3069,5 @@
!ObjectView class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/ObjectView.st,v 1.63 1999-02-17 20:07:23 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/ObjectView.st,v 1.64 1999-02-20 17:36:31 cg Exp $'
! !