Skip to content

Commit 60605aa

Browse files
committed
init gui
0 parents  commit 60605aa

File tree

699 files changed

+195520
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

699 files changed

+195520
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 安装
2+
`npm install`
3+
`npm install --save ffi`
4+
5+
# 运行
6+
`npm run main`

Roboto-Regular.ttf

4.32 MB
Binary file not shown.

duck.ts

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import * as ffi from 'ffi';
2+
3+
const duck = ffi.Library('./duck', {
4+
init: ['int', []],
5+
fixnum: ['void*',['int']],
6+
flonum: ['void*',['float']],
7+
8+
scm_eval: ['void*', ['string']],
9+
scm_string: ['void*', ['string']],
10+
11+
scm_symbolp: ['int',['void*']],
12+
scm_procedurep: ['int',['void*']],
13+
scm_pairp: ['int',['void*']],
14+
scm_flonump: ['int',['void*']],
15+
scm_nullp: ['int',['void*']],
16+
scm_booleanp: ['int',['void*']],
17+
scm_vectorp: ['int',['void*']],
18+
19+
Stop_level_value: ['void*',['void*']],
20+
scm_my_read_string:['void*',['string']],
21+
22+
scm_print: ['void',['void*']],
23+
scm_call0: ['void*', ['string']],
24+
scm_call1: ['void*', ['string', 'void*']],
25+
scm_call2: ['void*', ['string', 'void*', 'void*']],
26+
scm_call3: ['void*', ['string', 'void*', 'void*', 'void*']],
27+
scm_call4: ['void*', ['string', 'void*', 'void*', 'void*', 'void*']]
28+
});
29+
30+
function initEnv() {
31+
process.env.LD_LIBRARY_PATH =
32+
'.:./packages:../packages/:../packages/gui:./apps:../:../lib:../packages/nanopass:../apps/duck-editor:../../duck-editor:/z/main/jni/apps/duck-editor/';
33+
process.env.DYLD_LIBRARY_PATH = process.env.LD_LIBRARY_PATH;
34+
process.env.CHEZSCHEMELIBDIRS = process.env.LD_LIBRARY_PATH;
35+
process.env.SCHEMEHEAPDIRS = '.';
36+
process.env.SCHEME_LIBRARY_PATH = '../packages/slib/';
37+
process.env.CHEZ_IMPLEMENTATION_PATH = '.';
38+
process.env.SCHEMEHEAPDIRS = '.';
39+
duck.init();
40+
}
41+
initEnv();
42+
43+
export class Duck {
44+
env = '';
45+
constructor() {
46+
const meval=`(define $meval
47+
(lambda (str)
48+
(try
49+
(let ((ret '()))
50+
(with-input-from-string str
51+
(lambda ()
52+
(let loop ()
53+
(let ((c ($my-read)))
54+
(cond
55+
((eof-object? c) c )
56+
((eq? c (void)) c)
57+
(else
58+
(set! ret (eval c))
59+
(loop)))
60+
))))
61+
ret)
62+
(catch (lambda (x)
63+
(display-condition x)
64+
)))
65+
))`
66+
this.call1('eval',this.read_from_string(meval) );
67+
}
68+
read_from_string(exp){
69+
return duck.scm_my_read_string(exp);
70+
}
71+
72+
top_value(exp){
73+
return duck.Stop_level_value(exp);
74+
}
75+
eval(string){
76+
const str=this.string(string);
77+
const ret=this.call1("$meval",str);
78+
return ret;;
79+
}
80+
my_eval(exp) {
81+
return duck.scm_eval(exp);
82+
}
83+
my_eval_str(exp) {
84+
return duck.eval_str(exp);
85+
}
86+
string(exp) {
87+
return duck.scm_string(exp);
88+
}
89+
int(exp){
90+
return duck.fixnum(exp);
91+
}
92+
float(exp){
93+
return duck.flonum(exp);
94+
}
95+
print(exp){
96+
duck.scm_print(exp);
97+
}
98+
is_symbol(exp){
99+
return duck.scm_symbolp(exp);
100+
}
101+
is_procedure(exp){
102+
return duck.scm_procedurep(exp);
103+
}
104+
is_vector(exp){
105+
return duck.scm_vectorp(exp);
106+
}
107+
108+
call0(name) {
109+
return duck.scm_call0(name);
110+
}
111+
call1(name, arg) {
112+
return duck.scm_call1(name, arg);
113+
}
114+
call2(name, arg0, arg1) {
115+
return duck.scm_call2(name, arg0, arg1);
116+
}
117+
call3(name, arg0, arg1, arg2) {
118+
return duck.scm_call3(name, arg0, arg1, arg2);
119+
}
120+
call4(name, arg0, arg1, arg2, arg3) {
121+
return duck.scm_call4(name, arg0, arg1, arg2, arg3);
122+
}
123+
124+
}

gaga.jpg

54.9 KB
Loading

