-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsandbox.html
93 lines (86 loc) · 2.17 KB
/
sandbox.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Sandbox</title>
<script src="https://unpkg.com/spritejs@2/dist/spritejs.min.js"></script>
<script src="/dist/spritly-runtime.js"></script>
<style>
html, body {
width: 100%;
min-width: 1000px;
height: 100%;
padding: 0;
margin: 0;
}
#main {
width: 100%;
height: 100%;
display: flex;
}
#controls {
position: absolute;
right: 10px;
top: 10px;
z-index: 9999;
}
#stage {
width: 100%;
}
</style>
</head>
<body>
<div id="main">
<div id="stage"></div>
</div>
<script>
/* global spritly */
function exec(code) {
const script = document.createElement('script');
script.innerHTML = code;
document.body.appendChild(script);
}
window.exec = exec;
spritly.runtime.ready((scene) => {
const fglayer = scene.layer('fglayer');
const label = new spritejs.Label('x=0, y=0');
label.attr({
font: '24px "宋体"',
fillColor: '#357',
anchor: [0, 1],
opacity: 0,
});
fglayer.appendChild(label);
fglayer.on('mousemove', (evt) => {
const {x, y} = evt;
label.attr({
pos: [x, y],
text: `x=${x}, y=${y}`,
zIndex: Infinity,
});
});
fglayer.on('mousedown', (evt) => {
if(evt.originalEvent.buttons & 2) {
label.attr('opacity', 0.618);
}
});
fglayer.on('mouseup', (evt) => {
label.attr('opacity', 0);
});
});
document.addEventListener('contextmenu', (evt) => {
evt.preventDefault();
});
window.top.runCode();
// document.addEventListener('mouseup', (event) => {
// const gesture = window.top.workspace.currentGesture_;
// if(gesture && typeof MouseEvent !== 'undefined') {
// // gesture.handleUp(event);
// window.top.spritly.Blockly.Gesture.prototype.handleUp.call(gesture, event);
// }
// });
</script>
</body>
</html>