'From Squeak3.7alpha of 11 September 2003 [latest update: #5765] on 6 March 2004 at 10:53:42 am'! "Change Set: MagnifierToolMerged-nk Date: 6 March 2004 Author: Ned Konz This change set merges the behavior of the HandDisplayingMagnifierMorph from my ENH called MagnifierTool-nk into MagnifierMorph as suggested by Ken Causey. It also improves the class comment and removes an unused instance variable (lastPos). When a MagnifierMorph is told showPointer: true then it will also: * display morphs that are held by the hand * display the hand's cursor position. "! BorderedMorph subclass: #MagnifierMorph instanceVariableNames: 'magnification trackPointer lastPos srcExtent showPointer ' classVariableNames: 'RecursionLock ' poolDictionaries: '' category: 'Morphic-Demo'! !MagnifierMorph commentStamp: '' prior: 0! MagnifierMorph instances are magnifying lenses that magnify the morphs below them (if grabbed or if trackPointer is false) or the area around the mouse pointer. Instance variables: magnification The magnification to use. If non-integer, smooths the magnified form. 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. srcExtent The extent of the source rectangle. Class variables: RecursionLock Used to avoid infinite recursion when getting the source patch to display.! !MagnifierMorph methodsFor: 'accessing' stamp: 'nk 3/6/2004 10:14'! showPointer: aBoolean "If aBoolean is true, display the current pointer position as a small square in the center of the lens." showPointer == aBoolean ifTrue: [ ^self ]. showPointer _ aBoolean. self changed.! ! !MagnifierMorph methodsFor: 'initialization' stamp: 'nk 3/6/2004 10:47'! initialize "initialize the state of the receiver" super initialize. trackPointer _ true. showPointer _ false. magnification _ 2. self extent: 128 @ 128! ! !MagnifierMorph methodsFor: 'magnifying' stamp: 'nk 3/6/2004 10:47'! magnifiedForm "Answer the magnified form" | srcRect form exclusion magnified | srcRect := self sourceRectFrom: self sourcePoint. (RecursionLock isNil and: [ showPointer or: [ srcRect intersects: self bounds ]]) ifTrue: [RecursionLock := self. exclusion := self isRound ifTrue: [owner] ifFalse: [self]. form := self currentWorld patchAt: srcRect without: exclusion andNothingAbove: false. RecursionLock := nil] ifFalse: ["cheaper method if the source is not occluded" form := Display copy: srcRect]. "smooth if non-integer scale" magnified := form magnify: form boundingBox by: magnification smoothing: (magnification isInteger ifTrue: [1] ifFalse: [2]). "display the pointer rectangle if desired" showPointer ifTrue: [magnified reverse: (magnified center - (2 @ 2) extent: 4 @ 4) fillColor: Color white]. ^ magnified! ! !MagnifierMorph methodsFor: 'menu' stamp: 'nk 3/6/2004 10:15'! addCustomMenuItems: aCustomMenu hand: aHandMorph super addCustomMenuItems: aCustomMenu hand: aHandMorph. aCustomMenu addLine; add: 'magnification...' translated action: #chooseMagnification; addUpdating: #trackingPointerString action: #toggleTrackingPointer; addUpdating: #showingPointerString action: #toggleShowingPointer; addUpdating: #toggleRoundString action: #toggleRoundness.! ! !MagnifierMorph methodsFor: 'menu' stamp: 'nk 3/6/2004 10:15'! showingPointerString ^ (showPointer ifTrue: ['stop showing pointer'] ifFalse: ['start showing pointer']) translated! ! !MagnifierMorph methodsFor: 'menu' stamp: 'nk 3/6/2004 10:15'! toggleShowingPointer showPointer _ showPointer not! ! !MagnifierMorph class methodsFor: 'instance creation' stamp: 'nk 3/6/2004 10:28'! newShowingPointer "Answer a Magnifier that also displays Morphs in the Hand and the Hand position" ^(self new) showPointer: true; setNameTo: 'HandMagnifier'; yourself! ! !MagnifierMorph class methodsFor: 'parts bin' stamp: 'nk 3/6/2004 10:27'! supplementaryPartsDescriptions ^ {DescriptionForPartsBin formalName: 'RoundGlass' categoryList: #(Useful) documentation: 'A round magnifying glass' globalReceiverSymbol: #MagnifierMorph nativitySelector: #newRound. DescriptionForPartsBin formalName: 'Hand Magnifier' categoryList: #(Useful) documentation: 'A magnifying glass that also shows Morphs in the Hand and displays the Hand position.' globalReceiverSymbol: #MagnifierMorph nativitySelector: #newShowingPointer }! ! BorderedMorph subclass: #MagnifierMorph instanceVariableNames: 'magnification trackPointer srcExtent showPointer' classVariableNames: 'RecursionLock' poolDictionaries: '' category: 'Morphic-Demo'!