updated for current interface
This commit is contained in:
parent
6abec7c2a1
commit
2298e207a0
|
@ -1,10 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
exec scsh -ll sunterlib-0.5/sunterlib.scm -lel scx/load.scm -o xlib -o rendezvous-channels -o threads -o srfi-1 -o signals -o xft -o xrender -s "$0" "$@"
|
||||||
../../scx <<EOF
|
!#
|
||||||
|
|
||||||
,batch on
|
|
||||||
|
|
||||||
,open srfi-1 signals xlib xft xrender rendezvous-channels threads
|
|
||||||
|
|
||||||
(define *font-size* 36.0)
|
(define *font-size* 36.0)
|
||||||
|
|
||||||
|
@ -114,7 +110,3 @@
|
||||||
(close-display dpy))))
|
(close-display dpy))))
|
||||||
|
|
||||||
(font-demo)
|
(font-demo)
|
||||||
|
|
||||||
,exit
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
exec scsh -ll sunterlib-0.5/sunterlib.scm -lel scx/load.scm -o xlib -o rendezvous-channels -o threads -s "$0" "$@"
|
||||||
../../scx <<EOF
|
!#
|
||||||
|
|
||||||
,batch on
|
|
||||||
|
|
||||||
,open xlib rendezvous-channels threads
|
|
||||||
|
|
||||||
(define (hello text)
|
(define (hello text)
|
||||||
(let* ((dpy (open-display))
|
(let* ((dpy (open-display))
|
||||||
|
@ -65,7 +61,3 @@
|
||||||
(close-display dpy))))
|
(close-display dpy))))
|
||||||
|
|
||||||
(hello "Hello World!")
|
(hello "Hello World!")
|
||||||
|
|
||||||
,exit
|
|
||||||
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
exec scsh -ll sunterlib-0.5/sunterlib.scm -lel scx/load.scm -o xlib -o rendezvous-channels -o threads -s "$0" "$@"
|
||||||
../../scx <<EOF
|
!#
|
||||||
|
|
||||||
,batch on
|
|
||||||
,open xlib
|
|
||||||
,batch off
|
|
||||||
|
|
||||||
(define (picture point-count)
|
(define (picture point-count)
|
||||||
(let* ((dpy (open-display))
|
(let* ((dpy (open-display))
|
||||||
|
@ -12,43 +8,43 @@
|
||||||
(height 400)
|
(height 400)
|
||||||
(black (black-pixel dpy))
|
(black (black-pixel dpy))
|
||||||
(white (white-pixel dpy))
|
(white (white-pixel dpy))
|
||||||
(root (display-root-window dpy))
|
(root (default-root-window dpy))
|
||||||
(win (create-window root width height
|
(win (create-simple-window dpy root 0 0 width height 1 black white))
|
||||||
'background-pixel white
|
(gc (create-gc dpy win
|
||||||
'event-mask '(exposure button-press)))
|
(make-gc-value-alist (background white)
|
||||||
(gc (create-gcontext win
|
(foreground black)))))
|
||||||
'background white 'foreground black)))
|
(init-sync-x-events dpy)
|
||||||
(map-window win)
|
(map-window dpy win)
|
||||||
(let event-loop ()
|
|
||||||
(let ((e (next-event dpy)))
|
(call-with-event-channel
|
||||||
(if
|
dpy win (event-mask exposure button-press)
|
||||||
(case (event-type e)
|
(lambda (channel)
|
||||||
((expose) (begin
|
(let loop ()
|
||||||
(clear-window win)
|
(if
|
||||||
(draw-points win gc point-count 0 0
|
(let ((e (receive channel)))
|
||||||
(/ width 2) (/ height 2))
|
(cond
|
||||||
(draw-poly-text win gc 10 10 "Click a button to exit"
|
((expose-event? e)
|
||||||
'1-byte)
|
(clear-window dpy win)
|
||||||
#f))
|
(draw-points dpy win gc point-count 0 0
|
||||||
(else #t))
|
(/ width 2) (/ height 2))
|
||||||
#t
|
(draw-image-string dpy win gc 10 10 "Click a button to exit"))
|
||||||
(event-loop))))
|
|
||||||
|
(else #f)))
|
||||||
|
(loop)))))
|
||||||
(close-display dpy)))
|
(close-display dpy)))
|
||||||
|
|
||||||
(define (draw-points win gc count x y hw hh)
|
(define (draw-points dpy win gc count x y hw hh)
|
||||||
(if (zero? (modulo count 100))
|
(if (zero? (modulo count 100))
|
||||||
(display-flush-output (window-display win)))
|
(display-flush dpy))
|
||||||
(if (not (zero? count))
|
(if (not (zero? count))
|
||||||
(let ((xf (floor (* (+ 1.2 x) hw ))) ; These lines center the picture
|
(let ((xf (floor (* (+ 1.2 x) hw ))) ; These lines center the picture
|
||||||
(yf (floor (* (+ 0.5 y) hh ))))
|
(yf (floor (* (+ 0.5 y) hh ))))
|
||||||
(draw-point win gc (cons (inexact->exact xf) (inexact->exact yf)))
|
(draw-point dpy win gc (inexact->exact xf) (inexact->exact yf))
|
||||||
(draw-points win gc (- count 1)
|
(draw-points dpy win gc
|
||||||
(- (* y (+ 1 (sin (* 0.7 x)))) (* 1.2 (sqrt (abs x))))
|
(- count 1)
|
||||||
|
(- (* y (+ 1 (sin (* 0.7 x))))
|
||||||
|
(* 1.2 (sqrt (abs x))))
|
||||||
(- 0.21 x)
|
(- 0.21 x)
|
||||||
hw hh))))
|
hw hh))))
|
||||||
|
|
||||||
(picture 1000)
|
(picture 1000)
|
||||||
|
|
||||||
,exit
|
|
||||||
y
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -1,73 +1,68 @@
|
||||||
../../scx <<EOF
|
#!/bin/sh
|
||||||
|
exec scsh -ll sunterlib-0.5/sunterlib.scm -lel scx/load.scm -o xlib -o rendezvous-channels -s "$0" "$@"
|
||||||
,batch on
|
!#
|
||||||
,open xlib
|
|
||||||
,batch off
|
|
||||||
|
|
||||||
(define (regions)
|
(define (regions)
|
||||||
(let* ((dpy (open-display))
|
(let* ((dpy (open-display))
|
||||||
(cm (display-default-colormap dpy))
|
(cm (screen:default-colormap (display:default-screen dpy)))
|
||||||
(black (black-pixel dpy))
|
(black (black-pixel dpy))
|
||||||
(white (white-pixel dpy))
|
(white (white-pixel dpy))
|
||||||
(blue (alloc-named-color cm 'blue))
|
(blue (color:pixel (alloc-named-color dpy cm "blue")))
|
||||||
(win (create-window (display-root-window dpy) 500 500
|
(win (create-simple-window dpy (default-root-window dpy)
|
||||||
'event-mask '(button-press exposure)
|
0 0 500 500 1
|
||||||
'background-pixel white))
|
black white))
|
||||||
(gc (create-gcontext win
|
(gc (create-gc dpy win
|
||||||
'background white
|
(make-gc-value-alist
|
||||||
'foreground black))
|
(background white)
|
||||||
|
(foreground black))))
|
||||||
|
|
||||||
(rectangles '((10 20 60 60) (50 100 30 30)))
|
(rectangles (list (make-rectangle 10 20 60 60)
|
||||||
(colors (list black blue))
|
(make-rectangle 50 100 30 30)))
|
||||||
(regions-alist
|
(colors (list black blue))
|
||||||
(list (cons (union-rectangle-with-region (car rectangles)
|
(regions-alist
|
||||||
(create-region))
|
(map (lambda (rect text)
|
||||||
"black rectangle")
|
(cons (union-rect-with-region (rectangle:x rect)
|
||||||
(cons (union-rectangle-with-region (cadr rectangles)
|
(rectangle:y rect)
|
||||||
(create-region))
|
(rectangle:width rect)
|
||||||
"blue rectangle")))
|
(rectangle:height rect)
|
||||||
|
(create-region))
|
||||||
|
text))
|
||||||
|
rectangles
|
||||||
|
'("black rectangle" "blue rectangle"))))
|
||||||
|
|
||||||
(handle-event
|
(map-window dpy win)
|
||||||
(lambda (e)
|
(init-sync-x-events dpy)
|
||||||
(let ((args (event-args e))
|
|
||||||
(type (event-type e)))
|
|
||||||
(case type
|
|
||||||
;; Zeichnen...
|
|
||||||
((expose) (begin
|
|
||||||
(for-each (lambda (rect color)
|
|
||||||
(set-gcontext-foreground! gc color)
|
|
||||||
(fill-rectangle win gc rect))
|
|
||||||
rectangles colors)
|
|
||||||
#t))
|
|
||||||
;; Hit-Tests
|
|
||||||
((button-press)
|
|
||||||
(let* ((x (cdr (assq 'x args)))
|
|
||||||
(y (cdr (assq 'y args)))
|
|
||||||
(rs (filter (lambda (r-n)
|
|
||||||
(point-in-region? (car r-n)
|
|
||||||
x y))
|
|
||||||
regions-alist)))
|
|
||||||
(for-each (lambda (region-name)
|
|
||||||
(display "You clicked: ")
|
|
||||||
(display (cdr region-name))
|
|
||||||
(newline))
|
|
||||||
rs)
|
|
||||||
;; break if none was hit.
|
|
||||||
(not (null? rs))))
|
|
||||||
)))))
|
|
||||||
|
|
||||||
(map-window win)
|
(call-with-event-channel
|
||||||
(let loop ()
|
dpy win (event-mask exposure button-press structure-notify)
|
||||||
(display-flush-output dpy)
|
(lambda (channel)
|
||||||
(let ((e (next-event dpy)))
|
(let loop ()
|
||||||
(if (handle-event e)
|
(let ((e (receive channel)))
|
||||||
(loop)
|
(cond
|
||||||
(close-display dpy))))))
|
;; Zeichnen...
|
||||||
|
((expose-event? e)
|
||||||
|
(for-each (lambda (rect color)
|
||||||
|
(set-gc-foreground! dpy gc color)
|
||||||
|
(fill-rectangles dpy win gc (list rect)))
|
||||||
|
rectangles colors))
|
||||||
|
;; Hit-Tests
|
||||||
|
((button-event? e)
|
||||||
|
(let* ((x (button-event-x e))
|
||||||
|
(y (button-event-y e))
|
||||||
|
(rs (filter (lambda (r-n)
|
||||||
|
(point-in-region? (car r-n)
|
||||||
|
x y))
|
||||||
|
regions-alist)))
|
||||||
|
(for-each (lambda (region-name)
|
||||||
|
(display "You clicked: ")
|
||||||
|
(display (cdr region-name))
|
||||||
|
(newline))
|
||||||
|
rs)
|
||||||
|
;; break if none was hit.
|
||||||
|
(if (null? rs)
|
||||||
|
(begin
|
||||||
|
(close-display dpy)
|
||||||
|
(exit)))))))
|
||||||
|
(loop))))))
|
||||||
|
|
||||||
(regions)
|
(regions)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
,exit
|
|
||||||
y
|
|
||||||
EOF
|
|
||||||
|
|
|
@ -1,33 +1,35 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
exec scsh -ll sunterlib-0.5/sunterlib.scm -lel scx/load.scm -o xlib -o rendezvous-channels -s "$0" "$@"
|
||||||
|
!#
|
||||||
|
|
||||||
../../scx <<EOF
|
(define all-events-mask
|
||||||
|
(event-mask
|
||||||
,batch on
|
key-press key-release button-press button-release enter-window leave-window
|
||||||
,open xlib
|
pointer-motion pointer-motion-hint button-1-motion button-2-motion
|
||||||
,batch off
|
button-3-motion button-4-motion button-5-motion button-motion keymap-state
|
||||||
|
exposure visibility-change structure-notify resize-redirect
|
||||||
|
substructure-notify substructure-redirect focus-change property-change
|
||||||
|
colormap-change owner-grab-button))
|
||||||
|
|
||||||
(define (scxev)
|
(define (scxev)
|
||||||
(let* ((dpy (open-display))
|
(let* ((dpy (open-display))
|
||||||
(black (black-pixel dpy))
|
(black (black-pixel dpy))
|
||||||
(white (white-pixel dpy))
|
(white (white-pixel dpy))
|
||||||
(win (create-window (display-default-root-window dpy)
|
(win (create-simple-window dpy (default-root-window dpy) 0 0
|
||||||
300 200
|
300 200 0 black white)))
|
||||||
'event-mask '(all-events)
|
|
||||||
'background-pixel white))
|
|
||||||
)
|
|
||||||
(set-wm-name! win '("scx Event Listener"))
|
|
||||||
(map-window win)
|
|
||||||
(let event-loop ()
|
|
||||||
(display-flush-output dpy)
|
|
||||||
(let ((e (wait-event dpy)))
|
|
||||||
(display (event-type e)) (display " Event, Data:\n")
|
|
||||||
(display (event-args e)) (newline) (newline)
|
|
||||||
|
|
||||||
(event-loop))
|
(set-wm-name! dpy win (string-list->property '("scx Event Listener")))
|
||||||
(close-display dpy))))
|
(map-window dpy win)
|
||||||
|
|
||||||
|
(init-sync-x-events dpy)
|
||||||
|
(call-with-event-channel
|
||||||
|
dpy win all-events-mask
|
||||||
|
(lambda (channel)
|
||||||
|
(let loop ()
|
||||||
|
(let ((e (receive channel)))
|
||||||
|
(display (any-event-type e)) (display " on window ")
|
||||||
|
(display (any-event-window e)) (newline)
|
||||||
|
(if (not (destroy-window-event? e))
|
||||||
|
(loop))))))))
|
||||||
|
|
||||||
(scxev)
|
(scxev)
|
||||||
|
|
||||||
,exit
|
|
||||||
y
|
|
||||||
EOF
|
|
Loading…
Reference in New Issue