MCPcopy Create free account
hub / github.com/bwasti/mebm / TextLayer

Class TextLayer

script.js:496–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494}
495
496class TextLayer extends MoveableLayer {
497 constructor(text) {
498 let f = {
499 name: text
500 };
501 super(f);
502 this.color = "#ffffff";
503 this.shadow = true;
504 this.ready = true;
505 }
506
507 init(player, preview) {
508 super.init(player, preview);
509
510 let settings = new Settings();
511
512 settings.add('text', null,
513 i => i.value = this.name,
514 e => this.update_name(e.target.value),
515 'textarea'
516 );
517
518 settings.add('color', 'color',
519 i => i.value = this.color,
520 e => this.color = e.target.value
521 );
522
523 settings.add('shadow', 'checkbox',
524 i => i.checked = this.shadow,
525 e => this.shadow = e.target.checked
526 );
527
528 let settings_link = document.createElement('a');
529 settings_link.style.float = "right";
530 settings_link.textContent = "[...]";
531 settings_link.addEventListener('click', function() {
532 popup(settings.div);
533 });
534 this.title_div.appendChild(settings_link);
535
536 }
537
538 update(change, ref_time) {
539 let rect = this.ctx.measureText(this.name);
540 this.width = rect.width;
541 this.height = rect.actualBoundingBoxAscent + rect.actualBoundingBoxDescent;
542 super.update(change, ref_time);
543 }
544
545 render(ctx_out, ref_time) {
546 let f = this.getFrame(ref_time);
547 if (f) {
548
549 let scale = f[2];
550 this.ctx.font = Math.floor(scale * 30) + "px Georgia";
551 let lines = this.name.split('\n');
552 let rect = this.ctx.measureText(this.name);
553 this.width = rect.width;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected