@@ -73,8 +73,8 @@ public class PGraphicsAndroid2D extends PGraphics {
73
73
static protected final int MATRIX_STACK_DEPTH = 32 ;
74
74
protected float [][] transformStack ;
75
75
public PMatrix2D transform ;
76
- protected Matrix tmpMatrix ;
77
- protected float [] tmpArray ;
76
+ protected Matrix transformMatrix ;
77
+ protected float [] transformArray ;
78
78
int transformCount ;
79
79
80
80
// Line2D.Float line = new Line2D.Float();
@@ -133,8 +133,8 @@ public class PGraphicsAndroid2D extends PGraphics {
133
133
public PGraphicsAndroid2D () {
134
134
transformStack = new float [MATRIX_STACK_DEPTH ][6 ];
135
135
transform = new PMatrix2D ();
136
- tmpMatrix = new Matrix ();
137
- tmpArray = new float [9 ];
136
+ transformMatrix = new Matrix ();
137
+ transformArray = new float [9 ];
138
138
139
139
path = new Path ();
140
140
rect = new RectF ();
@@ -1432,7 +1432,8 @@ public void pushMatrix() {
1432
1432
}
1433
1433
transform .get (transformStack [transformCount ]);
1434
1434
transformCount ++;
1435
- // canvas.save(Canvas.MATRIX_SAVE_FLAG);
1435
+
1436
+ // canvas.save();
1436
1437
}
1437
1438
1438
1439
@@ -1444,8 +1445,15 @@ public void popMatrix() {
1444
1445
}
1445
1446
transformCount --;
1446
1447
transform .set (transformStack [transformCount ]);
1447
- updateTmpMatrix ();
1448
- canvas .setMatrix (tmpMatrix );
1448
+ updateTransformMatrix ();
1449
+
1450
+ // Using canvas.restore() here and canvas.save() in popMatrix() and should achieve
1451
+ // the same effect as setting copying transform into transformMatrix with updateTransformMatrix()
1452
+ // and setting it below, although it has been reported that with the later approach, a push/pop
1453
+ // would not result in the initial matrix state:
1454
+ // https://github.com/processing/processing-android/issues/445
1455
+ // However, cannot find
1456
+ canvas .setMatrix (transformMatrix );
1449
1457
// canvas.restore();
1450
1458
}
1451
1459
@@ -1548,8 +1556,8 @@ public void resetMatrix() {
1548
1556
public void applyMatrix (float n00 , float n01 , float n02 ,
1549
1557
float n10 , float n11 , float n12 ) {
1550
1558
transform .apply (n00 , n01 , n02 , n10 , n11 , n12 );
1551
- updateTmpMatrix ();
1552
- canvas .concat (tmpMatrix );
1559
+ updateTransformMatrix ();
1560
+ canvas .concat (transformMatrix );
1553
1561
}
1554
1562
1555
1563
@@ -1600,8 +1608,8 @@ public PMatrix3D getMatrix(PMatrix3D target) {
1600
1608
@ Override
1601
1609
public void setMatrix (PMatrix2D source ) {
1602
1610
transform .set (source );
1603
- updateTmpMatrix ();
1604
- canvas .setMatrix (tmpMatrix );
1611
+ updateTransformMatrix ();
1612
+ canvas .setMatrix (transformMatrix );
1605
1613
}
1606
1614
1607
1615
@@ -1619,24 +1627,24 @@ public void printMatrix() {
1619
1627
1620
1628
protected Matrix getMatrixImp () {
1621
1629
Matrix m = new Matrix ();
1622
- updateTmpMatrix ();
1623
- m .set (tmpMatrix );
1630
+ updateTransformMatrix ();
1631
+ m .set (transformMatrix );
1624
1632
return m ;
1625
1633
// return canvas.getMatrix();
1626
1634
}
1627
1635
1628
1636
1629
- protected void updateTmpMatrix () {
1630
- tmpArray [0 ] = transform .m00 ;
1631
- tmpArray [1 ] = transform .m01 ;
1632
- tmpArray [2 ] = transform .m02 ;
1633
- tmpArray [3 ] = transform .m10 ;
1634
- tmpArray [4 ] = transform .m11 ;
1635
- tmpArray [5 ] = transform .m12 ;
1636
- tmpArray [6 ] = 0 ;
1637
- tmpArray [7 ] = 0 ;
1638
- tmpArray [8 ] = 1 ;
1639
- tmpMatrix .setValues (tmpArray );
1637
+ public void updateTransformMatrix () {
1638
+ transformArray [0 ] = transform .m00 ;
1639
+ transformArray [1 ] = transform .m01 ;
1640
+ transformArray [2 ] = transform .m02 ;
1641
+ transformArray [3 ] = transform .m10 ;
1642
+ transformArray [4 ] = transform .m11 ;
1643
+ transformArray [5 ] = transform .m12 ;
1644
+ transformArray [6 ] = 0 ;
1645
+ transformArray [7 ] = 0 ;
1646
+ transformArray [8 ] = 1 ;
1647
+ transformMatrix .setValues (transformArray );
1640
1648
}
1641
1649
1642
1650
@@ -1676,29 +1684,23 @@ protected void updateTmpMatrix() {
1676
1684
1677
1685
@ Override
1678
1686
public float screenX (float x , float y ) {
1679
- // canvas.getTransform().getMatrix(transform);
1680
- // return (float)transform[0]*x + (float)transform[2]*y + (float)transform[4];
1681
1687
if (screenPoint == null ) {
1682
1688
screenPoint = new float [2 ];
1683
1689
}
1684
1690
screenPoint [0 ] = x ;
1685
1691
screenPoint [1 ] = y ;
1686
- // canvas.getMatrix().mapPoints(screenPoint);
1687
1692
getMatrixImp ().mapPoints (screenPoint );
1688
1693
return screenPoint [0 ];
1689
1694
}
1690
1695
1691
1696
1692
1697
@ Override
1693
1698
public float screenY (float x , float y ) {
1694
- // canvas.getTransform().getMatrix(transform);
1695
- // return (float)transform[1]*x + (float)transform[3]*y + (float)transform[5];
1696
1699
if (screenPoint == null ) {
1697
1700
screenPoint = new float [2 ];
1698
1701
}
1699
1702
screenPoint [0 ] = x ;
1700
1703
screenPoint [1 ] = y ;
1701
- // canvas.getMatrix().mapPoints(screenPoint);
1702
1704
getMatrixImp ().mapPoints (screenPoint );
1703
1705
return screenPoint [1 ];
1704
1706
}
@@ -2188,12 +2190,10 @@ public void set(int x, int y, PImage src) {
2188
2190
src .setModified (false );
2189
2191
}
2190
2192
// set() happens in screen coordinates, so need to clear the ctm
2191
- // canvas.save(Canvas.MATRIX_SAVE_FLAG);
2192
2193
pushMatrix ();
2193
2194
canvas .setMatrix (null ); // set to identity
2194
2195
canvas .drawBitmap (bitmap , x , y , null );
2195
2196
popMatrix ();
2196
- // canvas.restore();
2197
2197
}
2198
2198
2199
2199
0 commit comments