If you have a cairo_t obtained from your expose_event callback and you 
call it "cr", then on the child widgets you can create a surface with 
cairo_surface_create_similar( cairo_get_target(cr), CAIRO_CONTENT_COLOR, 
theWidthOfYourChild, theHeightOfYourChild);.
That surface will have the same format and properties of the surface 
used in the expose event widget so it gives you the best performance.
Then you can create a cairo_t for that surface with: cairo_t *child_cr = 
cairo_create( the_cairo_surface_t_you_obtained_from_create_similar);.
In that child_cr you can draw everything your child needs to draw; you 
can cache it too so it can survive multiple expose events without 
problems and without needing to draw anything.
When you need to draw that child in your expose event, then you just 
need to do a cairo_rectangle() for the area you want to draw it on, then 
call cairo_set_source_surface(child_cr, startPosH, startPosV) and then 
cairo_fill() it :-).
IMPORTANT PERFORMANCE TIP: Carl Worth saw me crying about the bad 
performance of my application and told me to use absolute values for 
startPosH and startPosV (that is, instead of using say 54.35 use 54.00), 
you can do that if it is not noticeable to the human eye in your case 
(it depends on transformation matrices and scales you use, etc., just 
try it out and see). Try it, because it can use some very fast paths for 
drawing that in my application accelerated it a lot and it was really as 
simple as that: just using absolute values for positioning the surface.

Well, I hope I had explained it correctly but if you don't understand 
don't hesitate to ask for another try at explaining it, maybe a native 
English speaker can write it better than I.
Goodbye.
P.s.: I encourage you to join the Cairo mailing list, maybe you get 
faster and better answers relating to Cairo there.





El 02/10/06 08:58, Tommi Sakari Uimonen escribió:

>Hello. I'm trying to create a custom container widget that holds the child 
>widgets in a hbox (or scrollarea, after I learn how to use it). The child 
>widgets are using cairo for the drawing, and so is the container widget.
>
>I want to optimize the container drawing since the child widgets don't always 
>need complete redrawing.
>
>The child drawing is currently done to the container's cairo surface, which is 
>passed to each child widget, and childs draw to this surface. Reference to 
>this 
>surface is stored and I'm using a private variable in the container widget 
>that 
>keeps track of whether the childs need full redraw or can I use the stored 
>surface to do quick redraw without the need to call the childs' drawing 
>functions.
>
>Now, I want the child widgets to have their own surfaces and each child should 
>handle the "smart drawing". So the child widget decides whether it uses the 
>previously rendered surface or redraws some parts. The container then just 
>uses 
>set_source_surface to draw the child at desired position.
>
>What kind of surface I should create in the child widgets and how do I copy it 
>to the container surface?
>
>I've tried creating image surface, but I guess I was doing something wrong, 
>because nothing was drawn, or I got segfault. So I still have not found the 
>right way of doing it. The documentation is lacking examples, so I have 
>proceeded in "trial and error"-basis, and now I'm kind of stuck.
>
>
>Tommi
>_______________________________________________
>gtk-app-devel-list mailing list
>gtk-app-devel-list@gnome.org
>http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
>  
>

-- 
Ivan Baldo - [EMAIL PROTECTED] - http://ibaldo.codigolibre.net/
ICQ 10215364 - Phone/FAX (598) (2) 613 3223.
Caldas 1781, Malvin, Montevideo, Uruguay, South America.
We believe that we are free, but in reality we are not! Are we?
Alternatives: [EMAIL PROTECTED] - http://go.to/ibaldo


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to