Skip to content

Commit

Permalink
add mask loaded event
Browse files Browse the repository at this point in the history
  • Loading branch information
talenfisher committed Apr 24, 2019
1 parent 516e7cc commit f0b97b9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/mask/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Manifest from "../manifest";
import AnnotationHandler from "./annotation-handler";

import { EventEmitter } from "events";
import { Canvas } from "@talenfisher/canvas";
import createTexture from "gl-texture2d";

Expand All @@ -18,7 +19,7 @@ function loadImage(buffer: ArrayBuffer): Promise<HTMLImageElement> {
});
}

export default class Mask {
export default class Mask extends EventEmitter {
public annotations: { [name: string]: any };
public color: string;
public canvas?: Canvas;
Expand All @@ -28,6 +29,7 @@ export default class Mask {
private texture?: any;

constructor(options: MaskOptions) {
super();
let definition = options.manifest.getNode("Record3 Mask");
if(!definition) {
throw new Error("Record3 Mask is not defined in the manifest");
Expand Down Expand Up @@ -60,12 +62,12 @@ export default class Mask {
if(this.dataBuffer) {
let img = await loadImage(this.dataBuffer);
let el = this.canvas.el;
let ctx = this.canvas.context;

this.canvas.drawImage(img);

if(this.texture) {
this.texture.setPixels(el);
this.emit("loaded");
}

} else {
Expand Down

0 comments on commit f0b97b9

Please sign in to comment.