Files
XCharts/Runtime/Internal/Utilities/ChartDrawer.cs

202 lines
9.2 KiB
C#
Raw Normal View History

2020-07-10 09:36:56 +08:00
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
2021-01-11 08:54:28 +08:00
using XUGL;
2020-07-10 09:36:56 +08:00
2022-02-19 22:37:57 +08:00
namespace XCharts.Runtime
2020-07-10 09:36:56 +08:00
{
public static class ChartDrawer
{
public static void DrawSymbol(VertexHelper vh, SymbolType type, float symbolSize, float tickness,
Vector3 pos, Color32 color, Color32 toColor, float gap, float[] cornerRadius,
Color32 emptyColor, Color32 backgroundColor, Color32 borderColor, float smoothness, Vector3 startPos)
2020-07-10 09:36:56 +08:00
{
switch (type)
{
2021-11-23 13:20:07 +08:00
case SymbolType.None:
2020-07-10 09:36:56 +08:00
break;
2021-11-23 13:20:07 +08:00
case SymbolType.Circle:
2020-07-10 09:36:56 +08:00
if (gap > 0)
{
2021-01-11 08:54:28 +08:00
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + gap, backgroundColor, backgroundColor, color, smoothness);
2020-07-10 09:36:56 +08:00
}
else
{
if (tickness > 0)
UGL.DrawDoughnut(vh, pos, symbolSize, symbolSize + tickness, borderColor, borderColor, color, smoothness);
else
UGL.DrawCricle(vh, pos, symbolSize, color, toColor, smoothness);
2020-07-10 09:36:56 +08:00
}
break;
2021-11-23 13:20:07 +08:00
case SymbolType.EmptyCircle:
2020-07-10 09:36:56 +08:00
if (gap > 0)
{
2021-01-11 08:54:28 +08:00
UGL.DrawCricle(vh, pos, symbolSize + gap, backgroundColor, smoothness);
2021-12-08 08:31:32 +08:00
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
2020-07-10 09:36:56 +08:00
}
else
{
2021-12-08 08:31:32 +08:00
UGL.DrawEmptyCricle(vh, pos, symbolSize, tickness, color, color, emptyColor, smoothness);
2020-07-10 09:36:56 +08:00
}
break;
2021-11-23 13:20:07 +08:00
case SymbolType.Rect:
2020-07-10 09:36:56 +08:00
if (gap > 0)
{
2021-01-11 08:54:28 +08:00
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
UGL.DrawSquare(vh, pos, symbolSize, color, toColor);
2020-07-10 09:36:56 +08:00
}
else
{
if (tickness > 0)
{
UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true);
UGL.DrawBorder(vh, pos, symbolSize, symbolSize, tickness, borderColor, 0, cornerRadius);
}
else
UGL.DrawRoundRectangle(vh, pos, symbolSize * 2, symbolSize * 2, color, color, 0, cornerRadius, true);
2020-07-10 09:36:56 +08:00
}
break;
2021-12-08 08:31:32 +08:00
case SymbolType.EmptyRect:
if (gap > 0)
{
UGL.DrawSquare(vh, pos, symbolSize + gap, backgroundColor);
UGL.DrawBorder(vh, pos, symbolSize * 2, symbolSize * 2, tickness, color);
2021-12-08 08:31:32 +08:00
}
else
{
UGL.DrawBorder(vh, pos, symbolSize * 2 - tickness * 2, symbolSize * 2 - tickness * 2, tickness, color);
2021-12-08 08:31:32 +08:00
}
break;
2021-11-23 13:20:07 +08:00
case SymbolType.Triangle:
case SymbolType.EmptyTriangle:
2020-07-10 09:36:56 +08:00
if (gap > 0)
{
UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f + gap * 2, gap * 2, backgroundColor);
2020-07-10 09:36:56 +08:00
}
if (type == SymbolType.EmptyTriangle)
2020-07-10 09:36:56 +08:00
{
UGL.DrawEmptyTriangle(vh, pos, symbolSize * 1.4f, tickness * 2f, color, emptyColor);
}
else
{
UGL.DrawTriangle(vh, pos, symbolSize * 1.4f, color, toColor);
2020-07-10 09:36:56 +08:00
}
break;
2021-11-23 13:20:07 +08:00
case SymbolType.Diamond:
case SymbolType.EmptyDiamond:
var xRadius = symbolSize;
var yRadius = symbolSize * 1.5f;
2020-07-10 09:36:56 +08:00
if (gap > 0)
{
UGL.DrawEmptyDiamond(vh, pos, xRadius + gap, yRadius + gap, gap, backgroundColor);
2020-07-10 09:36:56 +08:00
}
if (type == SymbolType.EmptyDiamond)
2020-07-10 09:36:56 +08:00
{
UGL.DrawEmptyDiamond(vh, pos, xRadius, yRadius, tickness, color, emptyColor);
}
else
{
UGL.DrawDiamond(vh, pos, xRadius, yRadius, color, toColor);
2020-07-10 09:36:56 +08:00
}
break;
2021-11-23 13:20:07 +08:00
case SymbolType.Arrow:
case SymbolType.EmptyArrow:
2021-07-15 21:18:23 +08:00
var arrowWidth = symbolSize * 2;
var arrowHeight = arrowWidth * 1.5f;
var arrowOffset = 0;
var arrowDent = arrowWidth / 3.3f;
if (gap > 0)
{
arrowWidth = (symbolSize + gap) * 2;
arrowHeight = arrowWidth * 1.5f;
arrowOffset = 0;
arrowDent = arrowWidth / 3.3f;
var dir = (pos - startPos).normalized;
var sharpPos = pos + gap * dir;
UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight,
arrowOffset, arrowDent, backgroundColor);
}
arrowWidth = symbolSize * 2;
arrowHeight = arrowWidth * 1.5f;
arrowOffset = 0;
arrowDent = arrowWidth / 3.3f;
2021-07-15 21:18:23 +08:00
UGL.DrawArrow(vh, startPos, pos, arrowWidth, arrowHeight,
2022-05-22 22:17:38 +08:00
arrowOffset, arrowDent, color);
if (type == SymbolType.EmptyArrow)
{
arrowWidth = (symbolSize - tickness) * 2;
arrowHeight = arrowWidth * 1.5f;
arrowOffset = 0;
arrowDent = arrowWidth / 3.3f;
var dir = (pos - startPos).normalized;
var sharpPos = pos - tickness * dir;
UGL.DrawArrow(vh, startPos, sharpPos, arrowWidth, arrowHeight,
arrowOffset, arrowDent, backgroundColor);
}
2021-07-15 21:18:23 +08:00
break;
case SymbolType.Plus:
if (gap > 0)
{
UGL.DrawPlus(vh, pos, symbolSize + gap, tickness + gap, backgroundColor);
}
UGL.DrawPlus(vh, pos, symbolSize, tickness, color);
break;
case SymbolType.Minus:
if (gap > 0)
{
UGL.DrawMinus(vh, pos, symbolSize + gap, tickness + gap, backgroundColor);
}
UGL.DrawMinus(vh, pos, symbolSize, tickness, color);
break;
2020-07-10 09:36:56 +08:00
}
}
2021-11-23 13:20:07 +08:00
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
2022-05-22 22:17:38 +08:00
Color32 defaultColor, float themeWidth, LineStyle.Type themeType)
2021-01-11 08:54:28 +08:00
{
var type = lineStyle.GetType(themeType);
var width = lineStyle.GetWidth(themeWidth);
2021-05-16 23:38:06 +08:00
var color = lineStyle.GetColor(defaultColor);
2021-11-23 13:20:07 +08:00
DrawLineStyle(vh, type, width, startPos, endPos, color, color);
}
public static void DrawLineStyle(VertexHelper vh, LineStyle lineStyle, Vector3 startPos, Vector3 endPos,
float themeWidth, LineStyle.Type themeType, Color32 defaultColor, Color32 defaultToColor)
{
var type = lineStyle.GetType(themeType);
var width = lineStyle.GetWidth(themeWidth);
var color = lineStyle.GetColor(defaultColor);
var toColor = ChartHelper.IsClearColor(defaultToColor) ? color : defaultToColor;
DrawLineStyle(vh, type, width, startPos, endPos, color, toColor);
2021-01-11 08:54:28 +08:00
}
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
Vector3 startPos, Vector3 endPos, Color32 color)
2021-11-23 13:20:07 +08:00
{
DrawLineStyle(vh, lineType, lineWidth, startPos, endPos, color, color);
}
public static void DrawLineStyle(VertexHelper vh, LineStyle.Type lineType, float lineWidth,
Vector3 startPos, Vector3 endPos, Color32 color, Color32 toColor)
2020-07-10 09:36:56 +08:00
{
2021-01-11 08:54:28 +08:00
switch (lineType)
2020-07-10 09:36:56 +08:00
{
case LineStyle.Type.Dashed:
2021-11-23 13:20:07 +08:00
UGL.DrawDashLine(vh, startPos, endPos, lineWidth, color, toColor);
2020-07-10 09:36:56 +08:00
break;
case LineStyle.Type.Dotted:
2021-11-23 13:20:07 +08:00
UGL.DrawDotLine(vh, startPos, endPos, lineWidth, color, toColor);
2020-07-10 09:36:56 +08:00
break;
case LineStyle.Type.Solid:
2021-11-23 13:20:07 +08:00
UGL.DrawLine(vh, startPos, endPos, lineWidth, color, toColor);
2020-07-10 09:36:56 +08:00
break;
case LineStyle.Type.DashDot:
2021-01-11 08:54:28 +08:00
UGL.DrawDashDotLine(vh, startPos, endPos, lineWidth, color);
2020-07-10 09:36:56 +08:00
break;
case LineStyle.Type.DashDotDot:
2021-01-11 08:54:28 +08:00
UGL.DrawDashDotDotLine(vh, startPos, endPos, lineWidth, color);
2020-07-10 09:36:56 +08:00
break;
}
}
}
}