git @ Cat's Eye Technologies Circute / 5ba20bb
Try to improve the UI in the web demo using new yoob.Controller. catseye 12 years ago
2 changed file(s) with 55 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
11 <head>
22 <meta charset="utf-8">
33 <title>Circute Demo</title>
4 <style>
5 #input {
6 display: none;
7 }
8 #output {
9 border: 1px solid blue;
10 }
11 #load {
12 display: none;
13 }
14 </style>
415 </head>
516 <body>
617
718 <h1>Circute Demo</h1>
19
20 <button id="load">Load</button>
21 <button id="edit">Edit</button>
22 <button id="start">Start</button>
23 <button id="stop">Stop</button>
24 <button id="step">Step</button>
25 Speed: <input id="speed" type="range" min="0" max="200" value="0" />
826
927 <textarea id="input" rows="10">
1028 =========
1634 =========
1735 </textarea>
1836
19 <pre id="output" style="border: 1px solid blue">
20 </pre>
21
22 <button id="start">Start</button>
23 <button id="stop">Stop</button>
24 <button id="step">Step</button>
25 <button id="load">Load</button>
26 Speed: <input id="speed" type="range" min="0" max="200" value="0" />
37 <pre id="output"></pre>
2738
2839 </body>
2940 <script src="yoob/controller.js"></script>
4657 newPf.setDefault('Space');
4758 evolve_playfield(pf, newPf);
4859 pf = newPf;
49 var output = document.getElementById('output');
5060 output.innerHTML = pf.dump(dumpMapper);
5161 };
5262
5565 'stop': 'stop',
5666 'step': 'step',
5767 'load': 'load',
68 'edit': 'edit',
5869 'source': 'input',
70 'display': 'output',
5971 'speed': 'speed'
6072 });
73
74 c.click_load();
6175 </script>
00 /*
1 * This file is part of yoob.js version 0.2-PRE
1 * This file is part of yoob.js version 0.3-PRE
22 * This file is in the public domain. See http://unlicense.org/ for details.
33 */
44 if (window.yoob === undefined) yoob = {};
1919 this.delay = 100;
2020 this.source = undefined;
2121 this.speed = undefined;
22 this.controls = {};
2223
2324 var makeOnClick = function(controller, key) {
2425 if (controller['click_' + key] !== undefined)
3435 */
3536 this.connect = function(dict) {
3637 var self = this;
37 var keys = ["start", "stop", "step", "load"];
38 var keys = ["start", "stop", "step", "load", "edit"];
3839 for (var i in keys) {
3940 var key = keys[i];
4041 var value = dict[key];
4344 }
4445 if (value !== undefined) {
4546 value.onclick = makeOnClick(this, key);
47 this.controls[key] = value;
4648 }
4749 }
4850
49 var source = dict.source;
50 if (typeof source === 'string') {
51 source = document.getElementById(source);
52 }
53 if (source !== undefined) {
54 this.source = source;
51 var keys = ["source", "display"];
52 for (var i in keys) {
53 var key = keys[i];
54 var value = dict[key];
55 if (typeof value === 'string') {
56 value = document.getElementById(value);
57 }
58 if (value !== undefined) {
59 this[key] = value;
60 }
5561 }
5662
5763 var speed = dict.speed;
8389 this.click_load = function(e) {
8490 this.stop();
8591 this.load(this.source.value);
92 if (this.controls.edit) this.controls.edit.style.display = "inline";
93 if (this.controls.load) this.controls.load.style.display = "none";
94 if (this.controls.start) this.controls.start.disabled = false;
95 if (this.controls.step) this.controls.step.disabled = false;
96 if (this.controls.stop) this.controls.stop.disabled = false;
97 if (this.display) this.display.style.display = "block";
98 if (this.source) this.source.style.display = "none";
8699 };
87100
88101 this.load = function(text) {
89102 alert("load() NotImplementedError");
103 };
104
105 this.click_edit = function(e) {
106 this.stop();
107 if (this.controls.edit) this.controls.edit.style.display = "none";
108 if (this.controls.load) this.controls.load.style.display = "inline";
109 if (this.controls.start) this.controls.start.disabled = true;
110 if (this.controls.step) this.controls.step.disabled = true;
111 if (this.controls.stop) this.controls.stop.disabled = true;
112 if (this.display) this.display.style.display = "none";
113 if (this.source) this.source.style.display = "block";
90114 };
91115
92116 this.start = function() {