SGraphyItem.kt 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * iFHS7.
  5. * ;BBMBMBMc rZMBMBR BMB
  6. * MBEr:;PBM, 7MBMMEOBB: BBB RBW
  7. * XK: BO SB. :SZ MBM. c;; ir BBM :FFr :SSF: ;xBMB:r iuGXv. i:. iF2;
  8. * DBBM0r. :D S7 ;XMBMB GMBMu. MBM: BMB MBMBBBMBMS WMBMBMBBK MBMBMBM BMBRBMBW .MBMBMBMBB
  9. * :JMRMMD .. , 1MMRM1; ;MBMBBR: MBM ;MB: BMB: MBM. RMBr sBMH BM0 UMB, BMB. KMBv
  10. * ;. XOW B1; :uM: 1RE, i .2BMBs rMB. MBO MBO JMB; MBB MBM BBS 7MBMBOBM: MBW :BMc
  11. * OBRJ.SEE MRDOWOR, 3DE:7OBM . ;BMB RMR7BM BMB MBB. BMB ,BMR .BBZ MMB rMB, BMM rMB7
  12. * :FBRO0D0 RKXSXPR. JOKOOMPi BMBSSWBMB; BMBB: MBMB0ZMBMS .BMBOXRBMB MBMDE RBM2;SMBM; MBB xBM2
  13. * iZGE O0SHSPO. uGZ7. sBMBMBDL :BMO OZu:BMBK, rRBMB0; ,EBMB xBMBr:ER. RDU :OO;
  14. * ,BZ, 1D0 RPSFHXR. xWZ .SMr . .BBB
  15. * :0BMRDG RESSSKR. 2WOMBW; BMBMR
  16. * i0BM: SWKHKGO MBDv
  17. * .UB OOGDM. MK, Copyright (c) 2015-2019. 斯伯坦机器人
  18. * , XMW ..
  19. * r All rights reserved.
  20. *
  21. * ********************************************************************************************************************
  22. */
  23. package com.sybotan.android.graphy
  24. import android.graphics.Canvas
  25. import android.graphics.Matrix
  26. import android.graphics.PointF
  27. import android.graphics.RectF
  28. import android.util.Log
  29. import android.view.MotionEvent
  30. import com.sybotan.android.graphy.enums.SGraphyItemFlag
  31. import com.sybotan.android.graphy.listeners.SGraphyItemPosListener
  32. import com.sybotan.android.graphy.utils.MatrixUtil
  33. import com.sybotan.base.extensions.toJson
  34. import org.jetbrains.anko.doAsync
  35. import java.util.*
  36. /**
  37. * SGraphy图形引擎Item类
  38. *
  39. * @author 庞利祥(sybotan@126.com)
  40. */
  41. open class SGraphyItem(parent: SGraphyItem? = null) {
  42. /**
  43. * 类对象
  44. */
  45. companion object {
  46. private val TAG = SGraphyItem::class.java.name
  47. /** 当前移动Item */
  48. private var currentMoveItem: SGraphyItem? = null
  49. /** 当前焦点Item */
  50. private var currentFocusItem: SGraphyItem? = null
  51. /**
  52. * MotionEvent转子对象MotionEvent
  53. *
  54. * @param child 子item对象
  55. * @param e 事件参数
  56. * @return 子对象MotionEvent
  57. */
  58. fun toChildMotionEvent(child: SGraphyItem, e: SMotionEvent): SMotionEvent {
  59. val ce = SMotionEvent(e)
  60. // ce.matrix.postTranslate(child.pos.x, child.pos.y);
  61. // ce.matrix.postScale(child.scale.x, child.scale.y);
  62. // ce.matrix.postRotate(child.rotate,0f, 0f);
  63. ce.matrix.preTranslate(child.pos.x, child.pos.y);
  64. ce.matrix.preScale(child.scale.x, child.scale.y);
  65. ce.matrix.preRotate(child.rotate, 0f, 0f);
  66. // 不跟随缩放
  67. if (!child.isTransform) {
  68. val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
  69. // ce.matrix.postScale(child._inverseScaleX, child._inverseScaleY);
  70. ce.matrix.getValues(src)
  71. val matrix = Matrix()
  72. matrix.preTranslate(src[2], src[5])
  73. matrix.preScale(child.scale.x, child.scale.y)
  74. matrix.preRotate(child.rotate)
  75. ce.matrix = matrix
  76. }
  77. // se.setLocation((e.x - child.pos.x) / child.scale.x, (e.y - child.pos.y) / child.scale.y)
  78. val matrixMat = Matrix()
  79. ce.matrix.invert(matrixMat)
  80. val matrixTransform = MatrixUtil.matrixTransform(matrixMat, e.viewX, e.viewY)
  81. ce.x = matrixTransform.x
  82. ce.y = matrixTransform.y
  83. return ce
  84. } // Function toSceneMotionEvent()
  85. } // companion object
  86. /** 父节点 */
  87. var parent: SGraphyItem? = parent
  88. set(value) {
  89. if (field == value) { // 如果值没变化
  90. return
  91. }
  92. if (null != field) { // 如果原parent不为空
  93. // 将节点从原parent节点中摘除
  94. field!!.children.remove(this)
  95. }
  96. field = value
  97. if (null != field) { // 如果新parent不为空
  98. // 将节点加入到新parent节点中
  99. field!!.children.add(this)
  100. field!!.children.sortByDescending { it.zOrder }
  101. }
  102. invalidate()
  103. }
  104. /** 子节点列表 */
  105. val children = ArrayList<SGraphyItem>()
  106. /** item所属场景 */
  107. var scene: SGraphyScene? = null
  108. get() {
  109. return if (null != parent) {
  110. parent!!.scene
  111. } else {
  112. field
  113. }
  114. }
  115. /** item位置 */
  116. var pos: PointF = PointF(0f, 0f)
  117. set(value) {
  118. if (field == value) { // 如果值没变化
  119. return
  120. }
  121. field = value
  122. invalidate()
  123. posListener?.onMoveTo(field.x, field.y)
  124. }
  125. /** item位置变更监听器 */
  126. var posListener: SGraphyItemPosListener? = null
  127. /** z轴坐标,数值越大,越靠上 */
  128. var zOrder = 0f
  129. set(value) {
  130. if (field == value) { // 如果值没变化
  131. return
  132. }
  133. field = value
  134. if (null != parent) { // 如果你节点不空
  135. parent!!.children.sortByDescending { it.zOrder }
  136. }
  137. invalidate()
  138. }
  139. /** 缩放比例 */
  140. var scale = PointF(1f, 1f)
  141. /** 旋转 */
  142. var rotate = 0.0f
  143. /** 是否进行变形 */
  144. var isTransform = true;
  145. /** 放缩反比例 */
  146. var _inverseScaleX = 1f;
  147. var _inverseScaleY = 1f;
  148. /** item标志 */
  149. var flags: EnumSet<SGraphyItemFlag> = EnumSet.noneOf(SGraphyItemFlag::class.java)
  150. /** item是否可见 */
  151. var isVisible = true
  152. set(value) {
  153. if (field == value) { // 如果值没变化
  154. return
  155. }
  156. field = value
  157. invalidate()
  158. }
  159. /** item是否获得焦点 */
  160. var focus = false
  161. set(value) {
  162. if (!flags.contains(SGraphyItemFlag.ItemIsFocusable)) { // 如果item不能获得焦点
  163. return
  164. }
  165. if (field == value) { // 如果值没变化
  166. return
  167. }
  168. field = value
  169. if (value) { // 如果获得焦点
  170. currentFocusItem?.focus = false
  171. onGetFocus()
  172. currentFocusItem = this
  173. } else {
  174. onLostFocus()
  175. if (currentFocusItem === this) { // 如果当前焦点对象失去焦点
  176. currentFocusItem = null
  177. }
  178. }
  179. }
  180. /**
  181. * 当前获得焦点的item对象
  182. */
  183. val focusItem: SGraphyItem?
  184. get() = currentFocusItem
  185. /** item是否被选中 */
  186. var isSelected = false
  187. set(value) {
  188. if (field == value) { // 如果值没变化
  189. return
  190. }
  191. field = value
  192. invalidate()
  193. }
  194. /**
  195. * Item对象边界区域
  196. *
  197. * @return 边界区域
  198. */
  199. open fun boundingRect(): RectF {
  200. return RectF()
  201. } // Function boundingRect()
  202. /**
  203. * 更新Item
  204. *
  205. * @param rect 更新区域
  206. */
  207. fun invalidate(rect: RectF = RectF()) {
  208. scene?.update()
  209. return
  210. } // Function update()
  211. /**
  212. * 延迟刷新
  213. *
  214. * @param delayed 延时的时间
  215. */
  216. fun postInvalidateDelayed(delayed: Long) {
  217. doAsync {
  218. Thread.sleep(delayed)
  219. invalidate()
  220. }
  221. return
  222. } // Function postInvalidateDelayed()
  223. /**
  224. * 隐藏item
  225. */
  226. fun hide() {
  227. isVisible = false
  228. return
  229. } // Function hide()
  230. /**
  231. * 显示item
  232. */
  233. fun show() {
  234. isVisible = true
  235. return
  236. } // Function show()
  237. /**
  238. * 移动item到指定位置
  239. *
  240. * @param pos 新的位置
  241. */
  242. fun moveTo(pos: PointF) {
  243. this.pos = pos
  244. return
  245. } // Function move()
  246. /**
  247. * 移动item到指定位置
  248. *
  249. * @param x 新位置的x坐标
  250. * @param y 新位置的y坐标
  251. */
  252. fun moveTo(x: Float, y: Float) {
  253. pos = PointF(x, y)
  254. return
  255. } // Function move()
  256. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  257. // 坐标换算相关操作
  258. /**
  259. * 将场景中的xy坐标转换成item坐标。(该节点被加载到场景中,如果未被加载到场景中,计算会出错)
  260. *
  261. * @param x 场景中的横坐标
  262. * @param y 场景中的纵坐标
  263. *
  264. * @return 在item中的坐标
  265. */
  266. fun mapFromScene(x: Float, y: Float): PointF {
  267. val m = this.scene2itemMattrix()
  268. val matrix = Matrix()
  269. m.invert(matrix)
  270. return MatrixUtil.matrixTransform(matrix, x, y)
  271. } // Function mapFromScene()
  272. /**
  273. * 将场景中的xy坐标转换成item坐标。(该节点被加载到场景中,如果未被加载到场景中,计算会出错)
  274. *
  275. * @param point 场景中的坐标
  276. *
  277. * @return 在item中的坐标
  278. */
  279. fun mapFromScene(point: PointF): PointF {
  280. return mapFromScene(point.x, point.y)
  281. } // Function mapFromScene()
  282. /**
  283. * 将item中的xy坐标转换成场景坐标。(该节点被加载到场景中,如果未被加载到场景中,计算会出错)
  284. *
  285. * @param x item中的横坐标
  286. * @param y item中的纵坐标
  287. *
  288. * @return 在场景中的坐标
  289. */
  290. fun mapToScene(x: Float, y: Float): PointF {
  291. if (null == parent) {
  292. return PointF(x, y)
  293. }
  294. val m = this.scene2itemMattrix()
  295. return return MatrixUtil.matrixTransform(m, x, y)
  296. // return parent!!.mapToScene(x * scale.x + pos.x, y * scale.y + pos.y)
  297. } // Function mapToScene()
  298. /**
  299. * 将item中的xy坐标转换成场景坐标。(该节点被加载到场景中,如果未被加载到场景中,计算会出错)
  300. *
  301. * @param point item中的坐标
  302. *
  303. * @return 在场景中的坐标
  304. */
  305. fun mapToScene(point: PointF): PointF {
  306. return mapToScene(point.x, point.y)
  307. } // Function mapToScene()
  308. /**
  309. * 获得item的路径节点列表。(该节点被加载到场景中,如果未被加载到场景中,计算会出错)
  310. *
  311. * @return 从根节点到当前节点的路径节点列表。
  312. */
  313. fun itemPath(): MutableList<SGraphyItem> {
  314. if (null != parent) {
  315. val list = parent!!.itemPath()
  316. list.add(this)
  317. return list
  318. }
  319. return mutableListOf(this)
  320. } // Function itemPath()
  321. /**
  322. * 判断item是否包含点x,y
  323. *
  324. * @param x 横坐标(当前item)
  325. * @param y 纵坐标(当前item)
  326. *
  327. * @return true包含;false不包含。
  328. */
  329. open fun contains(x: Float, y: Float): Boolean {
  330. Log.e("boundingRect", boundingRect().contains(x, y).toString())
  331. return boundingRect().contains(x, y)
  332. } // Function ()
  333. /**
  334. * 判断item是否包含点x,y
  335. *
  336. * @param point 点坐标(当前item)
  337. *
  338. * @return true包含;false不包含。
  339. */
  340. fun contains(point: PointF): Boolean {
  341. return contains(point.x, point.y)
  342. } // Function ()
  343. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  344. // 事件回调
  345. /**
  346. * Item绘制操作
  347. *
  348. * @param canvas 画布对象
  349. * @param rect 更新区域
  350. */
  351. open fun onPaint(canvas: Canvas, rect: RectF) {
  352. canvas.save()
  353. // val mat1 = SJsonUtil.fromJson(canvas.matrix.toJson(), Matrix::class.java)
  354. this.onDraw(canvas)
  355. // canvas.matrix = mat1
  356. canvas.restore()
  357. val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
  358. for (i in 1..children.size) { // 倒序依次取item列中的所有item。将所有item的边界做并交处理。
  359. val item = children[children.size - i]
  360. if (!item.isVisible) { // 如果对象不可见
  361. continue
  362. }
  363. try {
  364. // 保存画布状态
  365. canvas.save()
  366. // val mat = SJsonUtil.fromJson(canvas.matrix.toJson(), Matrix::class.java)
  367. // item位移到指定位置绘制
  368. canvas.translate(item.pos.x, item.pos.y)
  369. canvas.scale(item.scale.x, item.scale.y)
  370. canvas.rotate(item.rotate)
  371. if (!item.isTransform) {
  372. canvas.matrix.getValues(src)
  373. val matrix = Matrix()
  374. matrix.preTranslate(src[2], src[5])
  375. matrix.preScale(item.scale.x, item.scale.y)
  376. matrix.preRotate(item.rotate)
  377. canvas.matrix = matrix
  378. // matrix.getValues(src)
  379. // item._inverseScaleX = 1.0f/src[0]
  380. // item._inverseScaleY = 1.0f/src[4]
  381. // canvas.scale(item._inverseScaleX,item._inverseScaleY)
  382. // matrix.preTranslate(src[2], src[5])
  383. // matrix.preTranslate(item.scale.x,item.scale.y)
  384. // matrix.preRotate(item.rotate)
  385. // canvas.matrix = matrix
  386. }
  387. // 设置绘制区域
  388. // canvas.clipRect(item.boundingRect())
  389. // 绘制item
  390. item.onPaint(canvas, rect)
  391. // 恢复画布状态
  392. canvas.restore()
  393. // canvas.matrix = mat;
  394. } catch (e: Exception) {
  395. e.printStackTrace()
  396. }
  397. }
  398. return
  399. } // Function paint()
  400. /**
  401. * Item 绘制操作
  402. *
  403. * @param painter 绘制对象
  404. */
  405. open fun onDraw(canvas: Canvas) {
  406. }
  407. /**
  408. * 获得焦点变更回调
  409. */
  410. open fun onGetFocus() {
  411. // DO NOTHING
  412. return
  413. } // Function onGetFocus()
  414. /**
  415. * 失去焦点变更回调
  416. */
  417. open fun onLostFocus() {
  418. // DO NOTHING
  419. return
  420. } // Function onLostFocus()
  421. /**
  422. * 用户按下触发.
  423. *
  424. * @param e 按下手势事件。
  425. * @return 如果事件被处理返回 true , 否则返回 false 。
  426. */
  427. open fun onDown(e: SMotionEvent): Boolean {
  428. for (item in children) {
  429. if (!item.isVisible) { // 如果对象不可见
  430. continue
  431. }
  432. val ce = toChildMotionEvent(item, e)
  433. if (item.contains(ce.x, ce.y) // 如果点在子项目上
  434. && item.onDown(ce)) { // 且子项目处理了事件
  435. return true
  436. }
  437. }
  438. if (flags.contains(SGraphyItemFlag.ItemIsFocusable)) { // 如果是可获得焦点Item
  439. focus = true
  440. return true
  441. }
  442. return false
  443. } // Function onDown()
  444. /**
  445. * 用户释放触发.
  446. *
  447. * @param e 释放手势事件。
  448. * @return 如果事件被处理返回 true , 否则返回 false 。
  449. */
  450. open fun onSingleTapUp(e: SMotionEvent): Boolean {
  451. Log.d(TAG, "onSingleTapUp: releaseItem")
  452. releaseItem()
  453. for (item in children) {
  454. if (!item.isVisible) { // 如果对象不可见
  455. Log.e("手势3scene", e.toJson())
  456. continue
  457. }
  458. val ce = toChildMotionEvent(item, e)
  459. Log.e("手势view", "${scene?.view?.scale}")
  460. Log.e("手势e", "${e.x}, ${e.y}")
  461. Log.e("手势ce", "${ce.x}, ${ce.y}")
  462. Log.e("手势1scene", (item.contains(ce.x, ce.y)).toString())
  463. if (item.contains(ce.x, ce.y) // 如果点在子项目上
  464. && item.onSingleTapUp(ce)) { // 且子项目处理了事件
  465. Log.e("手势4scene", e.toJson())
  466. return true
  467. }
  468. }
  469. Log.e("手势2scene", e.toJson())
  470. return false
  471. } // Function onSingleTapUp()
  472. open fun onActionUp() {
  473. releaseItem()
  474. }
  475. open fun onActionMove(event: MotionEvent) {
  476. }
  477. /**
  478. * 用户点击触发
  479. *
  480. * @param e 手势事件。
  481. * @return 如果事件被处理返回 true , 否则返回 false 。
  482. */
  483. open fun onShowPress(e: SMotionEvent): Boolean {
  484. Log.d(TAG, "onShowPress: releaseItem")
  485. for (item in children) {
  486. if (!item.isVisible) { // 如果对象不可见
  487. continue
  488. }
  489. val ce = toChildMotionEvent(item, e)
  490. if (item.contains(ce.x, ce.y) // 如果点在子项目上
  491. && item.onShowPress(ce)) { // 且子项目处理了事件
  492. return true
  493. }
  494. }
  495. return false
  496. } // Function onShowPress()
  497. /**
  498. * 长按触摸屏超过一定时间。
  499. *
  500. * @param e 长按手势事件。
  501. * @return 如果事件被处理返回 true , 否则返回 false 。
  502. */
  503. open fun onLongPress(e: SMotionEvent): Boolean {
  504. Log.d(TAG, "onLongPress: releaseItem")
  505. releaseItem()
  506. for (item in children) {
  507. if (!item.isVisible) { // 如果对象不可见
  508. continue
  509. }
  510. val ce = toChildMotionEvent(item, e)
  511. if (item.contains(ce.x, ce.y) // 如果点在子项目上
  512. && item.onLongPress(ce)) { // 且子项目处理了事件
  513. return true
  514. }
  515. }
  516. return false
  517. } // Function onLoagPress()
  518. /**
  519. * 用户按下触摸屏,并拖动。
  520. *
  521. * @param e1 第1个 ACTION_DOWN 手势事件
  522. * @param e2 最后一个 ACTION_MOVE 手势事件
  523. * @param distanceX X轴上的移动距离,单位:像素
  524. * @param distanceY Y轴上的移动距离,单位:像素
  525. * @return 如果事件被处理返回 true , 否则返回 false 。
  526. */
  527. open fun onScroll(e1: SMotionEvent, e2: SMotionEvent, distanceX: Float, distanceY: Float): Boolean {
  528. if (flags.contains(SGraphyItemFlag.ItemIsMovable) && currentMoveItem === this) {
  529. moveTo(pos.x - distanceX * scale.x, pos.y - distanceY * scale.y)
  530. return true
  531. }
  532. for (item in children) {
  533. if (!item.isVisible) { // 如果对象不可见
  534. continue
  535. }
  536. val ce1 = toChildMotionEvent(item, e1)
  537. val ce2 = toChildMotionEvent(item, e2)
  538. // 如果点在子项目上且子项目目处理了事件
  539. if (item.contains(ce2.x, ce2.y) // 如果点在子项目上
  540. && item.onScroll(ce1, ce2, distanceX / item.scale.x, distanceY / item.scale.y)) { // 且子项目处理了事件
  541. return true
  542. }
  543. }
  544. if (flags.contains(SGraphyItemFlag.ItemIsMovable) && null == currentMoveItem) { // 如果是可移动Item
  545. grabItem(this)
  546. currentMoveItem = this
  547. return true
  548. }
  549. return false
  550. } // Function onScroll()
  551. /**
  552. * 用户按下触摸屏、快速移动后松开。即滑动操作。
  553. *
  554. * @param e1 第1个 ACTION_DOWN 手势事件
  555. * @param e2 最后一个 ACTION_MOVE 手势事件
  556. * @param velocityX X轴上的移动速度,像素/秒
  557. * @param velocityY Y轴上的移动速度,像素/秒
  558. * @return 如果事件被处理返回 true , 否则返回 false 。
  559. */
  560. open fun onFling(e1: SMotionEvent, e2: SMotionEvent, velocityX: Float, velocityY: Float): Boolean {
  561. Log.d(TAG, "onFling: releaseItem")
  562. releaseItem()
  563. for (item in children) {
  564. if (!item.isVisible) { // 如果对象不可见
  565. continue
  566. }
  567. val ce1 = toChildMotionEvent(item, e1)
  568. val ce2 = toChildMotionEvent(item, e2)
  569. // 如果点在子项目上且子项目目处理了事件
  570. if (item.contains(ce2.x, ce2.y) // 如果点在子项目上
  571. && item.onFling(ce1, ce2, velocityX / item.scale.x, velocityY / item.scale.y)) { // 且子项目处理了事件
  572. return true
  573. }
  574. }
  575. return false
  576. } // Function onFling()
  577. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  578. // 私有方法
  579. /**
  580. * 锁定item
  581. *
  582. * @param item 被锁定的item
  583. */
  584. private fun grabItem(item: SGraphyItem) {
  585. Log.d(TAG, "grabItem")
  586. isSelected = true
  587. scene!!.grabItem = item
  588. return
  589. } // Function grabItem
  590. /**
  591. * 释放被锁定的item
  592. */
  593. private fun releaseItem() {
  594. isSelected = false
  595. currentMoveItem = null
  596. scene!!.grabItem = null
  597. return
  598. } // Function grabItem
  599. /**
  600. * 场景对象到 item 对象的转换矩阵
  601. *
  602. * @return 转换矩阵
  603. */
  604. fun scene2itemMattrix(): Matrix {
  605. var m = Matrix()
  606. val list = this.itemPath()
  607. for (item in list) {
  608. // m.postTranslate(item.pos.x, item.pos.y);
  609. // m.postScale(item.scale.x, item.scale.y);
  610. // m.postRotate(item.rotate)
  611. m.preTranslate(item.pos.x, item.pos.y);
  612. m.preScale(item.scale.x, item.scale.y);
  613. m.preRotate(item.rotate)
  614. // 如果不进行变形处理,则取消 painter 的变型操作
  615. if (!item.isTransform) {
  616. // m.postScale(item._inverseScaleX, item._inverseScaleY);
  617. /****************************************** 待确认 ************************************************/
  618. val src = kotlin.floatArrayOf(0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f)
  619. m.getValues(src)
  620. val matrix = Matrix()
  621. matrix.preTranslate(src[2], src[5])
  622. matrix.preScale(item.scale.x, item.scale.y)
  623. matrix.preRotate(item.rotate)
  624. m = matrix
  625. }
  626. }
  627. return m
  628. }
  629. } // Class SGraphyItem