(Dr) Racket 中的 GUI 元素
我需要一些基本的东西来使用 Racket 中的 GUI 库。
如何将回调函数设置为这样的按钮:
(定义下一个(新按钮%[父框架][标签“下一个->”]))
如何在画布创建后在画布上绘制内容:
(定义canvas(new canvas%[父框架] [绘画回调canvasdc])) (定义canvasdc(lambda(画布dc) (发送 dc set-text-foreground "black") (发送 dc 绘图文本“一些标题!”0 0) ))
我需要绘制(重新缩放的 jpeg,或者,如果不能的话)复合形状,并在每个按钮按下事件上用其他东西重新绘制
I need some basic stuff for working with the GUI library in Racket.
How do I set the callback function to a button like this:
(define next (new button% [parent frame] [label "Next ->"]))
How do I draw something on a canvas after it's been created like this:
(define canvas (new canvas% [parent frame] [paint-callback canvasdc])) (define canvasdc (lambda (canvas dc) (send dc set-text-foreground "black") (send dc draw-text "Some title!" 0 0) ))
I would need to draw (rescaled jpegs or, if not able) compound shapes and repaint with something else on every button pressed event
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
按钮构造函数有一个可选的
callback
参数。参见http://docs.racket-lang.org/draw/overview.html 。但我对你的问题感到困惑,因为你发布的代码包括在画布上绘图。对于图像,具体来说,
read-bitmap
将从文件中读取位图;draw-bitmap
会将位图绘制到 DC 中。您可以通过调用 set-scale 来缩放它(以及该 DC 上的所有其他绘图)。如果您要绘制的 DC 是bitmap-dc
(我不认为canvas-dc
是,但我不是Racket 专家,可能是错误的),那么您可以直接使用draw-bitmap-section-smooth
来完成。There's an optional
callback
argument to the button constructor.See http://docs.racket-lang.org/draw/overview.html. But I'm confused by your question since the code you've posted includes drawing to the canvas. For images, specifically,
read-bitmap
will read a bitmap from a file;draw-bitmap
will draw a bitmap into a DC. You can get it (along with all other drawing to that DC) scaled by callingset-scale
. If the DC you're drawing into is abitmap-dc
(I don't think acanvas-dc
is, but I am not a Racket expert and could be wrong) then you can do it directly usingdraw-bitmap-section-smooth
.