gui.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Duck } from './duck';
2+
3+
export class Gui extends Duck {
4+
constructor() {
5+
super();
6+
const ret = this.eval(
7+
`(import (scheme)
8+
(gui duck)
9+
(gui window)
10+
(gui widget)
11+
(glfw glfw)
12+
(utils trace) )
13+
(stack-trace-exception)
14+
`
15+
);
16+
}
17+
window(width, height, title) {
18+
const str = `(set! window (window-create ${width} ${height} "${title}")) window`;
19+
return this.eval(str);
20+
}
21+
loop() {
22+
this.eval(' (window-loop window)');
23+
}
24+
text(width, height, title) {
25+
return this.eval(
26+
`(text ${width.toFixed(2)} ${height.toFixed(2)} "${title}" )`
27+
);
28+
// return this.call3('text',this.float(width),this.float(height),this.string(title));
29+
}
30+
button(width, height, title) {
31+
return this.eval(
32+
`(button ${width.toFixed(2)} ${height.toFixed(2)} "${title}" )`
33+
);
34+
}
35+
image(width, height, src) {
36+
return this.eval(
37+
`(image ${width.toFixed(2)} ${height.toFixed(2)} "${src}" )`
38+
);
39+
}
40+
dialog(x, y, width, height, title) {
41+
const ret = this.eval(
42+
`(dialog ${x.toFixed(2)} ${y.toFixed(2)} ${width.toFixed(
43+
2
44+
)} ${height.toFixed(2)} "${title}" )`
45+
);
46+
return ret;
47+
}
48+
addChild(parent, child = null) {
49+
if (child == null) {
50+
return this.call1('widget-add', parent);
51+
}
52+
return this.call2('widget-add', parent, child);
53+
}
54+
}

main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// duck gui
2+
import { Gui } from './gui';
3+
4+
const gui = new Gui();
5+
gui.window(400, 300, 'hello gui');
6+
const t = gui.text(200.0, 300.0, 'test');
7+
const d = gui.dialog(10.0, 10.0, 200.0, 160.0, "hello 测试");
8+
const button =gui.button(80.0,30.0,"button");
9+
const image=gui.image(80.0,80.0,"./gaga.jpg");
10+
gui.addChild(d,button);
11+
gui.addChild(d,image);
12+
13+
gui.loop();

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "duck-typescript",
3+
"version": "1.0.0",
4+
"description": "evilbinary.org",
5+
"main": "ts-node duck.ts",
6+
"scripts": {
7+
"main": "ts-node -p main.ts",
8+
"testall": "mocha -r ts-node/register tests/**/tests.ts"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@types/ffi": "^0.2.2",
14+
"ffi": "^2.3.0"
15+
}
16+
}

