Skip to content

Commit 65614b8

Browse files
committed
Adds on-click methods
1 parent 1e00a31 commit 65614b8

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/controllers.lisp

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010

1111
;;; Mouse
1212

13+
(defparameter *buttons* '(:left nil :middle nil :right nil))
14+
15+
(defmethod on-click ((instance sketch) x y))
16+
(defmethod on-middle-click ((instance sketch) x y))
17+
(defmethod on-right-click ((instance sketch) x y))
18+
19+
(defmethod kit.sdl2:mousebutton-event ((instance sketch) state timestamp button x y)
20+
(let ((button (elt (list nil :left :middle :right) button))
21+
(method (elt (list nil #'on-click #'on-middle-click #'on-right-click) button)))
22+
(when (equal state :mousebuttondown)
23+
(setf (getf *buttons* button) t))
24+
(when (and (equal state :mousebuttonup) (getf *buttons* button))
25+
(setf (getf *buttons* button) nil)
26+
(funcall method instance x y))))
27+
1328
(defmethod kit.sdl2:mousemotion-event :after ((instance sketch)
1429
timestamp button-mask x y xrel yrel)
1530
(out :mouse (cons x y)

src/package.lisp

+5
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,9 @@
171171
:canvas-width
172172
:canvas-height
173173
:draw-canvas
174+
175+
;; Controllers
176+
:on-click
177+
:on-middle-click
178+
:on-right-click
174179
))

0 commit comments

Comments
 (0)