common lisp - Updating the window in response to CLIM frame commands -


while trying figure out clim, ran this example program. it's simple maze game. author claims have tested in lispworks (and has #+genera in there, implying program work on real lisp machine), i'm trying working in sbcl mcclim.

under sbcl/mcclim, window draws, nothing visible happens when press movement keys. non-movement keys cause text entered pane game instructions.

i figured out game command keys changing game's internal state, problem screen not update.

then realized couldn't write code redraw maze scope of code implements commands. methods draw receive stream argument clim, must passed graphics primitives. example:

(defun draw-stone (stream x y cell-width cell-height)   (let ((half-cell-width (/ cell-width 2))         (half-cell-height (/ cell-height 2)))     (draw-ellipse* stream                    (+ (* x cell-width) half-cell-width)                    (+ (* y cell-height) half-cell-height)                    half-cell-width 0                    0 half-cell-height                    :ink +red+))) 

but code handles keystrokes receives no stream argument:

(defmacro define-stone-move-command (name keystroke dx dy)   `(define-maze-frame-command (,name :keystroke ,keystroke) ()      (let ((maze-array (maze-array *application-frame*)))        (move-stone maze-array ,dx ,dy)        (check-for-win maze-array)))) 

what ended having save stream argument first (and only) call draw-maze-array global variable, add update code define-stone-command macro follows:

(defmacro define-stone-move-command (name keystroke dx dy)   `(define-maze-frame-command (,name :keystroke ,keystroke) ()      (let ((maze-array (maze-array *application-frame*)))        (move-stone maze-array ,dx ,dy)        (check-for-win maze-array)        (draw-maze-array *application-frame* *maze-stream*)))) 

this slight alteration gives desired behavior on sbcl mcclim, doesn't seem right, however. after all, author claimed code worked fine on lispworks. have few questions:

  1. can has lispworks confirm program works as-is on lispworks?
  2. does alteration code make fail on lispworks?
  3. what accepted way handle screen updating in clim applications?

drawing maze in command not right approach. putting maze-stream global variable bad. ;-)

the display pane has :display-function. idea after command whole application frame gets updated automagically. example :display-time :command-loop, display pane updated automagically, after command runs. there other ways update panes, in case keystroke runs command , top-level-loop call display-function each applicable pane. default toplevel-loop reads command (via mouse, command lines, keystrokes, ...), executes , updates application frame - in loop.

the whole redisplay thing extremely tricky/powerful. allows automagical redisplay mechanisms extremely fine-grained control.

you can read here: clim 2 spec. note: there might quite bit difference between spec , implementations provide...


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -