help wanted with Cairo - fairly inexperienced user

View: New views
2 Messages — Rating Filter:   Alert me  

help wanted with Cairo - fairly inexperienced user

by alanb :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I am happy with using cairo for basic drawing. My problem is that I have drawn a circular grid which is quite dense (spokes every 10 degrees, circles every 10 mm from 10 to 200mm radius) it uses transformations to centre grid set scale etc. In an editing mode I want to be able to draw a highlight line from the centre of the grid to the mouse and at the mouse position display radius and angle values. I am ok with the code to do this but when I run my program I get a lot of flicker because my code clears the area and redraws everything in the motion notify event handler. I really just want to clear the line drawn to the mouse and then redraw it at the next position. My past experience tells me that either, I want the grid to be on a base layer and the hilight line on an upper layer, and then to just clear the upper layer. Or Xor the previous line to restore the background before drawing the next line. Trouble is I dont know if cairo will allow me to do either of these options. Do I have to composite two surfaces instead? If so I havent a clue on how to do this. Or should I save the grid as an image and then use that as the background?

Could someone point me to an example or tutorial which would be of some help.

Thanks
Alan

Re: help wanted with Cairo - fairly inexperienced user

by mkbosmans :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alan,

First, in a modern graphics library like Cairo the Xor trick to erase a previously drawn line isn't possible anymore, due to antialiasing and the fact that Cairo can also output to vector formats.

The flickering can be eliminated by telling Gtk to use doublebuffering. I think this is on by default, but clearly in your case it isn't. Doublebuffering outputs the result of all the drawing commands to the screen in one go. For this to work, it is important to only do the drawing from the expose eventhandler, not in other parts of your app.

You could buffer the grid yourself by drawing it to a separate surface and then painting that surface to the screen in the expose event, but I would only do this if performance requires it. Anyway, it's not a solution for your flickering problems.

I'd suggest that if you have any further questions, you ask them on the Cairo list (http://cairographics.org/), or may be the gtk-app-devel list (http://www.gtk.org/mailing-lists.html). People over there have more knowledge about Cairo and Gtk+ and your question isn't specific to Gtk# or the Mono Cairo bindings.

Maarten


alanb wrote:
Hi,
I am happy with using cairo for basic drawing. My problem is that I have drawn a circular grid which is quite dense (spokes every 10 degrees, circles every 10 mm from 10 to 200mm radius) it uses transformations to centre grid set scale etc. In an editing mode I want to be able to draw a highlight line from the centre of the grid to the mouse and at the mouse position display radius and angle values. I am ok with the code to do this but when I run my program I get a lot of flicker because my code clears the area and redraws everything in the motion notify event handler. I really just want to clear the line drawn to the mouse and then redraw it at the next position. My past experience tells me that either, I want the grid to be on a base layer and the hilight line on an upper layer, and then to just clear the upper layer. Or Xor the previous line to restore the background before drawing the next line. Trouble is I dont know if cairo will allow me to do either of these options. Do I have to composite two surfaces instead? If so I havent a clue on how to do this. Or should I save the grid as an image and then use that as the background?

Could someone point me to an example or tutorial which would be of some help.

Thanks
Alan