gtkD:最小绘图示例?
我是一位相当有经验的程序员,但对 GUI 编程还是个新手。我正在尝试将我为 DFL 编写的绘图库移植到 gtkD,但无法显示绘图。以下代码为我生成一个空白窗口。有人可以告诉我它有什么问题,和/或发布最小的示例代码来将几行放到 DrawingArea
上并在 MainWindow
中显示结果吗?
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();
}
I'm a fairly experienced programmer, but new to GUI programming. I'm trying to port a plotting library I wrote for DFL to gtkD, and I can't get drawings to show up. The following code produces a blank window for me. Can someone please tell me what's wrong with it, and/or post minimal example code for getting a few lines onto a DrawingArea
and displaying the results in a MainWindow
?
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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在 D 方面没有任何经验,但在 GTK 方面有很多经验,因此在 gtkD 教程的帮助下,我设法编写了一个最小的示例:
在 GTK 中,
DrawingArea
实际上只是一个空白的小部件进行绘制,并且在小部件上进行绘制必须始终在expose-event
处理程序中完成。 (虽然我知道这会在 GTK 3 中改变!)我知道你不能将函数连接为信号回调,只能连接委托,所以这就是
DrawingTest
类的原因。I have no experience whatsoever in D, but lots in GTK, so with the help of the gtkD tutorial I managed to hack up a minimal example:
In GTK, a
DrawingArea
is actually just a blank widget for you to paint on, and painting on widgets must always be done in theexpose-event
handler. (Although I understand this will change in GTK 3!)I understand you can't connect functions as signal callbacks, only delegates, so that's the reason for the
DrawingTest
class.