so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: 9e9c3f200f25413e46527201ca8da8b6e0cc9de8 (25520 bytes)[doc][blame][raw]

1const LANG = {

2 en: {

3 'tool.colors': 'Colors',

4 'tool.scale': 'Scale',

5 'tool.clear': 'Clear',

6 'tool.screenshot': 'Screenshot',

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 'multiplayer.join': 'Join',

16 'multiplayer.join.info': 'Search for channel to join',

17 'multiplayer.create': 'Create',

18 'multiplayer.create.info': 'Create a new channel',

19 'multiplayer.host': 'Host',

20 'multiplayer.host.info': 'Host current state as channel',

21 'channel.information': 'Info',

22 'channel.information.info': 'Customize channel info',

23 'channel.invite-friends': 'Invite friends',

24 'channel.invite-friends.info': 'Share channel with others',

25 'channel.private': 'Private',

26 'channel.private.info': 'Prevent channel being listed',

27 'channel.permanent': 'Permanent',

28 'channel.permanent.info': 'Keep channel permanent online',

29 'channel.roles': 'Roles',

30 'channel.roles.info': 'Manage user permissions',

31 'account.profile': 'Profile',

32 'account.profile.info': 'View your profile',

33 'account.support': 'Support',

34 'account.support.info': 'Donate a cup of coffee',

35 'account.logout': 'Log out',

36 'account.logout.info': 'Sign out from account',

37 'setting.language': 'Language',

38 'setting.language.info': 'Choose preferred language',

39 'setting.language.default': 'Default language',

40 'setting.input-device': 'Input Device',

41 'setting.input-device.info': 'Choose preferred input device',

42 'setting.input-device.default': 'Default input device',

43 'setting.input-device.empty': 'No devices detected',

44 'setting.input-device.mouse': 'Mouse',

45 'setting.input-device.touch': 'Touch',

46 'setting.input-device.pencil': 'Pencil',

47 'setting.input-device.gamepad': 'Gamepad',

48 'setting.input-device.touch.info': 'Finger interaction',

49 'setting.input-device.pencil.info': 'Stylus pen, touch disabled',

50 'setting.input-device.gamepad.info': 'Stadia Controller supported',

51 'setting.dark-mode': 'Dark Mode',

52 'setting.dark-mode.info': 'More pleasant for your eyes',

53 'setting.appearance': 'Appearance',

54 'setting.appearance.info': 'Customize how you want'

55 },

56 de: {

57 'tool.colors': 'Farben',

58 'tool.scale': 'Skalierung',

59 'tool.clear': 'Löschen',

60 'tool.screenshot': 'Screenshot',

61 'action.multiplayer': 'Mehrspieler',

62 'action.account': 'Konto',

63 'action.settings': 'Einstellungen',

64 'notification.input-device.mouse.add': 'Maus erkannt',

65 'notification.input-device.touch.add': 'Touch erkannt',

66 'notification.input-device.pencil.add': 'Stift erkannt',

67 'notification.input-device.gamepad.add': 'Gamepad erkannt',

68 'notification.input-device.gamepad.remove': 'Gamepad entfernt',

69 'multiplayer.join': 'Beitreten',

70 'multiplayer.join.info': 'Suche nach beitretbaren Channels',

71 'multiplayer.create': 'Erstellen',

72 'multiplayer.create.info': 'Erstelle einen Channel',

73 'multiplayer.host': 'Hosten',

74 'multiplayer.host.info': 'Hoste aktuellen Stand als Channel',

75 'channel.information': 'Info',

76 'channel.information.info': 'Personalisiere Channel Info',

77 'channel.invite-friends': 'Freunde einladen',

78 'channel.invite-friends.info': 'Teile Channel mit anderen',

79 'channel.private': 'Privat',

80 'channel.private.info': 'Verhindere Channel Listung',

81 'channel.permanent': 'Permanent',

82 'channel.permanent.info': 'Behalte Channel dauerhaft online',

83 'channel.roles': 'Rollen',

84 'channel.roles.info': 'Verwalte Nutzerberechtigungen',

85 'account.profile': 'Profil',

86 'account.profile.info': 'Zu Profil gehen',

87 'account.support': 'Unterstützen',

88 'account.support.info': 'Spende eine Tasse Kaffee',

89 'account.logout': 'Abmelden',

90 'account.logout.info': 'Von Konto abmelden',

91 'setting.language': 'Sprache',

92 'setting.language.info': 'Wähle bevorzugte Sprache',

93 'setting.language.default': 'Standard Sprache',

94 'setting.input-device': 'Eingabegerät',

95 'setting.input-device.info': 'Wähle bevorzugtes Eingabegerät',

96 'setting.input-device.default': 'Standard Eingabegerät',

97 'setting.input-device.empty': 'Keine Geräte erkannt',

98 'setting.input-device.mouse': 'Maus',

99 'setting.input-device.touch': 'Touch',

100 'setting.input-device.pencil': 'Stift',

101 'setting.input-device.gamepad': 'Gamepad',

102 'setting.input-device.touch.info': 'Fingerinteraktion',

103 'setting.input-device.pencil.info': 'Stylus Stift, touch deaktiviert',

104 'setting.input-device.gamepad.info': 'Stadia Controller unterstützt',

105 'setting.dark-mode': 'Dark Mode',

106 'setting.dark-mode.info': 'Angenehmer für deine Augen',

107 'setting.appearance': 'Erscheinungsbild',

108 'setting.appearance.info': 'Gestalte wie du möchtest'

109 }

110};

