'From etoys2.2 of 21 September 2007 [latest update: #1777] on 14 November 2007 at 3:35:12 pm'! "Change Set: Paint-World-tk Date: 14 November 2007 Author: Ted Kaehler When painting the World background, if you erase the picture, and then keep, there is a divide-by-zero error. When painting the background, keep the result in the same place on the screen. Do not center it. Fix odd bug in computing the depth from the top of a project that is a DIskProxy."! !Project methodsFor: 'active process' stamp: 'tk 11/14/2007 15:29'! depth "Return the depth of this project from the top. topProject = 0, next = 1, etc." "Project current depth." | depth project | depth _ 0. project _ self. [project class == DiskProxy ifTrue: [^ depth]. project isTopProject] whileFalse: [project _ project parent. depth _ depth + 1]. ^ depth! ! !SketchEditorMorph methodsFor: 'initialization' stamp: 'tk 11/14/2007 15:20'! initializeFor: aSketchMorph inBounds: boundsToUse pasteUpMorph: aPasteUpMorph paintBoxPosition: aPosition "NB: if aPosition is nil, then it's assumed that the paintbox is obtained from a flap or some such, so do nothing special regarding a palette in this case. The palette needs already to be in the world for this to work." | w sketchPos | (w _ aPasteUpMorph world) addMorphInLayer: self. "in back of palette" enclosingPasteUpMorph _ aPasteUpMorph. hostView _ aSketchMorph. "may be ownerless" self bounds: boundsToUse. palette _ w paintBox focusMorph: self. palette beStatic. "give Nebraska whatever help we can" palette fixupButtons. palette addWeakDependent: self. aPosition ifNotNil: [w addMorphFront: palette. "bring to front" palette position: aPosition. Preferences useBiggerPaintingBox ifTrue: [palette beSupersized]]. paintingForm _ Form extent: bounds extent depth: w assuredCanvas depth. self dimTheWindow. self addRotationScaleHandles. sketchPos := (self hasProperty: #background) ifTrue: [aSketchMorph position] ifFalse: [paintingForm extent - aSketchMorph form extent // 2]. aSketchMorph ifNotNil: [aSketchMorph form displayOn: paintingForm at: sketchPos clippingBox: (0@0 extent: paintingForm extent) rule: Form over fillColor: nil. "assume they are the same depth". undoBuffer _ paintingForm deepCopy. rotationCenter _ aSketchMorph rotationCenter]! ! !SketchEditorMorph methodsFor: 'start & finish' stamp: 'tk 11/14/2007 15:09'! 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). screen := aPasteUpMorph world bounds. bnds := 0@0 corner: sketch form extent. bnds := bnds align: refPtOffset with: sketch referencePositionInWorld. "offset is relative inside bnds" 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 expandBy: margin. refPtOffset := refPtOffset + margin. delta := bnds amountToTranslateWithin: screen. bnds := bnds translateBy: delta]. "refPtOffset stays the same -- relative" forBackground ifTrue: [bnds := screen] ifFalse: [self setProperty: #refPtOffset toValue: refPtOffset]. ^ bnds! ! !SketchMorph methodsFor: 'menu' stamp: 'tk 11/14/2007 14:34'! 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 | self form: aForm. forBackground ifFalse: [ 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 rotationCenter: newRefPt asFloatPoint / aRect extent. "a fraction of extent of the final sketch form" self topRendererOrSelf == self ifFalse: [ 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!!" ] ifTrue: [ self position: aRect origin. self rotationCenter: aRect center. ]. 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 visible: true. 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]]]]! !