|
@@ -30,7 +30,7 @@ import android.graphics.RectF
|
|
import android.util.Log
|
|
import android.util.Log
|
|
import com.sybotan.android.graphy.enums.SGraphyItemFlag
|
|
import com.sybotan.android.graphy.enums.SGraphyItemFlag
|
|
import com.sybotan.android.graphy.listeners.SGraphyItemPosListener
|
|
import com.sybotan.android.graphy.listeners.SGraphyItemPosListener
|
|
-import com.sybotan.android.graphy.utils.MatrixTools
|
|
|
|
|
|
+import com.sybotan.android.graphy.utils.MatrixUtil
|
|
import com.sybotan.base.extensions.toJson
|
|
import com.sybotan.base.extensions.toJson
|
|
import org.jetbrains.anko.doAsync
|
|
import org.jetbrains.anko.doAsync
|
|
import java.util.*
|
|
import java.util.*
|
|
@@ -41,7 +41,6 @@ import java.util.*
|
|
* @author 庞利祥(sybotan@126.com)
|
|
* @author 庞利祥(sybotan@126.com)
|
|
*/
|
|
*/
|
|
open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 类对象
|
|
* 类对象
|
|
*/
|
|
*/
|
|
@@ -52,6 +51,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
/** 当前焦点Item */
|
|
/** 当前焦点Item */
|
|
private var currentFocusItem: SGraphyItem? = null
|
|
private var currentFocusItem: SGraphyItem? = null
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* MotionEvent转子对象MotionEvent
|
|
* MotionEvent转子对象MotionEvent
|
|
*
|
|
*
|
|
@@ -61,17 +61,28 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
*/
|
|
*/
|
|
fun toChildMotionEvent(child: SGraphyItem, e: SMotionEvent): SMotionEvent {
|
|
fun toChildMotionEvent(child: SGraphyItem, e: SMotionEvent): SMotionEvent {
|
|
val ce = SMotionEvent(e)
|
|
val ce = SMotionEvent(e)
|
|
- ce.matrix.postTranslate(child.pos.x, child.pos.y);
|
|
|
|
- ce.matrix.postScale(child.scale.x, child.scale.y);
|
|
|
|
- ce.matrix.postRotate(child.rotate,0f, 0f);
|
|
|
|
|
|
+// ce.matrix.postTranslate(child.pos.x, child.pos.y);
|
|
|
|
+// ce.matrix.postScale(child.scale.x, child.scale.y);
|
|
|
|
+// ce.matrix.postRotate(child.rotate,0f, 0f);
|
|
|
|
+ ce.matrix.preTranslate(child.pos.x, child.pos.y);
|
|
|
|
+ ce.matrix.preScale(child.scale.x, child.scale.y);
|
|
|
|
+ ce.matrix.preRotate(child.rotate,0f, 0f);
|
|
|
|
+
|
|
// 不跟随缩放
|
|
// 不跟随缩放
|
|
if (!child.isTransform) {
|
|
if (!child.isTransform) {
|
|
- ce.matrix.postScale(child._inverseScale, child._inverseScale);
|
|
|
|
|
|
+ val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
|
|
|
|
+// ce.matrix.postScale(child._inverseScaleX, child._inverseScaleY);
|
|
|
|
+ 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)
|
|
// se.setLocation((e.x - child.pos.x) / child.scale.x, (e.y - child.pos.y) / child.scale.y)
|
|
val matrixMat = Matrix()
|
|
val matrixMat = Matrix()
|
|
ce.matrix.invert(matrixMat)
|
|
ce.matrix.invert(matrixMat)
|
|
- val matrixTransform = MatrixTools.matrixTransform(matrixMat, e.viewX, e.viewY)
|
|
|
|
|
|
+ val matrixTransform = MatrixUtil.matrixTransform(matrixMat, e.viewX, e.viewY)
|
|
ce.x = matrixTransform.x
|
|
ce.x = matrixTransform.x
|
|
ce.y = matrixTransform.y
|
|
ce.y = matrixTransform.y
|
|
return ce
|
|
return ce
|
|
@@ -143,7 +154,8 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
/** 是否进行变形 */
|
|
/** 是否进行变形 */
|
|
var isTransform = true;
|
|
var isTransform = true;
|
|
/** 放缩反比例 */
|
|
/** 放缩反比例 */
|
|
- var _inverseScale = 1f;
|
|
|
|
|
|
+ var _inverseScaleX = 1f;
|
|
|
|
+ var _inverseScaleY = 1f;
|
|
/** item标志 */
|
|
/** item标志 */
|
|
var flags: EnumSet<SGraphyItemFlag> = EnumSet.noneOf(SGraphyItemFlag::class.java)
|
|
var flags: EnumSet<SGraphyItemFlag> = EnumSet.noneOf(SGraphyItemFlag::class.java)
|
|
|
|
|
|
@@ -282,7 +294,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
val m = this.scene2itemMattrix()
|
|
val m = this.scene2itemMattrix()
|
|
val matrix = Matrix()
|
|
val matrix = Matrix()
|
|
m.invert(matrix)
|
|
m.invert(matrix)
|
|
- return MatrixTools.matrixTransform(matrix,x,y)
|
|
|
|
|
|
+ return MatrixUtil.matrixTransform(matrix,x,y)
|
|
} // Function mapFromScene()
|
|
} // Function mapFromScene()
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -309,7 +321,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
return PointF(x, y)
|
|
return PointF(x, y)
|
|
}
|
|
}
|
|
val m = this.scene2itemMattrix()
|
|
val m = this.scene2itemMattrix()
|
|
- return return MatrixTools.matrixTransform(m,x,y)
|
|
|
|
|
|
+ return return MatrixUtil.matrixTransform(m,x,y)
|
|
// return parent!!.mapToScene(x * scale.x + pos.x, y * scale.y + pos.y)
|
|
// return parent!!.mapToScene(x * scale.x + pos.x, y * scale.y + pos.y)
|
|
} // Function mapToScene()
|
|
} // Function mapToScene()
|
|
|
|
|
|
@@ -372,7 +384,9 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
*/
|
|
*/
|
|
open fun onPaint(canvas : Canvas, rect: RectF) {
|
|
open fun onPaint(canvas : Canvas, rect: RectF) {
|
|
canvas.save()
|
|
canvas.save()
|
|
|
|
+// val mat1 = SJsonUtil.fromJson(canvas.matrix.toJson(), Matrix::class.java)
|
|
this.onDraw(canvas)
|
|
this.onDraw(canvas)
|
|
|
|
+// canvas.matrix = mat1
|
|
canvas.restore()
|
|
canvas.restore()
|
|
val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
|
|
val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
|
|
for (i in 1 .. children.size) { // 倒序依次取item列中的所有item。将所有item的边界做并交处理。
|
|
for (i in 1 .. children.size) { // 倒序依次取item列中的所有item。将所有item的边界做并交处理。
|
|
@@ -383,16 +397,28 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
try {
|
|
try {
|
|
// 保存画布状态
|
|
// 保存画布状态
|
|
canvas.save()
|
|
canvas.save()
|
|
|
|
+// val mat = SJsonUtil.fromJson(canvas.matrix.toJson(), Matrix::class.java)
|
|
// item位移到指定位置绘制
|
|
// item位移到指定位置绘制
|
|
canvas.translate(item.pos.x, item.pos.y)
|
|
canvas.translate(item.pos.x, item.pos.y)
|
|
canvas.scale(item.scale.x,item.scale.y)
|
|
canvas.scale(item.scale.x,item.scale.y)
|
|
canvas.rotate(item.rotate)
|
|
canvas.rotate(item.rotate)
|
|
|
|
|
|
if (!item.isTransform) {
|
|
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
|
|
|
|
+// matrix.getValues(src)
|
|
|
|
+// item._inverseScaleX = 1.0f/src[0]
|
|
|
|
+// item._inverseScaleY = 1.0f/src[4]
|
|
|
|
+// canvas.scale(item._inverseScaleX,item._inverseScaleY)
|
|
|
|
+
|
|
|
|
+// matrix.preTranslate(src[2], src[5])
|
|
|
|
+// matrix.preTranslate(item.scale.x,item.scale.y)
|
|
|
|
+// matrix.preRotate(item.rotate)
|
|
|
|
+// canvas.matrix = matrix
|
|
}
|
|
}
|
|
// 设置绘制区域
|
|
// 设置绘制区域
|
|
// canvas.clipRect(item.boundingRect())
|
|
// canvas.clipRect(item.boundingRect())
|
|
@@ -400,6 +426,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
item.onPaint(canvas, rect)
|
|
item.onPaint(canvas, rect)
|
|
// 恢复画布状态
|
|
// 恢复画布状态
|
|
canvas.restore()
|
|
canvas.restore()
|
|
|
|
+// canvas.matrix = mat;
|
|
} catch (e: Exception) {
|
|
} catch (e: Exception) {
|
|
e.printStackTrace()
|
|
e.printStackTrace()
|
|
}
|
|
}
|
|
@@ -467,18 +494,23 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
open fun onSingleTapUp(e: SMotionEvent): Boolean {
|
|
open fun onSingleTapUp(e: SMotionEvent): Boolean {
|
|
Log.d(TAG, "onSingleTapUp: releaseItem")
|
|
Log.d(TAG, "onSingleTapUp: releaseItem")
|
|
releaseItem()
|
|
releaseItem()
|
|
- Log.e("手势scene",e.toJson())
|
|
|
|
for (item in children) {
|
|
for (item in children) {
|
|
if (!item.isVisible) { // 如果对象不可见
|
|
if (!item.isVisible) { // 如果对象不可见
|
|
|
|
+ Log.e("手势3scene",e.toJson())
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
val ce = toChildMotionEvent(item, e)
|
|
val ce = toChildMotionEvent(item, e)
|
|
|
|
+ Log.e("手势view","${scene?.view?.scale}")
|
|
|
|
+ Log.e("手势e","${e.x}, ${e.y}")
|
|
|
|
+ Log.e("手势ce","${ce.x}, ${ce.y}")
|
|
|
|
+ Log.e("手势1scene",(item.contains(ce.x, ce.y)).toString())
|
|
if (item.contains(ce.x, ce.y) // 如果点在子项目上
|
|
if (item.contains(ce.x, ce.y) // 如果点在子项目上
|
|
&& item.onSingleTapUp(ce)) { // 且子项目处理了事件
|
|
&& item.onSingleTapUp(ce)) { // 且子项目处理了事件
|
|
|
|
+ Log.e("手势4scene",e.toJson())
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ Log.e("手势2scene",e.toJson())
|
|
return false
|
|
return false
|
|
} // Function onSingleTapUp()
|
|
} // Function onSingleTapUp()
|
|
|
|
|
|
@@ -623,15 +655,27 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
* @return 转换矩阵
|
|
* @return 转换矩阵
|
|
*/
|
|
*/
|
|
fun scene2itemMattrix() : Matrix{
|
|
fun scene2itemMattrix() : Matrix{
|
|
- val m = Matrix()
|
|
|
|
|
|
+ var m = Matrix()
|
|
val list = this.itemPath()
|
|
val list = this.itemPath()
|
|
for ( item in list) {
|
|
for ( item in list) {
|
|
- m.postTranslate(item.pos.x, item.pos.y);
|
|
|
|
- m.postScale(item.scale.x, item.scale.y);
|
|
|
|
- m.postRotate(item.rotate)
|
|
|
|
|
|
+// m.postTranslate(item.pos.x, item.pos.y);
|
|
|
|
+// m.postScale(item.scale.x, item.scale.y);
|
|
|
|
+// m.postRotate(item.rotate)
|
|
|
|
+ m.preTranslate(item.pos.x, item.pos.y);
|
|
|
|
+ m.preScale(item.scale.x, item.scale.y);
|
|
|
|
+ m.preRotate(item.rotate)
|
|
|
|
+
|
|
// 如果不进行变形处理,则取消 painter 的变型操作
|
|
// 如果不进行变形处理,则取消 painter 的变型操作
|
|
if (!item.isTransform){
|
|
if (!item.isTransform){
|
|
- m.postScale(item._inverseScale, item._inverseScale);
|
|
|
|
|
|
+// m.postScale(item._inverseScaleX, item._inverseScaleY);
|
|
|
|
+ /****************************************** 待确认 ************************************************/
|
|
|
|
+ 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
|
|
return m
|