packages/agave/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Quick start
2+
3+
## Setup
4+
5+
$ cd ~/scheme # Where '~/scheme' is the path to your Scheme libraries
6+
$ git clone git://github.com/dharmatech/surfage.git
7+
$ bzr branch lp:~derick-eddington/scheme-libraries/xitomatl
8+
$ git clone git://github.com/dharmatech/dharmalab.git
9+
$ git clone git://github.com/dharmatech/agave.git
10+
11+
## Run a demo in Ypsilon
12+
13+
$ ypsilon ~/scheme/agave/demos/flexi-line.scm
14+
15+
## Run a demo in Ikarus
16+
17+
$ ikarus --r6rs-script ~/scheme/agave/demos/flexi-line.scm
18+
19+
## Make a demo load faster in Ikarus
20+
21+
$ ikarus --compile-dependencies ~/scheme/agave/demos/flexi-line.scm
22+
23+
# Introduction
24+
25+
Agave started out as a collection of OpenGL demos written for R6RS
26+
Scheme. Eventually it grew to include libraries which support basic
27+
OpenGL programming idioms.
28+
29+
All of the demos run in Ikarus and Ypsilon.
30+
31+
# Libraries
32+
33+
Some of the libraries are:
34+
35+
```
36+
| library | notes |
37+
|-----------------------------------+-------|
38+
| (agave glamour window) | |
39+
| (agave glamour mouse) | |
40+
| (agave glamour misc) | |
41+
| (agave glamour frames-per-second) | |
42+
| (agave color rgba) | |
43+
| (agave color hsva) | |
44+
| (agave color conversion) | |
45+
| (agave geometry pt) | |
46+
| (agave geometry pt-3d) | |
47+
```
48+
49+
The rest of the libraries are mostly support for the demos.
50+
51+
# Demos
52+
53+
A few demo highlights.
54+
55+
## springies
56+
57+
Long before [Sodaplay](http://sodaplay.com) existed, [Doug DeCarlo](http://www.cs.rutgers.edu/~decarlo/) wrote [xspringies](http://www.cs.rutgers.edu/~decarlo/software.html). Springies
58+
is an implementation of the engine in xspringies. Note that this is
59+
not a binding to any C library; this is an honest to goodness mass and
60+
spring simulation written in pure Scheme. To me, this is a
61+
demonstration that Scheme can be a high-performance language.
62+
63+
![](https://raw.githubusercontent.com/dharmatech/dharmatech.github.com/master/images/springies-belt-tire.png)
64+
65+
## cfdg
66+
67+
An implementation of the [Context Free Art](http://www.contextfreeart.org) semantics. It also renders
68+
the models. :-) Only a subset of the full ContextFree language is
69+
supported, but I picked a subset which allows for some nice pieces to
70+
be rendered.
71+
72+
Screenshot:
73+
74+
![](https://raw.githubusercontent.com/dharmatech/dharmatech.github.com/master/images/cfdg-game1-turn6.png)
75+
76+
## flexi-line
77+
78+
A port of a [demo](http://www.openprocessing.org/visuals/?visualID=323) I found on [Open Processing](http://www.openprocessing.org).
79+
80+
## empathy
81+
82+
A port of a [demo](http://www.openprocessing.org/visuals/?visualID=1182) by [Kyle McDonald](http://www.openprocessing.org/portal/?userID=838) I found on [Open Processing](http://www.openprocessing.org).
83+
84+
## ca
85+
86+
Simulator for the [generations](http://www.mirekw.com/ca/rullex_gene.html) family of cellular automata.

packages/agave/color/conversion.sls

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
;; Copyright 2016 Eduardo Cavazos
2+
;;
3+
;; Licensed under the Apache License, Version 2.0 (the "License");
4+
;; you may not use this file except in compliance with the License.
5+
;; You may obtain a copy of the License at
6+
;;
7+
;; http://www.apache.org/licenses/LICENSE-2.0
8+
;;
9+
;; Unless required by applicable law or agreed to in writing, software
10+
;; distributed under the License is distributed on an "AS IS" BASIS,
11+
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
;; See the License for the specific language governing permissions and
13+
;; limitations under the License.
14+
15+
(library
16+
17+
(agave color conversion)
18+
19+
(export hsva->rgba)
20+
21+
(import (rnrs)
22+
(agave color rgba)
23+
(agave color hsva))
24+
25+
(define (hsva->rgba color)
26+
27+
(let ((hue (inexact (hsva-hue color)))
28+
(saturation (inexact (hsva-saturation color)))
29+
(value (inexact (hsva-value color)))
30+
(alpha (inexact (hsva-alpha color))))
31+
32+
(let ((Hi (mod (floor (/ hue 60.0)) 6.0)))
33+
34+
(let ((f (- (/ hue 60.0) Hi))
35+
(p (* (- 1.0 saturation) value)))
36+
37+
(let ((q (* (- 1.0 (* f saturation)) value))
38+
(t (* (- 1.0 (* (- 1.0 f) saturation)) value)))
39+
40+
(case (exact Hi)
41+
((0) (rgba value t p alpha))
42+
((1) (rgba q value p alpha))
43+
((2) (rgba p value t alpha))
44+
((3) (rgba p q value alpha))
45+
((4) (rgba t p value alpha))
46+
((5) (rgba value p q alpha))))))))
47+
)

packages/agave/color/hsva.sls

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
;; Copyright 2016 Eduardo Cavazos
2+
;;
3+
;; Licensed under the Apache License, Version 2.0 (the "License");
4+
;; you may not use this file except in compliance with the License.
5+
;; You may obtain a copy of the License at
6+
;;
7+
;; http://www.apache.org/licenses/LICENSE-2.0
8+
;;
9+
;; Unless required by applicable law or agreed to in writing, software
10+
;; distributed under the License is distributed on an "AS IS" BASIS,
11+
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
;; See the License for the specific language governing permissions and
13+
;; limitations under the License.
14+
15+
(library
16+
17+
(agave color hsva)
18+
19+
(export <hsva> hsva hsva? hsva-clone hsva-assign! apply-hsva
20+
21+
hsva-hue hsva-hue-set! hsva-hue-change!
22+
hsva-saturation hsva-saturation-set! hsva-saturation-change!
23+
hsva-value hsva-value-set! hsva-value-change!
24+
hsva-alpha hsva-alpha-set! hsva-alpha-change!)
25+
26+
(import (rnrs) (agave misc define-record-type))
27+
28+
(define-record-type++
29+
30+
(<hsva> hsva hsva? hsva-clone hsva-assign! apply-hsva)
31+
32+
(fields (mutable hue hsva-hue hsva-hue-set! hsva-hue-change!)
33+
(mutable saturation
34+
hsva-saturation
35+
hsva-saturation-set!
36+
hsva-saturation-change!)
37+
(mutable value hsva-value hsva-value-set! hsva-value-change!)
38+
(mutable alpha hsva-alpha hsva-alpha-set! hsva-alpha-change!)))
39+
40+
41+
)

0 commit comments

Comments
 (0)