'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 6 October 2008 at 12:09:44 pm'!
!classDefinition: #CheapImageLW category: #'LightWidgets-Kernel'!
ImageLW subclass: #CheapImageLW
	instanceVariableNames: 'updateTime'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!

!CheapImageLW commentStamp: '<historical>' prior: 0!
A space optimized version of ImageLW, that holds only one form, and therefore degrades if resized several times.
There is another optimization. If many instances of CheapImageLW share the same model, they will share the same form (this should be done only if they have the same extent...)!


!ImageLW methodsFor: 'accessing' stamp: 'jmv 8/25/2008 10:44'!
formToDraw
	^stretched! !

!ImageLW methodsFor: 'accessing' stamp: 'jmv 8/25/2008 10:44'!
formToDraw: aForm
	stretched _ aForm! !

!ImageLW methodsFor: 'initialization' stamp: 'jmv 8/25/2008 10:45'!
initialize
	super initialize.
	form _ Form makeStar.
	bounds _ 10@10 extent: form extent.
	self generateStretchedForm! !

!ImageLW methodsFor: 'drawing' stamp: 'jmv 8/25/2008 10:43'!
drawOn: aCanvas 
	| f |
	f _ self formToDraw.
	f notNil ifTrue: [
		aCanvas drawImage: f at: bounds topLeft ]! !

!ImageLW methodsFor: 'drawing' stamp: 'jmv 8/25/2008 10:45'!
generateStretchedForm
	| scale smoothPix pair |
	form isNil ifTrue: [
		self formToDraw: nil.
		^self ].
	scale _ 1.0 * bounds extent / form extent.
	smoothPix _ (scale x < 1.0 or: [scale y < 1.0]) 
		ifTrue: [2]
		ifFalse: [1].
	self formToDraw: (scale = (1 @ 1) 
				ifTrue: [form]
				ifFalse: [
					pair := WarpBlt current 
								rotate: form
								degrees: 0
								center: form boundingBox center
								scaleBy: scale
								smoothing: smoothPix.
					pair first])! !

!ImageLW methodsFor: 'layout' stamp: 'jmv 8/25/2008 10:45'!
layoutChanged
	"Update rotatedForm and compute new bounds."
	self changed.
	self generateStretchedForm.
	super layoutChanged.
	self changed! !

!ImageLW methodsFor: 'updating' stamp: 'jmv 8/25/2008 11:54'!
updateView
	self form: (target ifNotNil: [target form])! !


!CheapImageLW methodsFor: 'accessing' stamp: 'jmv 8/25/2008 10:46'!
formToDraw
	^form! !

!CheapImageLW methodsFor: 'accessing' stamp: 'jmv 8/25/2008 10:46'!
formToDraw: aForm
	form _ aForm! !

!CheapImageLW methodsFor: 'accessing' stamp: 'jmv 8/25/2008 12:51'!
updateTime
	^updateTime! !

!CheapImageLW methodsFor: 'updating' stamp: 'jmv 8/25/2008 12:53'!
findAnyExisting

	World allMorphsDo: [ :m |
		(m class = CheapImageLW and: [m target == target and: [(m == self) not]])
			ifTrue: [
				(m updateTime = target updateTime and: [m width = self width and: [m height = self height]])
					ifTrue: [^m]]].
	^nil! !

!CheapImageLW methodsFor: 'updating' stamp: 'jmv 8/25/2008 12:56'!
updateView
	| m |
	target isNil ifTrue: [
		self form: nil.
		updateTime _ nil.
		^ self].
	
	m _ self findAnyExisting.
	m notNil ifTrue: [
		updateTime _ m updateTime.
		self form: m formToDraw.
		^ self ].
		
	updateTime _ target updateTime.
	self form: target form! !


!LightWidget reorganize!
('DNU' doesNotUnderstand:)
('accessing' eventHandler isLocked isSticky morphsAt:behind:unlocked: owner privateOwner: world)
('accessing-properties' hasProperty:)
('add/remove' delete dismissViaHalo privateDelete)
('change reporting' invalidRect: invalidRect:from: ownerChanged)
('classification' isHandMorph isWorldMorph isWorldOrHandMorph)
('compatibility' allMorphsDo: isPlayfieldLike morphicLayerNumber morphicLayerNumberWithin: noteNewOwner: submorphs submorphsDo:)
('copying' duplicate)
('debug and other' buildDebugMenu:)
('defaults' borderStyleFor: borderStyleWith: defaultFont pressedBorderStyleWith:)
('drawing' areasRemainingToFill: drawErrorOn: drawHighlightOn: drawOn: drawingFails drawingFailsNot fullDrawOn: hide isKnownFailing shadowForm show visible visible:)
('dropping/grabbing' aboutToBeGrabbedBy: formerOwner: formerPosition: justDroppedInto:event: justGrabbedFrom: rejectDropMorphEvent: wantsToBeDroppedInto:)
('event handling' handlesMouseDown: handlesMouseOver: handlesMouseOverDragging: handlesMouseStillDown: mouseMove: mouseStillDown: mouseStillDownStepRate mouseStillDownThreshold mouseUp: transformFrom: transformedFrom:)
('events-processing' handleEvent: handleFocusEvent: handleKeyDown: handleKeyUp: handleKeystroke: handleMouseDown: handleMouseEnter: handleMouseLeave: handleMouseMove: handleMouseOver: handleMouseStillDown: handleMouseUp: handlerForMouseDown: handlesKeyboard: keyDown: keyStroke: keyUp: mouseDownPriority processEvent:using: rejectDropEvent: rejectsEvent:)
('focus handling' gotNavigationFocus keyboardFocusChange: lostNavigationFocus seizesNavigationFocus)
('geometry' bounds bounds: extent: fullBounds fullBoundsInWorld height height: point:from: point:in: pointInWorld: position position: referencePosition referencePosition: width width: worldBoundsForHalo)
('geometry testing' containsPoint: containsPoint:event: fullContainsPoint:)
('halos and balloon help' addHalo: addHalo:from: addHandlesTo:box: addOptionalHandlesTo:box: balloonHelpTextForHandle: balloonText halo haloClass removeHalo setExtentFromHalo: transferHalo:from: wantsBalloon wantsHaloFromClick)
('initialization' initialize intoWorld: openInWorld openInWorld:)
('layout' layoutChanged)
('menus' inspectInMorphic:)
('meta actions' blueButtonDown: blueButtonUp: dismissMorph: duplicateMorph: handlerForBlueButtonDown:)
('rotation scale and flex' rotationDegrees rotationDegrees:)
('stepping and presenter' shouldGetStepsFrom: startStepping:at:arguments:stepTime: stopSteppingSelector:)
('structure' activeHand allOwnersDo: firstOwnerSuchThat: hasOwner: isInWorld outermostWorldMorph ownerThatIsA: withAllOwnersDo:)
('submorphs-add/remove' comeToFront goBehind)
('testing' hasNavigationFocus isTextMorph resistsRemoval shouldDropOnMouseUp wantsSteps)
('updating' changed)
('view of a model or target' action action: actionAdaptor actionAdaptor: aspect aspect: aspect:adaptor:action:adaptor: aspectAdaptor aspectAdaptor: beMainViewOn: modelChanged performActionWith: safeModelChanged target target: target:action: target:aspect: target:aspect:action: target:aspect:aspectAdaptor: target:aspect:aspectAdaptor:modelChangeEvent: targetAspect updateView)
('private' privateFullMoveBy: privateMoveBy:)
!

