-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
345 lines (311 loc) · 13.9 KB
/
index.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<html>
<!DOCTYPE html>
<html>
<head>
<title>KolibriOS skin viewer</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
* {
box-sizing: border-box;
}
.window {
border: 1px solid;
border-top: none;
width: 300px;
display: none;
font-family: monospace;
font-size: 14px;
user-select: none;
margin-bottom: 10px;
}
.window .inner {
border: 1px solid;
height: 250px;
margin: 4px;
margin-top: 0;
}
.window .panel {
position: relative;
background-repeat: repeat-x;
}
.window .panel .left {
position: absolute;
}
.window .panel .button {
position: absolute;
}
.window .panel .close {
position: absolute;
/* border: 1px dotted red; */
}
.window .panel .min {
position: absolute;
/* border: 1px dotted red; */
}
.window .panel .title {
position: absolute;
left: 5px;
top: 4px;
/* font-weight: bold; */
}
.window button {
background: white;
color: #000;
padding: 3px;
margin: 5px;
}
.block {
display: flex;
align-items: center;
justify-content: space-around;
max-width: 800px;
margin: auto;
flex-wrap: wrap;
}
select {
padding: 5px;
}
</style>
</head>
<body>
<center>
<br><br>
<h2>KolibriOS skin viewer</h2>
<br>
Choose a .skn file and press View. Magic!
<br><br>
<input type="file" id="file-input" accept=".skn">
<button onclick="readSkin()">View!</button>
</center>
<br>
<div class="block">
<div class="window active">
<div class="panel">
<div class="left"></div>
<div class="title">Active window</div>
<div class="button"></div>
<div class="close"></div>
<div class="min"></div>
</div>
<div class="inner">
<button>Text on button</button>
<br>
<span>Text in window</span>
</div>
</div>
<div class="window inactive">
<div class="panel">
<div class="left"></div>
<div class="title">Inactive window</div>
<div class="button"></div>
<div class="close"></div>
<div class="min"></div>
</div>
<div class="inner">
<button>Text on button</button>
<br>
<span>Text in window</span>
</div>
</div>
</div>
<script src="js/lzma-d.js"></script>
<script src="js/unpack.js"></script>
<script>
function htmlColor(color) {
return "#" + color;
}
function loadStructureTheme(structure) {
var active = document.querySelector('.window.active');
var activeInner = active.querySelector('.inner');
active.style.borderColor = htmlColor(structure.active.outer);
active.style.backgroundColor = htmlColor(structure.active.frame);
activeInner.style.borderColor = htmlColor(structure.active.inner);
activeInner.style.backgroundColor = htmlColor(structure.dtp.work);
var inactive = document.querySelector('.window.inactive');
var inactiveInner = inactive.querySelector('.inner');
inactive.style.borderColor = htmlColor(structure.inactive.outer);
inactive.style.backgroundColor = htmlColor(structure.inactive.frame);
inactiveInner.style.borderColor = htmlColor(structure.inactive.inner);
inactiveInner.style.backgroundColor = htmlColor(structure.dtp.work);
var title_list = document.querySelectorAll('.title');
for (let i=0; i<title_list.length; i++) {
let item = title_list[i];
item.style.color = htmlColor(structure.dtp.window_title);
}
for (let i=0; i<structure.bitmap.length; i++) {
let item = structure.bitmap[i];
let element = item.type?active:inactive;
let panel = element.querySelector('.panel');
let button = element.querySelector('.button');
let left = element.querySelector('.left');
let title = element.querySelector('.title');
if (item.kind === 3) {
panel.style.backgroundImage = "url("+item.base64+')';
panel.style.height = item.height+'px';
}
else if (item.kind === 2) {
button.style.backgroundImage = "url("+item.base64+')';
button.style.height = item.height+'px';
button.style.width = item.width+'px';
button.style.right = '-1px';
}
else if (item.kind === 1) {
left.style.backgroundImage = "url("+item.base64+')';
left.style.height = item.height+'px';
left.style.width = item.width+'px';
left.style.left = '-1px';
//title.style.left = (item.width-1)+'px';
}
}
for (let i=0; i<structure.button.length; i++) {
let item = structure.button[i];
if (item.type === 1) {
let inactive_min = inactive.querySelector('.min');
let active_min = active.querySelector('.min');
active_min.style.top = inactive_min.style.top = item.top+'px';
active_min.style.right = inactive_min.style.right = -structure.margin.left+structure.margin.right+item.left+'px';
active_min.style.height = inactive_min.style.height = item.height+'px';
active_min.style.width = inactive_min.style.width = item.width+'px';
} else {
let inactive_close = inactive.querySelector('.close');
let active_close = active.querySelector('.close');
active_close.style.top = inactive_close.style.top = item.top+'px';
active_close.style.right = inactive_close.style.right = -structure.margin.left+structure.margin.right+item.left+'px';
active_close.style.height = inactive_close.style.height = item.height+'px';
active_close.style.width = inactive_close.style.width = item.width+'px';
}
}
var guibutton = document.querySelectorAll('.window button');
for (let i=0; i<guibutton.length; i++) {
let item = guibutton[i];
item.style.backgroundColor = htmlColor(structure.dtp.work_button);
item.style.color = htmlColor(structure.dtp.work_button_text);
}
var guitext = document.querySelectorAll('.window span');
for (let i=0; i<guitext.length; i++) {
let item = guitext[i];
item.style.color = htmlColor(structure.dtp.work_text);
}
}
function readSkin() {
const SKIN_MAGIC = 0x4E494B53 // 'SKIN'
const KPACK_MAGIC = 0x4B43504B // 'KPACK'
const file = document.getElementById('file-input').files[0];
const reader = new FileReader();
reader.onload = function(e) {
let skinBytes = e.target.result;
let skinData = new DataView(skinBytes);
let skinObj = new Object();
magic = skinData.getUint32(0, true);
if (magic == KPACK_MAGIC) {
try {
skinData = unpack(skinData);
} catch (e) {
alert('Unpacking error: ' + e);
return;
}
}
magic = skinData.getUint32(0, true);
if (magic != SKIN_MAGIC) {
alert('The uploaded file is not a skin!');
return;
}
skinObj.version = skinData.getUint32(4, true); // second param - little endian
let params = skinData.getUint32(8, true),
buttons = skinData.getUint32(12, true),
bitmaps = skinData.getUint32(16, true);
// alert(params + " " + buttons + " " + bitmaps)
skinObj.margin = new Object();
skinObj.margin.right = skinData.getUint16(params + 4, true);
skinObj.margin.left = skinData.getUint16(params + 6, true);
skinObj.margin.bottom = skinData.getUint16(params + 8, true);
skinObj.margin.top = skinData.getUint16(params + 10, true);
let pad = function(num, len, rdx) {
num = num.toString(rdx);
while (num.length < len) num = "0" + num;
return num;
}
H6 = function(x) {return pad(x & 0x00FFFFFF, 6, 16)};
skinObj.active = new Object();
skinObj.active.inner = H6(skinData.getUint32(params + 12, true));
skinObj.active.outer = H6(skinData.getUint32(params + 16, true));
skinObj.active.frame = H6(skinData.getUint32(params + 20, true));
skinObj.inactive = new Object();
skinObj.inactive.inner = H6(skinData.getUint32(params + 24, true));
skinObj.inactive.outer = H6(skinData.getUint32(params + 28, true));
skinObj.inactive.frame = H6(skinData.getUint32(params + 32, true));
skinObj.dtp = new Object();
skinObj.dtp.size = skinData.getUint32(params + 36, true);
skinObj.dtp.taskbar = H6(skinData.getUint32(params + 40, true));
skinObj.dtp.taskbar_text = H6(skinData.getUint32(params + 44, true));
skinObj.dtp.work_dark = H6(skinData.getUint32(params + 48, true));
skinObj.dtp.work_light = H6(skinData.getUint32(params + 52, true));
skinObj.dtp.window_title = H6(skinData.getUint32(params + 56, true));
skinObj.dtp.work = H6(skinData.getUint32(params + 60, true));
skinObj.dtp.work_button = H6(skinData.getUint32(params + 64, true));
skinObj.dtp.work_button_text = H6(skinData.getUint32(params + 68, true));
skinObj.dtp.work_text = H6(skinData.getUint32(params + 72, true));
skinObj.dtp.work_graph = H6(skinData.getUint32(params + 76, true));
skinObj.button = [];
let pos = buttons;
while (skinData.getUint32(pos, true) != 0) {
let btn = new Object();
btn.type = skinData.getUint32(pos, true);
btn.left = skinData.getInt16(pos + 4, true);
btn.top = skinData.getInt16(pos + 6, true);
btn.width = skinData.getUint16(pos + 8, true);
btn.height = skinData.getUint16(pos + 10, true);
skinObj.button.push(btn);
pos += 12;
}
skinObj.bitmap = [];
pos = bitmaps;
while (skinData.getUint32(pos, true) != 0) {
let bmp = new Object();
bmp.kind = skinData.getUint16(pos, true);
bmp.type = skinData.getUint16(pos + 2, true);
let posbm = skinData.getUint32(pos + 4, true);
bmp.width = skinData.getUint32(posbm, true);
bmp.height = skinData.getUint32(posbm + 4, true);
let size = bmp.width*bmp.height*3;
let canvas = document.createElement("canvas");
canvas.width = bmp.width;
canvas.height = bmp.height;
let ctx = canvas.getContext("2d");
let canvasData = ctx.getImageData(0, 0, canvas.width, canvas.height);
for (let y = 0; y < bmp.height; y++) {
for (let x = 0; x < bmp.width; x++) {
let i = (x + y*bmp.width)*3;
let bb = skinData.getUint8(posbm + 8 + i);
let gg = skinData.getUint8(posbm + 8 + i + 1);
let rr = skinData.getUint8(posbm + 8 + i + 2);
i = (x + y*canvas.width)*4;
canvasData.data[i + 0] = rr;
canvasData.data[i + 1] = gg;
canvasData.data[i + 2] = bb;
canvasData.data[i + 3] = 255;
}
}
ctx.putImageData(canvasData, 0, 0);
bmp.base64 = canvas.toDataURL();
skinObj.bitmap.push(bmp);
pos += 8;
}
// alert(JSON.stringify(skinObj));
loadStructureTheme(skinObj);
let list = document.getElementsByClassName('window');
for (let i=0; i<list.length; i++) {
list[i].style.display = 'block';
}
}
reader.readAsArrayBuffer(file);
}
</script>
<footer>
<br><br>
<div style="float:right; text-align:right; margin-right: 100px;">
<a href="https://github.com/rgimad/kolibrios_skin_viewer">github.com/rgimad/kolibrios_skin_viewer</a><br><br>
</div>
</footer>
</body>
</html>