aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/03-font-render.lisp
blob: a85484349cc8f25c247e04144dbeb6a2df1ca7a9 (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

(defpackage #:ww.examples/3
  (:use :cl))

(in-package #:ww.examples/3)

(defclass font-display (ww::application) ())

(define-symbol-macro +speed+ 10)

(defun random-text-color ()
  (make-array 4 :initial-contents (list (random 1.0) (random 1.0) (random 1.0) 1.0)))

(ww::defhandler change-text-color
    (ww::on-keydown ()
      "Press any key to change the color of the text"
      (format t "Pressed a key, changing the color~%")
      (setf (ww::text-color target) (random-text-color))))

(ww::defhandler marquee
    (ww::on-perframe ()
      (when (< 900 (ww::unit-x target))
        (setf (ww::unit-x target)
              -800))
      (incf (ww::unit-x target) 5)))

(defmethod ww::boot ((app font-display))
  (let ((hello
          (make-instance
           'ww::text
           :content "Hell! Oh World..."
           :font (ww::get-asset "Ticketing.ttf" :asset-args '(:oversample 2)))))

    (setf (ww::unit-width hello)
          (* 5 (ww::unit-width hello))

          (ww::unit-height hello)
          (* 5 (ww::unit-height hello))

          (ww::unit-x hello) 100

          (ww::unit-y hello) 400)

    (ww::add-handler hello #'marquee)
    (ww::add-handler hello #'change-text-color)
    (ww::refocus-on hello)

    (ww::add-unit app hello)))


(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/")
             :x 2380))