using System;
using UnityEngine;
namespace XCharts.Runtime
{
    [System.Serializable]
    public class ChildComponent
    {
        public virtual int index { get; set; }
        [NonSerialized] protected bool m_VertsDirty;
        [NonSerialized] protected bool m_ComponentDirty;
        [NonSerialized] protected Painter m_Painter;
        /// 
        /// 图表重绘标记。
        /// 
        public virtual bool vertsDirty { get { return m_VertsDirty; } }
        /// 
        /// 组件重新初始化标记。
        /// 
        public virtual bool componentDirty { get { return m_ComponentDirty; } }
        /// 
        /// 需要重绘图表或重新初始化组件。
        /// 
        public bool anyDirty { get { return vertsDirty || componentDirty; } }
        public Painter painter { get { return m_Painter; } set { m_Painter = value; } }
        public Action refreshComponent { get; set; }
        public GameObject gameObject { get; set; }
        public static void ClearVerticesDirty(ChildComponent component)
        {
            if (component != null)
                component.ClearVerticesDirty();
        }
        public static void ClearComponentDirty(ChildComponent component)
        {
            if (component != null)
                component.ClearComponentDirty();
        }
        public static bool IsVertsDirty(ChildComponent component)
        {
            return component == null?false : component.vertsDirty;
        }
        public static bool IsComponentDirty(ChildComponent component)
        {
            return component == null?false : component.componentDirty;
        }
        public virtual void SetVerticesDirty()
        {
            m_VertsDirty = true;
        }
        public virtual void ClearVerticesDirty()
        {
            m_VertsDirty = false;
        }
        public virtual void SetComponentDirty()
        {
            m_ComponentDirty = true;
        }
        public virtual void ClearComponentDirty()
        {
            m_ComponentDirty = false;
        }
        public virtual void ClearDirty()
        {
            ClearVerticesDirty();
            ClearComponentDirty();
        }
        public virtual void SetAllDirty()
        {
            SetVerticesDirty();
            SetComponentDirty();
        }
    }
}