'From Squeak3.7-m17n of 21 July 2004 [latest update: #19] on 25 July 2004 at 3:48:07 pm'! "Change Set: e06HollowShapes-sw Date: 25 July 2004 Author: Scott Wallace Makes the shape tools in the etoy painting system draw hollow shapes (rather than solid shapes), using the selected color and pen width to govern the border characteristics. This works with the rectangle tool, the ellipse tool, the polygon tool, and the star tool. Derived from update 0215hollowShapes-sw.cs of Squeakland. Note that this cs reverts method GrafPort.frameRect:borderWidth: to Andreas's version prior to update 5289GrafPort-frameRect-efc -- that update achieved a speedup at the expense of breaking the basic behavior..."! !GrafPort methodsFor: 'drawing support' stamp: 'ar 2/17/2000 14:44'! frameRect: rect borderWidth: borderWidth sourceX _ 0. sourceY _ 0. (rect areasOutside: (rect insetBy: borderWidth)) do: [:edgeStrip | self destRect: edgeStrip; copyBits]. ! ! !SketchEditorMorph methodsFor: 'actions & preps' stamp: 'sw 4/21/2004 13:23'! ellipse: evt "Draw an ellipse from the center. " | rect oldRect ww ext oldExt cColor sOrigin priorEvt | sOrigin _ self get: #strokeOrigin for: evt. cColor _ self getColorFor: evt. ext _ (sOrigin - evt cursorPoint) abs * 2. evt shiftPressed ifTrue: [ext _ self shiftConstrainPoint: ext]. rect _ Rectangle center: sOrigin extent: ext. ww _ (self getNibFor: evt) width. (priorEvt _ self get: #lastEvent for: evt) ifNotNil: [ oldExt _ (sOrigin - priorEvt cursorPoint) abs + ww * 2. priorEvt shiftPressed ifTrue: [oldExt _ self shiftConstrainPoint: oldExt]. (oldExt < ext) ifFalse: ["Last draw sticks out, must erase the area" oldRect _ Rectangle center: sOrigin extent: oldExt. self restoreRect: oldRect]]. cColor == Color transparent ifFalse: [formCanvas fillOval: rect color: Color transparent borderWidth: ww borderColor: cColor] ifTrue: [formCanvas fillOval: rect color: cColor borderWidth: ww borderColor: Color black]. self invalidRect: rect. ! ! !SketchEditorMorph methodsFor: 'actions & preps' stamp: 'sw 7/5/2004 03:20'! polyNew: evt "Create a new polygon. Add it to the sketch, and let the user drag its vertices around!! Freeze it into the painting when the user chooses another tool." | poly cColor | self polyEditing ifTrue:[ self polyFreeze. (self hasProperty: #polyCursor) ifTrue:[palette plainCursor: (self valueOfProperty: #polyCursor) event: evt. self removeProperty: #polyCursor]. ^self]. cColor _ self getColorFor: evt. self polyFreeze. "any old one we were working on" poly _ PolygonMorph new "addHandles". poly referencePosition: poly bounds origin. poly align: poly bounds center with: evt cursorPoint. poly borderWidth: (self getNibFor: evt) width. poly borderColor: (cColor isTransparent ifTrue: [Color black] ifFalse: [cColor]). poly color: Color transparent. self addMorph: poly. poly changed. self setProperty: #polygon toValue: poly.! ! !SketchEditorMorph methodsFor: 'actions & preps' stamp: 'sw 7/25/2004 03:16'! rect: evt "While moving corner, just write on the canvas. When done, write on the paintingForm" | rect oldRect now diff cor cColor sOrigin priorEvt | sOrigin _ self get: #strokeOrigin for: evt. rect _ sOrigin rect: (now _ evt cursorPoint). cColor _ self getColorFor: evt. evt shiftPressed ifTrue: [diff _ evt cursorPoint - sOrigin. now _ sOrigin + (Point r: (diff x abs min: diff y abs) * 2 degrees: diff degrees // 90 * 90 + 45). rect _ sOrigin rect: now]. (priorEvt _ self get: #lastEvent for: evt) isNil ifFalse: [oldRect _ sOrigin rect: priorEvt cursorPoint. priorEvt shiftPressed ifTrue: [diff _ priorEvt cursorPoint - sOrigin. cor _ sOrigin + (Point r: (diff x abs min: diff y abs) * 2 degrees: diff degrees // 90 * 90 + 45). oldRect _ sOrigin rect: cor]. self restoreRect: oldRect]. "Last draw will stick out, must erase the area" cColor == Color transparent ifTrue: [formCanvas frameAndFillRectangle: rect fillColor: Color transparent borderWidth: (self getNibFor: evt) width borderColor: Color black] ifFalse: [formCanvas frameAndFillRectangle: rect fillColor: Color transparent borderWidth: (self getNibFor: evt) width borderColor: cColor]. self invalidRect: rect! ! !SketchEditorMorph methodsFor: 'actions & preps' stamp: 'sw 7/5/2004 03:10'! star: evt "Draw an star from the center." | poly ext ww rect oldExt oldRect oldR verts pt cColor sOrigin priorEvt | sOrigin _ self get: #strokeOrigin for: evt. cColor _ self getColorFor: evt. ww _ (self getNibFor: evt) width. ext _ (pt _ sOrigin - evt cursorPoint) r + ww * 2. rect _ Rectangle center: sOrigin extent: ext. (priorEvt _ self get: #lastEvent for: evt) ifNotNil: [oldExt _ (sOrigin - priorEvt cursorPoint) r + ww * 2. "Last draw sticks out, must erase the area" oldRect _ Rectangle center: sOrigin extent: oldExt. self restoreRect: oldRect]. ext _ pt r. oldR _ ext. verts _ (0 to: 350 by: 36) collect: [:angle | (Point r: (oldR _ oldR = ext ifTrue: [ext * 5 // 12] ifFalse: [ext]) degrees: angle + pt degrees) + sOrigin]. poly _ PolygonMorph new addHandles. poly borderColor: (cColor isTransparent ifTrue: [Color black] ifFalse: [cColor]). poly borderWidth: (self getNibFor: evt) width. poly fillStyle: Color transparent. "can't handle thick brushes" self invalidRect: rect. "self addMorph: poly." poly privateOwner: self. poly bounds: (sOrigin extent: ext). poly setVertices: verts. poly drawOn: formCanvas. "poly delete." self invalidRect: rect! ! !SketchEditorMorph methodsFor: 'event handling' stamp: 'sw 7/5/2004 03:23'! mouseEnter: evt "Set the cursor. Reread colors if embedded editable polygon needs it." | poly cColor | super mouseEnter: evt. (self get: #action for: evt) == #scaleOrRotate ifTrue: [ self set: #action for: evt to: (self get: #priorAction for: evt). ]. "scale and rotate are not real modes. If we enter with one, wear the previous tool." evt hand showTemporaryCursor: (self getCursorFor: evt). palette getSpecial == #polygon: ifFalse: [^self]. (poly _ self valueOfProperty: #polygon) ifNil: [^ self]. cColor _ self getColorFor: evt. poly borderColor: cColor; borderWidth: (self getNibFor: evt) width. poly changed.! !