From 3d4dba9f2533c28146eac5a66050be1daf4ead38 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 25 Jun 2013 19:31:43 -0400 Subject: Add mouse-button and keymod enums and a couple of convenience procedures. --- 2d/input.scm | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/2d/input.scm b/2d/input.scm index fcc1195..f929347 100644 --- a/2d/input.scm +++ b/2d/input.scm @@ -22,8 +22,13 @@ ;;; Code: (define-module (2d input) + #:use-module (srfi srfi-1) #:use-module (figl runtime) ;; For the define-enumeration macro - #:export (keycode)) + #:export (keycode + any-keycode? + keymod + all-keymods? + mouse-button)) ;;; ;;; Keyboard @@ -263,3 +268,34 @@ (power 320) (euro 321) (undo 322)) + +(define (any-keycode? keycode . keycodes) + "Returns true if keycode equals any of the keycodes provided and +returns false otherwise." + (any (lambda (key) (= keycode key)) keycodes)) + +;; Modifier keys +(define-enumeration + keymod + (none 0) + (shift 3) + (ctrl 192) + (alt 768) + (meta 3072) + (num 4096 ) + (caps 8192)) + +(define (all-keymods? mod . expected) + "Returns true if all expected modifier bits are set and returns +false otherwise." + (not (zero? (apply logand mod expected)))) + +;;; +;;; Mouse +;;; + +(define-enumeration + mouse-button + (left 1) + (middle 2) + (right 4)) -- cgit v1.2.3