On Thu, Apr 15, 2010 at 12:25 AM, N K <li...@exposurescience.org> wrote:
> Hi, > > I'm trying to draw some crosshairs and floating X,Y coordinates in a text > box that follow the mouse cursor around on an embedded R plotting area > (asCairoDevice). i.e., I want to have Cairo line and text objects that > are updated whenever the mouse moves over an R plot. > > I used the commands below but the text flickers, like it is being erased > immediately after being drawn. Has anyone solved this problem or have > some pointers, demos, examples, etc? Is there some limitation with the > R Cairo device that prevents user interaction like this? Before calling > asCairoDevice I can draw on the gtk drawing area, but not after. Any > help appreciated! > > There's going to be flicker, because the cairo graphics device will blit from its off-screen buffer as you move the mouse, erasing what you have drawn. You'll need to combine the two drawing operations into one. Easiest way is probably to pass a GdkPixmap to asCairoDevice, and then implement the expose-event of the GtkDrawingArea so that it will blit the pixmap and then draw your text, in the same callback (GTK+ will double buffer). There is a demo in the RGtk2 package that shows how to target cairo device to the off-screen pixmap. Good luck, Michael > plotArea <- gtkDrawingArea() > gtkWidgetSetSizeRequest(plotArea, 300, 400) > # Receive mouse events.... > gtkWidgetAddEvents(plotArea, 2) > asCairoDevice(plotArea) > gtkWidgetShow(plotArea) > plotArea$AddCallback("motion-notify-event", function(w,ev) { > x <- ev$x > y <- ev$y > cr$moveTo(x,y) > coor <- win2plot(x, y) # Note this converts from screen to user > coordinates > cr$showText(paste(coor[1],coor[2], sep=", ")) > }) > cr <- gdkCairoCreate(plotArea$window) > plot(1:10) > > --Neil > > _______________________________________________ > R-SIG-GUI mailing list > R-SIG-GUI@stat.math.ethz.ch > https://stat.ethz.ch/mailman/listinfo/r-sig-gui > [[alternative HTML version deleted]] _______________________________________________ R-SIG-GUI mailing list R-SIG-GUI@stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-gui