diff options
-rw-r--r-- | examples/02-moving-bitmp.lisp | 22 | ||||
-rw-r--r-- | examples/03-font-render.lisp | 25 | ||||
-rw-r--r-- | wheelwork.lisp | 4 |
3 files changed, 30 insertions, 21 deletions
diff --git a/examples/02-moving-bitmp.lisp b/examples/02-moving-bitmp.lisp index 318bed4..53a4f35 100644 --- a/examples/02-moving-bitmp.lisp +++ b/examples/02-moving-bitmp.lisp @@ -47,14 +47,14 @@ (:scancode-up (setf dy 1 desty (+ ty (ww::unit-height target)))) (:scancode-left (setf dx -1 destx (- tx (ww::unit-width target)))) (:scancode-right (setf dx 1 destx (+ tx (ww::unit-width target))))) - (ww::set-handler + (ww::add-handler target (ww::on-perframe () (with-slots ((cx ww::x) (cy ww::y)) target (if (and (= cx destx) (= cy desty)) (progn (remhash target *shared-anim-table*) - (ww::unset-handler target 'ww::perframe)) + (ww::remove-handler target 'ww::perframe)) (setf cx (+ cx dx) cy (+ cy dy))))))))))) @@ -91,22 +91,22 @@ (make-instance 'ww::bitmap :texture (ww::get-asset "RootBear.png")))) - (ww::set-handler app #'wheelie) + (ww::add-handler app #'wheelie) ;; first (ww::refocus-on bm) - (ww::set-handler bm #'animate-move-thing ) - (ww::set-handler bm #'thing-clicked) - (ww::set-handler bm #'mouse-over) + (ww::add-handler bm #'animate-move-thing ) + (ww::add-handler bm #'thing-clicked) + (ww::add-handler bm #'mouse-over) (ww::add-unit app bm) ;;second (setf (ww::unit-x bm2) 90 (ww::unit-y bm2) 90) - (ww::set-handler bm2 #'move-thing) - (ww::set-handler bm2 #'flip-on-click ) - (ww::set-handler bm2 #'look-at-me) - (ww::set-handler bm2 #'look-away) - (ww::set-handler bm2 #'wheelie) + (ww::add-handler bm2 #'move-thing) + (ww::add-handler bm2 #'flip-on-click ) + (ww::add-handler bm2 #'look-at-me) + (ww::add-handler bm2 #'look-away) + (ww::add-handler bm2 #'wheelie) (ww::add-unit app bm2))) diff --git a/examples/03-font-render.lisp b/examples/03-font-render.lisp index e04d0c8..47ac9cb 100644 --- a/examples/03-font-render.lisp +++ b/examples/03-font-render.lisp @@ -1,18 +1,27 @@ -(defpackage #:ww.example/3 +(defpackage #:ww.examples/3 (:use :cl)) -(in-package #:ww.example/3) +(in-package #:ww.examples/3) (defclass font-display (ww::application) ()) +(define-symbol-macro +speed+ 2) + (ww::defhandler move-on-keydown (ww::on-keydown () (case scancode - (:scancode-up (incf (ww::unit-y target))) - (:scancode-down (decf (ww::unit-y target))) - (:scancode-left (decf (ww::unit-x target))) - (:scancode-right (incf (ww::unit-x target)))))) + (:scancode-up (incf (ww::unit-y target) +speed+)) + (:scancode-down (decf (ww::unit-y target) +speed+)) + (:scancode-left (decf (ww::unit-x target) +speed+)) + (:scancode-right (incf (ww::unit-x target) +speed+))))) + +(ww::defhandler marquee + (ww::on-perframe () + (when (< 800 (ww::unit-x target)) + (setf (ww::unit-x target) + -800)) + (incf (ww::unit-x target) +speed+))) (defmethod ww::boot ((app font-display)) (let ((hello @@ -31,8 +40,7 @@ (ww::unit-y hello) 100) - (ww::set-handler hello #'move-on-keydown) - + (ww::add-handler hello #'marquee) (ww::refocus-on hello) (ww::add-unit app hello))) @@ -40,6 +48,7 @@ (defun start () (ww::start (make-instance 'font-display + :fps 60 :refocus-on-mousedown-p nil :title "Wheelwork Example: Font display" :asset-root "~/projects/wheelwork/examples/"))) diff --git a/wheelwork.lisp b/wheelwork.lisp index 952dd22..161f5b7 100644 --- a/wheelwork.lisp +++ b/wheelwork.lisp @@ -122,7 +122,7 @@ necessary." (after-dropped (after-dropped-table listener)) (before-dropped (before-dropped-table listener)))) -(defun set-handler (interactive handler) +(defun add-handler (interactive handler) (when (null (listener interactive)) (setf (listener interactive) (make-instance 'listener))) (setf @@ -130,7 +130,7 @@ necessary." (gethash interactive (listener-table-for (listener interactive) (event-type handler))) handler)) -(defun unset-handler (interactive handler-or-event-type) +(defun remove-handler (interactive handler-or-event-type) "Handler can be an instance of EVENT-HANDLER or can be a symbol whose name is an event type." (when (listener interactive) |