WallItem.kt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.ys.bdtp.cad.items
  2. import android.graphics.*
  3. import com.ys.bdtp.cad.Opt
  4. import com.ys.bdtp.cad.types.Wall
  5. import com.ys.bdtp.graph.SGraphyItem
  6. import java.util.*
  7. /**
  8. * 墙item
  9. *
  10. * @author 郝建龙
  11. */
  12. class WallItem(private val data: Wall, parent: SGraphyItem? = null) : SGraphyItem(parent) {
  13. /** 画笔 */
  14. private val paint = Paint()
  15. /** 墙轮廓 */
  16. private val pathList = ArrayList<Path>()
  17. /** X坐标最小值 */
  18. private var minX = 0f
  19. /** X坐标最大值 */
  20. private var maxX = 0f
  21. /** Y坐标最小值 */
  22. private var minY = 0f
  23. /** Y坐标最大值 */
  24. private var maxY = 0f
  25. /**
  26. * 构造
  27. */
  28. init {
  29. try {
  30. if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
  31. minX = data.outLine!![0][0].x
  32. maxX = data.outLine!![0][0].x
  33. minY = data.outLine!![0][0].y
  34. maxY = data.outLine!![0][0].y
  35. for (line in data.outLine!!) {
  36. if (line.size < 1) {
  37. continue
  38. }
  39. val path = Path()
  40. path.moveTo(line[0].x, -line[0].y)
  41. for (p in line) {
  42. if (p.x < minX) {
  43. minX = p.x
  44. }
  45. if (p.x > maxX) {
  46. maxX = p.x
  47. }
  48. if (-p.y < minY) {
  49. minY = -p.y
  50. }
  51. if (-p.y > maxY) {
  52. maxY = -p.y
  53. }
  54. path.lineTo(p.x, -p.y)
  55. }
  56. path.close()
  57. pathList.add(path)
  58. }
  59. }
  60. } catch (e: Exception) {
  61. e.printStackTrace()
  62. }
  63. } // Constructor
  64. /**
  65. * Item对象边界区域
  66. *
  67. * @return 边界区域
  68. */
  69. override fun boundingRect(): RectF {
  70. return RectF(minX, minY, maxX, maxY)
  71. } // Function boundingRect()
  72. /**
  73. * Item绘制操作
  74. *
  75. * @param canvas 画布
  76. * @param rect 绘制区域
  77. */
  78. override fun onDraw(canvas: Canvas) {
  79. paint.style = Paint.Style.FILL
  80. paint.color = Opt.wallColor
  81. for (path in pathList) {
  82. canvas.drawPath(path, paint)
  83. }
  84. } // Function onDraw()
  85. } // Class WallItem