|
@@ -25,13 +25,13 @@ package com.sybotan.android.graphy
|
|
|
|
|
|
import android.graphics.*
|
|
import android.graphics.*
|
|
import android.util.Log
|
|
import android.util.Log
|
|
-import android.view.MotionEvent
|
|
|
|
import com.sybotan.android.base.extensions.adjusted
|
|
import com.sybotan.android.base.extensions.adjusted
|
|
import com.sybotan.android.graphy.data.SLineF
|
|
import com.sybotan.android.graphy.data.SLineF
|
|
import com.sybotan.android.graphy.enums.SGraphyItemFlag
|
|
import com.sybotan.android.graphy.enums.SGraphyItemFlag
|
|
import com.sybotan.android.graphy.items.SGraphyImageItem
|
|
import com.sybotan.android.graphy.items.SGraphyImageItem
|
|
import com.sybotan.android.graphy.items.SGraphyLineItem
|
|
import com.sybotan.android.graphy.items.SGraphyLineItem
|
|
import com.sybotan.android.graphy.items.SGraphyRectItem
|
|
import com.sybotan.android.graphy.items.SGraphyRectItem
|
|
|
|
+import com.sybotan.android.graphy.utils.MatrixTools
|
|
|
|
|
|
/**
|
|
/**
|
|
* SGraphy图形引擎场景类
|
|
* SGraphy图形引擎场景类
|
|
@@ -208,7 +208,7 @@ open class SGraphyScene {
|
|
* @param e 按下手势事件。
|
|
* @param e 按下手势事件。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- open fun onDown(e: MotionEvent): Boolean {
|
|
|
|
|
|
+ open fun onDown(e: SMotionEvent): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
return true
|
|
return true
|
|
}
|
|
}
|
|
@@ -222,7 +222,7 @@ open class SGraphyScene {
|
|
* @param e 释放手势事件。
|
|
* @param e 释放手势事件。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- open fun onSingleTapUp(e: MotionEvent): Boolean {
|
|
|
|
|
|
+ open fun onSingleTapUp(e: SMotionEvent): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
return grabItem!!.onSingleTapUp(ie)
|
|
return grabItem!!.onSingleTapUp(ie)
|
|
@@ -236,7 +236,7 @@ open class SGraphyScene {
|
|
* @param e 手势事件。
|
|
* @param e 手势事件。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- fun onShowPress(e: MotionEvent): Boolean {
|
|
|
|
|
|
+ fun onShowPress(e: SMotionEvent): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
grabItem!!.onShowPress(ie)
|
|
grabItem!!.onShowPress(ie)
|
|
@@ -252,7 +252,7 @@ open class SGraphyScene {
|
|
* @param e 长按手势事件。
|
|
* @param e 长按手势事件。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- open fun onLongPress(e: MotionEvent): Boolean {
|
|
|
|
|
|
+ open fun onLongPress(e: SMotionEvent): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
val ie = toGrabItemMotionEvent(grabItem!!, e)
|
|
return grabItem!!.onLongPress(ie)
|
|
return grabItem!!.onLongPress(ie)
|
|
@@ -269,7 +269,7 @@ open class SGraphyScene {
|
|
* @param distanceY Y轴上的移动距离,单位:像素
|
|
* @param distanceY Y轴上的移动距离,单位:像素
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- open fun onScroll(e1: MotionEvent, e2: MotionEvent, distanceX: Float, distanceY: Float): Boolean {
|
|
|
|
|
|
+ open fun onScroll(e1: SMotionEvent, e2: SMotionEvent, distanceX: Float, distanceY: Float): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
val ie1 = toGrabItemMotionEvent(grabItem!!, e1)
|
|
val ie1 = toGrabItemMotionEvent(grabItem!!, e1)
|
|
val ie2 = toGrabItemMotionEvent(grabItem!!, e2)
|
|
val ie2 = toGrabItemMotionEvent(grabItem!!, e2)
|
|
@@ -289,7 +289,7 @@ open class SGraphyScene {
|
|
* @param velocityY Y轴上的移动速度,像素/秒
|
|
* @param velocityY Y轴上的移动速度,像素/秒
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
* @return 如果事件被处理返回 true , 否则返回 false 。
|
|
*/
|
|
*/
|
|
- open fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
|
|
|
|
|
+ open fun onFling(e1: SMotionEvent, e2: SMotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
if (null != grabItem) { // 如果当前锁定item不为空
|
|
val ie1 = toGrabItemMotionEvent(grabItem!!, e1)
|
|
val ie1 = toGrabItemMotionEvent(grabItem!!, e1)
|
|
val ie2 = toGrabItemMotionEvent(grabItem!!, e2)
|
|
val ie2 = toGrabItemMotionEvent(grabItem!!, e2)
|
|
@@ -307,10 +307,20 @@ open class SGraphyScene {
|
|
* @param e 场景事件
|
|
* @param e 场景事件
|
|
* @return item事件
|
|
* @return item事件
|
|
*/
|
|
*/
|
|
- private fun toGrabItemMotionEvent(item: SGraphyItem, e: MotionEvent): MotionEvent {
|
|
|
|
- val se = MotionEvent.obtain(e)
|
|
|
|
- val p = item.mapFromScene(e.x, e.y)
|
|
|
|
- se.setLocation(p.x, p.y)
|
|
|
|
|
|
+ private fun toGrabItemMotionEvent(item: SGraphyItem, e: SMotionEvent): SMotionEvent {
|
|
|
|
+ val se = SMotionEvent(e)
|
|
|
|
+ se.matrix = Matrix()
|
|
|
|
+ if (this.view != null ){
|
|
|
|
+ se.matrix.postTranslate(this.view!!.pos.x, this.view!!.pos.y);
|
|
|
|
+ se.matrix.postScale(this.view!!.scale, this.view!!.scale)
|
|
|
|
+ se.matrix.postRotate(this.view!!.rotate)
|
|
|
|
+ }
|
|
|
|
+ se.matrix.postConcat(item.scene2itemMattrix())
|
|
|
|
+ val matrixTransform = MatrixTools.matrixTransform(se.matrix, se.x, se.y)
|
|
|
|
+ se.x = matrixTransform.x
|
|
|
|
+ se.y = matrixTransform.y
|
|
|
|
+// val p = item.mapFromScene(e.x, e.y)
|
|
|
|
+// se.setLocation(p.x, p.y)
|
|
return se
|
|
return se
|
|
} // Function toItemMotionEvent()
|
|
} // Function toItemMotionEvent()
|
|
|
|
|
|
@@ -329,7 +339,6 @@ open class SGraphyScene {
|
|
p.x = p.x / child.scale.x
|
|
p.x = p.x / child.scale.x
|
|
p.y = p.y / child.scale.y
|
|
p.y = p.y / child.scale.y
|
|
}
|
|
}
|
|
-
|
|
|
|
return p
|
|
return p
|
|
} // Function toGrabItemDistance()
|
|
} // Function toGrabItemDistance()
|
|
|
|
|