Skip to content
Prev 181262 / 398502 Next

Draw a rectangle on top of an image using RGtk2?

Thanks, Michael. Just one more follow-up question. Is there other way
to get the "GdkDrawable" (here da2) without using <<- or other
assignment operation from within expose_fn? I thought
da$GetRootWindow() would work, but it does not.

da <- gtkDrawingArea()
da2 <- NULL

expose_fn <- function(widget,event,...){
img <- gdkPixbufNewFromFile("/media/wind/Pictures/kaehatu.jpg")$retval
da2 <<-widget[["window"]]
gdkDrawPixbuf(da2, gc = NULL, pixbuf=img,
event[["area"]][["x"]], event[["area"]][["y"]],
event[["area"]][["x"]], event[["area"]][["y"]],
event[["area"]][["width"]], event[["area"]][["height"]])
 return(FALSE)
}
gSignalConnect(da,"expose-event",expose_fn)
w<-gtkWindow(show=F)
w$SetSizeRequest(400,300)
w$Add(da)
w$Show()

dgc <- gdkGCNew(da2)
gdkGCSetLineAttributes(dgc, line.width=2, line.style="solid","round","round")
gdkDrawRectangle(da2,dgc,FALSE,10,10,100,100)


Ronggui

2009/5/23 Michael Lawrence <mflawren at fhcrc.org>: