'From etoys2.1 of 6 September 2007 [latest update: #1652] on 17 September 2007 at 10:50:43 am'! "Change Set: repaint-rot2-tk Date: 17 September 2007 Author: Ted Kaehler After repainting, leave the top left of the object where is was before. This is wrong if the user added or removed paint area from the top left. I am not able to get this code right. It is compilcated. In a highly rotated and scaled painting, the topLeft can be at any place around the outside of the painting in the unrotated version!! More info needs to be stored -- such as the current topLeft, but in unrotated coordinates. This fix should make Kathleen's example work."! !SketchMorph methodsFor: 'menu' stamp: 'tk 9/17/2007 10:43'! editDrawingIn: aPasteUpMorph forBackground: forBackground "Edit an existing sketch." | w bnds sketchEditor pal aPaintTab aWorld aPaintBox tfx oldRefPt newRefPt newRefPt2 trans | 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 | newRefPt := (sketchEditor valueOfProperty: #refPtOffset) - (aRect origin - bnds origin). "in scale or original painting" newRefPt2 := self topRendererOrSelf == self ifTrue: [newRefPt - (self rotationCenter * self extent)] ifFalse: ["transformed" trans := owner transform. (trans localPointToGlobal: newRefPt) - (trans localPointToGlobal: (self rotationCenter * self extent))]. self visible: true. self form: aForm. 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 + newRefPt2). "We do not understand how to get the vector from the new topLeft to the rotation center, so leave the object where it was!! Ugh!!" 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]]]]! ! SketchEditorMorph removeSelector: #findBounds:in:!