11; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2- ; 作者:evilbinary on 11/19/16.
3- ; 邮箱:rootdebug@163.com
2+ ; ;Copyright 2016-2080 evilbinary.
3+ ; ;作者:evilbinary on 12/24/16.
4+ ; ;邮箱:rootdebug@163.com
45; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
56(library (gui terminal)
6- (export
7- terminal-create
8- terminal-render
9- terminal-destroy
10- terminal-key-event
11- terminal-char-event
12- terminal-resize
13- terminal-set-mvp
14- terminal
15- )
16- (import (scheme) (utils libutil) (cffi cffi) (gles gles2)
17- (gui graphic) (gui widget) (gui layout)
18- (gui draw)
19- )
20- (load-librarys " libterminal" )
21-
22- (def-function terminal-create " terminal_create" (void* float float float) void*)
23- (def-function terminal-render " terminal_render" (void* float float) void)
24- (def-function terminal-destroy " terminal_destroy" (void*) void)
25- (def-function terminal-key-event " terminal_key_event" (void* int int int int) void)
26- (def-function terminal-char-event " terminal_char_event" (void* int int) void)
27- (def-function terminal-resize " terminal_resize" (void* int int) void)
28- (def-function terminal-set-mvp " terminal_set_mvp" (void* void* float float) void)
29-
30- (define my-width 0)
31- (define my-height 0)
32- (define my-ratio 0)
33- (define font-program 0)
34- (define font-mvp 0)
35-
36- (define (terminal w h )
37- (let ((widget (widget-new 0.0 0.0 w h " " ))
38- (term '() ))
39- (set! term (terminal-create (widget-get-attrs widget 'font (graphic-get-font " RobotoMono-Regular.ttf" )) (widget-get-attrs widget 'font-size 40.0 ) w h))
40- (terminal-set-mvp term font-mvp my-width my-height)
41-
42- (widget-set-attrs widget 'terminal term)
43- (widget-set-layout
44- widget
45- flow-layout
46- )
47-
7+ (export terminal-create terminal-render terminal-destroy
8+ terminal-key-event terminal-char-event terminal-resize
9+ terminal-set-mvp terminal)
10+ (import (scheme) (utils libutil) (cffi cffi) (gles gles2)
11+ (gui graphic) (gui widget) (gui layout) (gui draw))
12+ (load-librarys " libterminal" )
13+ (def-function
14+ terminal-create
15+ " terminal_create"
16+ (void* float float float)
17+ void*)
18+ (def-function
19+ terminal-render
20+ " terminal_render"
21+ (void* float float)
22+ void)
23+ (def-function
24+ terminal-destroy
25+ " terminal_destroy"
26+ (void*)
27+ void)
28+ (def-function
29+ terminal-key-event
30+ " terminal_key_event"
31+ (void* int int int int)
32+ void)
33+ (def-function
34+ terminal-char-event
35+ " terminal_char_event"
36+ (void* int int)
37+ void)
38+ (def-function
39+ terminal-resize
40+ " terminal_resize"
41+ (void* int int)
42+ void)
43+ (def-function
44+ terminal-set-mvp
45+ " terminal_set_mvp"
46+ (void* void* float float)
47+ void)
48+ (define my-width 0)
49+ (define my-height 0)
50+ (define my-ratio 0)
51+ (define font-program 0)
52+ (define font-mvp 0)
53+ (define (terminal w h )
54+ (let ([widget (widget-new 0.0 0.0 w h " " )] [term '() ])
55+ (set! term
56+ (terminal-create
57+ (widget-get-attrs
58+ widget
59+ 'font
60+ (graphic-get-font " RobotoMono-Regular.ttf" ))
61+ (widget-get-attrs widget 'font-size 40.0 )
62+ w
63+ h))
64+ (terminal-set-mvp term font-mvp my-width my-height)
65+ (widget-set-attrs widget 'terminal term)
66+ (widget-set-layout widget flow-layout)
4867 (widget-set-draw
49- widget
50- (lambda (widget parent ); ;draw
51- (let ((x (vector-ref widget %x))
52- (y (vector-ref widget %y))
53- (w (vector-ref widget %w))
54- (h (vector-ref widget %h))
55- (draw (vector-ref widget %draw))
56-
57- (top (vector-ref widget %top))
58- (left (vector-ref widget %left))
59- (right (vector-ref widget %right))
60- (bottom (vector-ref widget %bottom))
61-
62- (gx (widget-in-parent-gx widget parent) )
63- (gy (widget-in-parent-gy widget parent) )
64- )
65-
66- (vector-set! widget %gx gx )
67- (vector-set! widget %gy gy )
68+ widget
69+ (lambda (widget parent )
70+ (let ([x (vector-ref widget %x)]
71+ [y (vector-ref widget %y)]
72+ [w (vector-ref widget %w)]
73+ [h (vector-ref widget %h)]
74+ [draw (vector-ref widget %draw)]
75+ [top (vector-ref widget %top)]
76+ [left (vector-ref widget %left)]
77+ [right (vector-ref widget %right)]
78+ [bottom (vector-ref widget %bottom)]
79+ [gx (widget-in-parent-gx widget parent)]
80+ [gy (widget-in-parent-gy widget parent)])
81+ (vector-set! widget %gx gx)
82+ (vector-set! widget %gy gy)
6883 (graphic-sissor-begin gx gy w h)
69-
70- ; (if (equal? '() background)
71- ; (draw-panel gx gy w h '())
72- ; (draw-panel gx gy w h '() background))
73- (terminal-render term (+ left gx) (+ top gy) )
74-
75-
76- (widget-draw-child widget)
77-
78- (graphic-sissor-end)
79-
80- )))
81-
84+ (terminal-render term (+ left gx) (+ top gy))
85+ (widget-draw-child widget)
86+ (graphic-sissor-end))))
8287 (widget-set-event
83- widget
84- (lambda (widget parent type data )
85- (if (and (= type %event-mouse-button) )
86- (begin
87- ; ;(widget-active widget)
88- (widget-child-rect-event-mouse-button widget type data)
89- ; (printf "view click event ~a ~a ~a\n" type (widget-get-attr widget %text) data)
90- ; ;(draw-widget-child-rect parent widget )
91- ))
92- (if (= type %event-scroll)
93- (begin
94- (widget-child-rect-event-scroll widget type data)
95- ))
96- (if (and (or (= type %event-char) (= type %event-key)) ) ; ;(= (vector-ref widget %status) %status-active)
97- (begin
98- ; ;(printf "\nview ~a key event ~a ~a status=~a\n" (widget-get-attr widget %text) type data (vector-ref widget %status) )
99- (widget-child-key-event widget type data)
100- (if (= type %event-key)
101- (terminal-key-event term
102- (vector-ref data 0 )
103- (vector-ref data 1 )
104- (vector-ref data 2 )
105- (vector-ref data 3 ) ))
106- (if (= type %event-char)
107- (begin
108- (terminal-char-event term
109- (vector-ref data 0 )
110- (vector-ref data 1 ) ) )
111- )
112- ; ;(draw-widget-child-rect parent widget )
113- ))
114- (if (= type %event-motion)
115- (widget-child-rect-event-mouse-motion widget type data))
116- ))
88+ widget
89+ (lambda (widget parent type data )
90+ (if (and (= type %event-mouse-button))
91+ (begin
92+ (widget-child-rect-event-mouse-button widget type data)))
93+ (if (= type %event-scroll)
94+ (begin (widget-child-rect-event-scroll widget type data)))
95+ (if (and (or (= type %event-char) (= type %event-key)))
96+ (begin
97+ (widget-child-key-event widget type data)
98+ (if (= type %event-key)
99+ (terminal-key-event term (vector-ref data 0 ) (vector-ref data 1 )
100+ (vector-ref data 2 ) (vector-ref data 3 )))
101+ (if (= type %event-char)
102+ (begin
103+ (terminal-char-event
104+ term
105+ (vector-ref data 0 )
106+ (vector-ref data 1 ))))))
107+ (if (= type %event-motion)
108+ (widget-child-rect-event-mouse-motion widget type data))))
117109 widget))
110+ (graphic-add-init-event
111+ (lambda (g w h )
112+ (set! my-width w)
113+ (set! my-height h)
114+ (set! font-program (hashtable-ref g 'font-program '() ))
115+ (set! my-ratio (hashtable-ref g 'ratio 1.0 ))
116+ (set! font-mvp (hashtable-ref g 'font-mvp '() )))))
118117
119-
120- (graphic-add-init-event (lambda (g w h )
121- (set! my-width w)
122- (set! my-height h)
123- (set! font-program (hashtable-ref g 'font-program '() ))
124- (set! my-ratio (hashtable-ref g 'ratio 1.0 ))
125- (set! font-mvp (hashtable-ref g 'font-mvp '() ))
126- ))
127-
128- )
0 commit comments