111

112const PRIME_CODE = '<b class="prime-badge">Prime</b>';

113const BETA_CODE = '<b class="beta-badge">Beta</b>';

114

115const KEY_BINDING = {

116 0: 'A',

117 1: 'B',

118 2: 'X',

119 3: 'Y',

120 4: 'L1',

121 5: 'R1',

122 6: 'L2',

123 7: 'R2',

124 8: 'Option',

125 9: 'Menu',

126 10: 'L3',

127 11: 'R3',

128 12: 'Up',

129 13: 'Down',

130 14: 'Left',

131 15: 'Right',

132 16: 'Power',

133 17: 'Assist',

134 18: 'Capture'

135};

136

137const COLORS = {

138 0: '#FFCDD2',

139 1: '#E57373',

140 2: '#F44336',

141 3: '#D32F2F',

142 4: '#B71C1C',

143 5: '#F8BBD0',

144 6: '#F06292',

145 7: '#E91E63',

146 8: '#C2185B',

147 9: '#880E4F',

148 10: '#E1BEE7',

149 11: '#BA68C8',

150 12: '#9C27B0',

151 13: '#7B1FA2',

152 14: '#4A148C',

153 15: '#BBDEFB',

154 16: '#64B5F6',

155 17: '#2196F3',

156 18: '#1976D2',

157 19: '#0D47A1',

158 20: '#B2EBF2',

159 21: '#4DD0E1',

160 22: '#00BCD4',

161 23: '#0097A7',

162 24: '#006064',

163 25: '#B2DFDB',

164 26: '#4DB6AC',

165 27: '#009688',

166 28: '#00796B',

167 29: '#004D40',

168 30: '#C8E6C9',

169 31: '#81C784',

170 32: '#4CAF50',

171 33: '#388E3C',

172 34: '#1B5E20',

173 35: '#FFF9C4',

174 36: '#FFF176',

175 37: '#FFEB3B',

176 38: '#FBC02D',

177 39: '#F57F17',

178 40: '#FFE0B2',

179 41: '#FFB74D',

180 42: '#FF9800',

181 43: '#F57C00',

182 44: '#E65100',

183 45: '#D7CCC8',

184 46: '#A1887F',

185 47: '#795548',

186 48: '#5D4037',

187 49: '#3E2723',

188 50: '#F5F5F5',

189 51: '#E0E0E0',

190 52: '#9E9E9E',

191 53: '#616161',

192 54: '#141414'

193};

