Re: using cairo surfaces
- From: Tommi Sakari Uimonen <tuimonen cc hut fi>
- To: Ivan Baldo <ibaldo adinet com uy>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: using cairo surfaces
- Date: Wed, 18 Oct 2006 09:41:18 +0300 (EEST)
Hi, thanks for your answer!
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);.
Yes, this I already did. But I still have problems with gtk regarding what
kind of widgets to use as the container and child. Currently the child is
GtkImage. The container is the hard part. I have managed to use GtkHBox,
but I would like to use something like GtkLayout, or actually I don't know
what would be best. The container has also some cairo drawing, which draws
on top of the child widgets.
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);.
This is what I'm doing.
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 :-).
You missed the surface:
cairo_set_source_surface(child_cr, my_stored_surface, startPosH,
startPosV)
Now, since the stored surface is the same height and width as the whole
widget, I set startPosH and startPosV to 0, otherwise the rectangle to be
drawn is not taken from the correct position in the stored surface.
Or am I wrong? I'm not quite sure, maybe the next example lights things
up:
Let's imagine the surfaces as two identical playing cards. If small area
on the center of the card needs to be redrawn, I just place the new card
on top of the old one and draw the needed area from the new card, while
other areas in the old card remain untouched. If I put nonzero values to
startPosH/V the cards are no longer aligned and yields to incorrect
result.
What does the cairo_rectangle actually do? And how does the
set_cairo_surface restrict to drawing only to the exposed area, or does
cairo handle the drawing for the exposed area only even if I draw the
whole surface?
I'm not quite sure how to copy a small part of previously stored surface
to current surface at the same position, or if I do scrolling I just copy
most of the stored surface to slightly different position and draw the
new information.
What happens, no matter what size the exposed event area is, if I draw the
whole wiget area? Does cairo ignore the draw commands that affect outside
the exposed area? Does this give bad performace?
It needs some logic to decide what to draw and where, if I'm supposed to
draw only the exposed area. I know I'm bound to do that at some point, but
for now I just draw the whole thing. It's nothing very complex, it's just
text.
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).
Ok, thanks. I'll try that.
Tommi
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 - ibaldo adinet com uy - 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: ibaldo codigolibre net - http://go.to/ibaldo
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]