Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. (function () {
  2. "use strict";
  3. function ColorMaskFilter(color) {
  4. this.color = color;
  5. }
  6. var p = createjs.extend(ColorMaskFilter, createjs.Filter);
  7. p.applyFilter = function (ctx, x, y, width, height, targetCtx, targetX, targetY) {
  8. if (!this.color) { return true; }
  9. targetCtx = targetCtx || ctx;
  10. if (targetX == null) { targetX = x; }
  11. if (targetY == null) { targetY = y; }
  12.  
  13. targetCtx.save();
  14. if (ctx != targetCtx) {
  15. return false;
  16. }
  17.  
  18. targetCtx.globalCompositeOperation = "source-out"; // Use source-in to fill the shape instead
  19. targetCtx.fillStyle = this.color;
  20. targetCtx.rect(targetX,targetY,width,height);
  21. targetCtx.fill();
  22.  
  23. targetCtx.restore();
  24. return true;
  25. };
  26. p.clone = function () {
  27. return new AlphaMaskFilter(this.color);
  28. };
  29. createjs.ColorMaskFilter = createjs.promote(ColorMaskFilter, "Filter");
  30. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement