mouse wrapper
This commit is contained in:
parent
32e7a46b41
commit
5eccb25379
3
README
3
README
|
@ -1,7 +1,4 @@
|
||||||
lux - a simple library for creating real-time graphical apps
|
lux - a simple library for creating real-time graphical apps
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
xxx chaos/gui/mouse (take gui)
|
|
||||||
xxx chaos/gui/key (take gui)
|
xxx chaos/gui/key (take gui)
|
||||||
xxx chaos/srpnt
|
|
||||||
xxx chaos/gui/mode-lambda
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
#lang racket/base
|
||||||
|
(require (for-syntax racket/base
|
||||||
|
racket/syntax)
|
||||||
|
racket/match
|
||||||
|
racket/class
|
||||||
|
racket/gui/base
|
||||||
|
racket/generic
|
||||||
|
racket/contract/base
|
||||||
|
data/queue
|
||||||
|
lux/chaos)
|
||||||
|
|
||||||
|
(struct mouse-state
|
||||||
|
(_
|
||||||
|
x y
|
||||||
|
left? right? middle?
|
||||||
|
shift? control? meta? alt?
|
||||||
|
mod3? mod4? mod5?)
|
||||||
|
#:mutable)
|
||||||
|
|
||||||
|
(define-syntax (set-mouse-state stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ ms me id)
|
||||||
|
(with-syntax ([set-mouse-state-id?!
|
||||||
|
(format-id #'id "set-mouse-state-~a?!" #'id)]
|
||||||
|
[get-id-down
|
||||||
|
(format-id #'id "get-~a-down" #'id)])
|
||||||
|
(syntax/loc stx
|
||||||
|
(set-mouse-state-id?! ms (send me get-id-down))))]))
|
||||||
|
(define-syntax-rule (set-mouse-states ms me (id ...))
|
||||||
|
(begin (set-mouse-state ms me id) ...))
|
||||||
|
|
||||||
|
(struct gui/mouse (ms g)
|
||||||
|
#:methods gen:chaos
|
||||||
|
[(define/generic super-fps chaos-fps)
|
||||||
|
(define/generic super-yield chaos-yield)
|
||||||
|
(define/generic super-inputs chaos-inputs)
|
||||||
|
(define/generic super-output! chaos-output!)
|
||||||
|
(define/generic super-label! chaos-label!)
|
||||||
|
(define/generic super-swap! chaos-swap!)
|
||||||
|
(define (chaos-fps c)
|
||||||
|
(super-fps (gui/mouse-g c)))
|
||||||
|
(define (chaos-yield c e)
|
||||||
|
(super-yield (gui/mouse-g c) e))
|
||||||
|
(define (chaos-inputs c)
|
||||||
|
(define ms (gui/mouse-ms c))
|
||||||
|
(define inner (super-inputs (gui/mouse-g c)))
|
||||||
|
(define q (make-queue))
|
||||||
|
(for ([e inner])
|
||||||
|
(match e
|
||||||
|
[(? (λ (x) (is-a? x mouse-event%)) me)
|
||||||
|
(set-mouse-state-x! ms (send me get-x))
|
||||||
|
(set-mouse-state-y! ms (send me get-y))
|
||||||
|
(set-mouse-states
|
||||||
|
ms me
|
||||||
|
(left right middle shift control meta alt mod3 mod4 mod5))]
|
||||||
|
[_
|
||||||
|
(enqueue! q e)]))
|
||||||
|
(enqueue! q ms)
|
||||||
|
(in-queue q))
|
||||||
|
(define (chaos-output! c o)
|
||||||
|
(super-output! (gui/mouse-g c) o))
|
||||||
|
(define (chaos-label! c l)
|
||||||
|
(super-label! (gui/mouse-g c) l))
|
||||||
|
(define (chaos-swap! c t)
|
||||||
|
(super-swap! (gui/mouse-g c) t))])
|
||||||
|
|
||||||
|
(define (make-gui/mouse g)
|
||||||
|
(define ms
|
||||||
|
(mouse-state (gensym) 0 0 #f #f #f #f #f #f #f #f #f #f))
|
||||||
|
(gui/mouse ms g))
|
||||||
|
(provide
|
||||||
|
(contract-out
|
||||||
|
[struct mouse-state
|
||||||
|
([_ symbol?]
|
||||||
|
[x exact-integer?]
|
||||||
|
[y exact-integer?]
|
||||||
|
[left? boolean?]
|
||||||
|
[right? boolean?]
|
||||||
|
[middle? boolean?]
|
||||||
|
[shift? boolean?]
|
||||||
|
[control? boolean?]
|
||||||
|
[meta? boolean?]
|
||||||
|
[alt? boolean?]
|
||||||
|
[mod3? boolean?]
|
||||||
|
[mod4? boolean?]
|
||||||
|
[mod5? boolean?])]
|
||||||
|
[make-gui/mouse
|
||||||
|
(-> chaos?
|
||||||
|
chaos?)]))
|
|
@ -5,7 +5,8 @@
|
||||||
racket/gui/base
|
racket/gui/base
|
||||||
racket/class
|
racket/class
|
||||||
lux
|
lux
|
||||||
lux/chaos/gui)
|
lux/chaos/gui
|
||||||
|
lux/chaos/gui/mouse)
|
||||||
|
|
||||||
(define COLORS
|
(define COLORS
|
||||||
'("red" "orange" "yellow" "green" "blue" "indigo" "violet"))
|
'("red" "orange" "yellow" "green" "blue" "indigo" "violet"))
|
||||||
|
@ -21,9 +22,9 @@
|
||||||
(match e
|
(match e
|
||||||
['close
|
['close
|
||||||
(set! closed? #t)]
|
(set! closed? #t)]
|
||||||
[(? (λ (x) (is-a? x mouse-event%)) me)
|
[(? mouse-state? ms)
|
||||||
(set! x (send me get-x))
|
(set! x (mouse-state-x ms))
|
||||||
(set! y (send me get-y))]
|
(set! y (mouse-state-y ms))]
|
||||||
[(? (λ (x) (is-a? x key-event%)) ke)
|
[(? (λ (x) (is-a? x key-event%)) ke)
|
||||||
(set! color (fxmodulo (fx+ 1 color) (length COLORS)))]))
|
(set! color (fxmodulo (fx+ 1 color) (length COLORS)))]))
|
||||||
(match closed?
|
(match closed?
|
||||||
|
@ -42,5 +43,5 @@
|
||||||
|
|
||||||
(module+ main
|
(module+ main
|
||||||
(call-with-chaos
|
(call-with-chaos
|
||||||
(make-gui 60.0)
|
(make-gui/mouse (make-gui 60.0))
|
||||||
(λ () (fiat-lux (spin 0 0 400 300)))))
|
(λ () (fiat-lux (spin 0 0 400 300)))))
|
||||||
|
|
Loading…
Reference in New Issue