I have implemented the canvas on which we draw with a brush in Smalltak Squeak but with only a single color and a single size. I'd like to add the possibility of changing the color and the size of the brush. Could anyone help me please ?
Thank you in advance.
The differents methods are:
"Methods"
extent: aPoint
| newForm |
super extent: aPoint.
newForm := Form extent: self extent depth: 16.
newForm fillColor: Color veryLightGray.
form ifNotNil: [form displayOn: newForm].
form := newForm.
initialize
super initialize.
self extent: 400@350.
drawOn: aCanvas
aCanvas image: form at: bounds origin.
handlesMouseDown: evt
^ true
mouseDown: evt
brush := Pen newOnForm: form.
brush roundNib: 3.
brush color: Color red.
lastMouse := evt cursorPoint - bounds origin.
brush drawFrom: lastMouse to: lastMouse.
self invalidRect:
((lastMouse - brush sourceForm extent corner:
lastMouse + brush sourceForm extent)
translateBy: bounds origin).
mouseMove: evt
| p |
p := evt cursorPoint - bounds origin.
p = lastMouse ifTrue: [^ self].
brush drawFrom: lastMouse to: p.
self invalidRect: ((
((lastMouse min: p) - brush sourceForm extent) corner:
((lastMouse max: p) + brush sourceForm extent))
translateBy: bounds origin).
lastMouse := p.
addCustomMenuItems: aCustomMenu hand: aHandMorph
super addCustomMenuItems: aCustomMenu hand: aHandMorph.
aCustomMenu add: 'clear' action: #clear.
clear
form fillColor: Color veryLightGray.
self changed.