'From Squeak3.8gamma of ''24 November 2004'' [latest update: #6662] on 10 May 2005 at 4:28:30 pm'!
"Change Set: CMagnifier-3
Date: 10 May 2005
Author: Takashi Yamamiya
CMagnifier is a similar object as etoys' magnifier in Tweak.
See PartsBin,"!
CPlayer subclass: #CMagnifier
instanceVariableNames: '
trackPointer
showPointer
sourcePlayer
'
classVariableNames: ''
poolDictionaries: ''
category: 'Tweak-EToys'!
!CMagnifier commentStamp: '' prior: 0!
CMagnifierPlayer instances are magnifying lenses that magnify the player below them (if grabbed or if trackPointer is false) or the area around the mouse pointer.
Each parameter is controlled by a slot in viewer.
Instance variables:
magnification The magnification to use. If non-integer, smooths the magnified form.
sourcePlayer indicates the position of the source area.
trackPointer If set, magnifies the area around the Hand. If not, magnfies the area underneath the magnifier center.
showPointer If set, display a small reversed rectangle in the center of the lens. Also enables the display of Morphs in the Hand itself.
CMagnifierPlayer new openInHand!
TestCase subclass: #CMagnifierTest
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Tweak-EToys'!
CPlayer subclass: #CScreeningCostume
instanceVariableNames: '
screen
passingColor
'
classVariableNames: ''
poolDictionaries: ''
category: 'Tweak-EToys'!
!CScreeningCostume commentStamp: '' prior: 0!
I am a costume like ScreeningMorph. screen is used as 1-bit mask, the passing color is decided from the center pixel of screen.
Structure:
screen CPlayer -- a player used as mask.
passingColor Color -- a passing color of screen player.!
!CMagnifier methodsFor: 'initialize' stamp: 'tak 5/9/2005 15:57'!
initialize
super initialize
showPointer := false.
! !
!CMagnifier methodsFor: 'initialize' stamp: 'tak 5/9/2005 16:08'!
setupCostume
super setupCostume.
self graphicEnabled: true.
self scale := 2.
self color := Color transparent.
self extent := 128 @ 128.
self graphicFit := #rigid.
self borderWidth := 1.
self borderColor := Color black.
self borderStyle := #simple.
sourcePlayer := self hand.
! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 4/30/2005 20:05'!
showPointer
"Answer the showPointer of the receiver"
^self propertyValueAt: #showPointer! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 4/30/2005 20:05'!
showPointer: aValue
"Modify the receiver's showPointer"
^self propertyValueAt: #showPointer put: aValue with: #showPointerChanged! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 5/5/2005 17:08'!
sourcePlayer
"Answer the sourcePlayer of the receiver"
^self propertyValueAt: #sourcePlayer! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 5/5/2005 17:08'!
sourcePlayer: aValue
"Modify the receiver's sourcePlayer"
^self propertyValueAt: #sourcePlayer put: aValue with: #sourcePlayerChanged! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 5/5/2005 17:38'!
trackPointer
"Answer the trackPointer of the receiver"
^ sourcePlayer = self hand! !
!CMagnifier methodsFor: 'accessing' stamp: 'tak 5/9/2005 15:55'!
trackPointer: aValue
"It provides same protocol of MagnifierMorph"
aValue
ifTrue: [sourcePlayer := self hand]
ifFalse: [sourcePlayer := self]
! !
!CMagnifier methodsFor: 'updating' stamp: 'tak 5/9/2005 12:20'!
updateGraphics
self root
ifNotNil: [self graphic: self sourceForm]! !
!CMagnifier methodsFor: 'updating' stamp: 'tak 5/5/2005 17:42'!
updatePosition
self updateGraphics! !
!CMagnifier methodsFor: 'updating' stamp: 'tak 5/9/2005 09:16'!
updateTick
self updateGraphics.
self invalidate! !
!CMagnifier methodsFor: 'magnifying' stamp: 'tak 5/9/2005 16:12'!
sourceForm
"Answer the source form"
| srcRect srcForm |
srcRect _ self sourceRectFrom: sourcePlayer center.
srcForm _ (srcRect intersects: self globalBounds)
ifTrue: [self root asPrimCostume
patchAt: srcRect
without: self
andNothingAbove: false]
ifFalse: ["optimization"
self root display copy: srcRect].
showPointer
ifTrue: [srcForm
reverse: (srcForm center - (1 @ 1) extent: 2 @ 2)
fillColor: Color white].
^ srcForm! !
!CMagnifier methodsFor: 'magnifying' stamp: 'tak 5/9/2005 16:06'!
sourceRectFrom: aPoint
| srcExtent |
srcExtent _ self localBounds extent - (2 * borderWidth).
^ (aPoint extent: srcExtent)
translateBy: srcExtent // -2! !
!CMagnifier class methodsFor: 'class initialization' stamp: 'tak 5/2/2005 16:22'!
initialize
"self initialize"
self registerWithPartsBin.
! !
!CMagnifier class methodsFor: 'class initialization' stamp: 'tak 5/9/2005 14:06'!
newbornPartToDropIn: player
^ super newbornPartToDropIn: player! !
!CMagnifier class methodsFor: 'class initialization' stamp: 'tak 5/10/2005 15:57'!
registerWithPartsBin
"Register the receiver in the basic category"
CPartsBin
registerPartDescription: (CPartDescription
partDescriptionWithLabel: 'Magnifier'
balloonHelp: 'A magnifying glass'
category: 'miscellaneous'
creator: self
selector: #newbornPartToDropIn:
customForm: nil).
CPartsBin
registerPartDescription: (CPartDescription
partDescriptionWithLabel: 'RoundGlass'
balloonHelp: 'A round magnifying glass'
category: 'miscellaneous'
creator: self
selector: #newRound
customForm: nil)! !
!CMagnifier class methodsFor: 'instance creation' stamp: 'tak 5/9/2005 17:01'!
newRound
"CMagnifierPlayer newRound openInHand"
| aMagnifier costume screen |
aMagnifier _ self new.
costume := CScreeningCostume new.
screen := CEllipsePlayer new.
screen bounds := aMagnifier bounds.
screen color := Color gray.
aMagnifier costume: costume.
costume screen: screen.
aMagnifier setupCostume.
aMagnifier name: 'Round glass'.
^ aMagnifier! !
!CMagnifierTest methodsFor: 'testing' stamp: 'tak 5/9/2005 16:25'!
testNewRound
"self debug: #testNewRound"
| mag |
mag _ CMagnifier newRound.
self assert: mag costume screen class == CEllipsePlayer.! !
!CMagnifierTest methodsFor: 'testing' stamp: 'tak 5/6/2005 15:02'!
testScreen
"self debug: #testScreen"
| c screen |
c _ CScreeningCostume new.
c screen: (screen _ CEllipsePlayer new color: Color red; yourself).
self assert: c passingColor = Color red.
! !
!CMagnifierTest methodsFor: 'testing' stamp: 'tak 5/9/2005 16:25'!
testSourceRect
"self debug: #testSourceRect"
| p |
p _ CMagnifier new.
p scale: 1.
p extent: 10 @ 10.
p borderWidth: 2.
self assert: (p sourceRectFrom: 0@0) = (-3@-3 extent: 6@6).
p scale: 2.
p extent: 10 @ 10.
p borderWidth: 2. "actually 4"
self assert: (p sourceRectFrom: 0@0) = (-1@-1 extent: 1@1).
! !
!CPartPrecursor methodsFor: 'events' stamp: 'tak 5/9/2005 16:23'!
onDropped
"Invoked when the receiver has been dropped in a container. Create the actual object and transform the receiver into that objec.t"
| theNewInstance |
(container == nil or: [partDescription == nil]) ifTrue: [^ self]. "Both have been seen..."
theNewInstance _ partDescription newInstanceIn: container.
container elements replace: self with: theNewInstance.
theNewInstance position: self position. "keep scale"
self destroy "is necessary for terminating scripts etc? probably not"! !
!CPartsBin class methodsFor: 'standard default parts bin' stamp: 'tak 5/9/2005 16:25'!
addDescriptionsForMiscellaneous
"Add part descriptions for miscellaneous category"
self addDescriptionsFor: #miscellaneous from: #(
(CEToyHolder 'Holder' 'A container for other objects')
(CTrashCan 'TrashCan' 'A place for discarding things')
(CStopStepGoControls 'Script Controls' 'Controls for the scripts in this project')).
CStickyPad registerWithPartsBin. "on account of custom form"
CMagnifier registerWithPartsBin.
! !
!CScreeningCostume methodsFor: 'accessing' stamp: 'tak 5/6/2005 10:02'!
mergeWith: aForm
| mergeForm |
mergeForm _ aForm copy.
(BitBlt current toForm: mergeForm)
copyForm: self screenForm
to: 0 @ 0
rule: Form and
colorMap: (Bitmap with: 0 with: 4294967295).
^ mergeForm! !
!CScreeningCostume methodsFor: 'accessing' stamp: 'tak 5/5/2005 20:22'!
passingColor
"Answer the passingColor of the receiver"
^self propertyValueAt: #passingColor! !
!CScreeningCostume methodsFor: 'accessing' stamp: 'tak 5/5/2005 20:22'!
passingColor: aValue
"Modify the receiver's passingColor"
^self propertyValueAt: #passingColor put: aValue with: #passingColorChanged! !
!CScreeningCostume methodsFor: 'accessing' stamp: 'tak 5/5/2005 20:22'!
screen
"Answer the screen of the receiver"
^self propertyValueAt: #screen! !
!CScreeningCostume methodsFor: 'accessing' stamp: 'tak 5/6/2005 15:19'!
screen: aValue
"Modify the receiver's screen"
passingColor := aValue asForm colorAt: aValue center.
self border _ aValue border copy.
^self propertyValueAt: #screen put: aValue with: #screenChanged! !
!CScreeningCostume methodsFor: 'initialize' stamp: 'tak 5/6/2005 14:15'!
initialize
super initialize.
self userDraw := true.
screen := CEllipsePlayer new color: Color gray; yourself.
! !
!CScreeningCostume methodsFor: 'drawing' stamp: 'tak 5/6/2005 11:35'!
drawOn: aCanvas in: drawingBounds
screen drawOn: aCanvas in: drawingBounds.
aCanvas
paintImage: (self mergeWith: self sourceForm)
at: drawingBounds origin! !
!CScreeningCostume methodsFor: 'drawing' stamp: 'tak 5/6/2005 07:52'!
screenForm
| screenForm screenImage colorMap pickValue elseValue |
passingColor ifNil: [passingColor := Color black].
pickValue := 4294967295.
elseValue := 0.
screenImage := screen costume asFormOfDepth: Display depth.
colorMap := screenImage newColorMap atAllPut: elseValue.
colorMap
at: (passingColor indexInMap: colorMap)
put: pickValue.
screenForm := Form extent: screenImage extent.
screenForm
copyBits: screenForm boundingBox
from: screenImage
at: 0 @ 0
colorMap: colorMap.
^ screenForm! !
!CScreeningCostume methodsFor: 'drawing' stamp: 'tak 5/9/2005 16:17'!
sourceForm
| box aCanvas |
box _ self localBounds.
aCanvas _ CTransformCanvas extent: box extent depth: Display depth.
aCanvas
translateBy: box origin negated
during: [:cc | costume drawOn: cc in: box].
^ aCanvas form! !
!CScreeningCostume methodsFor: 'events' stamp: 'tak 5/6/2005 15:19'!
onBorderChanged
screen border := border copy! !
!CScreeningCostume methodsFor: 'events' stamp: 'tak 5/6/2005 12:03'!
onExtentChanged
screen extent := extent! !
!CScreeningCostume class methodsFor: 'examples' stamp: 'tak 5/6/2005 14:59'!
example1
"self example1"
| player |
player _ CTrashCan new.
player costume: self new.
player costume screen: (CPolygonPlayer new color: Color gray; yourself).
player openInHand.! !
!CScreeningCostume class methodsFor: 'examples' stamp: 'tak 5/6/2005 15:24'!
example2
"self example2"
| player |
player _ CTrashCan new.
player costume: self new.
player costume screen: (CEllipsePlayer new color: Color gray; yourself).
player costume costume: self new.
player costume costume screen: (CPolygonPlayer new color: Color gray; borderWidth: 0; yourself).
player openInHand.! !
!CTileDefinition class methodsFor: 'reading' stamp: 'tak 5/9/2005 16:27'!
defaultViewerSpec
"CTileDefinition readXmlFrom: self defaultViewerSpec readStream"
^'
'! !
CMagnifier initialize!