| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package com.ys.bdtp.cad.items
- import android.graphics.*
- import com.ys.bdtp.cad.Opt
- import com.ys.bdtp.cad.types.Wall
- import com.ys.bdtp.graph.SGraphyItem
- import java.util.*
- /**
- * 墙item
- *
- * @author 郝建龙
- */
- class WallItem(private val data: Wall, parent: SGraphyItem? = null) : SGraphyItem(parent) {
- /** 画笔 */
- private val paint = Paint()
- /** 墙轮廓 */
- private val pathList = ArrayList<Path>()
- /** X坐标最小值 */
- private var minX = 0f
- /** X坐标最大值 */
- private var maxX = 0f
- /** Y坐标最小值 */
- private var minY = 0f
- /** Y坐标最大值 */
- private var maxY = 0f
- /**
- * 构造
- */
- init {
- try {
- if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size > 0) {
- minX = data.outLine!![0][0].x
- maxX = data.outLine!![0][0].x
- minY = data.outLine!![0][0].y
- maxY = data.outLine!![0][0].y
- for (line in data.outLine!!) {
- if (line.size < 1) {
- continue
- }
- val path = Path()
- path.moveTo(line[0].x, -line[0].y)
- for (p in line) {
- if (p.x < minX) {
- minX = p.x
- }
- if (p.x > maxX) {
- maxX = p.x
- }
- if (-p.y < minY) {
- minY = -p.y
- }
- if (-p.y > maxY) {
- maxY = -p.y
- }
- path.lineTo(p.x, -p.y)
- }
- path.close()
- pathList.add(path)
- }
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- } // Constructor
- /**
- * Item对象边界区域
- *
- * @return 边界区域
- */
- override fun boundingRect(): RectF {
- return RectF(minX, minY, maxX, maxY)
- } // Function boundingRect()
- /**
- * Item绘制操作
- *
- * @param canvas 画布
- * @param rect 绘制区域
- */
- override fun onDraw(canvas: Canvas) {
- paint.style = Paint.Style.FILL
- paint.color = Opt.wallColor
- for (path in pathList) {
- canvas.drawPath(path, paint)
- }
- } // Function onDraw()
- } // Class WallItem
|