-
Notifications
You must be signed in to change notification settings - Fork 2
/
tippse.html
180 lines (164 loc) · 5.21 KB
/
tippse.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<html>
<head>
<style>
body {background-color:#000;}
#tippse {font-family:monospace; width:100%; height:100%; overflow:hidden; border:1px solid #000; margin:0; padding:0; position:relative; background-color:#000;}
#tippse_display {width:100%; height:100%; overflow:hidden; margin:0; padding:0;}
#tippse_cursor {left:0; top:0; position:absolute; height:1em; width:1px; background-color:#f00; z-index:2;}
#tippse_monospaced {position:absolute; margin:0; padding:0; top:-10em; left:-10em;}
.tippse_text {position:absolute; margin:0; padding:0;}
</style>
<script type="text/javascript">
var TIPPSE_KEY_MOD_SHIFT = 0x1000;
var TIPPSE_KEY_MOD_CTRL = 0x2000;
var TIPPSE_KEY_MOD_ALT = 0x4000;
var TIPPSE_KEY_MASK = 0xfff;
var tippse_key_state = {};
var tippse_key_map = {
"ArrowUp":1,
"ArrowDown":2,
"ArrowRight":3,
"ArrowLeft":4,
"PageUp":5,
"PageDown":6,
"Backspace":7,
"Delete":8,
"Insert":9,
"Home":10,
"End":11,
"Tab":12,
"Enter":14,
"Escape":17,
"F1":18,
"F2":19,
"F3":20,
"F4":21,
"F5":22,
"F6":23,
"F7":24,
"F8":25,
"F9":26,
"F10":27,
"F11":28,
"F12":29
};
var tippse_cursor_active = false;
var tippse_cursor_x = 0;
var tippse_cursor_y = 0;
var tippse_screen = [];
var tippse_char_size_x = 0;
var tippse_char_size_y = 0;
function tippse_resize() {
var monospaced = document.getElementById("tippse_monospaced");
var draw_area = document.getElementById("tippse_display");
while (draw_area.firstChild) {
draw_area.removeChild(draw_area.firstChild);
}
tippse_char_size_x = monospaced.offsetWidth;
tippse_char_size_y = monospaced.offsetHeight;
var width = draw_area.offsetWidth/tippse_char_size_x;
var height = draw_area.offsetHeight/tippse_char_size_y;
tippse_screen = [];
Module._tippse_resize(width, height);
}
function tippse_tick() {
Module._tippse_tick();
}
function tippse_keydown(e) {
console.log("keydown", e.key);
if (e.key=="Control" || e.key=="Shift" || e.key=="Alt" || e.key=="AltGraph") {
tippse_key_state[e.key] = true;
} else {
var code = 0;
var key = tippse_key_map[e.key];
if (key===undefined) {
key = 0;
code = e.key.charCodeAt(0);
}
if (tippse_key_state["Shift"]) {
key |= TIPPSE_KEY_MOD_SHIFT;
}
if (tippse_key_state["Control"]) {
key |= TIPPSE_KEY_MOD_CTRL;
}
if (tippse_key_state["Alt"]) {
key |= TIPPSE_KEY_MOD_ALT;
}
Module._tippse_keypress(key, code, 0, 0, 0, 0);
}
e.preventDefault();
return false;
}
function tippse_keyup(e) {
console.log("keyup", e.key);
if (e.key=="Control" || e.key=="Shift" || e.key=="Alt") {
tippse_key_state[e.key] = false;
}
e.preventDefault();
return false;
}
function tippse_load() {
console.log("load");
Module._tippse_init();
tippse_resize();
setInterval(tippse_tick, 100);
document.addEventListener('keydown', tippse_keydown);
document.addEventListener('keyup', tippse_keyup);
window.addEventListener('resize', tippse_resize);
}
function tippse_draw_char(x, y, text, length, foreground, background) {
if (tippse_screen[y]===undefined) {
tippse_screen[y] = [];
}
if (tippse_screen[y][x]===undefined) {
var e = document.createElement("div");
e.className = "tippse_text";
e.style.top = y*tippse_char_size_y+"px";
e.style.left = x*tippse_char_size_x+"px";
document.getElementById("tippse_display").appendChild(e);
tippse_screen[y][x] = e;
}
if (background==-1) {
background = foreground;
foreground = -2;
}
if (foreground==-1) {
foreground = 0xc0c0c0;
} else if (foreground==-2) {
foreground = 0x000000;
}
if (background==-1) {
background = 0xc0c0c0;
} else if (background==-2) {
background = 0x000000;
}
var copy = UTF8ToString(text, length);
if (copy=="" || copy==" ") {
copy = "\xa0";
}
tippse_screen[y][x].textContent = copy;
tippse_screen[y][x].style.color = "#"+(foreground+0x1000000).toString(16).substr(-6);
tippse_screen[y][x].style.backgroundColor = "#"+(background+0x1000000).toString(16).substr(-6);
}
function tippse_cursor(x, y, active) {
if (active!=tippse_cursor_active || x!=tippse_cursor_x || y!=tippse_cursor_y) {
tippse_cursor_active = active;
tippse_cursor_x = x;
tippse_cursor_y = y;
var cursor = document.getElementById("tippse_cursor");
cursor.style.left = (x*tippse_char_size_x)+"px";
cursor.style.top = (y*tippse_char_size_y)+"px";
cursor.style.height = (active?tippse_char_size_y:0)+"px";
}
}
</script>
<script type="text/javascript" src="tippse.js"></script>
</head>
<body>
<div id="tippse">
<span id="tippse_monospaced"> </span>
<div id="tippse_display"></div>
<div id="tippse_cursor"></div>
</div>
</body>
</html>