Peter Seibel wrote: 

> I want to use lispbuilder-sdl to implement a simple GUI (of a 
> Go board). 
>   Then I want to provide functions that I can call to place 
> and remove 
> stones from the board. But I want the SDL to be passive--just sitting 
> there until I call one of those functions. Basically the GUI 
> is going to 
> be one possible view into a Go engine that is actually 
> running the show 
> so I don't want the main loop to be in the SDL function.

Yes, it is possible, see the code below. It depends on your applications,
but maybe it is better to use an event loop and a second thread for a
computer player or network connection, because otherwise it is difficult to
poll the events for playing with the mouse.

BTW: nice Go board!


(defparameter *size* 300)
(defparameter *border* 10)

(defun scaled-coordinate (c)
  (+ (/ (* c (- *size* *border*)) 19) *border*))

(defun board-point (x y)
  (sdl:point :x (scaled-coordinate x)
             :y (scaled-coordinate y)))

(defun show-window ()
  (sdl:init-sdl)
  (sdl:window *size* *size* :title-caption "Go Board"))

(defun hide-window ()
  (sdl:quit-sdl :quit t))

(defun draw-board ()
  (sdl:clear-display (sdl:color :r #xcc :g #x99 :b #x33))
  (loop for i from 0 to 18
        do
        (sdl:draw-line (board-point 0 i)
                       (board-point 18 i)
                       :color (sdl:color :r 0 :g 0 :b 0))
        (sdl:draw-line (board-point i 0)
                       (board-point i 18)
                       :color (sdl:color :r 0 :g 0 :b 0)))

  (loop for x from 3 to 15 by 6 do
        (loop for y from 3 to 15 by 6 do
              (sdl:draw-filled-circle (board-point x y) 3
                                      :color (sdl:color :r 0 :g 0 :b 0))))
  (sdl:update-display))

(defun test ()
  (show-window)
  (draw-board)
  (sleep 2)
  (hide-window))


--
Frank Buss, [EMAIL PROTECTED]
http://www.frank-buss.de, http://www.it4-systems.de

_______________________________________________
application-builder mailing list
application-builder@lispniks.com
http://www.lispniks.com/mailman/listinfo/application-builder

Reply via email to