I see. So if I want to draw a rectangle by a function outside the expose_fn, I need to refer to the drawable within the expose_fn. One possibility is to use an environment, so I can refer to it dynamically. Thanks,
Ronggui 2009/5/25 Michael Lawrence <mflaw...@fhcrc.org>: > > > On Sat, May 23, 2009 at 8:27 AM, Ronggui Huang <ronggui.hu...@gmail.com> > wrote: >> >> 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. > > You need to be drawing the rectangle within expose_fn, otherwise it won't > show up. There should be no need to access the GdkWindow (da2) of the > drawing area outside of expose_fn. > > Michael > >> >> 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 <mflaw...@fhcrc.org>: >> > >> > >> > On Fri, May 22, 2009 at 11:27 PM, Ronggui Huang >> > <ronggui.hu...@gmail.com> >> > wrote: >> >> >> >> Dear all, >> >> >> >> I use gtkImageFromFile to display an image. Then I want to do some >> >> gsignal to handle mouse event. I click the mouse and move a another >> >> position and release. I can get the position of the firs click and the >> >> release position, then I would to draw a rectangle to display the >> >> region I have selected. I need some hints on what functions should I >> >> look for. I tried to google but don't know how. >> > >> > The GtkImage widget is just for showing images. If you want to start >> > doing >> > interactive graphics, I'd suggest moving to the more general >> > GtkDrawingArea >> > widget and connecting to the expose-event signal. You can then use >> > GdkPixbuf >> > for loading and drawing the image onto the drawing area. And then draw a >> > rectangle on top with gdkDrawRectangle(). >> > >> > See demos drawingArea and images. >> > >> > Michael >> > >> >> >> >> Thanks. >> >> >> >> -- >> >> HUANG Ronggui, Wincent >> >> PhD Candidate >> >> Dept of Public and Social Administration >> >> City University of Hong Kong >> >> Home page: http://asrr.r-forge.r-project.org/rghuang.html >> >> >> >> ______________________________________________ >> >> R-help@r-project.org mailing list >> >> https://stat.ethz.ch/mailman/listinfo/r-help >> >> PLEASE do read the posting guide >> >> http://www.R-project.org/posting-guide.html >> >> and provide commented, minimal, self-contained, reproducible code. >> > >> > >> >> >> >> -- >> HUANG Ronggui, Wincent >> PhD Candidate >> Dept of Public and Social Administration >> City University of Hong Kong >> Home page: http://asrr.r-forge.r-project.org/rghuang.html > > -- HUANG Ronggui, Wincent PhD Candidate Dept of Public and Social Administration City University of Hong Kong Home page: http://asrr.r-forge.r-project.org/rghuang.html ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.