[Newbies] Help with pen stuff

Bert Freudenberg bert at freudenbergs.de
Tue Jun 5 12:29:43 UTC 2012

On 05.06.2012, at 11:46, OrgmiGeek wrote:

> In my spare time I decided to rite a simple paint program! I have encountered
> some problems:
> #1 does paint stuff work in the BorderedMorph category?

With a Pen you paint on a Form (which is an picture object holding pixels). To display a Form in Morphic you can use an ImageMorph.

> #2 how would you make the program draw where your mouse pointer is? I think
> you do it like:
> myPen goto: 200 at 200.	but more like: myPen goto: mouseX at mouseY

Your morph can receive mouse events. You need to implement the handlesMouseDown: method to return true.

This will send mouse event messages to your morph. It will receive a mouseDown: message when the mouse button is pressed, and a mouseMove: message when the mouse is moved subsequently, and finally a mouseUp: message.

The argument to these messages is a MouseEvent. It has a position, but that is in world coordinates. You need to subtract the morph's topLeft coordinate from the event's position.

It's really just a handful of lines, but see the attached example for a working version.

- Bert -

-------------- next part --------------
A non-text attachment was scrubbed...
Name: BertsPaintMorph.st
Type: application/octet-stream
Size: 943 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/beginners/attachments/20120605/a5bc6b8a/BertsPaintMorph.obj

More information about the Beginners mailing list