From f311a9c510e4c54fb6cfaac2c3dc9681b6804b3a Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Mon, 27 Jun 2022 18:39:38 -0500 Subject: [add] can now hold many event handlers on a single listener --- examples/03-font-render.lisp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/03-font-render.lisp b/examples/03-font-render.lisp index e47341b..60ffcf2 100644 --- a/examples/03-font-render.lisp +++ b/examples/03-font-render.lisp @@ -26,6 +26,24 @@ -800)) (incf (ww::unit-x target) 5))) +(defvar *spin-table* (make-hash-table :synchronized t)) + +(ww::defhandler spin + (ww::on-perframe () + (let ((rot + (gethash target *spin-table* 0.0))) + (if (< rot (* 8 pi)) + (setf + (gethash target *spin-table*) (+ rot 0.2) + (ww::unit-rotation target) rot) + (progn + (ww::remove-handler target #'spin) + (remhash target *spin-table*)))))) + +(ww::defhandler twirl-on-click + (ww::on-mousedown () + (ww::add-handler target #'spin))) + (defmethod ww::boot ((app font-display)) (let ((hello (make-instance @@ -39,10 +57,7 @@ (ww::unit-y hello) 400) (ww::add-handler hello #'marquee) (ww::add-handler hello #'change-text-color) - (ww::add-handler hello - (ww::on-mousedown () - (format t "I Was Clicked at ~a,~a!~%" - x y))) + (ww::add-handler hello #'twirl-on-click) (ww::refocus-on hello) (ww::add-unit app hello))) -- cgit v1.2.3