Skip to content

Commit

Permalink
Merge pull request openfl#367 from leshido/master
Browse files Browse the repository at this point in the history
FIX: HTML5 canvas masks not working (closes openfl#366)
  • Loading branch information
jgranick committed Oct 27, 2014
2 parents fd2eff6 + 23beac7 commit 9e66536
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
2 changes: 1 addition & 1 deletion openfl/_internal/renderer/RenderSession.hx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RenderSession {
public var offset:Point;

public var shaderManager:ShaderManager;
public var maskManager:MaskManager;
public var maskManager:Dynamic;
public var filterManager:FilterManager;
public var blendModeManager:BlendModeManager;
public var spriteBatch:SpriteBatch;
Expand Down
4 changes: 2 additions & 2 deletions openfl/_internal/renderer/canvas/CanvasBitmap.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CanvasBitmap {

if (bitmap.__mask != null) {

//renderSession.maskManager.pushMask (__mask);
renderSession.maskManager.pushMask (bitmap.__mask);

}

Expand Down Expand Up @@ -70,7 +70,7 @@ class CanvasBitmap {

if (bitmap.__mask != null) {

//renderSession.maskManager.popMask ();
renderSession.maskManager.popMask ();

}

Expand Down
1 change: 1 addition & 0 deletions openfl/_internal/renderer/canvas/CanvasRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CanvasRenderer extends AbstractRenderer {
renderSession.context = context;
renderSession.roundPixels = true;
renderSession.renderer = this;
renderSession.maskManager = new MaskManager(renderSession);

}

Expand Down
62 changes: 62 additions & 0 deletions openfl/_internal/renderer/canvas/MaskManager.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package openfl._internal.renderer.canvas;

import openfl.display.*;
import openfl.geom.*;

class MaskManager {


private var renderSession:RenderSession;


public function new (renderSession:RenderSession) {

this.renderSession = renderSession;

}


public function pushMask (mask:IBitmapDrawable):Void {

var context = renderSession.context;

context.save ();

//var cacheAlpha = mask.__worldAlpha;
var transform = mask.__worldTransform;
if (transform == null) transform = new Matrix ();

context.setTransform (transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);

context.beginPath ();
mask.__renderMask (renderSession);

context.clip ();

//mask.worldAlpha = cacheAlpha;

}


public function pushRect (rect:Rectangle, transform:Matrix):Void {

var context = renderSession.context;
context.save ();

context.setTransform (transform.a, transform.c, transform.b, transform.d, transform.tx, transform.ty);

context.beginPath ();
context.rect (rect.x, rect.y, rect.width, rect.height);
context.clip ();

}


public function popMask ():Void {

renderSession.context.restore ();

}


}

0 comments on commit 9e66536

Please sign in to comment.