194

195const COLOR = {

196 0: '#141414',

197 1: '#F44336',

198 2: '#2196F3',

199 3: '#009688',

200 4: '#FFEB3B',

201 5: '#9C27B0'

202};

203

204const COLORS_LENGTH = Object.values(COLORS).length;

205const COLOR_LENGTH = Object.values(COLOR).length;

206

207let canvas;

208let overlay;

209let g;

210let o;

211let ad;

212let hotbar;

213let toolbar;

214let actionbar;

215let colors;

216let actions;

217let tools;

218let modals;

219let device_options;

220let device_empty;

221let current_modal;

222let current_tab;

223let modal_colors;

224let colors_modal;

225

226let device;

227let devices = {

228 mouse: false,

229 touch: false,

230 pen: false,

231 gamepad: false

232};

233let fallback_device;

234

235let lang = 'en';

236let notification_code;

237

238let cache;

239let point;

240let last;

241let index = 0;

242let radius = 14;

243let lock_x = false;

244let lock_y = false;

245let draw;

246let erase;

247let pressed = {};

248let arrow_y = 0;

249let arrow_x = 0;

250

251window.addEventListener('load', init);

252

253function init() {

254 canvas = document.querySelector('#canvas');

255 canvas.width = window.innerWidth;

256 canvas.height = window.innerHeight;

257 g = canvas.getContext('2d');

258 overlay = document.querySelector('#overlay');

259 overlay.width = window.innerWidth;

260 overlay.height = window.innerHeight;

261 o = overlay.getContext('2d');

262 window.onresize = function() {

263 cache = g.getImageData(0, 0, canvas.width, canvas.height);

264 canvas.width = window.innerWidth;

265 canvas.height = window.innerHeight;

266 g.putImageData(cache, 0, 0);

267 cache = o.getImageData(0, 0, overlay.width, overlay.height);

268 overlay.width = window.innerWidth;

269 overlay.height = window.innerHeight;

270 o.putImageData(cache, 0, 0);

271 }

272 let ripple = document.querySelectorAll('.ripple');

273 for(let item of ripple) {

274 item.addEventListener('mousedown', function(event) {

275 item.classList.add('ripple-active');

276 });

277 }

278 document.addEventListener('touchmove', function(event) {

279 event.preventDefault();

280 }, { passive: false });

281 document.addEventListener('mouseup', function(event) {

282 for(let item of ripple) {

283 item.classList.remove('ripple-active');

284 }

285 });

286

287 device_options = document.querySelectorAll('.settings-modal .device-tab .item[data-device]');

288 device_empty = document.querySelector('.settings-modal .device-tab .item.empty');

289

290 ad = document.querySelector('.controls .ad');

291 hotbar = document.querySelector('.controls .hotbar');

292 toolbar = document.querySelector('.controls .toolbar');

293 actionbar = document.querySelector('.controls .actionbar');

294 colors = Array.from(hotbar.querySelectorAll('.color'));

295 actions = document.querySelectorAll('.actionbar .action');

296 tools = document.querySelectorAll('.toolbar .tool');

297 modals = document.querySelectorAll('.modal');

298 modal_colors = document.querySelectorAll('.colors-modal .color');

299 colors_modal = document.querySelector('.toolbar .tool[data-modal="colors"]');

300 for(let i in colors) {

301 if(COLOR_LENGTH > i) {

302 if(i == index) {

303 colors[i].classList.add('active');

304 }

305 colors[i].style.background = COLOR[i];

306 colors[i].addEventListener('click', function(event) {

307 for(let j in colors) {

308 if(COLOR_LENGTH > j) {

309 if(j == i) {

310 index = j;

311 }

312 colors[j].classList[j == i ? 'add' : 'remove']('active');

313 }

314 }

315 });

316 }

317 }

318 for(let i in modal_colors) {

319 if(COLORS_LENGTH > i) {

320 modal_colors[i].style.background = COLORS[i];

321 /*

322 modal_colors[i].addEventListener('click', function(event) {

323 for(let j in colors) {

324 if(COLORS_LENGTH > j) {

325 if(j == i) {

326 index = j;

327 }

328 colors[j].classList[j == i ? 'add' : 'remove']('active');

329 }

330 }

331 });

332 */

333 }

334 }

335 document.addEventListener('dragstart', function(event) {

336 event.preventDefault();

337 });

338 document.addEventListener('contextmenu', function(event) {

339 event.preventDefault();

340 });

341 document.addEventListener('wheel', function(event) {

342 if(device !== 'gamepad') {

343 let { deltaY } = event;

344 let y = deltaY < 0 ? 1 : -1;

345 if(radius + y > 2 - 1 && radius + y < 50 + 1) {

346 radius += y;

347 }

348 }

349 });

350 document.addEventListener('wheel', function(event) {

351 if(device !== 'gamepad') {

352 let { ctrlKey } = event;

353 if(ctrlKey) {

354 event.preventDefault();

355 return;

356 }

357 }

358 }, { passive: false });

359 canvas.addEventListener('pointerdown', function(event) {

360 let { layerX, layerY, buttons, pointerType } = event;

361 if(!devices.touch && pointerType === 'touch') {

362 devices.touch = true;

363 if(device) {

364 show_notification('notification.input-device.touch.add');

365 }

366 }

367 if(!devices.pen && pointerType === 'pen') {

368 devices.pen = true;

369 show_notification('notification.input-device.pencil.add');

370 }

371 if(device !== 'gamepad') {

372 if(device === pointerType) {

373 if(!lock_x) {

374 point.x = layerX;

375 last.x = layerX;

376 }

377 if(!lock_y) {

378 point.y = layerY;

379 last.y = layerY;

380 }

381 draw = buttons == 1;

382 erase = buttons == 2;

383 ad.style.pointerEvents = 'none';

384 hotbar.style.pointerEvents = 'none';

385 toolbar.style.pointerEvents = 'none';

386 actionbar.style.pointerEvents = 'none';

387 for(let modal of modals) {

388 modal.style.pointerEvents = 'none';

389 }

390 }

391 }

392 });

393 document.addEventListener('pointermove', function(event) {

394 let { layerX, layerY, target, pointerType } = event;

395 if(!devices.mouse && pointerType === 'mouse') {

396 devices.mouse = true;

397 }

398 if(device !== 'gamepad') {

399 if(device === pointerType) {

400 if(target == canvas) {

401 if(!lock_x) {

402 point.x = layerX;

403 }

404 if(!lock_y) {

405 point.y = layerY;

406 }

407 }

408 }

409 if(!document.hasFocus()) {

410 draw = false;

411 erase = false;

412 }

413 }

414 });

415 document.addEventListener('pointerout', function(event) {

416 if(device !== 'gamepad') {

417 if(!lock_x && !lock_y) {

418 point.x = null;

419 point.y = null;

420 }

421 }

422 });

423 document.addEventListener('pointerup', function(event) {

424 if(device !== 'gamepad') {

425 let { buttons } = event;

426 draw = buttons == 1;

427 erase = buttons == 2;

428 last.x = null;

429 last.y = null;

430 ad.style.pointerEvents = '';

431 hotbar.style.pointerEvents = '';

432 toolbar.style.pointerEvents = '';

433 actionbar.style.pointerEvents = '';

434 for(let modal of modals) {

435 modal.style.pointerEvents = '';

436 }

437 }

438 });

439 document.addEventListener('keydown', function(event) {

440 let { code, ctrlKey, shiftKey, altKey } = event;

441 if(device !== 'gamepad') {

442 let lock = event.getModifierState("CapsLock");

443 if(!ctrlKey && !shiftKey && !altKey) {

444 if(code === 'KeyX') {

445 lock_y = !lock_y;

446 lock_x = false;

447 }

448 if(code === 'KeyZ') {

449 lock_x = !lock_x;

450 lock_y = false;

451 }

452 if(!lock) {

453 if(code.startsWith('Digit')) {

454 let number = parseInt(code.substr(5)) - 1;

455 if(number >= 0 && number < COLOR_LENGTH) {

456 index = number;

457 for(let i in colors) {

458 if(COLOR_LENGTH > i) {

459 colors[i].classList[i == index ? 'add' : 'remove']('active');

460 }

461 }

462 }

463 }

464 }

465 }

466 }

467 if(code === 'Escape') {

468 if(current_tab) {

469 close_tab(current_tab);

470 }

471 else if(current_modal) {

472 toggle_modal(current_modal);

473 }

474 }

475 });

476 point = { x: null, y: null };

477 last = { x: null, y: null };

478 update();

479}

480

481function read_input(gamepad) {

482 let input = {

483 button: {},

484 axes: {}

485 };

486 for(let [ id, key ] of Object.entries(KEY_BINDING)) {

487 if(gamepad.buttons[id]) {

488 input.button[key] = gamepad.buttons[id].pressed;

489 }

490 }

491 input.axes['Left'] = {

492 x: gamepad.axes[0],

493 y: gamepad.axes[1]

494 };

495 input.axes['Right'] = {

496 x: gamepad.axes[2],

497 y: gamepad.axes[3]

498 };

499 return input;

500}

501

502function key_pressed(key, input, func) {

503 if(input.button[key]) {

504 if(!pressed[key]) {

505 pressed[key] = true;

506 if(func) {

507 func();

508 }

509 }

510 }

511 else {

512 pressed[key] = false;

513 }

514}

515

516function update() {

517 if(radius < 2) {

518 radius = 2;

519 }

520 if(radius > 50) {

521 radius = 50;

522 }

523 let gamepad = navigator.getGamepads()[0];

524 if(gamepad) {

525 if(!devices.gamepad) {

526 devices.gamepad = true;

527 show_notification('notification.input-device.gamepad.add');

528 }

529 if(device === 'gamepad') {

530 if(point.x == null && point.y == null) {

531 point.x = parseInt(window.innerWidth / 2);

532 point.y = parseInt(window.innerHeight / 2);

533 }

534 let input = read_input(gamepad);

535 let speed = 4;

536 draw = input.button['A'];

537 erase = input.button['B'];

538 if(pressed['L2'] && !pressed['R2']) {

539 speed = 10;

540 }

541 if(pressed['R2'] && !pressed['L2']) {

542 speed = 1;

543 }

544 // move

545 if(!lock_x) {

546 point.x += input.axes['Left'].x * speed;

547 if(point.x < 0 ) {

548 point.x = 0;

549 }

550 if(point.x > window.innerWidth) {

551 point.x = window.innerWidth;

552 }

553 }

554 if(!lock_y) {

555 point.y += input.axes['Left'].y * speed;

556 if(point.y < 0) {

557 point.y = 0;

558 }

559 if(point.y > window.innerHeight) {

560 point.y = window.innerHeight;

561 }

562 }

563 // colors

564 key_pressed('Option', input, function() {

565 toggle_modal(colors_modal);

566 });

567 // draw

568 key_pressed('A', input, function() {

569 last.x = null;

570 last.y = null;

571 });

572 // erase

573 key_pressed('B', input, function() {

574 last.x = null;

575 last.y = null;

576 if(current_tab) {

577 close_tab(current_tab);

578 }

579 else if(current_modal) {

580 toggle_modal(current_modal);

581 }

582 });

583 // sprint

584 key_pressed('L2', input);

585 // sneak

586 key_pressed('R2', input);

587 // clear

588 key_pressed('Y', input, function() {

589 if(!current_modal) {

590 g.clearRect(0, 0, window.innerWidth, window.innerHeight);

591 }

592 });

593 // radius

594 let y = -(input.axes['Right'].y / 2);

595 if(y !== 0 && radius + y > 2 && radius + y < 50 + 1) {

596 radius += y;

597 }

598 // lock y

599 key_pressed('L3', input, function() {

600 lock_y = !lock_y;

601 lock_x = false;

602 });

603 // lock x

604 key_pressed('R3', input, function() {

605 lock_x = !lock_x;

606 lock_y = false;

607 });

608 // color-wheel left

609 key_pressed('L1', input, function() {

610 if(index > 0) {

611 index--;

612 for(let i in colors) {

613 if(COLOR_LENGTH > i) {

614 colors[i].classList[i == index ? 'add' : 'remove']('active');

615 }

616 }

617 }

618 });

619 // color-wheel right

620 key_pressed('R1', input, function() {

621 if(index < COLOR_LENGTH - 1) {

622 index++;

623 for(let i in colors) {

624 if(COLOR_LENGTH > i) {

625 colors[i].classList[i == index ? 'add' : 'remove']('active');

626 }

627 }

628 }

629 });

630 key_pressed('Up', input, function() {

631 if(arrow_y > 0) {

632 arrow_y--;

633 }

634 });

635 key_pressed('Down', input, function() {

636 if(arrow_y < 10) {

637 arrow_y++;

638 }

639 });

640 key_pressed('Left', input, function() {

641 if(arrow_x > 0) {

642 arrow_x--;

643 }

644 });

645 key_pressed('Right', input, function() {

646 if(arrow_x < 4) {

647 arrow_x++;

648 }

649 });

650 }

651 }

652 else {

653 if(devices.gamepad) {

654 devices.gamepad = false;

655 show_notification('notification.input-device.gamepad.remove');

656 }

657 }

658 if(device !== 'gamepad') {

659 let pos = arrow_y * 5 + arrow_x;

660 if(modal_colors[pos].classList.contains('focus')) {

661 modal_colors[pos].classList.remove('focus');

662 }

663 }

664 // device mouse option

665 let mouse_option = document.querySelector('.settings-modal .device-tab .item[data-device="mouse"]');

666 if(devices.mouse && mouse_option.classList.contains('hidden')) {

667 mouse_option.classList.remove('hidden');

668 if(!device) {

669 device = 'mouse';

670 fallback_device = 'mouse';

671 mouse_option.classList.add('active');

672 }

673 }

674 // device touch option

675 let touch_option = document.querySelector('.settings-modal .device-tab .item[data-device="touch"]');

676 if(devices.touch && touch_option.classList.contains('hidden')) {

677 touch_option.classList.remove('hidden');

678 if(!device) {

679 device = 'touch';

680 fallback_device = 'touch';

681 touch_option.classList.add('active');

682 }

683 }

684 // device pen option

685 let pen_option = document.querySelector('.settings-modal .device-tab .item[data-device="pen"]');

686 if(devices.pen && pen_option.classList.contains('hidden')) {

687 pen_option.classList.remove('hidden');

688 if(!device) {

689 device = 'pen';

690 fallback_device = 'pen';

691 pen_option.classList.add('active');

692 }

693 }

694 // device gamepad option

695 let gamepad_option = document.querySelector('.settings-modal .device-tab .item[data-device="gamepad"]');

696 if(devices.gamepad && gamepad_option.classList.contains('hidden')) {

697 gamepad_option.classList.remove('hidden');

698 if(!device) {

699 device = 'gamepad';

700 fallback_device = 'gamepad';

701 gamepad_option.classList.add('active');

702 }

703 }

704 if(!devices.gamepad && !gamepad_option.classList.contains('hidden')) {

705 gamepad_option.classList.add('hidden');

706 gamepad_option.classList.remove('active');

707 if(device !== fallback_device) {

708 device = fallback_device;

709 let option = document.querySelector(`.device-modal .item[data-device="${device}"]`);

710 option.classList.add('active');

711 }

712 else {

713 device = null;

714 }

715 }

716 // cursor visible

717 canvas.style.cursor = device === 'mouse' ? 'none' : 'default';

718 if(!current_modal) {

719 // pencil

720 if(draw && !erase) {

721 if(point.x !== null && point.y !== null) {

722 if(last.x !== null && last.y !== null) {

723 for(let p of lerp(point, last, radius)) {

724 g.fillStyle = COLOR[index];

725 g.beginPath();

726 g.arc(p.x, p.y, parseInt(radius), 2 * Math.PI, 0);

727 g.fill();

728 }

729 }

730 }

731 }

732 // eraser

733 if(erase && !draw) {

734 if(point.x !== null && point.y !== null) {

735 if(last.x !== null && last.y !== null) {

736 for(let p of lerp(point, last, radius)) {

737 g.fillStyle = 'white';

738 g.beginPath();

739 g.arc(p.x, p.y, parseInt(radius), 2 * Math.PI, 0);

740 g.fill();

741 }

742 }

743 }

744 }

745 }

746 // at least one device

747 let one_device = Object.values(devices).some(function(device) {

748 return device;

749 });

750 if(one_device && !device_empty.classList.contains('hidden')) {

751 device_empty.classList.add('hidden');

752 }

753 if(!one_device && device_empty.classList.contains('hidden')) {

754 device_empty.classList.remove('hidden');

755 }

756 // navigate colors

757 let pos = arrow_y * 5 + arrow_x;

758 if(device === 'gamepad') {

759 for(let [ i, item ] of Object.entries(modal_colors)) {

760 item.classList[parseInt(i) == pos ? 'add' : 'remove']('focus');

761 }

762 }

763 render();

764 if(draw || erase) {

765 last.x = point.x;

766 last.y = point.y;

767 }

768 requestAnimationFrame(update);

769}

770

771function render() {

772 if(radius < 2) {

773 radius = 2;

774 }

775 o.clearRect(0, 0, window.innerWidth, window.innerHeight);

776 if(point.x !== null && point.y !== null) {

777 o.fillStyle = 'white';

778 o.beginPath();

779 o.arc(point.x, point.y, parseInt(radius) + 2, 2 * Math.PI, 0);

780 o.fill();

781 o.fillStyle = COLOR[index];

782 o.beginPath();

783 o.arc(point.x, point.y, parseInt(radius), 2 * Math.PI, 0);

784 o.fill();

785 }

786 if(erase && !draw) {

787 o.beginPath();

788 o.lineWidth = 2;

789 o.strokeStyle = 'white';

790 o.moveTo(point.x, point.y - parseInt(radius) * 0.5);

791 o.lineTo(point.x, point.y + parseInt(radius) * 0.5);

792 o.moveTo(point.x - parseInt(radius) * 0.5, point.y);

793 o.lineTo(point.x + parseInt(radius) * 0.5, point.y);

794 o.stroke();

795 }

796 if(lock_x || lock_y) {

797 o.beginPath();

798 o.lineWidth = 2;

799 o.strokeStyle = 'white';

800 if(lock_x) {

801 o.moveTo(point.x, point.y - parseInt(radius));

802 o.lineTo(point.x, point.y + parseInt(radius));

803 }

804 if(lock_y) {

805 o.moveTo(point.x - parseInt(radius), point.y);

806 o.lineTo(point.x + parseInt(radius), point.y);

807 }

808 o.stroke();

809 }

810}

