gpt4 book ai didi

common-lisp - 使用 CLX 绘制矩形

转载 作者:行者123 更新时间:2023-12-05 05:42:18 25 4
gpt4 key购买 nike

我正在尝试使用 Common Lisp X 界面在窗口内绘制一个矩形:

(asdf:load-system "clx")

(in-package :xlib)

(defun main ()
(let* ((display (open-default-display))
(screen (display-default-screen display))
(colormap (screen-default-colormap screen))
(font (open-font display "fixed")))
(let* ((window (create-window
:parent (screen-root screen)
:x 0
:y 0
:width 512
:height 512
:border (screen-black-pixel screen)
:border-width 2
:bit-gravity :center
:colormap colormap
:background (alloc-color colormap
(lookup-color colormap
"white"))))
(foreground (create-gcontext
:drawable window
:fill-style :solid
:background (screen-white-pixel screen)
:foreground (alloc-color colormap
(lookup-color
colormap
"red"))
:font font)))
(map-window window)
(unwind-protect
(progn
(draw-rectangle window foreground 0 0 100 100 :fill-p) ;; no effect
(display-force-output display)
(display-finish-output display)
(sleep 2))
(CLOSE-DISPLAY display)))))

我得到的只是一个空窗口。你能告诉我我做错了什么吗?谢谢。

最佳答案

很有趣。在玩了你的代码相当长的一段时间后,我让它在一个循环中工作。 clx 好像要你至少画一次?在这里,如果您将 progn 替换为循环,它就会起作用,例如:

...
(unwind-protect
(loop repeat 3
do
(draw-rectangle window foreground 0 0 100 100 :fill-p) ;; no effect
(display-force-output display)
;;(display-finish-output display)
(sleep 1))
(CLOSE-DISPLAY display)))))

关于common-lisp - 使用 CLX 绘制矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72071648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com