Adding gui helpers
This commit is contained in:
parent
fd7d1512bc
commit
0e4cec8362
|
@ -26,12 +26,18 @@
|
|||
|
||||
(define (key-event? x)
|
||||
(is-a? x key-event%))
|
||||
(define (key-event-code ke)
|
||||
(match (send ke get-key-code)
|
||||
['release
|
||||
(cons 'release (send ke get-key-release-code))]
|
||||
[kc
|
||||
kc]))
|
||||
|
||||
(define (key-state-update! ks ke)
|
||||
(define ht (key-state-keys ks))
|
||||
(match (send ke get-key-code)
|
||||
['release
|
||||
(hash-set! ht (send ke get-key-release-code) #f)]
|
||||
(match (key-event-code ke)
|
||||
[(cons 'release kc)
|
||||
(hash-set! ht kc #f)]
|
||||
[kc
|
||||
(hash-set! ht kc #t)])
|
||||
(set-key-states
|
||||
|
@ -60,6 +66,10 @@
|
|||
[mod5? boolean?])]
|
||||
[key-event?
|
||||
(-> any/c boolean?)]
|
||||
[key-event-code
|
||||
(-> key-event?
|
||||
(or/c (cons/c 'release (or/c char? key-code-symbol?))
|
||||
(or/c char? key-code-symbol?)))]
|
||||
[make-key-state
|
||||
(-> key-state?)]
|
||||
[key-state-update!
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
(define (mouse-event? x)
|
||||
(is-a? x mouse-event%))
|
||||
(define (mouse-event-xy me)
|
||||
(values (send me get-x) (send me get-y)))
|
||||
|
||||
(define (mouse-state-update! ms me)
|
||||
(set-mouse-state-x! ms (send me get-x))
|
||||
|
@ -39,8 +41,8 @@
|
|||
(provide
|
||||
(contract-out
|
||||
[struct mouse-state
|
||||
([x exact-integer?]
|
||||
[y exact-integer?]
|
||||
([x real?]
|
||||
[y real?]
|
||||
[left? boolean?]
|
||||
[right? boolean?]
|
||||
[middle? boolean?]
|
||||
|
@ -53,6 +55,8 @@
|
|||
[mod5? boolean?])]
|
||||
[mouse-event?
|
||||
(-> any/c boolean?)]
|
||||
[mouse-event-xy
|
||||
(-> mouse-event? (values real? real?))]
|
||||
[make-mouse-state
|
||||
(-> mouse-state?)]
|
||||
[mouse-state-update!
|
||||
|
|
|
@ -203,6 +203,10 @@ Produces a @racket[key-state?] object with appropriate defaults.}
|
|||
|
||||
Identifies key events.}
|
||||
|
||||
@defproc[(key-event-code [ke key-event?]) (or/c (cons/c 'release (or/c char? key-code-symbol?)) (or/c char? key-code-symbol?))]{
|
||||
|
||||
Returns the code of the key event.}
|
||||
|
||||
@defproc[(key-state-update! [ks key-state?] [ke key-event?]) any]{
|
||||
|
||||
Updates @racket[ks] with @racket[ke].}
|
||||
|
@ -226,8 +230,8 @@ with each event as in @racket[word-event]. Such as system may be
|
|||
appropriate for interactive programs where input is only has an impact
|
||||
at a consistent tick rate.
|
||||
|
||||
@defstruct*[mouse-state ([x exact-integer?]
|
||||
[y exact-integer?]
|
||||
@defstruct*[mouse-state ([x real?]
|
||||
[y real?]
|
||||
[left? boolean?]
|
||||
[right? boolean?]
|
||||
[middle? boolean?]
|
||||
|
@ -249,6 +253,10 @@ Produces a @racket[mouse-state?] object with appropriate defaults.}
|
|||
|
||||
Identifies mouse events.}
|
||||
|
||||
@defproc[(mouse-event-xy [me mouse-event?]) (values real? real?)]{
|
||||
|
||||
Returns the position of the mouse event.}
|
||||
|
||||
@defproc[(mouse-state-update! [ms mouse-state?] [me mouse-event?]) any]{
|
||||
|
||||
Updates @racket[ms] with @racket[me].}
|
||||
|
|
Loading…
Reference in New Issue