811

812function lerp(point, last, radius) {

813 let result = [];

814 let delta = {

815 x: last.x - point.x,

816 y: last.y - point.y

817 };

818 let distance = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2));

819 let length = parseInt(distance / (radius / 20));

820 for(let i = 0; i < length; i++) {

821 let x = point.x + (delta.x / length * i);

822 let y = point.y + (delta.y / length * i);

823 result.push({ x: x, y: y });

824 }

825 if(length == 0) {

826 result.push({ x: point.x, y: point.y });

827 }

828 return result;

829}

830

831function change_device(element) {

832 device = element.dataset.device;

833 for(let item of device_options) {

834 item.classList[element === item ? 'add' : 'remove']('active');

835 }

836 if(device !== 'gamepad') {

837 point.x = null;

838 point.y = null;

839 last.x = null;

840 last.y = null;

841 }

842}

843

844function change_language(element) {

845 let code = element.dataset.code;

846 lang = code;

847 let items = document.querySelectorAll('[data-lang]');

848 for(let item of items) {

849 let prime = item.dataset.prime === 'true';

850 let beta = item.dataset.beta === 'true';

851 let type = item.dataset.type;

852 let text = LANG[code][item.dataset.lang];

853 if(text) {

854 if(type === 'tooltip') {

855 item.dataset.title = text;

856 }

857 else {

858 item.textContent = text;

859 }

860 if(prime && type !== 'tooltip') {

861 item.innerHTML += PRIME_CODE;

862 }

863 if(beta && type !== 'tooltip') {

864 item.innerHTML += BETA_CODE;

865 }

866 }

867 }

868 let options = document.querySelectorAll('.language-tab .item');

869 for(let option of options) {

870 option.classList[option === element ? 'add' : 'remove']('active');

871 }

872}

