Lisp HUG Maillist Archive

Animation with Timers

Hello,

I’ve searched through the examples for an animation example and found balloons.lisp.  I’ve come up with the following code:

(defpackage :typing
  (:use :cl :capi))
(in-package :typing)

(defparameter *typing-timer* nil)

(defun typing-display-callback (pane &optional x y w h)
  (unless *typing-timer*
    (setf *typing-timer* (mp:make-timer #'typing-display-callback pane)))

  (with-atomic-redisplay (pane)
    (gp:clear-graphics-port pane)
    (gp:draw-string pane "testing" (random 800) (random 450)))

  (mp:schedule-timer-relative *typing-timer* (/ 1 30)))

(defun typing ()
  (let ((pane (make-instance 'output-pane
                             :display-callback 'typing-display-callback
                             :background :white
                             :initial-constraints
                             '(:visible-min-width 800 :visible-min-height 450)
                             :title "Typing - the game")))
    (contain pane)))

I am expecting from this code the work “testing” jumping around the screen, but what I get is (usually) just a single frame and no further graphics updates, like something needs to be synched or flipped.  I know the timer is running, because if I put in a (format t “.”) I see a stream of dots in the output buffer.  I have searched for ways to swap or flush the buffer to screen (redisplay-all-screens) on Cocoa, as the documentation states that it is a buffered display to no avail.

Sometimes I do see what I expect, but only if I put another window obscuring part of the main window.

Any tips on how I can get animation output using CAPI?

Burton Samograd

Re: Animation with Timers

BusFactor1 wrote on Fri, 30 Dec 2016 18:06:28 -0800 (PST) 05:06:

| I've searched through the examples for an animation example and found
| balloons.lisp.  I've come up with the following code:
| ...snip...|
| (defun typing-display-callback (pane &optional x y w h)
|   (unless *typing-timer*
|     (setf *typing-timer* (mp:make-timer #'typing-display-callback pane)))
|     ...

You should invoke the typing-display-callback in the process of the pane.
For example:

  (setf *typing-timer* (mp:make-timer #'capi:apply-in-pane-process
                                 pane #'typing-display-callback
                                 (list pane))))
--
Sincerely,
Dmitry Ivanov
lisp.ystok.ru

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: Animation with Timers

Hi,

You've forgot to call gp:invalidate-rectangle to force display callback
to be called.

Have a look at attached slightly modified code, which works.


Updated at: 2020-12-10 08:31 UTC