CPF/CPF.ReoGrid/Views/Viewport.cs

212 lines
4.3 KiB
C#
Raw Permalink Normal View History

2024-06-24 10:15:59 +08:00
using System;
using System.Diagnostics;
using CPF.Drawing;
using CPF.ReoGrid.Graphics;
using CPF.ReoGrid.Interaction;
using CPF.ReoGrid.Main;
using CPF.ReoGrid.Rendering;
namespace CPF.ReoGrid.Views
{
internal abstract class Viewport : View, IViewport, IView, IUserVisual
{
internal Worksheet Worksheet
{
get
{
return this.sheet;
}
}
public Viewport(IViewportController vc) : base(vc)
{
this.sheet = vc.Worksheet;
}
public virtual GridRegion VisibleRegion
{
get
{
return this.visibleRegion;
}
set
{
this.visibleRegion = value;
}
}
public virtual Point ViewStart
{
get
{
return this.viewStart;
}
set
{
this.viewStart = value;
}
}
public virtual float ViewTop
{
get
{
return this.viewStart.Y;
}
set
{
this.viewStart.Y = value;
}
}
public virtual float ViewLeft
{
get
{
return this.viewStart.X;
}
set
{
this.viewStart.X = value;
}
}
public virtual Rect ViewBounds
{
get
{
float scrollViewLeft = this.ScrollViewLeft;
float scrollViewTop = this.ScrollViewTop;
float num = this.bounds.Width / this.scaleFactor;
float num2 = this.bounds.Height / this.scaleFactor;
return new Rect(ref scrollViewLeft, ref scrollViewTop, ref num, ref num2);
}
}
public virtual ScrollDirection ScrollableDirections { get; set; } = ScrollDirection.None;
public float ScrollX { get; set; }
public float ScrollY { get; set; }
public float ScrollViewLeft
{
get
{
return this.viewStart.X + this.ScrollX;
}
}
public float ScrollViewTop
{
get
{
return this.viewStart.Y + this.ScrollY;
}
}
public virtual void Scroll(float offX, float offY)
{
this.ScrollX += offX;
this.ScrollY += offY;
bool flag = this.ScrollX < 0f;
if (flag)
{
this.ScrollX = 0f;
}
bool flag2 = this.ScrollY < 0f;
if (flag2)
{
this.ScrollY = 0f;
}
}
public virtual void ScrollTo(float x, float y)
{
bool flag = x >= 0f && (this.ScrollableDirections & ScrollDirection.Horizontal) == ScrollDirection.Horizontal;
if (flag)
{
this.ScrollX = x;
}
bool flag2 = y >= 0f && (this.ScrollableDirections & ScrollDirection.Vertical) == ScrollDirection.Vertical;
if (flag2)
{
this.ScrollY = y;
}
bool flag3 = this.ScrollX < 0f;
if (flag3)
{
this.ScrollX = 0f;
}
bool flag4 = this.ScrollY < 0f;
if (flag4)
{
this.ScrollY = 0f;
}
}
public override Point PointToView(Point p)
{
float num = (p.X - this.bounds.Left + this.ScrollViewLeft * this.scaleFactor) / this.scaleFactor;
float num2 = (p.Y - this.bounds.Top + this.ScrollViewTop * this.scaleFactor) / this.scaleFactor;
return new Point(ref num, ref num2);
}
public override Point PointToController(Point p)
{
float num = (p.X - this.ScrollViewLeft) * this.scaleFactor + this.bounds.Left;
float num2 = (p.Y - this.ScrollViewTop) * this.scaleFactor + this.bounds.Top;
return new Point(ref num, ref num2);
}
public override void Draw(CellDrawingContext dc)
{
Stopwatch stopwatch = Stopwatch.StartNew();
bool flag = !this.Visible || this.bounds.Width <= 0f || this.bounds.Height <= 0f;
if (!flag)
{
IGraphics graphics = dc.Graphics;
bool performTransform = this.PerformTransform;
if (performTransform)
{
graphics.PushClip(this.bounds);
graphics.PushTransform();
graphics.TranslateTransform(this.bounds.Left - this.ScrollViewLeft * this.scaleFactor, this.bounds.Top - this.ScrollViewTop * this.scaleFactor);
}
this.DrawView(dc);
bool performTransform2 = this.PerformTransform;
if (performTransform2)
{
graphics.PopTransform();
graphics.PopClip();
}
stopwatch.Stop();
bool flag2 = stopwatch.ElapsedMilliseconds > 20L;
if (flag2)
{
Debug.WriteLine(string.Concat(new string[]
{
"draw viewport takes ",
stopwatch.ElapsedMilliseconds.ToString(),
" ms. visible region: rows: ",
this.visibleRegion.Rows.ToString(),
", cols: ",
this.visibleRegion.Cols.ToString()
}));
}
}
}
public virtual void DrawView(CellDrawingContext dc)
{
this.DrawChildren(dc);
}
protected Worksheet sheet;
protected GridRegion visibleRegion;
protected Point viewStart;
}
}