On 17.07.2010 07:57, "Jérôme M. Berger" wrote: > dsimcha wrote: >> == Quote from dsimcha (dsim...@yahoo.com)'s article >>> 1. Doesn't Window mean that the plot would have to exist in its own >>> window? I'd >>> like to be able to make a plot go to one section of a larger window. >>> 2. When I do: >>> drawable = (new DrawingArea(800, 600)).getWindow(); >>> drawable somehow ends up null. >> >> Never mind, I figured this stuff out, though the documentation is rather >> obtuse >> and in serious need of examples of how to accomplish simple things. >> However, I >> can't get the DrawingArea to actually show up on the screen. I just get a >> blank >> window. Here's a reduced test case. Can someone tell me what's wrong w/ it >> and/or provide minimal example code to get stuff drawn via DrawingArea to >> show up >> on screen? >> >> import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC, gdk.Drawable, >> gdk.Color; >> >> void main(string[] args) { >> Main.init(args); >> >> auto win = new MainWindow("Hello, world"); >> win.setDefaultSize(800, 600); >> auto drawingArea = new DrawingArea(800, 600); >> win.add(drawingArea); >> drawingArea.realize(); >> >> auto drawable = drawingArea.getWindow(); >> auto gc = new GC(drawable); >> gc.setForeground(new Color(255, 0, 0)); >> gc.setBackground(new Color(255, 255, 255)); >> drawable.drawLine(gc, 0, 0, 100, 100); >> >> drawingArea.showAll(); >> drawingArea.queueDraw(); >> win.showAll(); >> >> Main.run(); >> } > The problem is that gtk.DrawingArea is stateless. This means that > it won't remember what you draw on it. There are two solutions to this: > - Use a Canvas widget. There isn't one in gtk, but there are some > options out there. I don't know if any of them have a D wrapper; > - Define a callback for the "expose_event" signal on your > drawingArea and put your drawing code in there. > > Try the following (untested) code: > ========================================8<---------------------------------------- > import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC, > gdk.Drawable, gdk.Color; > > bool onExposeEvent (GdkEventExpose*, Widget drawingArea) { > auto drawable = drawingArea.getWindow(); > auto gc = new GC(drawable); > gc.setForeground(new Color(255, 0, 0)); > gc.setBackground(new Color(255, 255, 255)); > drawable.drawLine(gc, 0, 0, 100, 100); > } > > void main(string[] args) { > Main.init(args); > > auto win = new MainWindow("Hello, world"); > win.setDefaultSize(800, 600); > auto drawingArea = new DrawingArea(800, 600); > win.add(drawingArea); > drawingArea.realize(); > > drawingArea.addOnExpose ((GdkEventExpose* event, > Widget drawingArea) { > auto drawable = drawingArea.getWindow(); > auto gc = new GC(drawable); > gc.setForeground(new Color(255, 0, 0)); > gc.setBackground(new Color(255, 255, 255)); > drawable.drawLine(gc, 0, 0, 100, 100); > return true; > }); > > drawingArea.showAll(); > drawingArea.queueDraw(); > win.showAll(); > > Main.run(); > } > ---------------------------------------->8======================================== > > Jerome It's missing the gtk.Widget import and onExposeEvent is missing a return. ("TRUE to stop other handlers from being invoked for the event. FALSE to propagate the event further.") But with these small fixes, it's working.
@dsimcha there's an example in the gtkd source: demos/cairo/cairo_clock The gtkd Makefile doesn't compile it for some reason, but it is working with D2. -- Johannes Pfau