--On 09/03/04 09:52:59 PM -0400 Gregory Pierce wrote:
Okay here is the scenario (and I'm hoping there is something in the
API that permits this because at this point I haven't found anything).
What I have are two RoundRectangle2Ds that have an alpha of 50
percent. I want to draw a line connecting the centers of both of these
RoundRectangle2Ds.
A----B
If the RR2Ds were opaque I wouldn't have a problem, I would just draw
all of the links first and then draw all of the RR2Ds. Piece of cake.
However since the RR2Ds allow you to see through them, this clearly
won't work.
Are the connectors translucent as well? You could use a separate
buffer to render them. It gets a little more intensive if you have
items of different translucencies, though. Layers may be the easiest
and most flexible solution:
Solution 1 - everthing at the same translucency:
Create intermediate INT_ARGB buffer.
Fill it with transparency (it is created that way)
Render all objects to it opaquely.
Render it to the screen using a translucent
AlphaComposite object.
Solution 2 - things at different translucencies:
Create intermediate INT_ARGB buffer.
Fill it with transparency (it is created that way)
Get a graphics from intermediate buffer.
Set SRC mode on that graphics.
Render all objects to it with their respective
alphas in SRC mode
Render the intermediate buffer to the screen in
regular SRC_OVER mode (the default
rendering mode).
I've looked at using Graphics2D.setClip()
Clipping can be used here, but you need to worry about the difference
between calculating a clip shape from geometry and then expecting it to
clip out the exact same pixels as were drawn from those shapes. But,
rendering shapes involves lots of tradeoffs and calculations which
produce roundoffs in different ways that may not be reflected in your
"clip" calculations.
If you are going to go the "clip" route then you need to either:
- Accept some amount of "off by 1" problems
- Do absolutely all rendering using the "clip" mechanism.
No calls to draw() or fill() on a shape, just clip to a
shape and then call fill(largerect) and rely on clipping.
- Understand the specifics of the implementation well enough
to know where the pitfalls are and adjust for them. But,
there is enough leeway in the specs to make this impossible
to work for all implementations.
Also, this kind of a system would not be very compatible with
Antialiasing. The layers approach above would be compatible.
but this will only allow me
to clip the line against one of the shapes. I also looked into solving
the problem using CAG, but Area doesn't work with lines (though I will
try to adapt my pathing algorithms to use rectangles if that solves my
drawing problem (here's hoping).
Area works with "fillable geometry". If you want to use it with
"lines" then they enclose no area. If you want to use it with "what
would be drawn when I use the "draw()" method on a line", then you need
to turn it into a fillable shape using the Stroke.createStrokedShape()
method.
It would be nice if there was a way to do a Graphics2D.addClip(Shape)
so that I could clip the graphics region by a near infinite number of
shapes. Same for intersect() and the like.
The workaround, as others have suggested is to construct your big union
first and then call clip() once with the entire shape.
...jim
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".