Clipping to a non-rectangular region


#1

Hello everyone,

I’m developing a component that paints an equalizer frequency response graph. The graph itself is surrounded by a non-rectangular border, and sometimes the graph paints over the border.

So can anyone think of a good way to clip this? If it was rectangular, I could use Graphics::reduceClipRegion. Is there some way I can composite with an Image using the alpha channel?

Thanks,

Matt


#2

Ah… Non-rectangular clipping is going to be my next big update to the graphics classes, but it’s quite a significant bit of work to implement in the current software renderer.

In the meantime, you can use the option to fill an image’s alpha-channel with the current brush, and use an tiled image fill for the brush. Bit of an inefficient bodge, but it’ll get you going as long as you’re not after extreme speed.


#3

Sounds like it would be simpler to just make a change to my interface for now. Thanks, Jules.


#4

For clipping the straight lines in non rectangle clipping region we can use Liang Barsky Algorithm or Cyrus - Beck Algorithm.


#5

To implement a graphics context with non-rectangular clipping it’s actually much faster and more accurate to use an edge-table as the context’s clipping mask rather than trying to clip polygons geometrically. It also means that the clip region can be intersected with image alpha-channels, and it makes the rendering pipeline very straightforward.


#6