Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. class LayerExt extends dwv.html.Layer {
  2. constructor(app){
  3. super(app);
  4. console.log('123')
  5. this.flip = { flipH: false, flipV: false };
  6. this.rotateDegree = { degree: 0 };
  7. }
  8.  
  9. setFlip(object) {
  10. this.flip.flipH = object.flipH;
  11. this.flip.flipV = object.flipV;
  12. }
  13.  
  14. getFlip() {
  15. return this.flip;
  16. }
  17.  
  18. setRotateDegree(value) {
  19. this.rotateDegree.degree = value
  20. }
  21.  
  22. getRotateDegree() {
  23. return this.rotateDegree;
  24. }
  25.  
  26. draw() {
  27. const flipH = this.getFlip().flipH; // Get flip flags from gui
  28. const flipV = this.getFlip().flipV;
  29.  
  30. const scaleH = flipH ? -1 : 1; // Set horizontal scale to -1 if flip horizontal
  31. const scaleV = flipV ? -1 : 1; // Set vertical scale to -1 if flip vertical
  32.  
  33. // clear the context: reset the transform first
  34. // store the current transformation matrix
  35. this.context.save();
  36. // use the identity matrix while clearing the canvas
  37. this.context.setTransform(1, 0, 0, 1, 0, 0);
  38. this.context.clearRect(0, 0, canvas.width, canvas.height);
  39. // restore the transform
  40. this.context.restore();
  41.  
  42. // draw the cached canvas on the context
  43. // transform takes as input a, b, c, d, e, f to create
  44. // the transform matrix (column-major order):
  45. // [ a c e ]
  46. // [ b d f ]
  47. // [ 0 0 1 ]
  48. this.context.setTransform(this.zoom.x, 0, 0, this.zoom.y,
  49. this.origin.x + (this.trans.x * this.zoom.x),
  50. this.origin.y + (this.trans.y * this.zoom.y)
  51. );
  52.  
  53. // this.context.drawImage(this.cacheCanvas, 0, 0);
  54.  
  55. if (this.getRotateDegree().degree === 0 && (flipH || flipV) === false) {
  56. context.drawImage(cacheCanvas, 0, 0);
  57. } else {
  58. this.flipAndRotateImage(cacheCanvas, context, scaleH, scaleV);
  59. }
  60. console.log('OVERRIDED, BITCH!', this);
  61. }
  62. };
  63.  
  64.  
  65. dwv.html.Layer = LayerExt;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement