From 827dadbc91abdb8e2143c2a15b996e0e5ad87fc6 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 6 Jul 2022 09:37:47 -0500 Subject: [add] renderarea example --- examples/07-renderarea.lisp | 69 +++++++++++++++++++++++++++++++++++++++++++++ wheelwork-examples.asd | 3 +- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 examples/07-renderarea.lisp diff --git a/examples/07-renderarea.lisp b/examples/07-renderarea.lisp new file mode 100644 index 0000000..ead322f --- /dev/null +++ b/examples/07-renderarea.lisp @@ -0,0 +1,69 @@ +;;;; examples/07-scrollarea.lisp + +(defpackage #:ww.examples/7 + (:use #:cl) + (:export #:start)) + +(in-package #:ww.examples/7) + +(defclass scrollarea-example (ww::application) + ((cube :initarg :cube :accessor cube))) + +(ww::defhandler move-cube + (ww::on-keydown (app scancode) + (with-slots (cube) app + (case scancode + (:scancode-v + (setf (ww::unit-visiblep cube) + (not (ww::unit-visiblep cube)))) + (:scancode-left + (decf (ww::x cube) 15)) + (:scancode-right + (incf (ww::x cube) 15)) + (:scancode-up + (incf (ww::y cube) 15)) + (:scancode-down + (decf (ww::y cube) 15)))))) + +(ww::defhandler clicked + (ww::on-mousedown () + (format t "~a was clicked~%" target))) + +(defmethod ww::boot ((app scrollarea-example)) + (let ((cube + (make-instance + 'ww::bitmap + :texture (ww::get-asset "GelatinousCube.png"))) + (cube-container + (make-instance + 'ww::container + :bottom 200 :top 400 + :left 200 :right 600))) + + (setf (cube app) cube) + (ww::add-handler app #'move-cube) + (ww::add-handler cube #'clicked) + + + (setf (ww::x cube) 400 + (ww::y cube) 300) + + (ww::scale-by cube 2.0) + + (ww::add-unit cube-container cube) + (ww::add-unit app cube-container) + + (describe cube-container) + )) + + +(defun start () + (ww::start (make-instance + 'scrollarea-example + :fps 30 + :width 800 + :height 600 + :title "A scrollable area." + :asset-root (merge-pathnames + "examples/" + (asdf:system-source-directory :wheelwork))))) diff --git a/wheelwork-examples.asd b/wheelwork-examples.asd index d2515ed..a5a5498 100644 --- a/wheelwork-examples.asd +++ b/wheelwork-examples.asd @@ -11,4 +11,5 @@ (:file "03-font-render") (:file "04-a-button") (:file "05-frameset-animation") - (:file "06-sprite"))) + (:file "06-sprite") + (:file "07-renderarea"))) -- cgit v1.2.3