157 lines
3.7 KiB
C#
157 lines
3.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using CPF.Drawing;
|
|
using CPF.Input;
|
|
using CPF.ReoGrid.Interaction;
|
|
using CPF.ReoGrid.Rendering;
|
|
|
|
namespace CPF.ReoGrid.Drawing
|
|
{
|
|
[Serializable]
|
|
public class DrawingComponent : DrawingObject, IDrawingContainer, IDrawingObject, IFloatingObject, IUserVisual
|
|
{
|
|
public virtual Rect ClipBounds { get; set; }
|
|
|
|
protected override void OnPaint(RDrawingContext dc)
|
|
{
|
|
base.OnPaint(dc);
|
|
this.DrawChildren(dc);
|
|
}
|
|
|
|
protected virtual void DrawChildren(RDrawingContext dc)
|
|
{
|
|
foreach (IDrawingObject drawingObject in this.drawingObjects)
|
|
{
|
|
bool flag = drawingObject is DrawingObject;
|
|
if (flag)
|
|
{
|
|
DrawingObject drawingObject2 = (DrawingObject)drawingObject;
|
|
bool flag2 = !drawingObject2.Visible;
|
|
if (flag2)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
bool flag3 = this.ClipBounds.Width > 0f || this.ClipBounds.Height > 0f;
|
|
if (flag3)
|
|
{
|
|
Rect bounds = drawingObject.Bounds;
|
|
Rect clipBounds = this.ClipBounds;
|
|
bool flag4 = bounds.IntersectsWith(clipBounds);
|
|
if (flag4)
|
|
{
|
|
drawingObject.Draw(dc);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
drawingObject.Draw(dc);
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual IDrawingObjectCollection Children
|
|
{
|
|
get
|
|
{
|
|
bool flag = this.drawingObjectCollection == null;
|
|
if (flag)
|
|
{
|
|
this.drawingObjectCollection = new DrawingObjectCollection(this);
|
|
}
|
|
return this.drawingObjectCollection;
|
|
}
|
|
}
|
|
|
|
public virtual void OnChildAdded(IDrawingObject child, int index)
|
|
{
|
|
}
|
|
|
|
public virtual void OnChildRemoved(IDrawingObject child, int index)
|
|
{
|
|
}
|
|
|
|
public virtual void OnChildrenClear()
|
|
{
|
|
}
|
|
|
|
public new IDrawingComponentStyle Style
|
|
{
|
|
get
|
|
{
|
|
bool flag = this.style == null;
|
|
if (flag)
|
|
{
|
|
this.style = new DrawingComponentStyle(this);
|
|
}
|
|
return this.style;
|
|
}
|
|
}
|
|
|
|
public override void OnBoundsChanged(Rect oldRect)
|
|
{
|
|
base.OnBoundsChanged(oldRect);
|
|
float num = (oldRect.Width == 0f) ? 1f : (base.Width / oldRect.Width);
|
|
float num2 = (oldRect.Height == 0f) ? 1f : (base.Height / oldRect.Height);
|
|
bool flag = num != 1f || num2 != 1f;
|
|
if (flag)
|
|
{
|
|
this.ScaleChildren(num, num2);
|
|
}
|
|
}
|
|
|
|
protected void ScaleChildren(float scaleX, float scaleY)
|
|
{
|
|
bool flag = this.Children != null;
|
|
if (flag)
|
|
{
|
|
foreach (IDrawingObject drawingObject in this.Children)
|
|
{
|
|
Rect bounds = drawingObject.Bounds;
|
|
IFloatingObject floatingObject = drawingObject;
|
|
float num = drawingObject.X * scaleX;
|
|
float num2 = drawingObject.Y * scaleY;
|
|
float num3 = drawingObject.Width * scaleX;
|
|
float num4 = drawingObject.Height * scaleY;
|
|
floatingObject.Bounds = new Rect(ref num, ref num2, ref num3, ref num4);
|
|
Debug.Assert(!double.IsInfinity((double)drawingObject.Width) && !double.IsInfinity((double)drawingObject.Height));
|
|
}
|
|
}
|
|
}
|
|
|
|
public override bool OnMouseDown(Point location, MouseButtons button, InputModifiers modifiers)
|
|
{
|
|
bool flag = false;
|
|
foreach (IDrawingObject drawingObject in this.drawingObjects)
|
|
{
|
|
bool flag2 = drawingObject.Bounds.Contains(location);
|
|
if (flag2)
|
|
{
|
|
IUserVisual userVisual = drawingObject;
|
|
float num = location.X - drawingObject.X;
|
|
float num2 = location.Y - drawingObject.Y;
|
|
flag = userVisual.OnMouseDown(new Point(ref num, ref num2), button, modifiers);
|
|
bool flag3 = flag;
|
|
if (flag3)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
bool flag4 = !flag;
|
|
if (flag4)
|
|
{
|
|
flag = base.OnMouseDown(location, button, modifiers);
|
|
}
|
|
return flag;
|
|
}
|
|
|
|
internal List<IDrawingObject> drawingObjects = new List<IDrawingObject>();
|
|
|
|
private DrawingObjectCollection drawingObjectCollection = null;
|
|
|
|
private DrawingComponentStyle style;
|
|
}
|
|
}
|