873

874function toggle_modal(element) {

875 let code = element.dataset.modal;

876 let modal = document.querySelector(`.${code}-modal`);

877 if(modal) {

878 let open = modal.classList.contains('hidden');

879 if(open) {

880 current_modal = element;

881 for(let item of actions) {

882 if(item !== element) {

883 item.classList.remove('active');

884 }

885 }

886 for(let item of tools) {

887 if(item !== element) {

888 item.classList.remove('active');

889 }

890 }

891 for(let item of modals) {

892 if(item !== modal) {

893 item.classList.add('hidden');

894 }

895 let main = item.querySelector('.main');

896 if(main) {

897 main.classList.remove('hidden');

898 main.style.marginLeft = '0';

899 }

900 let tab_list = item.querySelector('.tab-list');

901 if(tab_list) {

902 let tabs = tab_list.querySelectorAll('.tab');

903 for(let tab of tabs) {

904 tab.classList.add('hidden');

905 }

906 }

907 }

908 if(code === 'colors') {

909 if(device === 'gamepad') {

910 modal_colors[0].classList.add('focus');

911 arrow_x = 0;

912 arrow_y = 0;

913 }

914 }

915 }

916 else {

917 current_modal = null;

918 }

919 element.classList[open ? 'add' : 'remove']('active');

920 modal.classList[open ? 'remove' : 'add']('hidden');

921 modal.animate([

922 { opacity: 0, marginTop: '-6px' },

923 { opacity: 1, marginTop: '0' }

924 ], {

925 duration: 100,

926 fill: 'both'

927 });

928 }

929}

