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