1 (defpackage #:cowl-glfw
4 #:mouse-button-callback
7 #:edit-mode-char-callback
11 #:setup-input-callbacks
12 #:teardown-input-callbacks
))
14 (in-package #:cowl-glfw
)
16 (pushnew 'cowl
:delete-default-font cl-glfw
:*terminate-hooks
*)
18 (defun mouse-button-callback (button action
)
19 "Callback for capturing GLFW mouse button events and passing them to Cowl."
20 (cowl:mouse-button-event button
(eql action glfw
:+press
+)))
22 (defun key-callback (key action
)
23 "The key capture GLFW callback, note that this is not intended for
24 capturing character input, use edit-mode-char-callback for that."
25 ;; unless it's a character in edit mode.
26 (unless (and (characterp key
)
27 (typep cowl
:*focused-widget
* 'cowl
:input
))
28 (cowl:key-event key
(eql action glfw
:+press
+))))
30 ;;; for cowl:input boxes
31 (defun edit-mode-char-callback (character action
)
32 "Character capture GLFW callback. Note that this is not intended for capturing
33 non-textual and modifier keys, use key-callback for that."
34 (cowl:key-event character
(eql action glfw
:+press
+)))
36 (defun enter-edit-mode-hook ()
37 "The cowl-glfw callback to set up GLFW for reading
39 (glfw:enable glfw
:+key-repeat
+)
40 (glfw:set-char-callback
#'edit-mode-char-callback
))
42 (defun leave-edit-mode-hook ()
43 "The cowl-glfw callback to undo enter-edit-mode-hook."
44 (glfw:disable glfw
:+key-repeat
+)
45 (glfw:set-char-callback nil
))
47 (defun setup-input-callbacks ()
48 "Set the callbacks for Cowl on GLFW."
49 (glfw:set-mouse-button-callback
'mouse-button-callback
)
50 (glfw:set-mouse-pos-callback
'cowl
:mouse-motion-event
)
51 (glfw:set-mouse-wheel-callback
'cowl
:mouse-wheel-event
)
52 (glfw:set-key-callback
'key-callback
)
53 (pushnew 'enter-edit-mode-hook cowl
:*enter-edit-mode-hooks
*)
54 (pushnew 'leave-edit-mode-hook cowl
:*leave-edit-mode-hooks
*))
56 (defun clear-input-events ()
57 "Forces event collection with the cowl:*ignore-events* flag set.
58 This effectively clears all the input events, by flushing and ignoring them."
59 (let ((cowl:*ignore-events
* t
))
63 (defun teardown-input-callbacks ()
64 "Removed all of the input callbacks. NB. this won't discriminate cowl-glfw callbacks
65 from anything else you might have put there."
66 (glfw:set-mouse-button-callback nil
)
67 (glfw:set-mouse-pos-callback nil
)
68 (glfw:set-mouse-wheel-callback nil
)
69 (glfw:set-key-callback nil
)
70 (glfw:set-char-callback nil
))