930

931function open_tab(element) {

932 let code = element.dataset.tab;

933 let main = element.parentNode.parentNode;

934 main.style.marginLeft = '-100%';

935 let tab = document.querySelector(`.${code}-tab`);

936 current_tab = tab.querySelector('.back');

937 tab.classList.remove('hidden');

938 main.classList.add('hidden');

939}

940

941function close_tab(element) {

942 let modal = element.parentNode.parentNode.parentNode.parentNode;

943 let main = modal.querySelector('.main');

944 let tab_list = modal.querySelector('.tab-list');

945 let tabs = tab_list.querySelectorAll('.tab');

946 for(let tab of tabs) {

947 tab.classList.add('hidden');

948 }

949 main.classList.remove('hidden');

950 main.style.marginLeft = '0';

951 current_tab = null;

952}

953

954function show_notification(message) {

955 let code = uuid();

956 notification_code = code;

957 let element = document.querySelector('.notification');

958 let content = element.querySelector('.content');

959 content.textContent = LANG[lang][message];

960 element.animate([

961 { opacity: 0 },

962 { opacity: 1}

963 ], {

964 duration: 200,

965 fill: 'both'

966 });

967 setTimeout(function() {

968 if(notification_code === code) {

969 element.animate([

970 { opacity: 1 },

971 { opacity: 0}

972 ], {

973 duration: 200,

974 fill: 'both'

975 });

976 }

977 }, 2000);

978}

979

980function uuid() {

981 return 'xxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {

982 let r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);

983 return v.toString(16);

984 });

985}