1)正如标题所述,当我调整窗口大小时,我绘制的对象消失,但矩形保持原样。
2)原点从左上角开始,但我希望它在左下角。
3)除了绘图库之外,我找不到任何缩放功能,所以如果我希望实现这样的功能,一个选项是通过绘制更大的对象并刷新画布来“缩放”?
(define top-frame (new frame%
[label "KR"]
[width 500]
[height 500]))
;Make a frame by instantiating the frame% class
(define image (pict->bitmap (rectangle 50 50)))
(define canvas (new canvas%
[parent top-frame]
[paint-callback (lambda (canvas dc)
(send dc draw-bitmap image 0 0))]))
(define drawer (send canvas get-dc))
(send top-frame show #t)
; Show the frame by calling its show method
(define (draw-object x)
(sleep/yield 0.1)
(case (first x)
[("LINE") (send drawer draw-line
(second x) (third x)
(fourth x) (fifth x))]
[("CIRCLE") (send drawer draw-bitmap (pict->bitmap (circle (round (fourth x)))) (round (second x)) (round (third x)))]
[("POINT") (send drawer draw-point (round (second x)) (round (third x)))]
[else "Not drawing anything!"]))
(draw-object (find-specific-values (third list-of-objects)))
(map draw-object (map find-specific-values list-of-objects))
ad 1) “...当我调整窗口大小时,我绘制的对象会消失,...”
当您调整窗口大小时,系统需要重新绘制窗口的内容。发出重绘事件,最终 Racket GUI 层将调用绘制回调。因此:创建一个函数来完成所有绘图。从绘制回调中调用它。在这里查看类似的问题:https://stackoverflow.com/a/16086594/23567 https://stackoverflow.com/a/16086594/23567
ad 2) 一种选择是在绘图上下文中进行坐标变换。请参阅 dc 文档中的集合转换。是这样的:
(send dc set-transformation
(vector (trans->vector t)
0 0 ; x and y origin
1 -1 ; x and y scale
0)))
y 尺度的 -1 将翻转 y 轴。您可能想移动原点。
ad 3) 可以通过更改 x 和 y 比例,然后重新绘制来完成缩放。
您可以尝试将比例调整为 1/2 -1/2 。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)