Skip to content

Commit 903a47d

Browse files
committed
Improvements to HTML5 drawTiles
git-svn-id: https://nekonme.googlecode.com/svn/trunk@2187 1509560c-5e2a-0410-865c-31c25e1cfdef
1 parent bec82e7 commit 903a47d

File tree

1 file changed

+47
-57
lines changed

1 file changed

+47
-57
lines changed

jeash/display/Graphics.hx

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@ class Graphics
203203
public static inline var TILE_ROTATION = 0x0002;
204204
public static inline var TILE_RGB = 0x0004;
205205
public static inline var TILE_ALPHA = 0x0008;
206-
206+
public static inline var TILE_TRANS_2x2 = 0x0010;
207+
208+
public static inline var TILE_BLEND_NORMAL = 0x00000000;
209+
public static inline var TILE_BLEND_ADD = 0x00010000;
210+
207211
public var jeashSurface(default, null):HTMLCanvasElement;
208212
private var jeashChanged:Bool;
209213

@@ -671,31 +675,20 @@ class Graphics
671675
{
672676
var useScale = (flags & TILE_SCALE) > 0;
673677
var useRotation = (flags & TILE_ROTATION) > 0;
678+
var useTransform = (flags & TILE_TRANS_2x2) > 0;
674679
var useRGB = (flags & TILE_RGB) > 0;
675680
var useAlpha = (flags & TILE_ALPHA) > 0;
676681

682+
if (useTransform) { useScale = false; useRotation = false; }
683+
677684
var index = 0;
678685
var numValues = 3;
679686

680-
if (useScale)
681-
{
682-
numValues ++;
683-
}
684-
685-
if (useRotation)
686-
{
687-
numValues ++;
688-
}
689-
690-
if (useRGB)
691-
{
692-
numValues += 3;
693-
}
694-
695-
if (useAlpha)
696-
{
697-
numValues ++;
698-
}
687+
if (useScale) numValues ++;
688+
if (useRotation) numValues ++;
689+
if (useTransform) numValues += 4;
690+
if (useRGB) numValues += 3;
691+
if (useAlpha) numValues ++;
699692

700693
while (index < tileData.length) {
701694

@@ -712,38 +705,25 @@ class Graphics
712705

713706
var useScale = (flags & TILE_SCALE) > 0;
714707
var useRotation = (flags & TILE_ROTATION) > 0;
708+
var useTransform = (flags & TILE_TRANS_2x2) > 0;
715709
var useRGB = (flags & TILE_RGB) > 0;
716710
var useAlpha = (flags & TILE_ALPHA) > 0;
717711

712+
if (useTransform) { useScale = false; useRotation = false; }
713+
718714
var scaleIndex = 0;
719715
var rotationIndex = 0;
720716
var rgbIndex = 0;
721717
var alphaIndex = 0;
722-
var numValues = 3;
723-
724-
if (useScale)
725-
{
726-
scaleIndex = numValues;
727-
numValues ++;
728-
}
718+
var transformIndex = 0;
729719

730-
if (useRotation)
731-
{
732-
rotationIndex = numValues;
733-
numValues ++;
734-
}
735-
736-
if (useRGB)
737-
{
738-
rgbIndex = numValues;
739-
numValues += 3;
740-
}
720+
var numValues = 3;
741721

742-
if (useAlpha)
743-
{
744-
alphaIndex = numValues;
745-
numValues ++;
746-
}
722+
if (useScale) { scaleIndex = numValues; numValues ++; }
723+
if (useRotation) { rotationIndex = numValues; numValues ++; }
724+
if (useTransform) { transformIndex = numValues; numValues += 4; }
725+
if (useRGB) { rgbIndex = numValues; numValues += 3; }
726+
if (useAlpha) { alphaIndex = numValues; numValues ++; }
747727

748728
var totalCount = tileData.length;
749729
var itemCount = Std.int (totalCount / numValues);
@@ -771,27 +751,37 @@ class Graphics
771751

772752
}
773753

774-
ctx.save ();
775-
ctx.translate (tileData[index], tileData[index + 1]);
776-
777-
if (useRotation) {
754+
if (rect != null && center != null) {
778755

779-
ctx.rotate (-tileData[index + rotationIndex]);
756+
ctx.save ();
757+
ctx.translate (tileData[index], tileData[index + 1]);
780758

781-
}
782-
783-
var scale = 1.0;
784-
785-
if (useScale) {
759+
if (useRotation && !useTransform) {
760+
761+
ctx.rotate (-tileData[index + rotationIndex]);
762+
763+
}
764+
765+
var scale = 1.0;
786766

787-
scale = tileData[index + scaleIndex];
767+
if (useScale && !useTransform) {
768+
769+
scale = tileData[index + scaleIndex];
770+
771+
}
772+
773+
if (useTransform) {
774+
775+
ctx.transform (tileData[index + transformIndex], tileData[index + transformIndex + 1], tileData[index + transformIndex + 2], tileData[index + transformIndex + 3], 0, 0);
776+
777+
}
778+
779+
ctx.drawImage (surface, rect.x, rect.y, rect.width, rect.height, -center.x * scale, -center.y * scale, rect.width * scale, rect.height * scale);
780+
ctx.restore ();
788781

789782
}
790783

791-
ctx.drawImage (surface, rect.x, rect.y, rect.width, rect.height, -center.x * scale, -center.y * scale, rect.width * scale, rect.height * scale);
792-
793784
index += numValues;
794-
ctx.restore ();
795785

796786
}
797787

0 commit comments

Comments
 (0)