CrosshairView.java
2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.sw.laryngoscope.widget;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.Region;
import android.util.AttributeSet;
import com.sw.laryngoscope.common.Constant;
import com.sw.laryngoscope.manager.SpManager;
import com.sw.laryngoscope.utils.Logger;
/**
* @des CrosshairView
* @date 2023/7/10
* @author gx
*/
public class CrosshairView extends androidx.appcompat.widget.AppCompatImageView {
private float mWidth;
private float mHeight;
public static final int RIGHT = 90;
private Paint m_paint;
public CrosshairView(Context context) {
super(context);
init(context, null, 0);
}
public CrosshairView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}
public CrosshairView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}
private void init(Context context, AttributeSet attrs, int defStyle) {
initPaint();
}
private void initPaint() {
m_paint = new Paint();
m_paint.setColor(Color.parseColor("#FF0000"));
m_paint.setStrokeWidth(1);
m_paint.setAntiAlias(true);
}
public CrosshairView setWidth(float width){
this.mWidth = width;
return this;
}
/**
* @Params [height]
* @Return com.sw.laryngoscope.widget.CrosshairView
* @Author gx
* @Date 2023/7/10
*/
public CrosshairView setHeight(float height){
this.mHeight = height;
return this;
}
/**
*
* @Title: setColor
* @Description: 给三角形填充颜色
* @param @param color
* @return TriangleView this
* @throws
*/
public CrosshairView setColor(int color){
invalidate();
return this;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
paintLine(canvas);
}
private void paintLine(Canvas canvas) {
mWidth = getWidth();
mHeight = getHeight();
int spacing = 0;
// 2.设置竖线的位置
float startX = mWidth / 2;
float startY = spacing;
float stopX = startX;
float stopY = mHeight - spacing;
//Logger.d( "startX " + startX);
canvas.drawLine(startX, startY, stopX, stopY, m_paint);
// 3.设置横线的位置
startX = spacing;
startY = mHeight / 2;
stopX = mWidth - spacing;
stopY = startY;
canvas.drawLine(startX, startY, stopX, stopY, m_paint);
}
}