Making an inverted ellipse morph?

Joshua Channing Gargus schwa at cc.gatech.edu
Sat Dec 2 20:08:07 UTC 2000


Hi,

Couldn't you fill a Form with the color you want the rectangle to be, and
then fill an ellipse in it with Color transparent, and then draw this 
Form on the display?  I've got to run right now, but take a look at how
the sketch editor eraser works.  I'd imagine you could do something very
similar.

Joshua

On Sat, Dec 02, 2000 at 02:37:37PM -0800, Dino wrote:
> Actually, the Form>>replaceColor:withColor: thing doesn't work.  The
> stuff in the drawOn: method uses canvas functions that completely avoid
> drawing the object if the color is transparent.  Simply replacing the
> color with transparency would seem to work, but it doesn't.  If you
> replace the color with transparency, you get a white background.
> 
> It would be cool if somehow we could have boolean operations with shapes
> to get "holes" in shapes...   like circle xor: square...
> 
> Seems like the only way to draw a circle cut out of a square is to do
> the brute force method which I don't really like doing.
> 
> Dean
> 
> Doug Way wrote:
> > 
> > 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:.)





More information about the Squeak-dev mailing list