grumpytoad / Canvas/NME (http://flashsandy.org/haxe)
A re-implementation of NME for use with the HTML5 canvas element on the javascript target. Currently implemented against Neash. This project is no longer actively maintained against the current neash version.
Clone this repository (size: 107.4 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/grumpytoad/canvas-nme/
| commit 23: | 966c697574b5 |
| parent 22: | a8eb40a796e5 |
| branch: | default |
patch from anonymous - simplifies code into two transforms.
10 months ago
Changed (Δ668 bytes):
raw changeset »
canvas/display/Graphics.hx (10 lines added, 31 lines removed)
Up to file-list canvas/display/Graphics.hx:
| … | … | @@ -309,6 +309,8 @@ class Graphics |
309 |
309 |
ctx.rotate( mInitRotation ); |
310 |
310 |
ctx.scale( mInitScaleX, mInitScaleY ); |
311 |
311 |
|
312 |
ctx.transform(inMatrix.a, inMatrix.b, inMatrix.c, inMatrix.d, inMatrix.tx, inMatrix.ty); |
|
313 |
||
312 |
314 |
var len : Int = mDrawList.length; |
313 |
315 |
for ( i in 0...len ) { |
314 |
316 |
var d = mDrawList[i]; |
| … | … | @@ -334,8 +336,8 @@ class Graphics |
334 |
336 |
} |
335 |
337 |
var fillColour = d.fillColour; |
336 |
338 |
var fillAlpha = d.fillAlpha; |
337 |
if ( fillAlpha > 0. ) { |
|
338 |
if ( fillAlpha < 1. ) |
|
339 |
if ( fillAlpha >= 0. ) { |
|
340 |
if ( fillAlpha <= 1. ) |
|
339 |
341 |
{ |
340 |
342 |
var r:Float; |
341 |
343 |
var g:Float; |
| … | … | @@ -350,36 +352,19 @@ class Graphics |
350 |
352 |
ctx.restore(); |
351 |
353 |
|
352 |
354 |
var bitmap = d.bitmap; |
353 |
if ( bitmap != null |
|
355 |
if ( bitmap != null && bitmap.texture_buffer.src != "") { |
|
354 |
356 |
ctx.save(); |
355 |
357 |
ctx.clip(); |
356 |
358 |
var img = bitmap.texture_buffer; |
357 |
359 |
var matrix = bitmap.matrix; |
358 |
360 |
|
359 |
// Bleeding-Edge browsers should implement setTransform natively, |
|
360 |
// other browsers do not and must decompose the drawing matrix |
|
361 |
||
362 |
try { |
|
363 |
ctx.setTransform( matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty ); |
|
364 |
ctx.drawImage( img, 0,0 ); |
|
365 |
||
366 |
ctx.restore(); |
|
367 |
} catch (e:Dynamic) { |
|
368 |
361 |
try { |
369 |
// first attempt to get inverse matrix through the determinant |
|
370 |
||
371 |
var det = matrix.a * matrix.d - matrix.b * matrix.c; |
|
372 |
||
373 |
// negative determinant, try svd |
|
374 |
if ( det < 0 ) throw "notInvertible"; |
|
375 |
ctx.transform( matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty ); |
|
376 |
ctx.drawImage( img, 0,0 ); |
|
377 |
||
362 |
if(matrix != null) { |
|
363 |
ctx.transform( matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty ); |
|
364 |
} |
|
365 |
ctx.drawImage( img, 0, 0 ); |
|
366 |
||
378 |
367 |
ctx.restore(); |
379 |
var iDet = 1 / det; |
|
380 |
ctx.transform( matrix.d * iDet, -matrix.b * iDet, -matrix.c * iDet, matrix.a * iDet, 0., 0. ); |
|
381 |
ctx.translate( -matrix.tx, -matrix.ty ); |
|
382 |
||
383 |
368 |
} catch (e:Dynamic) { |
384 |
369 |
// fallback - should work for most canvas-browsers |
385 |
370 |
|
| … | … | @@ -393,13 +378,7 @@ class Graphics |
393 |
378 |
ctx.restore(); |
394 |
379 |
} |
395 |
380 |
} |
396 |
||
397 |
//ctx.drawImage( img, 0,0 ); |
|
398 |
||
399 |
//ctx.restore(); |
|
400 |
} |
|
401 |
381 |
} |
402 |
//ctx.translate( -mInitX, -mInitY ); |
|
403 |
382 |
ctx.restore(); |
404 |
383 |
#else |
405 |
384 |
