A web-based drawing app
git clone git://soophie.de/outline
blob: 27e966eea3d77e4fbbb60f29ec504263adb72b2d (28294 bytes)[doc][blame][raw]
1
const LANG = {2
en: {3
'tool.colors': 'Colors',4
'tool.scale': 'Scale',5
'tool.clear': 'Clear',6
'tool.capture': 'Capture',7
'action.multiplayer': 'Multiplayer',8
'action.account': 'Account',9
'action.settings': 'Settings',10
'notification.input-device.mouse.add': 'Mouse detected',11
'notification.input-device.touch.add': 'Touch detected',12
'notification.input-device.pencil.add': 'Pencil detected',13
'notification.input-device.gamepad.add': 'Gamepad detected',14
'notification.input-device.gamepad.remove': 'Gamepad removed',15
'notification.clear': 'Screen cleared',16
'multiplayer.join': 'Join',17
'multiplayer.join.info': 'Search for channel to join',18
'multiplayer.create': 'Create',19
'multiplayer.create.info': 'Create a new channel',20
'multiplayer.host': 'Host',21
'multiplayer.host.info': 'Host current state as channel',22
'multiplayer.invite-friends': 'Invite friends',23
'multiplayer.invite-friends.info': 'Share channel with others',24
'channel.information': 'Info',25
'channel.information.info': 'Customize channel info',26
'channel.private': 'Private',27
'channel.private.info': 'Prevent channel being listed',28
'channel.permanent': 'Permanent',29
'channel.permanent.info': 'Keep channel permanent online',30
'channel.roles': 'Roles',31
'channel.roles.info': 'Manage user permissions',32
'account.upgrade': 'Upgrade',33
'account.upgrade.info': 'Unlock all fancy features',34
'account.profile': 'Profile',35
'account.profile.info': 'View your profile',36
'account.support': 'Support',37
'account.support.info': 'Donate a cup of coffee',38
'account.feedback': 'Feedback',39
'account.feedback.info': 'Improve our service',40
'account.logout': 'Log out',41
'account.logout.info': 'Sign out from account',42
'setting.help': 'Help',43
'setting.help.info': 'Learn more about the features',44
'setting.language': 'Language',45
'setting.language.info': 'Choose preferred language',46
'setting.language.default': 'Default language',47
'setting.input-device': 'Input Device',48
'setting.input-device.info': 'Choose preferred input device',49
'setting.input-device.default': 'Default input device',50
'setting.input-device.empty': 'No devices detected',51
'setting.input-device.mouse': 'Mouse',52
'setting.input-device.touch': 'Touch',53
'setting.input-device.pencil': 'Pencil',54
'setting.input-device.gamepad': 'Gamepad',55
'setting.input-device.touch.info': 'Finger interaction',56
'setting.input-device.pencil.info': 'Stylus pen, touch disabled',57
'setting.input-device.gamepad.info': 'Stadia Controller supported',58
'setting.dark-mode': 'Dark Mode',59
'setting.dark-mode.info': 'More pleasant for your eyes',60
'setting.appearance': 'Appearance',61
'setting.appearance.info': 'Customize how you want'62
},63
de: {64
'tool.colors': 'Farben',65
'tool.scale': 'Skalierung',66
'tool.clear': 'Löschen',67
'tool.capture': 'Capture',68
'action.multiplayer': 'Mehrspieler',69
'action.account': 'Konto',70
'action.settings': 'Einstellungen',71
'notification.input-device.mouse.add': 'Maus erkannt',72
'notification.input-device.touch.add': 'Touch erkannt',73
'notification.input-device.pencil.add': 'Stift erkannt',74
'notification.input-device.gamepad.add': 'Gamepad erkannt',75
'notification.input-device.gamepad.remove': 'Gamepad entfernt',76
'notification.clear': 'Bildschirm gelöscht',77
'multiplayer.join': 'Beitreten',78
'multiplayer.join.info': 'Suche nach beitretbaren Channels',79
'multiplayer.create': 'Erstellen',80
'multiplayer.create.info': 'Erstelle einen Channel',81
'multiplayer.host': 'Hosten',82
'multiplayer.invite-friends': 'Freunde einladen',83
'multiplayer.invite-friends.info': 'Teile Channel mit anderen',84
'multiplayer.host.info': 'Hoste aktuellen Stand als Channel',85
'channel.information': 'Info',86
'channel.information.info': 'Personalisiere Channel Info',87
'channel.private': 'Privat',88
'channel.private.info': 'Verhindere Channel Listung',89
'channel.permanent': 'Permanent',90
'channel.permanent.info': 'Behalte Channel dauerhaft online',91
'channel.roles': 'Rollen',92
'channel.roles.info': 'Verwalte Nutzerberechtigungen',93
'account.upgrade': 'Upgrade',94
'account.upgrade.info': 'Schalte alle Features frei',95
'account.profile': 'Profil',96
'account.profile.info': 'Zu Profil gehen',97
'account.support': 'Unterstützen',98
'account.support.info': 'Spende eine Tasse Kaffee',99
'account.feedback': 'Feedback',100
'account.feedback.info': 'Verbessere unseren Service',101
'account.logout': 'Abmelden',102
'account.logout.info': 'Von Konto abmelden',103
'setting.help': 'Hilfe',104
'setting.help.info': 'Erfahre mehr über die Funktionen',105
'setting.language': 'Sprache',106
'setting.language.info': 'Wähle bevorzugte Sprache',107
'setting.language.default': 'Standard Sprache',108
'setting.input-device': 'Eingabegerät',109
'setting.input-device.info': 'Wähle bevorzugtes Eingabegerät',110
'setting.input-device.default': 'Standard Eingabegerät',111
'setting.input-device.empty': 'Keine Geräte erkannt',112
'setting.input-device.mouse': 'Maus',113
'setting.input-device.touch': 'Touch',114
'setting.input-device.pencil': 'Stift',115
'setting.input-device.gamepad': 'Gamepad',116
'setting.input-device.touch.info': 'Fingerinteraktion',117
'setting.input-device.pencil.info': 'Stylus Stift, touch deaktiviert',118
'setting.input-device.gamepad.info': 'Stadia Controller unterstützt',119
'setting.dark-mode': 'Dark Mode',120
'setting.dark-mode.info': 'Angenehmer für deine Augen',121
'setting.appearance': 'Erscheinungsbild',122
'setting.appearance.info': 'Gestalte wie du möchtest'123
}124
};126
const KEY_BINDING = {127
0: 'A',128
1: 'B',129
2: 'X',130
3: 'Y',131
4: 'L1',132
5: 'R1',133
6: 'L2',134
7: 'R2',135
8: 'Option',136
9: 'Menu',137
10: 'L3',138
11: 'R3',139
12: 'Up',140
13: 'Down',141
14: 'Left',142
15: 'Right',143
16: 'Power',144
17: 'Assist',145
18: 'Capture'146
};148
const COLORS = {149
0: '#FFCDD2',150
1: '#E57373',151
2: '#F44336',152
3: '#D32F2F',153
4: '#B71C1C',154
5: '#F8BBD0',155
6: '#F06292',156
7: '#E91E63',157
8: '#C2185B',158
9: '#880E4F',159
10: '#E1BEE7',160
11: '#BA68C8',161
12: '#9C27B0',162
13: '#7B1FA2',163
14: '#4A148C',164
15: '#BBDEFB',165
16: '#64B5F6',166
17: '#2196F3',167
18: '#1976D2',168
19: '#0D47A1',169
20: '#B2EBF2',170
21: '#4DD0E1',171
22: '#00BCD4',172
23: '#0097A7',173
24: '#006064',174
25: '#B2DFDB',175
26: '#4DB6AC',176
27: '#009688',177
28: '#00796B',178
29: '#004D40',179
30: '#C8E6C9',180
31: '#81C784',181
32: '#4CAF50',182
33: '#388E3C',183
34: '#1B5E20',184
35: '#FFF9C4',185
36: '#FFF176',186
37: '#FFEB3B',187
38: '#FBC02D',188
39: '#F57F17',189
40: '#FFE0B2',190
41: '#FFB74D',191
42: '#FF9800',192
43: '#F57C00',193
44: '#E65100',194
45: '#D7CCC8',195
46: '#A1887F',196
47: '#795548',197
48: '#5D4037',198
49: '#3E2723',199
50: '#F5F5F5',200
51: '#E0E0E0',201
52: '#9E9E9E',202
53: '#616161',203
54: '#141414'204
};206
const COLOR = {207
0: '#141414',208
1: '#F44336',209
2: '#2196F3',210
3: '#009688',211
4: '#FFEB3B',212
5: '#9C27B0'213
};215
const COLORS_LENGTH = Object.values(COLORS).length;216
const COLOR_LENGTH = Object.values(COLOR).length;218
let canvas;219
let overlay;220
let g;221
let o;222
let ad;223
let hotbar;224
let toolbar;225
let actionbar;226
let colors;227
let actions;228
let tools;229
let modals;230
let device_options;231
let device_empty;232
let current_modal;233
let current_tab;234
let modal_colors;235
let colors_modal;236
let capture_modal;237
let clear_modal;238
let scale_range;240
let device;241
let devices = {242
mouse: false,243
touch: false,244
pen: false,245
gamepad: false246
};247
let fallback_device;249
let lang = 'en';250
let notification_code;252
let cache;253
let point;254
let last;255
let start;256
let index = 0;257
let radius = 14;258
let lock_x = false;259
let lock_y = false;260
let draw;261
let erase;262
let pressed = {};263
let arrow_y = 0;264
let arrow_x = 0;265
let left_modal = false;267
window.addEventListener('load', init);269
function init() {270
canvas = document.querySelector('#canvas');271
canvas.width = window.innerWidth;272
canvas.height = window.innerHeight;273
g = canvas.getContext('2d');274
overlay = document.querySelector('#overlay');275
overlay.width = window.innerWidth;276
overlay.height = window.innerHeight;277
o = overlay.getContext('2d');278
window.onresize = function() {279
cache = g.getImageData(0, 0, canvas.width, canvas.height);280
canvas.width = window.innerWidth;281
canvas.height = window.innerHeight;282
g.putImageData(cache, 0, 0);283
cache = o.getImageData(0, 0, overlay.width, overlay.height);284
overlay.width = window.innerWidth;285
overlay.height = window.innerHeight;286
o.putImageData(cache, 0, 0);287
}288
let ripple = document.querySelectorAll('.ripple');289
for(let item of ripple) {290
item.addEventListener('pointerdown', function(event) {291
item.classList.add('ripple-active');292
});293
}294
document.addEventListener('touchmove', function(event) {295
let { target } = event;296
if(target !== scale_range) {297
event.preventDefault();298
}299
}, { passive: false });300
document.addEventListener('pointerup', function(event) {301
for(let item of ripple) {302
item.classList.remove('ripple-active');303
}304
});305
device_options = document.querySelectorAll('.settings-modal .device-tab .item[data-device]');306
device_empty = document.querySelector('.settings-modal .device-tab .item.empty');308
ad = document.querySelector('.controls .ad');309
hotbar = document.querySelector('.controls .hotbar');310
toolbar = document.querySelector('.controls .toolbar');311
actionbar = document.querySelector('.controls .actionbar');312
colors = Array.from(hotbar.querySelectorAll('.color'));313
actions = document.querySelectorAll('.actionbar .action');314
tools = document.querySelectorAll('.toolbar .tool');315
modals = document.querySelectorAll('.modal');316
modal_colors = document.querySelectorAll('.colors-modal .color');317
colors_modal = document.querySelector('.toolbar .tool[data-modal="colors"]');318
capture_modal = document.querySelector('.toolbar .tool[data-modal="capture"]');319
clear_modal = document.querySelector('.toolbar .tool[data-modal="clear"]');320
scale_range = document.querySelector('.scale-modal input[type="range"]');321
for(let i in colors) {322
if(COLOR_LENGTH > i) {323
if(i == index) {324
colors[i].classList.add('active');325
}326
colors[i].style.background = COLOR[i];327
colors[i].addEventListener('pointerdown', function(event) {328
for(let j in colors) {329
if(COLOR_LENGTH > j) {330
if(j == i) {331
index = j;332
}333
colors[j].classList[j == i ? 'add' : 'remove']('active');334
}335
}336
});337
}338
}339
for(let i in modal_colors) {340
if(COLORS_LENGTH > i) {341
modal_colors[i].style.background = COLORS[i];342
}343
}344
document.addEventListener('dragstart', function(event) {345
event.preventDefault();346
});347
document.addEventListener('contextmenu', function(event) {348
event.preventDefault();349
});350
scale_range.addEventListener('input', function(event) {351
radius = parseInt(scale_range.value);352
left_modal = false;353
point.x = parseInt(window.innerWidth / 2);354
point.y = parseInt(window.innerHeight / 2);355
});356
document.addEventListener('wheel', function(event) {357
if(device !== 'gamepad') {358
let { deltaY } = event;359
let y = deltaY < 0 ? 1 : -1;360
if(radius + y > 2 - 1 && radius + y < 50 + 1) {361
radius += y;362
scale_range.value = radius;363
}364
}365
});366
document.addEventListener('wheel', function(event) {367
if(device !== 'gamepad') {368
let { ctrlKey } = event;369
if(ctrlKey) {370
event.preventDefault();371
return;372
}373
}374
}, { passive: false });375
canvas.addEventListener('pointerdown', function(event) {376
let { layerX, layerY, buttons, pointerType, target } = event;377
if(!devices.touch && pointerType === 'touch') {378
devices.touch = true;379
if(device) {380
show_notification('notification.input-device.touch.add');381
}382
}383
if(!devices.pen && pointerType === 'pen') {384
devices.pen = true;385
show_notification('notification.input-device.pencil.add');386
}387
if(device !== 'gamepad') {388
if(!lock_x) {389
start.x = layerX;390
}391
if(!lock_y) {392
start.y = layerY;393
}394
if(current_modal && target === canvas) {395
toggle_modal(current_modal);396
left_modal = true;397
}398
else {399
left_modal = false;400
}401
if(device === pointerType) {402
if(!current_modal && !left_modal) {403
if(start.x !== null && start.y !== null) {404
if(buttons == 1) {405
draw_line(start, null, radius, COLOR[index]);406
}407
if(buttons == 2) {408
draw_line(start, null, radius, 'white');409
erase = true;410
last.x = null;411
last.y = null;412
}413
}414
}415
ad.style.pointerEvents = 'none';416
hotbar.style.pointerEvents = 'none';417
toolbar.style.pointerEvents = 'none';418
actionbar.style.pointerEvents = 'none';419
for(let modal of modals) {420
modal.style.pointerEvents = 'none';421
}422
}423
}424
});425
document.addEventListener('pointermove', function(event) {426
let { layerX, layerY, target, pointerType, buttons } = event;427
if(!devices.mouse && pointerType === 'mouse') {428
devices.mouse = true;429
}430
if(device !== 'gamepad') {431
draw = buttons == 1;432
erase = buttons == 2;433
if(buttons == 3) {434
draw = true;435
erase = true;436
}437
if(start.x !== null || start.y !== null) {438
last = start;439
start = {440
x: null,441
y: null442
};443
}444
if(device === pointerType) {445
left_modal = false;446
if(target == canvas) {447
if(!lock_x) {448
point.x = layerX;449
}450
if(!lock_y) {451
point.y = layerY;452
}453
}454
if(draw && erase) {455
last.x = null;456
last.y = null;457
}458
}459
if(!document.hasFocus()) {460
draw = false;461
erase = false;462
}463
}464
});465
document.addEventListener('pointerout', function(event) {466
if(device !== 'gamepad') {467
if(!lock_x && !lock_y) {468
point.x = null;469
point.y = null;470
}471
}472
});473
document.addEventListener('pointerup', function(event) {474
if(device !== 'gamepad') {475
let { buttons } = event;476
draw = buttons == 1;477
erase = buttons == 2;478
last.x = null;479
last.y = null;480
ad.style.pointerEvents = '';481
hotbar.style.pointerEvents = '';482
toolbar.style.pointerEvents = '';483
actionbar.style.pointerEvents = '';484
for(let modal of modals) {485
modal.style.pointerEvents = '';486
}487
}488
});489
document.addEventListener('keydown', function(event) {490
let { code, ctrlKey, shiftKey, altKey } = event;491
if(device !== 'gamepad') {492
let lock = event.getModifierState("CapsLock");493
if(!ctrlKey && !shiftKey && !altKey) {494
if(code === 'KeyX') {495
lock_y = !lock_y;496
lock_x = false;497
}498
if(code === 'KeyZ') {499
lock_x = !lock_x;500
lock_y = false;501
}502
if(!lock) {503
if(code.startsWith('Digit')) {504
let number = parseInt(code.substr(5)) - 1;505
if(number >= 0 && number < COLOR_LENGTH) {506
index = number;507
for(let i in colors) {508
if(COLOR_LENGTH > i) {509
colors[i].classList[i == index ? 'add' : 'remove']('active');510
}511
}512
}513
}514
}515
}516
}517
if(code === 'Escape') {518
if(current_tab) {519
close_tab(current_tab);520
}521
else if(current_modal) {522
toggle_modal(current_modal);523
}524
}525
});526
point = { x: null, y: null };527
last = { x: null, y: null };528
start = { x: null, y: null };529
update();530
}532
function read_input(gamepad) {533
let input = {534
button: {},535
axes: {}536
};537
for(let [ id, key ] of Object.entries(KEY_BINDING)) {538
if(gamepad.buttons[id]) {539
input.button[key] = gamepad.buttons[id].pressed;540
}541
}542
input.axes['Left'] = {543
x: gamepad.axes[0],544
y: gamepad.axes[1]545
};546
input.axes['Right'] = {547
x: gamepad.axes[2],548
y: gamepad.axes[3]549
};550
return input;551
}553
function key_pressed(key, input, func) {554
if(input.button[key]) {555
if(!pressed[key]) {556
pressed[key] = true;557
if(func) {558
func();559
}560
}561
}562
else {563
pressed[key] = false;564
}565
}567
function update() {568
if(radius < 2) {569
radius = 2;570
}571
if(radius > 50) {572
radius = 50;573
}574
let gamepad = navigator.getGamepads()[0];575
if(gamepad) {576
if(!devices.gamepad) {577
devices.gamepad = true;578
show_notification('notification.input-device.gamepad.add');579
if(gamepad.vibrationActuator) {580
gamepad.vibrationActuator.playEffect("dual-rumble", {581
startDelay: 0,582
duration: 100,583
weakMagnitude: 1.0,584
strongMagnitude: 1.0585
});586
}587
}588
if(device === 'gamepad') {589
if(point.x == null && point.y == null) {590
point.x = parseInt(window.innerWidth / 2);591
point.y = parseInt(window.innerHeight / 2);592
}593
let input = read_input(gamepad);594
let speed = 4;595
draw = input.button['A'];596
erase = input.button['B'];597
if(pressed['L2'] && !pressed['R2']) {598
speed = 10;599
}600
if(pressed['R2'] && !pressed['L2']) {601
speed = 1;602
}603
// move604
if(!lock_x) {605
point.x += input.axes['Left'].x * speed;606
if(point.x < 0 ) {607
point.x = 0;608
}609
if(point.x > window.innerWidth) {610
point.x = window.innerWidth;611
}612
}613
if(!lock_y) {614
point.y += input.axes['Left'].y * speed;615
if(point.y < 0) {616
point.y = 0;617
}618
if(point.y > window.innerHeight) {619
point.y = window.innerHeight;620
}621
}622
// colors623
key_pressed('Option', input, function() {624
toggle_modal(colors_modal);625
});626
// capture627
key_pressed('Capture', input, function() {628
toggle_modal(capture_modal);629
});630
// draw631
key_pressed('A', input, function() {632
last.x = null;633
last.y = null;634
if(!current_modal) {635
left_modal = false;636
}637
});638
// erase639
key_pressed('B', input, function() {640
last.x = null;641
last.y = null;642
if(current_tab) {643
close_tab(current_tab);644
left_modal = true;645
}646
else if(current_modal) {647
toggle_modal(current_modal);648
left_modal = true;649
}650
else {651
left_modal = false;652
}653
});654
// sprint655
key_pressed('L2', input);656
// sneak657
key_pressed('R2', input);658
// clear659
key_pressed('Y', input, function() {660
toggle_modal(clear_modal);661
});662
// radius663
let y = -(input.axes['Right'].y / 2);664
if(y !== 0 && radius + y > 2 && radius + y < 50 + 1) {665
radius += y;666
scale_range.value = radius;667
}668
// lock y669
key_pressed('L3', input, function() {670
lock_y = !lock_y;671
lock_x = false;672
});673
// lock x674
key_pressed('R3', input, function() {675
lock_x = !lock_x;676
lock_y = false;677
});678
// color-wheel left679
key_pressed('L1', input, function() {680
if(index > 0) {681
index--;682
for(let i in colors) {683
if(COLOR_LENGTH > i) {684
colors[i].classList[i == index ? 'add' : 'remove']('active');685
}686
}687
}688
});689
// color-wheel right690
key_pressed('R1', input, function() {691
if(index < COLOR_LENGTH - 1) {692
index++;693
for(let i in colors) {694
if(COLOR_LENGTH > i) {695
colors[i].classList[i == index ? 'add' : 'remove']('active');696
}697
}698
}699
});700
key_pressed('Up', input, function() {701
if(arrow_y > 0) {702
arrow_y--;703
}704
});705
key_pressed('Down', input, function() {706
if(arrow_y < 10) {707
arrow_y++;708
}709
});710
key_pressed('Left', input, function() {711
if(arrow_x > 0) {712
arrow_x--;713
}714
});715
key_pressed('Right', input, function() {716
if(arrow_x < 4) {717
arrow_x++;718
}719
});720
}721
}722
else {723
if(devices.gamepad) {724
devices.gamepad = false;725
show_notification('notification.input-device.gamepad.remove');726
}727
}728
if(device !== 'gamepad') {729
let pos = arrow_y * 5 + arrow_x;730
if(modal_colors[pos].classList.contains('focus')) {731
modal_colors[pos].classList.remove('focus');732
}733
}734
// device mouse option735
let mouse_option = document.querySelector('.settings-modal .device-tab .item[data-device="mouse"]');736
if(devices.mouse && mouse_option.classList.contains('inactive')) {737
mouse_option.classList.remove('inactive');738
if(!device) {739
device = 'mouse';740
fallback_device = 'mouse';741
mouse_option.classList.add('active');742
}743
}744
// device touch option745
let touch_option = document.querySelector('.settings-modal .device-tab .item[data-device="touch"]');746
if(devices.touch && touch_option.classList.contains('inactive')) {747
touch_option.classList.remove('inactive');748
if(!device) {749
device = 'touch';750
fallback_device = 'touch';751
touch_option.classList.add('active');752
}753
}754
// device pen option755
let pen_option = document.querySelector('.settings-modal .device-tab .item[data-device="pen"]');756
if(devices.pen && pen_option.classList.contains('inactive')) {757
pen_option.classList.remove('inactive');758
if(!device) {759
device = 'pen';760
fallback_device = 'pen';761
pen_option.classList.add('active');762
}763
}764
// device gamepad option765
let gamepad_option = document.querySelector('.settings-modal .device-tab .item[data-device="gamepad"]');766
if(devices.gamepad && gamepad_option.classList.contains('inactive')) {767
gamepad_option.classList.remove('inactive');768
if(!device) {769
device = 'gamepad';770
fallback_device = 'gamepad';771
gamepad_option.classList.add('active');772
}773
}774
if(!devices.gamepad && !gamepad_option.classList.contains('inactive')) {775
gamepad_option.classList.add('inactive');776
gamepad_option.classList.remove('active');777
if(device === 'gamepad') {778
if(device !== fallback_device) {779
device = fallback_device;780
let option = document.querySelector(`.settings-modal .device-tab .item[data-device="${device}"]`);781
option.classList.add('active');782
}783
else {784
device = null;785
}786
point.x = null;787
point.y = null;788
last.x = null;789
last.y = null;790
}791
}792
// cursor visible793
canvas.style.cursor = device === 'mouse' ? 'none' : 'default';794
if(!current_modal && !left_modal) {795
// pencil796
if(draw && !erase) {797
if(point.x !== null && point.y !== null) {798
if(last.x !== null && last.y !== null) {799
draw_line(point, last, radius, COLOR[index]);800
}801
}802
}803
// eraser804
if(erase && !draw) {805
if(point.x !== null && point.y !== null) {806
if(last.x !== null && last.y !== null) {807
draw_line(point, last, radius, 'white');808
}809
}810
}811
}812
// at least one device813
let one_device = Object.values(devices).some(function(device) {814
return device;815
});816
if(one_device && !device_empty.classList.contains('hidden')) {817
device_empty.classList.add('hidden');818
}819
if(!one_device && device_empty.classList.contains('hidden')) {820
device_empty.classList.remove('hidden');821
}822
// navigate colors823
let pos = arrow_y * 5 + arrow_x;824
if(device === 'gamepad') {825
for(let [ i, item ] of Object.entries(modal_colors)) {826
item.classList[parseInt(i) == pos ? 'add' : 'remove']('focus');827
}828
}829
render();830
if(draw || erase) {831
last.x = point.x;832
last.y = point.y;833
}834
requestAnimationFrame(update);835
}837
function render() {838
if(radius < 2) {839
radius = 2;840
}841
o.clearRect(0, 0, window.innerWidth, window.innerHeight);842
if(point.x !== null && point.y !== null) {843
let touch_device = (device === 'touch' || device === 'pen');844
if(touch_device) {845
if(!left_modal) {846
o.fillStyle = 'white';847
o.beginPath();848
o.arc(point.x, point.y, parseInt(radius) + 2, 2 * Math.PI, 0);849
o.fill();850
o.fillStyle = COLOR[index];851
o.beginPath();852
o.arc(point.x, point.y, parseInt(radius), 2 * Math.PI, 0);853
o.fill();854
}855
}856
else {857
o.fillStyle = 'white';858
o.beginPath();859
o.arc(point.x, point.y, parseInt(radius) + 2, 2 * Math.PI, 0);860
o.fill();861
o.fillStyle = COLOR[index];862
o.beginPath();863
o.arc(point.x, point.y, parseInt(radius), 2 * Math.PI, 0);864
o.fill();865
}866
}867
if(!left_modal) {868
if(erase && !draw) {869
o.beginPath();870
o.lineWidth = 2;871
o.strokeStyle = 'white';872
o.moveTo(point.x, point.y - parseInt(radius) * 0.5);873
o.lineTo(point.x, point.y + parseInt(radius) * 0.5);874
o.moveTo(point.x - parseInt(radius) * 0.5, point.y);875
o.lineTo(point.x + parseInt(radius) * 0.5, point.y);876
o.stroke();877
}878
}879
if(lock_x || lock_y) {880
o.beginPath();881
o.lineWidth = 2;882
o.strokeStyle = 'white';883
if(lock_x) {884
o.moveTo(point.x, point.y - parseInt(radius));885
o.lineTo(point.x, point.y + parseInt(radius));886
}887
if(lock_y) {888
o.moveTo(point.x - parseInt(radius), point.y);889
o.lineTo(point.x + parseInt(radius), point.y);890
}891
o.stroke();892
}893
}895
function draw_line(point, last, radius, color) {896
if(last) {897
g.lineCap = 'round';898
g.strokeStyle = color;899
g.lineWidth = 2 * parseInt(radius);900
g.beginPath();901
g.moveTo(last.x + 0.5, last.y + 0.5);902
g.lineTo(point.x + 0.5, point.y + 0.5);903
g.stroke();904
}905
else {906
g.fillStyle = color;907
g.beginPath();908
g.arc(point.x, point.y, parseInt(radius), 2 * Math.PI, 0);909
g.fill();910
}911
}913
function change_device(element) {914
let value = element.dataset.device;915
if(devices[value]) {916
device = value;917
for(let item of device_options) {918
item.classList[element === item ? 'add' : 'remove']('active');919
}920
if(device !== 'gamepad') {921
point.x = null;922
point.y = null;923
last.x = null;924
last.y = null;925
}926
}927
}929
function change_language(element) {930
let code = element.dataset.code;931
lang = code;932
let items = document.querySelectorAll('[data-lang]');933
for(let item of items) {934
let prime = item.dataset.prime === 'true';935
let beta = item.dataset.beta === 'true';936
let type = item.dataset.type;937
let text = LANG[code][item.dataset.lang];938
let prime_content;939
let beta_content;940
if(prime) {941
prime_content = item.querySelector('b.prime-badge').textContent;942
}943
if(beta) {944
beta_content = item.querySelector('b.beta-badge').textContent;945
}946
if(text) {947
if(type === 'tooltip') {948
item.dataset.title = text;949
}950
else {951
item.textContent = text;952
}953
if(prime && type !== 'tooltip') {954
item.innerHTML += `<b class="prime-badge">${prime_content}</b>`;955
}956
if(beta && type !== 'tooltip') {957
item.innerHTML += `<b class="beta-badge">${beta_content}</b>`;958
}959
}960
}961
let options = document.querySelectorAll('.language-tab .item');962
for(let option of options) {963
option.classList[option === element ? 'add' : 'remove']('active');964
}965
}967
function toggle_modal(element) {968
let code = element.dataset.modal;969
let modal = document.querySelector(`.${code}-modal`);970
if(modal) {971
let open = modal.classList.contains('hidden');972
if(open) {973
current_modal = element;974
for(let item of actions) {975
if(item !== element) {976
item.classList.remove('active');977
}978
}979
for(let item of tools) {980
if(item !== element) {981
item.classList.remove('active');982
}983
}984
for(let item of modals) {985
if(item !== modal) {986
item.classList.add('hidden');987
}988
let main = item.querySelector('.main');989
if(main) {990
main.classList.remove('hidden');991
main.style.marginLeft = '0';992
}993
let tab_list = item.querySelector('.tab-list');994
if(tab_list) {995
let tabs = tab_list.querySelectorAll('.tab');996
for(let tab of tabs) {997
tab.classList.add('hidden');998
}999
}1000
}1001
if(code === 'colors') {1002
if(device === 'gamepad') {1003
modal_colors[0].classList.add('focus');1004
arrow_x = 0;1005
arrow_y = 0;1006
}1007
}1008
}1009
else {1010
current_modal = null;1011
}1012
element.classList[open ? 'add' : 'remove']('active');1013
modal.classList[open ? 'remove' : 'add']('hidden');1014
modal.animate([1015
{ opacity: 0, marginTop: '-6px' },1016
{ opacity: 1, marginTop: '0' }1017
], {1018
duration: 100,1019
fill: 'both'1020
});1021
}1022
}1024
function open_tab(element) {1025
let code = element.dataset.tab;1026
let main = element.parentNode.parentNode1027
let tab = document.querySelector(`.${code}-tab`);1028
if(tab) {1029
main.style.marginLeft = '-100%';1030
current_tab = tab.querySelector('.back');1031
tab.classList.remove('hidden');1032
main.classList.add('hidden');1033
}1034
}1036
function close_tab(element) {1037
let modal = element.parentNode.parentNode.parentNode.parentNode;1038
let main = modal.querySelector('.main');1039
let tab_list = modal.querySelector('.tab-list');1040
let tabs = tab_list.querySelectorAll('.tab');1041
for(let tab of tabs) {1042
tab.classList.add('hidden');1043
}1044
main.classList.remove('hidden');1045
main.style.marginLeft = '0';1046
current_tab = null;1047
}1049
function show_notification(message) {1050
let code = uuid();1051
notification_code = code;1052
let element = document.querySelector('.notification');1053
let content = element.querySelector('.content');1054
content.textContent = LANG[lang][message];1055
element.animate([1056
{ opacity: 0 },1057
{ opacity: 1}1058
], {1059
duration: 200,1060
fill: 'both'1061
});1062
setTimeout(function() {1063
if(notification_code === code) {1064
element.animate([1065
{ opacity: 1 },1066
{ opacity: 0}1067
], {1068
duration: 200,1069
fill: 'both'1070
});1071
}1072
}, 2000);1073
}1075
function uuid() {1076
return 'xxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {1077
let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);1078
return v.toString(16);1079
});1080
}1082
function clear_screen() {1083
g.clearRect(0, 0, canvas.width, canvas.height);1084
show_notification('notification.clear');1085
toggle_modal(clear_modal);1086
}