[cairo] Clipping

Travis Griggs tgriggs at cincom.com
Wed Jan 21 22:25:51 PST 2009


On Jan 21, 2009, at 6:12 PM, alexo at mail333.com wrote:

> Hi all !
> I can't understand how cairo clipping work.
> I have code:
>
> void OnPaint(HWND hwnd)
> {
> 	PAINTSTRUCT ps;
> 	HDC hdc=::BeginPaint(hwnd,&ps);
>
> 	RECT rect;
> 	::GetClientRect(hwnd,&rect);
>
> 	cairo_surface_t*    surface=cairo_win32_surface_create(hdc);
> 	cairo_t * cr = cairo_create (surface);
>
> 	cairo_set_operator(cr,CAIRO_OPERATOR_DEST_OVER);//this is default  
> operation
> 	cairo_rectangle(cr,100,100,200,200);
> 	cairo_clip(cr);
>
> 	cairo_set_source_rgb(cr,1,0,0);
> 	cairo_rectangle(cr,0,0,rect.right,rect.bottom);
> 	cairo_fill(cr);
>
>
> 	cairo_destroy(cr);
> 	cairo_surface_destroy(surface);
>
> 	SelectClipRgn(hdc,NULL);
>
> 	::EndPaint(hwnd,&ps);
> }
>
> I need to fill surrounding space of cairo_rectangle(100,100,200,200).
> But that code fiil only this box.
> Changing flag in cairo_set_operator do nothing.
> How can I do this?
> And what difference between clipping and masking?

If I understand correctly, you want to fill the whole window EXCEPT  
the rectangle in the middle.

For this, you want to use what I call "negative" clip. I don't know if  
that's the right term or not, but it's the one I use. :) In fact, I  
don't even think you need to get the rect of the client. I *think* the  
following sequence should work, replace the middle six lines with  
these four

cairo_rectangle(cr, 100, 300, 200, -200); // defining ONE of the  
rectangle dimensions negative makes it wind the other way
cairo_clip(cr);
cairo_set_source_rgb(cr, 1, 0, 0);
cairo_paint(cr); // paint() is like fill(), where everything in the  
surface's clip is filled

--
Travis Griggs
Objologist
My Other Machine runs OSX. But then... so does this one.





More information about the cairo mailing list