www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do you draw in gtkD? Simple example overriding Widget.draw()

reply Enjoys Math <enjoysmath gmail.com> writes:
import gtk.MainWindow;
import gtk.Main;
import gtk.DrawingArea;
import cairo.Context;
import std.stdio;

void main(string[] args) {
     Main.init(args);
     auto win = new MainWindow("Hello World");
     win.setDefaultSize(200, 100);
     win.add(new MyDrawingArea());
     win.showAll();
     Main.run();
}

class MyDrawingArea : DrawingArea {
	override bool draw(Context cairo) {
		writeln("Hello");
		return true;
	}
}

Error:
Error: function main.MyDrawingArea.draw does not override any 
function, did you mean to override 'gtk.Widget.Widget.draw'?		
Jan 26
parent reply Enjoys Math <enjoysmath gmail.com> writes:
On Wednesday, 27 January 2016 at 01:54:53 UTC, Enjoys Math wrote:
 import gtk.MainWindow;
 import gtk.Main;
 import gtk.DrawingArea;
 import cairo.Context;
 import std.stdio;

 void main(string[] args) {
     Main.init(args);
     auto win = new MainWindow("Hello World");
     win.setDefaultSize(200, 100);
     win.add(new MyDrawingArea());
     win.showAll();
     Main.run();
 }

 class MyDrawingArea : DrawingArea {
 	override bool draw(Context cairo) {
 		writeln("Hello");
 		return true;
 	}
 }

 Error:
 Error: function main.MyDrawingArea.draw does not override any 
 function, did you mean to override 'gtk.Widget.Widget.draw'?
Oh i see, there are examples under the GDk directory under 'demos'.
Jan 26
parent Gerald <gerald.b.nunn gmail.com> writes:
Generally don't override methods in GtkD, use event handlers like 
addOnDraw. Because GtkD wraps GTK functions an overriden D method 
of GtkD will never get called by GTK since it is working with the 
underlying C functions directly.
Jan 26