【问题标题】:Drawing a rectangle using CLX使用 CLX 绘制矩形
【发布时间】:2022-10-09 09:01:08
【问题描述】:

我正在尝试使用 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)))))

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

【问题讨论】:

  • 你可以在 :fill-p 选项中添加一个 t 吗?像这样:(绘制矩形窗口前景 0 0 100 100 :fill-p t)
  • 不,因为它违反了函数签名。 CLX 将#'draw-rectangle 定义为 (draw-rectangle drawable gcontext x y width height &optional fill-p),因此不能再添加一个额外的参数。可以把 t 代替 :fill-p 并编译。但它也没有效果。

标签: common-lisp x11


【解决方案1】:

有趣的。在玩了你的代码很长一段时间后,我让它在一个循环中工作。似乎 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)))))

【讨论】:

    猜你喜欢
    • 2014-03-20
    • 2011-02-17
    • 2020-11-25
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多