mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-23 17:30:10 +00:00
修复圆角绘制异常的问题
This commit is contained in:
@@ -263,7 +263,7 @@ namespace XCharts
|
|||||||
var backgroundName = s_BackgroundObjectName + GetInstanceID();
|
var backgroundName = s_BackgroundObjectName + GetInstanceID();
|
||||||
m_BackgroundRoot = ChartHelper.AddObject(backgroundName, transform.parent, m_ChartMinAnchor,
|
m_BackgroundRoot = ChartHelper.AddObject(backgroundName, transform.parent, m_ChartMinAnchor,
|
||||||
m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);
|
m_ChartMaxAnchor, m_ChartPivot, m_ChartSizeDelta);
|
||||||
//m_BackgroundRoot.hideFlags = chartHideFlags;
|
m_BackgroundRoot.hideFlags = chartHideFlags;
|
||||||
var backgroundImage = ChartHelper.GetOrAddComponent<Image>(m_BackgroundRoot);
|
var backgroundImage = ChartHelper.GetOrAddComponent<Image>(m_BackgroundRoot);
|
||||||
var backgroundRect = m_BackgroundRoot.GetComponent<RectTransform>();
|
var backgroundRect = m_BackgroundRoot.GetComponent<RectTransform>();
|
||||||
backgroundRect.position = rectTransform.position;
|
backgroundRect.position = rectTransform.position;
|
||||||
|
|||||||
@@ -316,7 +316,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip);
|
CheckClipAndDrawPolygon(vh, plb, plt, prt, prb, areaColor, areaToColor, serie.clip);
|
||||||
}
|
}
|
||||||
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius);
|
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -342,7 +342,7 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip);
|
CheckClipAndDrawPolygon(vh, ref prb, ref plb, ref plt, ref prt, areaColor, areaToColor, serie.clip);
|
||||||
}
|
}
|
||||||
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius);
|
ChartDrawer.DrawBorder(vh, center, itemWidth, itemHeight, borderWidth, borderColor, 0, itemStyle.cornerRadius, isYAxis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,46 +262,52 @@ namespace XCharts
|
|||||||
vh.AddUIVertexQuad(vertex);
|
vh.AddUIVertexQuad(vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void InitCornerRadius(float[] cornerRadius, float width, float height, ref float brLt,
|
private static void InitCornerRadius(float[] cornerRadius, float width, float height, bool isYAxis, ref float brLt,
|
||||||
ref float brRt, ref float brRb, ref float brLb, ref bool needRound)
|
ref float brRt, ref float brRb, ref float brLb, ref bool needRound)
|
||||||
{
|
{
|
||||||
brLt = cornerRadius != null && cornerRadius.Length > 0 ? cornerRadius[0] : 0;
|
if (cornerRadius == null) return;
|
||||||
brRt = cornerRadius != null && cornerRadius.Length > 1 ? cornerRadius[1] : 0;
|
brLt = cornerRadius.Length > 0 ? cornerRadius[0] : 0;
|
||||||
brRb = cornerRadius != null && cornerRadius.Length > 2 ? cornerRadius[2] : 0;
|
brRt = cornerRadius.Length > 1 ? cornerRadius[1] : 0;
|
||||||
brLb = cornerRadius != null && cornerRadius.Length > 3 ? cornerRadius[3] : 0;
|
brRb = cornerRadius.Length > 2 ? cornerRadius[2] : 0;
|
||||||
|
brLb = cornerRadius.Length > 3 ? cornerRadius[3] : 0;
|
||||||
needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0;
|
needRound = brLb != 0 || brRt != 0 || brRb != 0 || brLb != 0;
|
||||||
if (needRound)
|
if (needRound)
|
||||||
{
|
{
|
||||||
var min = Mathf.Min(width, height);
|
var min = Mathf.Min(width, height);
|
||||||
|
if (brLt == 1 && brRt == 1 && brRb == 1 && brLb == 1)
|
||||||
|
{
|
||||||
|
brLt = brRt = brRb = brLb = min / 2;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (brLt > 0 && brLt <= 1) brLt = brLt * min;
|
if (brLt > 0 && brLt <= 1) brLt = brLt * min;
|
||||||
if (brRt > 0 && brRt <= 1) brRt = brRt * min;
|
if (brRt > 0 && brRt <= 1) brRt = brRt * min;
|
||||||
if (brRb > 0 && brRb <= 1) brRb = brRb * min;
|
if (brRb > 0 && brRb <= 1) brRb = brRb * min;
|
||||||
if (brLb > 0 && brLb <= 1) brLb = brLb * min;
|
if (brLb > 0 && brLb <= 1) brLb = brLb * min;
|
||||||
if (brLt + brRt > width)
|
if (brLt + brRt >= width)
|
||||||
{
|
{
|
||||||
var total = brLt + brRt;
|
var total = brLt + brRt;
|
||||||
brLt = width * (brLt / total);
|
brLt = width * (brLt / total);
|
||||||
brRt = width * (brRt / total);
|
brRt = width * (brRt / total);
|
||||||
}
|
}
|
||||||
if (brRt + brRb > height)
|
if (brRt + brRb >= height)
|
||||||
{
|
{
|
||||||
var total = brRt + brRb;
|
var total = brRt + brRb;
|
||||||
brRt = height * (brRt / total);
|
brRt = height * (brRt / total);
|
||||||
brRb = height * (brRb / total);
|
brRb = height * (brRb / total);
|
||||||
}
|
}
|
||||||
if (brRb + brLb > width)
|
if (brRb + brLb >= width)
|
||||||
{
|
{
|
||||||
var total = brRb + brLb;
|
var total = brRb + brLb;
|
||||||
brRb = width * (brRb / total);
|
brRb = width * (brRb / total);
|
||||||
brLb = width * (brLb / total);
|
brLb = width * (brLb / total);
|
||||||
}
|
}
|
||||||
if (brLb + brLt > height)
|
if (brLb + brLt >= height)
|
||||||
{
|
{
|
||||||
var total = brLb + brLt;
|
var total = brLb + brLt;
|
||||||
brLb = height * (brLb / total);
|
brLb = height * (brLb / total);
|
||||||
brLt = height * (brLt / total);
|
brLt = height * (brLt / total);
|
||||||
}
|
}
|
||||||
if (brLt + brRb > height)
|
if (brLt + brRb >= height)
|
||||||
{
|
{
|
||||||
var total = brLt + brRb;
|
var total = brLt + brRb;
|
||||||
brLt = height * (brLt / total);
|
brLt = height * (brLt / total);
|
||||||
@@ -333,7 +339,7 @@ namespace XCharts
|
|||||||
var halfHig = rectHeight / 2;
|
var halfHig = rectHeight / 2;
|
||||||
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
||||||
bool needRound = false;
|
bool needRound = false;
|
||||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound);
|
InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound);
|
||||||
var tempCenter = Vector3.zero;
|
var tempCenter = Vector3.zero;
|
||||||
var lbIn = new Vector3(center.x - halfWid, center.y - halfHig);
|
var lbIn = new Vector3(center.x - halfWid, center.y - halfHig);
|
||||||
var ltIn = new Vector3(center.x - halfWid, center.y + halfHig);
|
var ltIn = new Vector3(center.x - halfWid, center.y + halfHig);
|
||||||
@@ -400,13 +406,13 @@ namespace XCharts
|
|||||||
{
|
{
|
||||||
DrawPolygon(vh, lbIn2, lbIn2 + maxdown * Vector3.up, rbIn2 + maxdown * Vector3.up, rbIn2, color, toColor);
|
DrawPolygon(vh, lbIn2, lbIn2 + maxdown * Vector3.up, rbIn2 + maxdown * Vector3.up, rbIn2, color, toColor);
|
||||||
DrawPolygon(vh, lbIn, lbIn + (maxdown - brLb) * Vector3.up, roundLb + (maxdown - brLb) * Vector3.up, roundLb, color, color);
|
DrawPolygon(vh, lbIn, lbIn + (maxdown - brLb) * Vector3.up, roundLb + (maxdown - brLb) * Vector3.up, roundLb, color, color);
|
||||||
DrawPolygon(vh, roundRb, roundRb + (maxdown - brRb) * Vector3.up, rbIn2 + (maxdown - brRb) * Vector3.up, rbIn2, toColor, toColor);
|
DrawPolygon(vh, roundRb, roundRb + (maxdown - brRb) * Vector3.up, rbIn + (maxdown - brRb) * Vector3.up, rbIn, toColor, toColor);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DrawPolygon(vh, lbIn2, lbIn2 + maxdown * Vector3.up, rbIn2 + maxdown * Vector3.up, rbIn2, color, color);
|
DrawPolygon(vh, lbIn2, lbIn2 + maxdown * Vector3.up, rbIn2 + maxdown * Vector3.up, rbIn2, color, color);
|
||||||
DrawPolygon(vh, lbIn, lbIn + (maxdown - brLb) * Vector3.up, roundLb + (maxdown - brLb) * Vector3.up, roundLb, color, color);
|
DrawPolygon(vh, lbIn, lbIn + (maxdown - brLb) * Vector3.up, roundLb + (maxdown - brLb) * Vector3.up, roundLb, color, color);
|
||||||
DrawPolygon(vh, roundRb, roundRb + (maxdown - brRb) * Vector3.up, rbIn2 + (maxdown - brRb) * Vector3.up, rbIn2, color, color);
|
DrawPolygon(vh, roundRb, roundRb + (maxdown - brRb) * Vector3.up, rbIn + (maxdown - brRb) * Vector3.up, rbIn, color, color);
|
||||||
}
|
}
|
||||||
var clt = new Vector3(center.x - halfWid, center.y + halfHig - maxup);
|
var clt = new Vector3(center.x - halfWid, center.y + halfHig - maxup);
|
||||||
var crt = new Vector3(center.x + halfWid, center.y + halfHig - maxup);
|
var crt = new Vector3(center.x + halfWid, center.y + halfHig - maxup);
|
||||||
@@ -437,7 +443,7 @@ namespace XCharts
|
|||||||
/// <param name="rotate"></param>
|
/// <param name="rotate"></param>
|
||||||
/// <param name="cornerRadius"></param>
|
/// <param name="cornerRadius"></param>
|
||||||
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
public static void DrawBorder(VertexHelper vh, Vector3 center, float rectWidth, float rectHeight,
|
||||||
float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null)
|
float borderWidth, Color32 color, float rotate = 0, float[] cornerRadius = null, bool isYAxis = false)
|
||||||
{
|
{
|
||||||
if (borderWidth == 0 || ChartHelper.IsClearColor(color)) return;
|
if (borderWidth == 0 || ChartHelper.IsClearColor(color)) return;
|
||||||
var halfWid = rectWidth / 2;
|
var halfWid = rectWidth / 2;
|
||||||
@@ -452,7 +458,7 @@ namespace XCharts
|
|||||||
var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth);
|
var rbOt = new Vector3(center.x + halfWid + borderWidth, center.y - halfHig - borderWidth);
|
||||||
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
float brLt = 0, brRt = 0, brRb = 0, brLb = 0;
|
||||||
bool needRound = false;
|
bool needRound = false;
|
||||||
InitCornerRadius(cornerRadius, rectWidth, rectHeight, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound);
|
InitCornerRadius(cornerRadius, rectWidth, rectHeight, isYAxis, ref brLt, ref brRt, ref brRb, ref brLb, ref needRound);
|
||||||
var tempCenter = Vector3.zero;
|
var tempCenter = Vector3.zero;
|
||||||
if (needRound)
|
if (needRound)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user