Skip to content

Commit

Permalink
坐标轴区分正负
Browse files Browse the repository at this point in the history
修复CanvasAidUtils,为坐标轴区分正负,添加了两个方法,并为之前的两个方法标记了废弃。
  • Loading branch information
GcsSloop committed Aug 29, 2016
1 parent 262d8ff commit c3c4281
Showing 1 changed file with 59 additions and 2 deletions.
61 changes: 59 additions & 2 deletions Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public class CanvasAidUtils {

private static Paint mPaint;
private static int LEN_X = 500;
private static int LEN_NX = 0;
private static int LEN_Y = 700;
private static int LEN_NY = 0;

private static int LINE_WIDTH = 5;
private static int LINE_COLOR = Color.GRAY;
Expand Down Expand Up @@ -54,9 +56,31 @@ public static void setStyle(int lenX, int lenY, int lineWidth, int lineColor) {
LINE_COLOR = lineColor;
}

/**
* 设置坐标轴长度
* @param lenX x坐标轴长度
* @param lenY y坐标轴长度
* @deprecated 被标记为删除, 后续版本中可能移除该方法, 请使用 {@link #setCoordinateLen(int, int, int, int)}
*/
public static void setLen(int lenX, int lenY) {
LEN_X = lenX;
LEN_Y = lenY;
LEN_NX = lenX;
LEN_NY = lenY;
}

/**
* 设置坐标轴长度
* @param lenX x正坐标轴长度.
* @param lenNX x负坐标轴长度.
* @param lenY y正坐标轴长度.
* @param lenNY y负坐标轴长度.
*/
public static void setCoordinateLen(int lenX, int lenNX, int lenY, int lenNY){
LEN_X = lenX;
LEN_Y = lenY;
LEN_NX = lenNX;
LEN_NY = lenNY;
}

public static void setLineWidth(int lineWidth) {
Expand All @@ -67,6 +91,13 @@ public static void setLineColor(int lineColor) {
LINE_COLOR = lineColor;
}

/**
* 绘制坐标系.
* 修复名称,标记为删除,可能在几个版本后移除该方法.
* @param canvas 画布
* @deprecated 被标记为删除,后续版本中可能移除该方法,请使用 {@link #drawCoordinateSpace(Canvas)}
*/
@Deprecated
public static void drawCoordinateSystem(Canvas canvas) {
if (!isDrawAid) {
return;
Expand All @@ -88,6 +119,32 @@ public static void drawCoordinateSystem(Canvas canvas) {
canvas.restore();
}


/**
* 绘制坐标空间.
* @param canvas 画布
*/
public static void drawCoordinateSpace(Canvas canvas) {
if (!isDrawAid) {
return;
}

initPaint();
initPoint();

canvas.save();

CanvasUtils.drawLine(XHead, XTail, canvas, mPaint);
CanvasUtils.drawLine(XHead, XCap1, canvas, mPaint);
CanvasUtils.drawLine(XHead, XCap2, canvas, mPaint);

CanvasUtils.drawLine(YHead, YTail, canvas, mPaint);
CanvasUtils.drawLine(YHead, YCap1, canvas, mPaint);
CanvasUtils.drawLine(YHead, YCap2, canvas, mPaint);

canvas.restore();
}

private static void initPaint() {
mPaint = new Paint();
mPaint.setAntiAlias(true);
Expand All @@ -100,12 +157,12 @@ private static void initPaint() {
private static void initPoint() {

XHead = new Point(+LEN_X, 0);
XTail = new Point(-LEN_X, 0);
XTail = new Point(-LEN_NX, 0);
XCap1 = new Point(LEN_X - Cap_Head_Distance, +Cap_Axis_Distance);
XCap2 = new Point(LEN_X - Cap_Head_Distance, -Cap_Axis_Distance);

YHead = new Point(0, +LEN_Y);
YTail = new Point(0, -LEN_Y);
YTail = new Point(0, -LEN_NY);
YCap1 = new Point(+Cap_Axis_Distance, LEN_Y - Cap_Head_Distance);
YCap2 = new Point(-Cap_Axis_Distance, LEN_Y - Cap_Head_Distance);
}
Expand Down

0 comments on commit c3c4281

Please sign in to comment.