289 lines
4.7 KiB
C#
Raw Normal View History

2024-06-24 10:15:59 +08:00
using System;
using System.Collections.Generic;
using CPF.Drawing;
using CPF.Input;
using CPF.ReoGrid.Interaction;
using CPF.ReoGrid.Rendering;
namespace CPF.ReoGrid.Views
{
internal class View : IView, IUserVisual
{
public IViewportController ViewportController
{
get
{
return this.viewportController;
}
set
{
this.viewportController = value;
}
}
public View()
{
float num = 0f;
float num2 = 0f;
float num3 = 0f;
float num4 = 0f;
this.bounds = new Rect(ref num, ref num2, ref num3, ref num4);
this.scaleFactor = 1f;
this.children = null;
this.Visible = true;
this.PerformTransform = true;
}
public View(IViewportController vc) : this()
{
this.viewportController = vc;
}
public virtual Rect Bounds
{
get
{
return this.bounds;
}
set
{
this.bounds = value;
}
}
public virtual float Top
{
get
{
return this.bounds.Top;
}
set
{
this.bounds.Y = value;
}
}
public virtual float Left
{
get
{
return this.bounds.Left;
}
set
{
this.bounds.X = value;
}
}
public virtual float Right
{
get
{
return this.bounds.Right;
}
}
public virtual float Bottom
{
get
{
return this.bounds.Bottom;
}
}
public virtual float Width
{
get
{
return this.bounds.Width;
}
set
{
this.bounds.Width = value;
}
}
public virtual float Height
{
get
{
return this.bounds.Height;
}
set
{
this.bounds.Height = value;
}
}
public virtual float ScaleFactor
{
get
{
return this.scaleFactor;
}
set
{
this.scaleFactor = value;
}
}
public virtual bool Visible { get; set; }
public virtual bool PerformTransform { get; set; }
public virtual void Draw(CellDrawingContext dc)
{
this.DrawChildren(dc);
}
public virtual void DrawChildren(CellDrawingContext dc)
{
bool flag = this.children != null;
if (flag)
{
foreach (IView view in this.children)
{
bool visible = view.Visible;
if (visible)
{
dc.CurrentView = view;
view.Draw(dc);
dc.CurrentView = null;
}
}
}
}
public virtual Point PointToView(Point p)
{
float num = (p.X - this.bounds.Left) / this.scaleFactor;
float num2 = (p.Y - this.bounds.Top) / this.scaleFactor;
return new Point(ref num, ref num2);
}
public virtual Point PointToController(Point p)
{
float num = p.X * this.scaleFactor + this.bounds.Left;
float num2 = p.Y * this.scaleFactor + this.bounds.Top;
return new Point(ref num, ref num2);
}
public virtual IView GetViewByPoint(Point p)
{
IView childrenByPoint = this.GetChildrenByPoint(p);
bool flag = childrenByPoint != null;
IView result;
if (flag)
{
result = childrenByPoint;
}
else
{
result = (this.bounds.Contains(p) ? this : null);
}
return result;
}
public virtual IView GetChildrenByPoint(Point p)
{
bool flag = this.children != null && this.children.Count > 0;
if (flag)
{
for (int i = this.children.Count - 1; i >= 0; i--)
{
IView view = this.children[i];
bool flag2 = !view.Visible;
if (!flag2)
{
IView viewByPoint = view.GetViewByPoint(p);
bool flag3 = viewByPoint != null;
if (flag3)
{
return viewByPoint;
}
}
}
}
return null;
}
public virtual void Invalidate()
{
bool flag = this.viewportController != null;
if (flag)
{
this.viewportController.Invalidate();
}
}
public virtual bool OnMouseDown(Point location, MouseButtons buttons, InputModifiers modifiers)
{
return false;
}
public virtual bool OnMouseMove(Point location, MouseButtons buttons)
{
return false;
}
public virtual bool OnMouseUp(Point location, MouseButtons buttons, InputModifiers modifiers)
{
return false;
}
public virtual bool OnMouseDoubleClick(Point location, MouseButtons buttons)
{
return false;
}
public virtual bool OnKeyDown(KeyCode key)
{
return false;
}
public virtual void UpdateView()
{
bool flag = this.children != null;
if (flag)
{
foreach (IView view in this.children)
{
view.UpdateView();
}
}
}
public virtual void SetFocus()
{
this.ViewportController.FocusView = this;
}
public virtual void FreeFocus()
{
this.ViewportController.FocusView = null;
}
public IViewport Parent { get; set; }
public IList<IView> Children
{
get
{
return this.children;
}
set
{
this.children = value;
}
}
private IViewportController viewportController;
protected Rect bounds;
protected float scaleFactor;
protected IList<IView> children;
}
}