|
@@ -31,6 +31,7 @@ import android.util.Log
|
|
|
import com.sybotan.android.graphy.enums.SGraphyItemFlag
|
|
|
import com.sybotan.android.graphy.listeners.SGraphyItemPosListener
|
|
|
import com.sybotan.android.graphy.utils.MatrixTools
|
|
|
+import com.sybotan.base.extensions.toJson
|
|
|
import org.jetbrains.anko.doAsync
|
|
|
import java.util.*
|
|
|
|
|
@@ -276,15 +277,10 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
* @return 在item中的坐标
|
|
|
*/
|
|
|
fun mapFromScene(x: Float, y: Float): PointF {
|
|
|
- val list = itemPath()
|
|
|
- var x0 = x
|
|
|
- var y0 = y
|
|
|
- for (item in list) {
|
|
|
- x0 = (x0 - item.pos.x) / item.scale.x
|
|
|
- y0 = (y0 - item.pos.y) / item.scale.y
|
|
|
- }
|
|
|
-
|
|
|
- return PointF(x0, y0)
|
|
|
+ val m = this.scene2itemMattrix()
|
|
|
+ val matrix = Matrix()
|
|
|
+ m.invert(matrix)
|
|
|
+ return MatrixTools.matrixTransform(matrix,x,y)
|
|
|
} // Function mapFromScene()
|
|
|
|
|
|
/**
|
|
@@ -295,7 +291,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
* @return 在item中的坐标
|
|
|
*/
|
|
|
fun mapFromScene(point: PointF): PointF {
|
|
|
- return PointF(point.x, point.y)
|
|
|
+ return mapFromScene(point.x, point.y)
|
|
|
} // Function mapFromScene()
|
|
|
|
|
|
/**
|
|
@@ -310,8 +306,9 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
if (null == parent) {
|
|
|
return PointF(x, y)
|
|
|
}
|
|
|
-
|
|
|
- return parent!!.mapToScene(x * scale.x + pos.x, y * scale.y + pos.y)
|
|
|
+ val m = this.scene2itemMattrix()
|
|
|
+ return return MatrixTools.matrixTransform(m,x,y)
|
|
|
+// return parent!!.mapToScene(x * scale.x + pos.x, y * scale.y + pos.y)
|
|
|
} // Function mapToScene()
|
|
|
|
|
|
/**
|
|
@@ -322,7 +319,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
* @return 在场景中的坐标
|
|
|
*/
|
|
|
fun mapToScene(point: PointF): PointF {
|
|
|
- return PointF(point.x, point.y)
|
|
|
+ return mapToScene(point.x, point.y)
|
|
|
} // Function mapToScene()
|
|
|
|
|
|
/**
|
|
@@ -371,8 +368,11 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
* @param canvas 画布对象
|
|
|
* @param rect 更新区域
|
|
|
*/
|
|
|
- open fun onDraw(canvas : Canvas, rect: RectF)
|
|
|
- {
|
|
|
+ open fun onPaint(canvas : Canvas, rect: RectF) {
|
|
|
+ canvas.save()
|
|
|
+ this.onDraw(canvas)
|
|
|
+ canvas.restore()
|
|
|
+ val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
|
|
|
for (i in 1 .. children.size) { // 倒序依次取item列中的所有item。将所有item的边界做并交处理。
|
|
|
val item = children[children.size - i]
|
|
|
if (!item.isVisible) { // 如果对象不可见
|
|
@@ -383,10 +383,19 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
canvas.save()
|
|
|
// item位移到指定位置绘制
|
|
|
canvas.translate(item.pos.x, item.pos.y)
|
|
|
+ canvas.scale(item.scale.x,item.scale.y)
|
|
|
+ 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.clipRect(item.boundingRect())
|
|
|
// 绘制item
|
|
|
- item.onDraw(canvas, rect)
|
|
|
+ item.onPaint(canvas, rect)
|
|
|
// 恢复画布状态
|
|
|
canvas.restore()
|
|
|
} catch (e: Exception) {
|
|
@@ -397,6 +406,15 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
} // Function paint()
|
|
|
|
|
|
/**
|
|
|
+ * Item 绘制操作
|
|
|
+ *
|
|
|
+ * @param painter 绘制对象
|
|
|
+ */
|
|
|
+ open fun onDraw(canvas : Canvas) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获得焦点变更回调
|
|
|
*/
|
|
|
open fun onGetFocus() {
|
|
@@ -447,7 +465,7 @@ open class SGraphyItem(parent: SGraphyItem? = null) {
|
|
|
open fun onSingleTapUp(e: SMotionEvent): Boolean {
|
|
|
Log.d(TAG, "onSingleTapUp: releaseItem")
|
|
|
releaseItem()
|
|
|
-
|
|
|
+ Log.e("手势scene",e.toJson())
|
|
|
for (item in children) {
|
|
|
if (!item.isVisible) { // 如果对象不可见
|
|
|
continue
|