aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/13-menus.lisp
blob: 5188cdfad8f6e5fa8f84e22e80d9e931038e933f (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
52
53
54
55
56
57
58
59
60
61
;;;; 13-menus.lisp

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

(in-package :ww.examples/13)

(defclass menus-demo (ww::application) ())

(defclass numbered-image (ww::image)
  ((n :initarg :num :reader num)
   (menu :initarg :menu :accessor item-menu)))

(defmethod ww::add-menu-item :after ((menu ww::menu) (item numbered-image))
  (setf (item-menu item) menu))

(ww:defhandler item-clicked
    (ww::on-mousedown (img)
      (ww::remove-menu-item (item-menu img) img)))

(ww::defhandler indicate-focus
    (ww::on-focus (img)
      (format t "~a got focus~%" (num img))))

(ww::defhandler indicate-blur
    (ww::on-blur (img)
      (format t "~a lost focus~%" (num img))))

(defmethod ww::boot ((app menus-demo))
  (let ((vscroller
          (make-instance 'ww::vscroller
                         :scroll-speed 10
                         :region (make-instance 'ww::region
                                                :left 0 :right 100
                                                :top 250 :bottom 0))))
    (loop for i to 10 
          for img = (make-instance 'numbered-image
                                   :num i
                                   :texture (ww:get-asset "Fezghoul.png"))
          do 
             (ww:add-handler img #'item-clicked)
             (ww:add-handler img #'indicate-blur)
             (ww:add-handler img #'indicate-focus)
             (ww::add-menu-item vscroller img))
    (ww:add-unit vscroller)
    (ww:refocus-on vscroller)))


(defun start (&optional (scale 1.0) (side 500))
  (ww:start
   (make-instance
    'menus-demo
    :fps 30
    :width (round (* scale side))
    :height (round (* scale side))
    :scale scale
    :title "Scrolling menues demo"
    :asset-root (merge-pathnames
                 "examples/"
                 (asdf:system-source-directory :wheelwork)))))