using System; using CPF.Drawing; using CPF.ReoGrid.Drawing; using CPF.ReoGrid.Graphics; using CPF.ReoGrid.Rendering; namespace CPF.ReoGrid.Chart { public class ChartLegendItem : DrawingObject { public virtual Rect SymbolBounds { get { return this.symbolBounds; } set { this.symbolBounds = value; } } public virtual Rect LabelBounds { get { return this.labelBounds; } set { this.labelBounds = value; } } public virtual void SetSymbolLocation(float x, float y) { this.symbolBounds.X = x; this.symbolBounds.Y = y; } public virtual void SetLabelLocation(float x, float y) { this.labelBounds.X = x; this.labelBounds.Y = y; } public virtual ChartLegend ChartLegend { get; protected set; } public ChartLegendItem(ChartLegend chartLegend, int legendIndex) { this.ChartLegend = chartLegend; this.LegendIndex = legendIndex; } public virtual int LegendIndex { get; set; } protected override void OnPaint(RDrawingContext dc) { bool flag = this.symbolBounds.Width > 0f && this.symbolBounds.Height > 0f; if (flag) { this.OnPaintSymbol(dc); } bool flag2 = this.labelBounds.Width > 0f && this.labelBounds.Height > 0f; if (flag2) { this.OnPaintLabel(dc); } } public virtual void OnPaintSymbol(RDrawingContext dc) { IGraphics graphics = dc.Graphics; bool flag = this.ChartLegend != null; if (flag) { ChartLegend chartLegend = this.ChartLegend; bool flag2 = chartLegend.Chart != null; if (flag2) { DataSerialStyleCollection dataSerialStyles = chartLegend.Chart.DataSerialStyles; bool flag3 = dataSerialStyles != null; if (flag3) { IDataSerialStyle dataSerialStyle = dataSerialStyles[this.LegendIndex]; graphics.DrawAndFillRectangle(this.symbolBounds, dataSerialStyle.LineColor, dataSerialStyle.FillColor); } } } } public virtual void OnPaintLabel(RDrawingContext dc) { bool flag = this.ChartLegend != null; if (flag) { ChartLegend chartLegend = this.ChartLegend; bool flag2 = chartLegend.Chart != null && chartLegend.Chart.DataSource != null; if (flag2) { WorksheetChartDataSource dataSource = chartLegend.Chart.DataSource; string label = dataSource[this.LegendIndex].Label; bool flag3 = !string.IsNullOrEmpty(label); if (flag3) { dc.Graphics.DrawText(label, this.FontName, this.FontSize, base.ForeColor, this.labelBounds, ReoGridHorAlign.Left, ReoGridVerAlign.Middle); } } } } private Rect symbolBounds; private Rect labelBounds; } }