From 2e2ad0a1f2f13dbed9d8afbbd493a4d041a607db Mon Sep 17 00:00:00 2001 From: monitor1394 Date: Wed, 9 Aug 2023 08:39:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0`Symbol`=E7=9A=84`EmptyTriang?= =?UTF-8?q?le`=E5=92=8C`EmptyDiamond`=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Runtime/Internal/Utilities/ChartDrawer.cs | 22 ++++---- Runtime/XUGL/UGL.cs | 63 +++++++++++++++++++++++ 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/Runtime/Internal/Utilities/ChartDrawer.cs b/Runtime/Internal/Utilities/ChartDrawer.cs index da6b0871..c6cfbf9b 100644 --- a/Runtime/Internal/Utilities/ChartDrawer.cs +++ b/Runtime/Internal/Utilities/ChartDrawer.cs @@ -71,17 +71,16 @@ namespace XCharts.Runtime case SymbolType.EmptyTriangle: if (gap > 0) { - UGL.DrawTriangle(vh, pos, symbolSize * 1.4f + gap * 2f, backgroundColor); - UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor); + UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f + gap * 2, gap * 2, backgroundColor); + } + if (type == SymbolType.EmptyTriangle) + { + UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f, tickness * 2f, color, emptyColor); } else { UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor); } - if (type == SymbolType.EmptyTriangle) - { - UGL.DrawTriangle(vh, pos, symbolSize * 1.4f - tickness * 2, backgroundColor); - } break; case SymbolType.Diamond: case SymbolType.EmptyDiamond: @@ -89,17 +88,16 @@ namespace XCharts.Runtime var yRadius = symbolSize * 1.5f; if (gap > 0) { - UGL.DrawDiamond(vh, pos, xRadius + gap, yRadius + gap, backgroundColor, backgroundColor); - UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor); + UGL.DrawEmptyDiamond(vh, pos, xRadius + gap, yRadius + gap, gap, backgroundColor); + } + if (type == SymbolType.EmptyDiamond) + { + UGL.DrawEmptyDiamond(vh, pos, xRadius, yRadius, tickness, color, emptyColor); } else { UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor); } - if (type == SymbolType.EmptyDiamond) - { - UGL.DrawDiamond(vh, pos, xRadius - tickness, (symbolSize - tickness) * 1.5f, backgroundColor, backgroundColor); - } break; case SymbolType.Arrow: case SymbolType.EmptyArrow: diff --git a/Runtime/XUGL/UGL.cs b/Runtime/XUGL/UGL.cs index 54e74d41..28321d19 100644 --- a/Runtime/XUGL/UGL.cs +++ b/Runtime/XUGL/UGL.cs @@ -456,6 +456,37 @@ namespace XUGL DrawTriangle(vh, p3, p4, p2, color, color, toColor); } + public static void DrawEmptyDiamond(VertexHelper vh, Vector3 center, float xRadius, float yRadius, float tickness, Color32 color) + { + DrawEmptyDiamond(vh, center, xRadius, yRadius, tickness, color, s_ClearColor32); + } + + public static void DrawEmptyDiamond(VertexHelper vh, Vector3 center, float xRadius, float yRadius, float tickness, Color32 color, Color32 emptyColor) + { + var p1 = new Vector2(center.x - xRadius, center.y); + var p2 = new Vector2(center.x, center.y + yRadius); + var p3 = new Vector2(center.x + xRadius, center.y); + var p4 = new Vector2(center.x, center.y - yRadius); + + var xRadius1 = xRadius - tickness; + var yRadius1 = yRadius - tickness * 1.5f; + var ip1 = new Vector2(center.x - xRadius1, center.y); + var ip2 = new Vector2(center.x, center.y + yRadius1); + var ip3 = new Vector2(center.x + xRadius1, center.y); + var ip4 = new Vector2(center.x, center.y - yRadius1); + + if (!UGLHelper.IsClearColor(emptyColor)) + { + DrawQuadrilateral(vh, ip1, ip2, ip3, ip4, emptyColor); + } + + AddVertToVertexHelper(vh, p1, ip1, color, false); + AddVertToVertexHelper(vh, p2, ip2, color); + AddVertToVertexHelper(vh, p3, ip3, color); + AddVertToVertexHelper(vh, p4, ip4, color); + AddVertToVertexHelper(vh, p1, ip1, color); + } + /// /// Draw a square. 画正方形 /// @@ -1229,6 +1260,38 @@ namespace XUGL vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2); } + public static void DrawEmptyTriangle(VertexHelper vh, Vector3 pos, float size, float tickness, Color32 color) + { + DrawEmptyTriangle(vh, pos, size, tickness, color, s_ClearColor32); + } + + public static void DrawEmptyTriangle(VertexHelper vh, Vector3 pos, float size, float tickness, Color32 color, Color32 backgroundColor) + { + var cos30 = Mathf.Cos(30 * Mathf.PI / 180); + var sin30 = Mathf.Sin(30 * Mathf.PI / 180); + var x = size * cos30; + var y = size * sin30; + var outsideLeft = new Vector2(pos.x - x, pos.y - y); + var outsideTop = new Vector2(pos.x, pos.y + size); + var outsideRight = new Vector2(pos.x + x, pos.y - y); + + var size2 = size - tickness; + var x1 = size2 * cos30; + var y1 = size2 * sin30; + var insideLeft = new Vector2(pos.x - x1, pos.y - y1); + var insideTop = new Vector2(pos.x, pos.y + size2); + var insideRight = new Vector2(pos.x + x1, pos.y - y1); + + if (!UGLHelper.IsClearColor(backgroundColor)) + { + DrawTriangle(vh, insideLeft, insideTop, insideRight, backgroundColor, backgroundColor, backgroundColor); + } + AddVertToVertexHelper(vh, outsideLeft, insideLeft, color, false); + AddVertToVertexHelper(vh, outsideTop, insideTop, color); + AddVertToVertexHelper(vh, outsideRight, insideRight, color); + AddVertToVertexHelper(vh, outsideLeft, insideLeft, color); + } + public static void DrawCricle(VertexHelper vh, Vector3 center, float radius, Color32 color, float smoothness = 2f) {