widget-tree sync eventloop - 2
This commit is contained in:
parent
85fb2c868b
commit
1e372d54ee
|
@ -1,4 +1,5 @@
|
||||||
;;; scgamewidgets.scm - a scheme game library (needs scx-0.2 or scheme48-fb)
|
;;; scgamewidgets.scm - a scheme game library widgets
|
||||||
|
;; (needs scx-0.2 or scheme48-fb)
|
||||||
;;;
|
;;;
|
||||||
;;; Copyright (c) 2011-2012 Johan Ceuppens
|
;;; Copyright (c) 2011-2012 Johan Ceuppens
|
||||||
;;;
|
;;;
|
||||||
|
@ -85,6 +86,21 @@
|
||||||
#t))
|
#t))
|
||||||
#f))
|
#f))
|
||||||
|
|
||||||
|
(define (draw-widget-tree widget-tree)
|
||||||
|
(define (frec l)
|
||||||
|
(cond ((null? l) #f)
|
||||||
|
((list? (car l))
|
||||||
|
(frec (car l)))
|
||||||
|
((widget? (car l))
|
||||||
|
(((car l) 'draw)))
|
||||||
|
(else (frec (cdr l)))))
|
||||||
|
|
||||||
|
(if (widget-node? node)
|
||||||
|
(for-each frec (force node))
|
||||||
|
#f))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; widgets
|
;; widgets
|
||||||
|
|
||||||
(define (make-scgame-widget)
|
(define (make-scgame-widget)
|
||||||
|
@ -210,18 +226,20 @@
|
||||||
;; This is the main loop you call on your window's
|
;; This is the main loop you call on your window's
|
||||||
;; widget tree (see above)
|
;; widget tree (see above)
|
||||||
|
|
||||||
(define (widget-tree-eventloop dpy win widget-tree)
|
(define (widget-tree-eventloop dpy win tree)
|
||||||
(let ((mousex 0)
|
(let ((mousex 0))
|
||||||
(mousey 0))
|
(let ((mousey 0))
|
||||||
|
(let ((widget-tree tree))
|
||||||
(init-sync-x-events dpy)
|
(init-sync-x-events dpy)
|
||||||
(map-window dpy win)
|
(map-window dpy win)
|
||||||
(call-with-event-channel
|
(call-with-event-channel
|
||||||
dpy win (event-mask button-press)
|
dpy win (event-mask button-press)
|
||||||
(lambda (channel)
|
(lambda (channel)
|
||||||
;; FIXME calibrate at 10 times or using nanosleep
|
;; FIXME calibrate at 10 times or using nanosleep for your machine
|
||||||
(let loop ()
|
(let loop ()
|
||||||
(if
|
(if
|
||||||
(let ((e (receive channel)))
|
(let ((e (receive channel)))
|
||||||
|
;; process events
|
||||||
(cond
|
(cond
|
||||||
((motion-event? e)
|
((motion-event? e)
|
||||||
(set! mousex motion-event-x)
|
(set! mousex motion-event-x)
|
||||||
|
@ -240,6 +258,9 @@
|
||||||
(expose-window dpy expose-event-window))
|
(expose-window dpy expose-event-window))
|
||||||
((destroy-widow-event? e)
|
((destroy-widow-event? e)
|
||||||
(expose-window dpy destroy-window-event-window))
|
(expose-window dpy destroy-window-event-window))
|
||||||
(else #f))))
|
(else #f))
|
||||||
(loop))))))
|
;; draw widgets in tree
|
||||||
|
(draw-widget-tree widget-tree)
|
||||||
|
))
|
||||||
|
(loop))))))))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue