From c3c4281821d180bc4bc426575776383e4efd7fd6 Mon Sep 17 00:00:00 2001 From: GcsSloop Date: Tue, 30 Aug 2016 03:24:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=90=E6=A0=87=E8=BD=B4=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E6=AD=A3=E8=B4=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复CanvasAidUtils,为坐标轴区分正负,添加了两个方法,并为之前的两个方法标记了废弃。 --- .../gcssloop/view/utils/CanvasAidUtils.java | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java b/Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java index dfb6446..28982e6 100644 --- a/Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java +++ b/Library/src/main/java/com/gcssloop/view/utils/CanvasAidUtils.java @@ -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; @@ -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) { @@ -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; @@ -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); @@ -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); }