Re: porting gdk -> cairo



On Tue, 10 Aug 2010, Dov Grobgeld wrote:

(in response to my query about drawing a resizable outline
rectangle on top of an image displayed in a GTK window, using
cairo instead of the GDK drawing API)

The following solution does the job though it causes flickering.

   - If there is a previous backing store (see below) then restore it to the
   underlying image.
   - Define the rectangle to draw by the button-press and the
   motion-notify-events.
   - Copy the four edges of below the rectangle to four GdkPixmaps, that I
   call backing store.
   - Draw the rectangle.

The following more complex solution should take care of flickering:

Preparation:

   - Create an expose handle that is called after the default expose handle
   which uses cairo to draw a rectangle in coordinates determined by structure
   R (see below). Note that this expose handle will be called up to eight times
   every time a motion notify event occurs.
   - Create a fifo buffer containing up to eight CairoRectangles to be
   exposed.

During motion:

   - Define the new rectangle to draw by button-press and motion-notify
   events and store it in the structure R available by the expose handle.
   - Push four areas corresponding to the four edges of the rectangles to
   the fifo buffer.
   - Expose the eight areas in the fifo buffer.
   - Pop off the first four areas of the fifo buffer.

This solution relies on the underlying expose handle. If that expose handle
is slow (e.g. complex vector graphics), the solution may be made faster by
initiating the process (e.g. at button-press) by copying the entire widget
window to an off screen pixmap, and then block the underlying expose handle.

I'd be interested if there is a more compact solution.

Thanks very much for your thoughts on this.

It seems to me that what you're describing is a rather complex
workaround for missing functionality in cairo.

I hope that the GTK developers will ensure that there's a
reasonable way of doing this sort of thing in cairo before getting
rid of GdkGC.  I'd imagine that the effect I'm after is something
that many GTP apps have need of, and it's trivial to achieve with
the GDK API.

Allin Cottrell



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]