FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Example code for DrawingArea

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Fri Jul 16, 2010 10:55 pm    Post subject: Example code for DrawingArea Reply with quote

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
View user's profile Send private message
jpf2



Joined: 15 Aug 2009
Posts: 7

PostPosted: Sat Jul 17, 2010 1:24 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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