Making an inverted ellipse morph?

Doug Way dway at riskmetrics.com
Wed Nov 29 23:58:25 UTC 2000


Dean Pu Mao wrote:
> 
> I'm curious if it's easily possible to make an inverted ellipse.  (It's
> like an ellipse only that the bounding rectangle is not transparent and
> the ellipse itself is transparent (and all clicks go through it)).
> 
> I could subclass EllipseMorph and make it so that the
> containsPoint: returns an opposite value so that clicks go through, but
> that still doesn't solve the drawOn: problem.  How can I make drawOn: to
> draw everything around the ellipse keeping the insides transparent?

There are a few different approaches you could try...

The brute force method would be to use the debugger to drill down to where the ellipse drawing code actually happens.  If you halt in EllipseMorph>>drawOn:, you'll eventually get down to GrafPort>>fillOval:, which seems to be where the action is.  You could try to copy this code (into your subclassed drawOn: method or wherever) and modify it so that it draws outside the ellipse instead of inside.

However, there might be an easier way.  The first thought I had was, in your new drawOn: method, to first draw a rectangle (fillRectangle:color:) in the ellipse's color, and then draw an ellipse on top of that in with 'Color transparent'.  But that doesn't work because the rectangle shows through behind the transparent ellipse.

Something that would probably work would be to use Form>>replaceColor:withColor:.  First you'd draw the rectangle on the Form in one color, then you'd draw the ellipse in a second color, and then do a "aForm replaceColor: secondColor withColor: Color transparent".  Then draw this Form on your canvas.  (Or, simply get the Form from the canvas in the first place, with something like Canvas>>contentsOfArea:.)

Hopefully, this will be enough for you to go on...

- Doug Way
  dway at riskmetrics.com





More information about the Squeak-dev mailing list