View previous topic :: View next topic |
Author |
Message |
dsimcha
Joined: 24 Oct 2008 Posts: 16
|
Posted: Fri Jul 16, 2010 10:55 pm Post subject: Example code for DrawingArea |
|
|
I'm trying to use DrawingArea to create custom drawings on a Window. I've read over the docs and the following code seems reasonable to create a minimal drawing with a single line. When I run it, I get a blank window. Can someone please tell me what's wrong with it and post the minimal code for creating a visible drawing on a main window?
Code: |
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();
}
|
|
|
Back to top |
|
|
jpf2
Joined: 15 Aug 2009 Posts: 7
|
Posted: Sat Jul 17, 2010 1:24 am Post subject: |
|
|
Just reposting Jeromes example from the newsgroup
Code: |
import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC,
gdk.Drawable, gtk.Widget, 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();
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();
}
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|