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

Class ImageLayer

script.js:462–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460}
461
462class ImageLayer extends MoveableLayer {
463 constructor(file) {
464 super(file);
465 // assume images are 10 seconds
466 this.img = new Image();
467
468 this.reader = new FileReader();
469 this.reader.addEventListener("load", (function() {
470 this.img.src = this.reader.result;
471 this.img.addEventListener('load', (function() {
472 this.width = this.img.naturalWidth;
473 this.height = this.img.naturalHeight;
474 this.ready = true;
475 }).bind(this));
476 }).bind(this), false);
477 this.reader.readAsDataURL(file);
478 }
479
480 render(ctx_out, ref_time) {
481 if (!this.ready) {
482 return;
483 }
484 let f = this.getFrame(ref_time);
485 if (f) {
486 let scale = f[2];
487 let x = f[0] + this.canvas.width / 2 - this.width / 2;
488 let y = f[1] + this.canvas.height / 2 - this.height / 2;
489 this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
490 this.ctx.drawImage(this.img, 0, 0, this.width, this.height, x, y, scale * this.width, scale * this.height);
491 this.drawScaled(this.ctx, ctx_out);
492 }
493 }
494}
495
496class TextLayer extends MoveableLayer {
497 constructor(text) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected