-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lisp
55 lines (48 loc) · 1.65 KB
/
menu.lisp
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
;;
;; Lire - menu
;;
(in-package :lire)
(defclass menu (widget)
((buttons :initform
`(("save" ,#'save-lire)
("load" ,#'load-lire)))))
(defmethod reshape ((menu menu))
(with-slots (window x y (m-width width) (m-height height) buttons) menu
(with-slots (width height) window
(setf m-width *menu-width*
m-height (* *menu-button-height* (length buttons))
x (- width m-width *menu-offset*)
y (- height m-height *menu-offset*)))))
;;;
;; Events
;;;
(defmethod mouse ((menu menu) button state x y)
(with-slots (parent (my y) buttons) menu
(when (and (eq button :left-button)
(eq state :down))
(let ((n (floor (/ (- y my) *menu-button-height*))))
(funcall (second (nth n buttons)))))))
;;;
;; Draw
;;;
(defmethod draw ((menu menu) active)
(with-slots (window x y height buttons) menu
(gl:with-pushed-matrix
(gl:translate x y 0)
(when active
(apply #'gl:color *normal-color*)
(gl:line-width 1)
(aligned-quad-lines 0 0 0 *menu-width* height))
(apply #'gl:color *dimm-color*)
(aligned-quad-shape 0 0 0 *menu-width* height)
(let ((b-width/2 (/ *menu-width* 2))
(b-height/2 (/ *menu-button-height* 2)))
(loop
for button in buttons
and i from 0 do
(let ((b-y (* i *menu-button-height*)))
(aligned-quad-lines 0 b-y 0
*menu-width* *menu-button-height*)
(text (car button)
b-width/2 (+ b-y b-height/2)
(/ *menu-button-height* 3) 0)))))))