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. Regards, Dov On Tue, Aug 10, 2010 at 17:16, Allin Cottrell <cottr...@wfu.edu> wrote: > I gather from recent discussion on the gtk-devel list that a good > deal of the old GDK drawing API may be removed for GTK 3 in favor > of use of cairo: in particular GdkGC seems likely to disappear. > There appear to be good arguments for this, but it means some > extra work for people trying to get their apps GTK3-ready. > > Benjamin Otte has some notes on porting at > http://blogs.gnome.org/otte/2010/07/27/rendering-cleanup/ but > there's one piece of GDK code I've been using for which I can't > figure out the cairo equivalent and I wonder if anyone can help. > > The context is zooming to a selected portion of a graphic > displayed in a GTK window. If the user selects a Zoom menu item > she can then drag out a rectangular outline on the current image, > and when the mouse button is released the view snaps to the chosen > rectangle. > > The tricky part is avoiding a horrible mess as the user drags the > rectangle. This is achieved via a cycle of draw-display-erase as > the mouse pointer moves. In GDK, the "erase" part is done by > redrawing the last-shown rectangle using an inverted GdkGC: > > gdk_gc_set_function(gc, GDK_INVERT); > > How would you do this in cairo? Thanks. > > -- > Allin Cottrell > Department of Economics > Wake Forest University > > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list