Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LayerExt extends dwv.html.Layer {
- constructor(app){
- super(app);
- console.log('123')
- this.flip = { flipH: false, flipV: false };
- this.rotateDegree = { degree: 0 };
- }
- setFlip(object) {
- this.flip.flipH = object.flipH;
- this.flip.flipV = object.flipV;
- }
- getFlip() {
- return this.flip;
- }
- setRotateDegree(value) {
- this.rotateDegree.degree = value
- }
- getRotateDegree() {
- return this.rotateDegree;
- }
- draw() {
- const flipH = this.getFlip().flipH; // Get flip flags from gui
- const flipV = this.getFlip().flipV;
- const scaleH = flipH ? -1 : 1; // Set horizontal scale to -1 if flip horizontal
- const scaleV = flipV ? -1 : 1; // Set vertical scale to -1 if flip vertical
- // clear the context: reset the transform first
- // store the current transformation matrix
- this.context.save();
- // use the identity matrix while clearing the canvas
- this.context.setTransform(1, 0, 0, 1, 0, 0);
- this.context.clearRect(0, 0, canvas.width, canvas.height);
- // restore the transform
- this.context.restore();
- // draw the cached canvas on the context
- // transform takes as input a, b, c, d, e, f to create
- // the transform matrix (column-major order):
- // [ a c e ]
- // [ b d f ]
- // [ 0 0 1 ]
- this.context.setTransform(this.zoom.x, 0, 0, this.zoom.y,
- this.origin.x + (this.trans.x * this.zoom.x),
- this.origin.y + (this.trans.y * this.zoom.y)
- );
- // this.context.drawImage(this.cacheCanvas, 0, 0);
- if (this.getRotateDegree().degree === 0 && (flipH || flipV) === false) {
- context.drawImage(cacheCanvas, 0, 0);
- } else {
- this.flipAndRotateImage(cacheCanvas, context, scaleH, scaleV);
- }
- console.log('OVERRIDED, BITCH!', this);
- }
- };
- dwv.html.Layer = LayerExt;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement