|
3 | 3 | ;邮箱:rootdebug@163.com |
4 | 4 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
5 | 5 | (import (scheme) (gles1) (glut) (imgui) ) |
6 | | -(define (app-calc) |
7 | | - (glut-init) |
8 | | - (imgui-init) |
9 | | - ;(android) |
10 | | - ;(imgui-scale (* 1.5 (android-get-density)) (* 1.5 (android-get-density))) |
11 | | - (glut-touch-event (lambda (type x y) |
12 | | - (imgui-touch-event type x y) |
13 | 6 |
|
14 | | - )) |
15 | | - (glut-mouse-event (lambda (button state) |
16 | | - ;(glut-log "mouse-event") |
17 | | - (imgui-mouse-event button state))) |
18 | | - (glut-motion-event (lambda (x y) |
19 | | - ;(glut-log "motion-event") |
20 | | - (imgui-motion-event x y) |
21 | | - )) |
22 | | - (glut-key-event (lambda (event) |
23 | | - (imgui-key-event |
24 | | - (glut-event-get event 'type) |
25 | | - (glut-event-get event 'keycode) |
26 | | - (glut-event-get event 'char) |
27 | | - (glut-event-get event 'chars)) |
28 | | - (if (= 4 (glut-event-get event 'keycode )) |
29 | | - (begin (imgui-exit) |
30 | | - (glut-exit))) |
31 | | - )) |
32 | 7 |
|
33 | | - (glut-display (lambda () |
34 | | - (imgui-render-start) |
35 | | - ;(imgui-test) |
36 | | - (imgui-set-next-window-size (imgui-make-vec2 210.0 280.0) 1) |
37 | | - (imgui-begin "calculator" 0) |
38 | | - (imgui-text "exp:") |
39 | | - (imgui-separator) |
40 | 8 |
|
| 9 | +(define (infix-prefix lst) |
| 10 | + (if (list? lst) |
| 11 | + (if (null? (cdr lst)) |
| 12 | + (car lst) |
| 13 | + (list (cadr lst) |
| 14 | + (infix-prefix (car lst)) |
| 15 | + (infix-prefix (cddr lst)))) |
| 16 | + lst)) |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +(define (app-calc) |
| 21 | + (let ((exp "") (exp2 "")) |
| 22 | + (glut-init) |
| 23 | + (imgui-init) |
| 24 | + ;(android) |
| 25 | + ;(imgui-scale (* 1.5 (android-get-density)) (* 1.5 (android-get-density))) |
| 26 | + (glut-touch-event (lambda (type x y) |
| 27 | + (imgui-touch-event type x y) |
41 | 28 |
|
| 29 | + )) |
| 30 | + (glut-mouse-event (lambda (button state) |
| 31 | + ;(glut-log "mouse-event") |
| 32 | + (imgui-mouse-event button state))) |
| 33 | + (glut-motion-event (lambda (x y) |
| 34 | + ;(glut-log "motion-event") |
| 35 | + (imgui-motion-event x y) |
| 36 | + )) |
| 37 | + (glut-key-event (lambda (event) |
| 38 | + (imgui-key-event |
| 39 | + (glut-event-get event 'type) |
| 40 | + (glut-event-get event 'keycode) |
| 41 | + (glut-event-get event 'char) |
| 42 | + (glut-event-get event 'chars)) |
| 43 | + (if (= 4 (glut-event-get event 'keycode )) |
| 44 | + (begin (imgui-exit) |
| 45 | + (glut-exit))) |
| 46 | + )) |
42 | 47 |
|
43 | | - (if (imgui-button "C" (imgui-make-vec2 40.0 40.0) ) |
44 | | - 1; |
45 | | - ) |
46 | | - (imgui-same-line) |
47 | | - (if (imgui-button "+/-" (imgui-make-vec2 40.0 40.0) ) |
48 | | - 1; |
49 | | - ) |
50 | | - (imgui-same-line) |
51 | | - (if (imgui-button "%" (imgui-make-vec2 40.0 40.0) ) |
52 | | - 1; |
53 | | - ) |
54 | | - (imgui-same-line) |
55 | | - (if (imgui-button "÷" (imgui-make-vec2 40.0 40.0) ) |
56 | | - 1; |
57 | | - ) |
| 48 | + (glut-display (lambda () |
| 49 | + (imgui-render-start) |
| 50 | + ;(imgui-test) |
| 51 | + (imgui-set-next-window-size (imgui-make-vec2 210.0 280.0) 1) |
| 52 | + (imgui-begin "calculator" 0) |
| 53 | + (imgui-text (format "exp: ~A" exp)) |
| 54 | + (imgui-separator) |
58 | 55 |
|
| 56 | + (if (imgui-button "C" (imgui-make-vec2 40.0 40.0) ) |
| 57 | + ((set! exp "") (set! exp2 "")) |
| 58 | + ) |
| 59 | + (imgui-same-line) |
| 60 | + (if (imgui-button "+/-" (imgui-make-vec2 40.0 40.0) ) |
| 61 | + (set! exp (string-append exp " + ")) |
| 62 | + ) |
| 63 | + (imgui-same-line) |
| 64 | + (if (imgui-button "%" (imgui-make-vec2 40.0 40.0) ) |
| 65 | + ((set! exp (string-append exp " % ")) |
| 66 | + (set! exp2 (string-append exp2 " remainder ")))) |
| 67 | + (imgui-same-line) |
| 68 | + (if (imgui-button "÷" (imgui-make-vec2 40.0 40.0) ) |
| 69 | + (set! exp (string-append exp " / "))) |
59 | 70 |
|
60 | | - (if (imgui-button "7" (imgui-make-vec2 40.0 40.0) ) |
61 | | - 1; |
62 | | - ) |
63 | | - (imgui-same-line) |
64 | | - (if (imgui-button "8" (imgui-make-vec2 40.0 40.0) ) |
65 | | - 1; |
66 | | - ) |
67 | | - (imgui-same-line) |
68 | | - (if (imgui-button "9" (imgui-make-vec2 40.0 40.0) ) |
69 | | - 1; |
70 | | - ) |
71 | | - (imgui-same-line) |
72 | | - (if (imgui-button "x" (imgui-make-vec2 40.0 40.0) ) |
73 | | - 1; |
74 | | - ) |
| 71 | + (if (imgui-button "7" (imgui-make-vec2 40.0 40.0) ) |
| 72 | + (set! exp (string-append exp "7"))) |
| 73 | + |
| 74 | + (imgui-same-line) |
| 75 | + (if (imgui-button "8" (imgui-make-vec2 40.0 40.0) ) |
| 76 | + (set! exp (string-append exp "8"))) |
| 77 | + |
| 78 | + (imgui-same-line) |
| 79 | + (if (imgui-button "9" (imgui-make-vec2 40.0 40.0) ) |
| 80 | + (set! exp (string-append exp "9")) |
| 81 | + ) |
| 82 | + (imgui-same-line) |
| 83 | + (if (imgui-button "x" (imgui-make-vec2 40.0 40.0) ) |
| 84 | + (set! exp (string-append exp " * ")) |
| 85 | + ) |
75 | 86 |
|
76 | | - (if (imgui-button "4" (imgui-make-vec2 40.0 40.0) ) |
77 | | - 1; |
78 | | - ) |
79 | | - (imgui-same-line) |
80 | | - (if (imgui-button "5" (imgui-make-vec2 40.0 40.0) ) |
81 | | - 1; |
82 | | - ) |
83 | | - (imgui-same-line) |
84 | | - (if (imgui-button "6" (imgui-make-vec2 40.0 40.0) ) |
85 | | - 1; |
86 | | - ) |
| 87 | + (if (imgui-button "4" (imgui-make-vec2 40.0 40.0) ) |
| 88 | + (set! exp (string-append exp "4")) |
| 89 | + ) |
| 90 | + (imgui-same-line) |
| 91 | + (if (imgui-button "5" (imgui-make-vec2 40.0 40.0) ) |
| 92 | + (set! exp (string-append exp "5")) |
| 93 | + ) |
| 94 | + (imgui-same-line) |
| 95 | + (if (imgui-button "6" (imgui-make-vec2 40.0 40.0) ) |
| 96 | + (set! exp (string-append exp "6")) |
| 97 | + ) |
87 | 98 |
|
88 | | - (imgui-same-line) |
89 | | - (if (imgui-button "-" (imgui-make-vec2 40.0 40.0) ) |
90 | | - 1; |
91 | | - ) |
| 99 | + (imgui-same-line) |
| 100 | + (if (imgui-button "-" (imgui-make-vec2 40.0 40.0) ) |
| 101 | + (set! exp (string-append exp " - ")) |
| 102 | + ) |
92 | 103 |
|
93 | | - (if (imgui-button "1" (imgui-make-vec2 40.0 40.0) ) |
94 | | - 1; |
95 | | - ) |
96 | | - (imgui-same-line) |
97 | | - (if (imgui-button "2" (imgui-make-vec2 40.0 40.0) ) |
98 | | - 1; |
99 | | - ) |
100 | | - (imgui-same-line) |
101 | | - (if (imgui-button "3" (imgui-make-vec2 40.0 40.0) ) |
102 | | - 1; |
103 | | - ) |
104 | | - (imgui-same-line) |
105 | | - (if (imgui-button "+" (imgui-make-vec2 40.0 40.0) ) |
106 | | - 1; |
107 | | - ) |
| 104 | + (if (imgui-button "1" (imgui-make-vec2 40.0 40.0) ) |
| 105 | + (set! exp (string-append exp "1")) |
| 106 | + ) |
| 107 | + (imgui-same-line) |
| 108 | + (if (imgui-button "2" (imgui-make-vec2 40.0 40.0) ) |
| 109 | + (set! exp (string-append exp "2")) |
| 110 | + ) |
| 111 | + (imgui-same-line) |
| 112 | + (if (imgui-button "3" (imgui-make-vec2 40.0 40.0) ) |
| 113 | + (set! exp (string-append exp "3")) |
| 114 | + ) |
| 115 | + (imgui-same-line) |
| 116 | + (if (imgui-button "+" (imgui-make-vec2 40.0 40.0) ) |
| 117 | + (set! exp (string-append exp " + ")) |
| 118 | + ) |
108 | 119 |
|
109 | | - (if (imgui-button "0" (imgui-make-vec2 88.0 40.0) ) |
110 | | - 1; |
111 | | - ) |
112 | | - (imgui-same-line) |
113 | | - (if (imgui-button "." (imgui-make-vec2 40.0 40.0) ) |
114 | | - 1; |
115 | | - ) |
116 | | - |
117 | | - (imgui-same-line) |
118 | | - (if (imgui-button "=" (imgui-make-vec2 40.0 40.0) ) |
119 | | - 1; |
120 | | - ) |
| 120 | + (if (imgui-button "0" (imgui-make-vec2 88.0 40.0) ) |
| 121 | + (set! exp (string-append exp "0")) |
| 122 | + ) |
| 123 | + (imgui-same-line) |
| 124 | + (if (imgui-button "." (imgui-make-vec2 40.0 40.0) ) |
| 125 | + (set! exp (string-append exp ".")) |
| 126 | + ) |
| 127 | + |
| 128 | + (imgui-same-line) |
| 129 | + (if (imgui-button "=" (imgui-make-vec2 40.0 40.0) ) |
| 130 | + ;;(glut-log (infix-prefix (read (open-input-string exp)))) |
| 131 | + (set! exp (string-append exp (format " = ~a" |
| 132 | + (eval |
| 133 | + (infix-prefix |
| 134 | + (read (open-input-string |
| 135 | + (string-append (string-append "(" exp) ")")))))))) |
| 136 | + ) |
121 | 137 |
|
122 | | - (imgui-end) |
123 | | - (imgui-render-end) |
124 | | - )) |
125 | | - (glut-reshape (lambda(w h) |
| 138 | + (imgui-end) |
| 139 | + (imgui-render-end) |
| 140 | + )) |
| 141 | + (glut-reshape (lambda(w h) |
126 | 142 | (imgui-resize w h) |
127 | | - )) |
128 | | - (glut-main-loop) |
129 | | - (imgui-exit) |
130 | | - (glut-exit) |
131 | | - ) |
| 143 | + )) |
| 144 | + (glut-main-loop) |
| 145 | + (imgui-exit) |
| 146 | + (glut-exit) |
| 147 | + )) |
132 | 148 | (app-calc) |
0 commit comments