使用CLX绘制矩形



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

(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想让你至少画一次?在这里,如果用循环替换程序,它就可以工作,例如:

...
(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)))))

最新更新