aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/01-click-and-drag-image.lisp
blob: da6a12f50ba15fb628c5308a1f1cc9a541da8898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;;; 01-image-display-and-drag.lisp

(defpackage #:ww.examples/1
  (:use #:cl)
  (:export #:start))

(in-package :ww.examples/1)

(defclass image-display-and-drag (ww::application ) ())

(ww::defhandler dragging-unit
    (ww::on-mousemotion (app x y)
      (let ((unit
              (elt (ww::application-scene app) 0)))
        (setf (ww:x unit) x
              (ww:y unit) y))))

(ww:defhandler start-drag
    (ww:on-mousedown (target)
      (ww::add-handler
       ww::*application*
       #'dragging-unit)))

(ww:defhandler stop-drag
    (ww::on-mouseup (app)
      (ww::remove-handler app #'dragging-unit)))


(defmethod ww::boot ((app image-display-and-drag))
  (let ((bm
          (make-instance 'ww::image
                         :texture (ww::get-asset "Fezghoul.png"))))
    (describe (ww::model-matrix bm))
    (describe bm)
    (describe app)
    (ww::add-unit bm)
    (ww::add-handler bm #'start-drag)
    (ww::add-handler app #'stop-drag)
    (format t "CLICK AND DRAG THE GHOUL~%")
    ))


(defun start ()
  (ww::start
   (make-instance
    'image-display-and-drag
    :mouse-button-events-bubble-p t 
    :mouse-motion-events-bubble-p t
    :asset-root (merge-pathnames
                 "examples/"
                 (asdf:system-source-directory :wheelwork)))))