'From etoys2.1 of 6 September 2007 [latest update: #1654] on 17 September 2007 at 12:33:27 pm'! "Change Set: Paint-bulletproof-tk Date: 17 September 2007 Author: Ted Kaehler One more piece of safety code in case the user turns the page of a Guide while painting."! !SketchMorph methodsFor: 'menu' stamp: 'tk 9/17/2007 12:26'! 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. aWorld := self currentWorld. (aPaintTab := aWorld 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]]]]! !