[Newbies] Drawing with Morphic Transforms

Jeff G jgon.in.canada at gmail.com
Tue Oct 18 04:09:07 UTC 2011

Hi Everyone,

My question concerns how to correctly use transforms when drawing in
Morphic.  I have created a morph and overridden its drawOn: method so that I
can convert the canvas passed in to a BalloonCanvas so I can get
anti-aliasing when I draw, and subsequently to a clipping canvas so that I
can draw figures outside the bounds of the morph without actually drawing
past the morph and onto the Display.

One of the things that I would like to do is allow for shapes I am drawing
to be given an arbitrary scale, translation, and rotation.  Each shape would
have an associated transform so that when they are asked to draw they would
set their transform on the canvas and draw as though they are situated at
the origin and the transform will take care of having the actual rendering
occur in the correct location.  Ie if a rectangle has size of 20 at 20 and the
morph has its bounds starting from 500 at 400 (topLeft) then ultimately the
rectangle will start drawing from 500 at 400 to 520 at 420, and thus will display
correctly in the morph.

My problem is that I cannot seem to get the canvas to actually take into
account the transform that I am setting during drawing.  I can call
transformBy: or transformBy:clipTo:during: passing in either a
MatrixTransform2x3 or a MorphicTransform, with both being given an offset of
the Morph's topLeft.  I then draw a rectangle at 0 at 0 with a extent of
100 at 100.  My experience with other vector drawing toolkits would lead me to
believe that this should cause the rectangle to draw in the top left corner
of the morph no matter where it is onscreen, but alas the rectangle only
appears when I move the morph to the top left of the display, meaning that
the transform isn't causing an offset to take place during the drawing.

Any pointers that could be offered to allow me to get my drawing up and
fully transformed would be greatly appreciated as I would like to work on a
simple asteroids game after this, and I will be using transforms of basic
shapes extensively as they travel around the screen.

Thanks for your help,
Jeff G.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20111017/d611718f/attachment.htm

More information about the Beginners mailing list