'From etoys2.1 of 6 September 2007 [latest update: #1636] on 14 September 2007 at 12:07:02 pm'! "Change Set: Repaint-rot-tk Date: 14 September 2007 Author: Ted Kaehler Repaint a rotated and scaled sketchMorph. When you keep the changes, it used to place the sketch at a different place (top left of the screen). Now try to place it at the original location. Not perfect yet, but as close as I can get with my present level of understanding."! !SketchEditorMorph methodsFor: 'start & finish' stamp: 'tk 9/13/2007 13:30'! findBounds: sketch in: aPasteUpMorph "Return the final painting area (onion skin) where the user will paint. Compute the new location of the referencePoint (used to comput rotationCenter) as an offset in the paint area. Ugly but necessary." | margin refPtOffset bnds screen delta delta2 | "Always keep old sketch in center of paint area -- that is what onion skin blt will do" refPtOffset := "0@0 +" (sketch form extent * sketch rotationCenter). bnds := 0@0 corner: sketch form extent. bnds := bnds align: refPtOffset with: sketch referencePositionInWorld. "offset is relative inside bnds" screen := aPasteUpMorph world bounds. bnds extent > screen extent ifTrue: ["expanded sketch is bigger than world" refPtOffset := refPtOffset - (bnds extent - screen extent //2). "must keep at the right place in rectangle" bnds := screen] ifFalse: ["move so not off screen" delta := bnds amountToTranslateWithin: screen. bnds := bnds translateBy: delta]. "refPtOffset stays the same -- relative" "give it extra margin if any space left" delta2 := bnds extent - screen extent //2. delta2 < (0@0) ifTrue: [ margin := (60@60) max: ((aPasteUpMorph reasonablePaintingExtent - bnds extent) // 2). margin := margin min: delta2 negated. bnds := bnds translateBy: margin negated. bnds := bnds expandBy: margin. refPtOffset := refPtOffset + margin. delta := bnds amountToTranslateWithin: screen. bnds := bnds translateBy: delta]. "refPtOffset stays the same -- relative" self setProperty: #refPtOffset toValue: refPtOffset. ^ bnds! ! !SketchEditorMorph methodsFor: 'start & finish' stamp: 'tk 9/14/2007 11:59'! findBounds: sketch in: aPasteUpMorph forBackground: forBackground "Return the final painting area (onion skin) where the user will paint. Compute the new location of the referencePoint (used to comput rotationCenter) as an offset in the paint area. Ugly but necessary." | margin refPtOffset bnds screen delta delta2 | "Always keep old sketch in center of paint area -- that is what onion skin blt will do" refPtOffset := "0@0 +" (sketch form extent * sketch rotationCenter). bnds := 0@0 corner: sketch form extent. bnds := bnds align: refPtOffset with: sketch referencePositionInWorld. "offset is relative inside bnds" screen := aPasteUpMorph world bounds. bnds extent > screen extent ifTrue: ["expanded sketch is bigger than world" refPtOffset := refPtOffset - (bnds extent - screen extent //2). "must keep at the right place in rectangle" bnds := screen] ifFalse: ["move so not off screen" delta := bnds amountToTranslateWithin: screen. bnds := bnds translateBy: delta]. "refPtOffset stays the same -- relative" "give it extra margin if any space left" delta2 := bnds extent - screen extent //2. (forBackground not and: [delta2 < (0@0)]) ifTrue: [ margin := (60@60) max: ((aPasteUpMorph reasonablePaintingExtent - bnds extent) // 2). margin := margin min: delta2 negated. bnds := bnds translateBy: margin negated. bnds := bnds expandBy: margin. refPtOffset := refPtOffset + margin. delta := bnds amountToTranslateWithin: screen. bnds := bnds translateBy: delta]. "refPtOffset stays the same -- relative" self setProperty: #refPtOffset toValue: refPtOffset. ^ bnds! ! !SketchMorph methodsFor: 'menu' stamp: 'tk 9/14/2007 12:00'! editDrawingIn: aPasteUpMorph forBackground: forBackground "Edit an existing sketch." | w bnds sketchEditor pal aPaintTab aWorld aPaintBox tfx oldRefPt newRefPt | self world assureNotPaintingElse: [^self]. oldRefPt := self referencePositionInWorld. w := aPasteUpMorph world. w prepareToPaint. w displayWorld. self visible: false. ActiveHand eventRecorders do: [:er | er rememberPaintBoxSettingsAtRecordingOutset]. sketchEditor := SketchEditorMorph new. bnds := sketchEditor findBounds: self in: aPasteUpMorph forBackground: forBackground. "it saves refPtOffset" forBackground ifTrue: [sketchEditor setProperty: #background toValue: true]. w addMorphFront: sketchEditor. sketchEditor initializeFor: self inBounds: bnds pasteUpMorph: aPasteUpMorph. sketchEditor afterNewPicDo: [:aForm :aRect | self visible: true. self form: aForm. newRefPt := (sketchEditor valueOfProperty: #refPtOffset) - (aRect origin - bnds origin). self rotationCenter: newRefPt asFloatPoint / aRect extent. "a fraction of extent of the final sketch form" self position: (self rotationCenter * self extent) negated. tfx := aPasteUpMorph transformFrom: aPasteUpMorph world. "may have moved" "align reference points (rotation centers) with original sketch" self topRendererOrSelf position: (tfx globalPointToLocal: (oldRefPt - (newRefPt * (self extent / originalForm extent)))). self rotationStyle: sketchEditor rotationStyle. self forwardDirection: sketchEditor forwardDirection. (aPaintTab := (aWorld := self world) paintingFlapTab) ifNotNil: [aPaintTab hideFlap] ifNil: [(aPaintBox := aWorld paintBox) ifNotNil: [aPaintBox delete]]. self presenter drawingJustCompleted: self. forBackground ifTrue: [self goBehind "shouldn't be necessary"]] ifNoBits: ["If no bits drawn. Must keep old pic. Can't have no picture" self visible: true. aWorld := self currentWorld. "sometimes by now I'm no longer in a world myself, but we still need to get ahold of the world so that we can deal with the palette" ((pal := aPasteUpMorph standardPalette) notNil and: [pal isInWorld]) ifTrue: [(aPaintBox := aWorld paintBox) ifNotNil: [aPaintBox delete]. pal viewMorph: self] ifFalse: [(aPaintTab := (aWorld := self world) paintingFlapTab) ifNotNil: [aPaintTab hideFlap] ifNil: [(aPaintBox := aWorld paintBox) ifNotNil: [aPaintBox delete]]]]! !