Sfoglia il codice sorgente

********************************** *********************
添加矩阵,修改 isTransform 下的算法

zhangweixin 3 anni fa
parent
commit
dbef58c570

+ 23 - 7
sybotan-android-graphy/src/main/java/com/sybotan/android/graphy/SGraphyItem.kt

@@ -69,7 +69,14 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
 
             // 不跟随缩放
             if (!child.isTransform) {
-                ce.matrix.postScale(child._inverseScale, child._inverseScale);
+//                ce.matrix.postScale(child._inverseScale, child._inverseScale);
+                val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
+                ce.matrix.getValues(src)
+                val matrix = Matrix()
+                matrix.preTranslate(src[2], src[5])
+                matrix.preScale(child.scale.x,child.scale.y)
+                matrix.preRotate(child.rotate)
+                ce.matrix = matrix
             }
 //            se.setLocation((e.x - child.pos.x) / child.scale.x, (e.y - child.pos.y) / child.scale.y)
             val matrixMat = Matrix()
@@ -392,10 +399,12 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
                 canvas.rotate(item.rotate)
 
                 if (!item.isTransform) {
-                    val matrix = canvas.matrix
-                    matrix.getValues(src)
-                    item._inverseScale = 1.0f/src[0]
-                    canvas.scale(item._inverseScale,item._inverseScale)
+                    canvas.matrix.getValues(src)
+                    val matrix = Matrix()
+                    matrix.preTranslate(src[2], src[5])
+                    matrix.preScale(item.scale.x,item.scale.y)
+                    matrix.preRotate(item.rotate)
+                    canvas.matrix = matrix
                 }
                 // 设置绘制区域
                 // canvas.clipRect(item.boundingRect())
@@ -626,7 +635,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
      * @return 转换矩阵
      */
     fun scene2itemMattrix() : Matrix{
-        val m = Matrix()
+        var m = Matrix()
         val list = this.itemPath()
         for ( item in list) {
             m.preTranslate(item.pos.x, item.pos.y);
@@ -634,7 +643,14 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
             m.preRotate(item.rotate)
             // 如果不进行变形处理,则取消 painter 的变型操作
             if (!item.isTransform){
-                m.postScale(item._inverseScale, item._inverseScale);
+//                m.postScale(item._inverseScale, item._inverseScale);
+                val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
+                m.getValues(src)
+                val matrix = Matrix()
+                matrix.preTranslate(src[2], src[5])
+                matrix.preScale(item.scale.x,item.scale.y)
+                matrix.preRotate(item.rotate)
+                m = matrix
             }
         }
         return m