[ENH]SketchEditorMorph
Karl Ramberg
karl.ramberg at chello.se
Tue Apr 25 16:18:10 UTC 2000
Enhancement to SketchEditorMorph.
When using the rect., ellipse, star and polygon
tools on would always get a black outline the thickness of the selected
brush.
This changeset removes the outline unless a transparent color is
selected.
Then it will draw the outline black the thickness of the selected brush.
The star and the polygon tools does not handle thick brushes so I fixed
their
border size to one pixel. The polygon still picks up the brush size
somewhere and
draws incorrectly :- ( .This bug is just inherited from the old
implementation, not
caused by me.
Karl Ramberg
PS
SMA wanted the changesets gz. How do one do that? From Squeak or a free
program?
I'm on a mac.
-------------- next part --------------
'From Squeak2.8alpha of 19 February 2000 [latest update: #2005] on 25 April 2000 at 6:03:31 pm'!
!SketchEditorMorph methodsFor: 'actions & preps' stamp: 'kfr 4/25/2000 17:50'!
ellipse: evt
"Draw an ellipse from the center. "
| rect oldRect ww ext oldExt |
ext _ (strokeOrigin - evt cursorPoint) abs * 2.
evt shiftPressed ifTrue: [ext _ ext r].
rect _ Rectangle center: strokeOrigin extent: ext.
ww _ palette getNib width.
lastEvent ifNotNil: [
oldExt _ (strokeOrigin - lastEvent cursorPoint) abs + ww * 2.
lastEvent shiftPressed ifTrue: [oldExt _ oldExt r].
(oldExt < ext) ifFalse: ["Last draw sticks out, must erase the area"
oldRect _ Rectangle center: strokeOrigin extent: oldExt.
self restoreRect: oldRect]].
currentColor == Color transparent
ifFalse:[
formCanvas fillOval: rect color: currentColor
borderWidth: 0 borderColor: Color transparent.]
ifTrue:[
formCanvas fillOval: rect color: currentColor
borderWidth: ww borderColor: Color black].
self invalidRect: rect.
! !
!SketchEditorMorph methodsFor: 'actions & preps' stamp: 'kfr 4/25/2000 17:51'!
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 |
self polyFreeze. "any old one we were working on"
poly _ PolygonMorph new addHandles.
currentColor == Color transparent
ifFalse:[
poly color: currentColor; borderWidth: 0;
borderColor: Color transparent]
ifTrue:[
poly color: currentColor; borderWidth: 1; "still some problems with brushsize !!!!"
borderColor: Color black].
poly position: evt cursorPoint.
self addMorph: poly.
poly changed.
self setProperty: #polygon toValue: poly.! !
!SketchEditorMorph methodsFor: 'actions & preps' stamp: 'kfr 4/25/2000 17:52'!
rect: evt
"While moving corner, just write on the canvas. When done, write
on the paintingForm"
| rect within oldRect now diff cor |
rect _ strokeOrigin rect: (now _ evt cursorPoint).
evt shiftPressed ifTrue:
[diff _ evt cursorPoint - strokeOrigin.
now _ strokeOrigin +
(Point r: (diff x abs min: diff y abs)*2 degrees:
(diff degrees // 90 * 90 + 45)).
rect _ strokeOrigin rect: now].
lastEvent == nil ifFalse:
[oldRect _ strokeOrigin rect: lastEvent cursorPoint.
lastEvent shiftPressed ifTrue:
[diff _ lastEvent cursorPoint - strokeOrigin.
cor _ strokeOrigin + (Point r: (diff x abs min:
diff y abs)*2
degrees: (diff degrees //
90 * 90 + 45)).
oldRect _ strokeOrigin rect: cor].
within _ (rect containsRect: oldRect).
within & (currentColor isTransparent not) ifFalse:
["Last draw will stick out, must erase the area"
self restoreRect: oldRect]].
currentColor == Color transparent
ifFalse:[
formCanvas frameAndFillRectangle: rect fillColor: currentColor
borderWidth: 0 borderColor: Color transparent.]
ifTrue:[
formCanvas frameAndFillRectangle: rect fillColor: currentColor
borderWidth: (palette getNib width) borderColor: Color black].
self invalidRect: rect.! !
!SketchEditorMorph methodsFor: 'actions & preps' stamp: 'kfr 4/25/2000 17:54'!
star: evt
"Draw an star from the center. "
| poly ext ww rect oldExt oldRect oldR verts pt |
ww _ palette getNib width.
ext _ (pt _ strokeOrigin - evt cursorPoint) r + ww * 2.
rect _ Rectangle center: strokeOrigin extent: ext.
ww _ palette getNib width.
lastEvent ifNotNil: [
oldExt _ (strokeOrigin - lastEvent cursorPoint) r + ww * 2.
"Last draw sticks out, must erase the area"
oldRect _ Rectangle center: strokeOrigin 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)
+ strokeOrigin].
poly _ PolygonMorph new addHandles.
currentColor == Color transparent
ifFalse:[
poly color: currentColor; borderWidth: 0; borderColor: Color transparent.]
ifTrue:[
poly color: currentColor; borderWidth: 1; borderColor: Color black ]. " can't handle thick brushes"
self invalidRect: rect.
"self addMorph: poly."
poly privateOwner: self.
poly bounds: (strokeOrigin extent: ext).
poly setVertices: verts.
poly drawOn: formCanvas.
"poly delete."
self invalidRect: rect.
! !
More information about the Squeak-dev
mailing list
|