CPF/CPF.ReoGrid/Views/RowOutlineView.cs

136 lines
5.0 KiB
C#
Raw Normal View History

2024-06-24 10:15:59 +08:00
using System;
using System.Diagnostics;
using System.Linq;
using CPF.Drawing;
using CPF.ReoGrid.Drawing;
using CPF.ReoGrid.Graphics;
using CPF.ReoGrid.Main;
using CPF.ReoGrid.Outline;
using CPF.ReoGrid.Rendering;
namespace CPF.ReoGrid.Views
{
internal class RowOutlineView : OutlineView
{
public RowOutlineView(IViewportController vc) : base(vc, RowOrColumn.Row)
{
this.ScrollableDirections = ScrollDirection.Vertical;
}
public override void Draw(CellDrawingContext dc)
{
IGraphics graphics = dc.Graphics;
ControlAppearanceStyle controlStyle = this.sheet.workbook.controlAdapter.ControlStyle;
graphics.FillRectangle(this.bounds.X, this.bounds.Y, this.bounds.Width, this.bounds.Height + 1f, controlStyle[ControlAppearanceColors.OutlinePanelBackground]);
base.Draw(dc);
graphics.DrawLine(this.bounds.Right, this.bounds.Top, this.bounds.Right, this.bounds.Bottom, controlStyle[ControlAppearanceColors.OutlinePanelBorder]);
}
public override void DrawView(CellDrawingContext dc)
{
IGraphics graphics = dc.Graphics;
ControlAppearanceStyle controlStyle = this.sheet.workbook.controlAdapter.ControlStyle;
Stopwatch stopwatch = Stopwatch.StartNew();
OutlineCollection<ReoGridOutline> outlineCollection = this.sheet.outlines[RowOrColumn.Row];
bool flag = outlineCollection != null;
if (flag)
{
CPFPen pen = dc.Renderer.GetPen(controlStyle[ControlAppearanceColors.OutlineButtonBorder]);
float num = Math.Min(this.scaleFactor, 1f);
float num2 = 6.5f * num;
for (int i = 0; i < outlineCollection.Count; i++)
{
OutlineGroup<ReoGridOutline> outlineGroup = null;
bool flag2 = i < outlineCollection.Count - 1;
if (flag2)
{
outlineGroup = outlineCollection[i];
foreach (ReoGridOutline reoGridOutline in outlineGroup)
{
RowHeader rowHeader = this.sheet.rows[reoGridOutline.End];
bool flag3 = !rowHeader.IsVisible;
if (!flag3)
{
bool flag4 = this.scaleFactor > 0.5f;
if (flag4)
{
pen.Width = 2f;
}
Rect toggleButtonBounds = reoGridOutline.ToggleButtonBounds;
float num3 = toggleButtonBounds.X + toggleButtonBounds.Width / 2f;
float num4 = toggleButtonBounds.Y + toggleButtonBounds.Height / 2f;
bool internalCollapsed = reoGridOutline.InternalCollapsed;
if (internalCollapsed)
{
graphics.DrawLine(pen, num3, toggleButtonBounds.Top + 3f, num3, toggleButtonBounds.Bottom - 2f);
}
else
{
RowHeader rowHeader2 = this.sheet.rows[reoGridOutline.Start];
float num5 = (float)rowHeader2.Top * this.scaleFactor;
graphics.DrawLine(pen, toggleButtonBounds.Right - 1f, num5, num3, num5);
graphics.DrawLine(pen, num3, num5 - 1f, num3, toggleButtonBounds.Top);
}
graphics.DrawLine(pen, toggleButtonBounds.Left + 3f, num4, toggleButtonBounds.Right - 2f, num4);
pen.Width = 1f;
graphics.DrawRectangle(pen, toggleButtonBounds.X, toggleButtonBounds.Y, toggleButtonBounds.Width, toggleButtonBounds.Height);
}
}
}
OutlineGroup<ReoGridOutline> outlineGroup2 = (i <= 0) ? null : outlineCollection[i - 1];
bool flag5 = outlineGroup2 != null;
if (flag5)
{
int num6 = (int)Math.Round((double)((float)(16 * i) * num));
foreach (ReoGridOutline reoGridOutline2 in outlineGroup2)
{
bool flag6 = !reoGridOutline2.InternalCollapsed;
if (flag6)
{
int r2;
int r;
for (r = reoGridOutline2.Start; r < reoGridOutline2.End; r = r2 + 1)
{
bool flag7 = outlineGroup == null || !outlineGroup.Any((ReoGridOutline o) => o.Start <= r && o.End >= r);
if (flag7)
{
RowHeader rowHeader3 = this.sheet.rows[r];
bool isVisible = rowHeader3.IsVisible;
if (isVisible)
{
float num7 = ((float)rowHeader3.Top + (float)rowHeader3.InnerHeight / 2f) * this.scaleFactor;
graphics.DrawLine(pen, (float)num6 + num2, num7 - 1f, (float)num6 + num2 + 1f, num7 - 1f);
graphics.DrawLine(pen, (float)num6 + num2, num7, (float)num6 + num2 + 1f, num7);
}
}
r2 = r;
}
}
}
}
}
}
stopwatch.Stop();
long elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
bool flag8 = elapsedMilliseconds > 10L;
if (flag8)
{
Debug.WriteLine("draw row outlines takes " + elapsedMilliseconds.ToString() + " ms.");
}
}
protected override Rect CreateToggleButtonRect(int loc, int pos, int buttonSize)
{
RowHeader rowHeader = this.sheet.rows[pos];
float num = (float)rowHeader.Top * this.scaleFactor;
float num2 = ((float)rowHeader.InnerHeight * this.scaleFactor - (float)buttonSize) / 2f;
int num3 = (int)Math.Round((double)(num + num2));
float num4 = (float)(loc + 1);
float num5 = (float)num3;
float num6 = (float)buttonSize;
float num7 = (float)buttonSize;
return new Rect(ref num4, ref num5, ref num6, ref num7);
}
}
}