2021-11-23 13:20:07 +08:00
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
using XUGL;
|
|
|
|
|
|
2022-02-19 22:37:57 +08:00
|
|
|
namespace XCharts.Runtime
|
2021-11-23 13:20:07 +08:00
|
|
|
{
|
|
|
|
|
[UnityEngine.Scripting.Preserve]
|
|
|
|
|
internal sealed class BackgroundHandler : MainComponentHandler<Background>
|
|
|
|
|
{
|
|
|
|
|
private readonly string s_BackgroundObjectName = "background";
|
|
|
|
|
public override void InitComponent()
|
|
|
|
|
{
|
|
|
|
|
component.painter = chart.painter;
|
2024-01-11 08:03:36 +08:00
|
|
|
component.refreshComponent = delegate ()
|
2021-11-23 13:20:07 +08:00
|
|
|
{
|
|
|
|
|
var backgroundObj = ChartHelper.AddObject(s_BackgroundObjectName, chart.transform, chart.chartMinAnchor,
|
2024-12-07 22:21:55 +08:00
|
|
|
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta, -1, chart.childrenNodeNames);
|
2021-11-23 13:20:07 +08:00
|
|
|
component.gameObject = backgroundObj;
|
|
|
|
|
backgroundObj.hideFlags = chart.chartHideFlags;
|
|
|
|
|
|
2023-02-13 07:20:50 +08:00
|
|
|
var backgroundImage = ChartHelper.EnsureComponent<Image>(backgroundObj);
|
2021-11-23 13:20:07 +08:00
|
|
|
ChartHelper.UpdateRectTransform(backgroundObj, chart.chartMinAnchor,
|
|
|
|
|
chart.chartMaxAnchor, chart.chartPivot, chart.chartSizeDelta);
|
|
|
|
|
backgroundImage.sprite = component.image;
|
|
|
|
|
backgroundImage.type = component.imageType;
|
2022-06-14 07:01:46 +08:00
|
|
|
backgroundImage.color = chart.theme.GetBackgroundColor(component);
|
2021-11-23 13:20:07 +08:00
|
|
|
|
|
|
|
|
backgroundObj.transform.SetSiblingIndex(0);
|
2024-01-11 08:03:36 +08:00
|
|
|
backgroundObj.SetActive(component.show && component.image != null);
|
2021-11-23 13:20:07 +08:00
|
|
|
};
|
|
|
|
|
component.refreshComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-14 07:01:46 +08:00
|
|
|
public override void Update()
|
|
|
|
|
{
|
|
|
|
|
if (component.gameObject != null && component.gameObject.transform.GetSiblingIndex() != 0)
|
|
|
|
|
component.gameObject.transform.SetSiblingIndex(0);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 13:20:07 +08:00
|
|
|
public override void DrawBase(VertexHelper vh)
|
|
|
|
|
{
|
|
|
|
|
if (!component.show)
|
|
|
|
|
return;
|
2022-06-14 07:01:46 +08:00
|
|
|
if (component.image != null)
|
|
|
|
|
return;
|
2021-11-23 13:20:07 +08:00
|
|
|
|
|
|
|
|
var backgroundColor = chart.theme.GetBackgroundColor(component);
|
2024-01-11 08:03:36 +08:00
|
|
|
var borderWidth = component.borderStyle.GetRuntimeBorderWidth();
|
|
|
|
|
var borderColor = component.borderStyle.GetRuntimeBorderColor();
|
|
|
|
|
var cornerRadius = component.borderStyle.GetRuntimeCornerRadius();
|
|
|
|
|
UGL.DrawRoundRectangleWithBorder(vh, chart.chartRect, backgroundColor, backgroundColor, cornerRadius,
|
2024-07-09 23:16:08 +08:00
|
|
|
borderWidth, borderColor, 0, 1f);
|
2021-11-23 13:20:07 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|