|
@@ -1,12 +1,15 @@
|
|
|
package cn.sagacloud.android.cadengine.items
|
|
|
|
|
|
-import android.graphics.Canvas
|
|
|
-import android.graphics.Paint
|
|
|
-import android.graphics.Path
|
|
|
-import android.graphics.RectF
|
|
|
+import android.graphics.*
|
|
|
import cn.sagacloud.android.cadengine.types.Door
|
|
|
import cn.sagacloud.android.cadengine.types.Opt
|
|
|
import com.sybotan.android.graphy.SGraphyItem
|
|
|
+import kotlin.math.atan
|
|
|
+import kotlin.math.atan2
|
|
|
+import kotlin.math.sqrt
|
|
|
+import android.view.View.X
|
|
|
+import kotlin.math.abs
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 门item
|
|
@@ -15,53 +18,82 @@ import com.sybotan.android.graphy.SGraphyItem
|
|
|
*/
|
|
|
class DoorItem(private val data: Door, 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
|
|
|
+ private val paint1 = Paint()
|
|
|
+ private val paint2 = Paint()
|
|
|
+ /** 门长度 */
|
|
|
+ private var d = 0f
|
|
|
+
|
|
|
+ /** 角度 */
|
|
|
+ private var angle = 0f
|
|
|
+ /** 旋转点 */
|
|
|
+ private var p = PointF(0f, 0f)
|
|
|
+ /** 旋转起始角度 */
|
|
|
+ private var startAng = 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
|
|
|
+ paint1.style = Paint.Style.STROKE
|
|
|
+ paint1.color = Opt.doorColor
|
|
|
+ paint1.strokeWidth = 100f
|
|
|
+ paint2.style = Paint.Style.STROKE
|
|
|
+ paint2.color = Opt.doorColor
|
|
|
+ paint2.strokeWidth = 50f
|
|
|
+ paint2.pathEffect = DashPathEffect(floatArrayOf(200f, 200f), 0f)
|
|
|
|
|
|
- for (line in data.outLine!!) {
|
|
|
- if (line.size < 1) {
|
|
|
- continue
|
|
|
- }
|
|
|
+ zOrder = 2f
|
|
|
+ if (data.outLine != null && data.outLine!!.size > 0 && data.outLine!![0].size >= 2) {
|
|
|
+ // 取门的两个端点
|
|
|
+ val p1 = PointF(data.outLine!![0][0].x, -data.outLine!![0][0].y)
|
|
|
+ val p2 = PointF(data.outLine!![0][1].x, -data.outLine!![0][1].y)
|
|
|
+ d = sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y))
|
|
|
|
|
|
- val path = Path()
|
|
|
- path.moveTo(line[0].x, -line[0].y)
|
|
|
- for (p in line) {
|
|
|
- if (p.x < minX) {
|
|
|
- minX = p.x
|
|
|
+ // 角度为
|
|
|
+ val fo = atan2(-data.faceDirection!!.y, data.faceDirection!!.x)
|
|
|
+ // 门朝向角度
|
|
|
+ angle = if(data.faceDirection!!.x > 0) {
|
|
|
+ fo
|
|
|
+ } else {
|
|
|
+ fo + Math.PI.toFloat()
|
|
|
+ }
|
|
|
+
|
|
|
+// val dir = data.faceDirection!!.x * (data.handDirection!!.y - data.faceDirection!!.y) - data.faceDirection!!.y * (data.handDirection!!.x - data.faceDirection!!.x)
|
|
|
+// if (dir < 0) {
|
|
|
+// startAng = -90f
|
|
|
+// }
|
|
|
+
|
|
|
+ // 计算旋转点
|
|
|
+ if (abs(data.handDirection!!.x) > abs(data.handDirection!!.y)) {
|
|
|
+ p = if (data.handDirection!!.x > 0) {
|
|
|
+ if (p1.x > p2.x) {
|
|
|
+ p1
|
|
|
+ } else {
|
|
|
+ p2
|
|
|
}
|
|
|
- if (p.x > maxX) {
|
|
|
- maxX = p.x
|
|
|
+ } else {
|
|
|
+ if (p1.x < p2.x) {
|
|
|
+ p1
|
|
|
+ } else {
|
|
|
+ p2
|
|
|
}
|
|
|
- if (-p.y < minY) {
|
|
|
- minY = -p.y
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ p = if (data.handDirection!!.y > 0) {
|
|
|
+ if (p1.y > p2.y) {
|
|
|
+ p1
|
|
|
+ } else {
|
|
|
+ p2
|
|
|
}
|
|
|
- if (-p.y > maxY) {
|
|
|
- maxY = -p.y
|
|
|
+ } else {
|
|
|
+ if (p1.y < p2.y) {
|
|
|
+ p1
|
|
|
+ } else {
|
|
|
+ p2
|
|
|
}
|
|
|
- path.lineTo(p.x, -p.y)
|
|
|
}
|
|
|
- path.close()
|
|
|
- pathList.add(path)
|
|
|
}
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
@@ -70,26 +102,21 @@ class DoorItem(private val data: Door, parent: SGraphyItem? = null) : SGraphyIte
|
|
|
} // 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, rect: RectF) {
|
|
|
- paint.style = Paint.Style.FILL
|
|
|
- paint.color = Opt.windowColor
|
|
|
- for (path in pathList) {
|
|
|
- canvas.drawPath(path, paint);
|
|
|
- }
|
|
|
+ canvas.translate(p.x, p.y);
|
|
|
+ canvas.rotate(angle * 180f / Math.PI.toFloat())
|
|
|
+
|
|
|
+ paint1.style = Paint.Style.FILL
|
|
|
+ canvas.drawArc(-d, -d, d, d, 0f, 360f ,false, paint1)
|
|
|
+
|
|
|
+// canvas.drawLine(0f, 0f, d, 0f, paint1)
|
|
|
+//
|
|
|
+// canvas.drawArc(-d, -d, d, d, startAng, 90f ,false, paint2)
|
|
|
super.onDraw(canvas, rect)
|
|
|
} // Function onDraw()
|
|
|
} // Class DoorItem
|