CPF/CPF.ReoGrid/Drawing/FloatingObject.cs
2024-06-24 10:15:59 +08:00

241 lines
4.0 KiB
C#

using System;
using System.Diagnostics;
using CPF.Drawing;
using CPF.Input;
using CPF.ReoGrid.Interaction;
namespace CPF.ReoGrid.Drawing
{
[Serializable]
public abstract class FloatingObject : IFloatingObject
{
public FloatingObject()
{
Size preferredSize = this.GetPreferredSize();
this.Size = preferredSize;
this.innerWidth = preferredSize.Width;
this.innerHeight = preferredSize.Height;
}
public float X
{
get
{
return this.innerX;
}
set
{
bool flag = this.innerX != value;
if (flag)
{
Rect bounds = this.Bounds;
this.innerX = value;
this.InternalBoundsUpdate(bounds);
}
}
}
public float Y
{
get
{
return this.innerY;
}
set
{
bool flag = this.innerY != value;
if (flag)
{
Rect bounds = this.Bounds;
this.innerY = value;
this.InternalBoundsUpdate(bounds);
}
}
}
public Point Location
{
get
{
return new Point(ref this.innerX, ref this.innerY);
}
set
{
bool flag = this.innerX != value.X || this.innerY != value.Y;
if (flag)
{
Rect bounds = this.Bounds;
this.innerX = value.X;
this.innerY = value.Y;
this.InternalBoundsUpdate(bounds);
}
}
}
public float Width
{
get
{
return this.innerWidth;
}
set
{
bool flag = this.innerWidth != value;
if (flag)
{
Rect bounds = this.Bounds;
this.innerWidth = value;
this.InternalBoundsUpdate(bounds);
}
}
}
public float Height
{
get
{
return this.innerHeight;
}
set
{
bool flag = this.innerHeight != value;
if (flag)
{
Rect bounds = this.Bounds;
this.innerHeight = value;
this.InternalBoundsUpdate(bounds);
}
}
}
public float Left
{
get
{
return this.innerX;
}
}
public float Top
{
get
{
return this.innerY;
}
}
public float Right
{
get
{
return this.innerX + this.innerWidth;
}
}
public float Bottom
{
get
{
return this.innerY + this.innerHeight;
}
}
public Size Size
{
get
{
return new Size(ref this.innerWidth, ref this.innerHeight);
}
set
{
Rect bounds = this.Bounds;
this.innerWidth = value.Width;
this.innerHeight = value.Height;
this.InternalBoundsUpdate(bounds);
}
}
public Rect Bounds
{
get
{
return new Rect(ref this.innerX, ref this.innerY, ref this.innerWidth, ref this.innerHeight);
}
set
{
Rect bounds = this.Bounds;
this.innerX = value.X;
this.innerY = value.Y;
this.innerWidth = value.Width;
this.innerHeight = value.Height;
this.InternalBoundsUpdate(bounds);
}
}
protected internal virtual void InternalBoundsUpdate(Rect oldBounds)
{
this.OnBoundsChanged(oldBounds);
}
public virtual void OnBoundsChanged(Rect oldRect)
{
}
public virtual Size GetPreferredSize()
{
float num = 160f;
float num2 = 100f;
return new Size(ref num, ref num2);
}
//[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public event EventHandler<MouseEventArgs> MouseDown;
public virtual bool OnMouseDown(Point location, MouseButtons buttons, InputModifiers modifiers)
{
bool flag = this.MouseDown != null;
if (flag)
{
this.MouseDown(this, new MouseEventArgs(location, buttons));
}
return true;
}
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 keys)
{
return false;
}
public virtual void SetFocus()
{
}
public virtual void FreeFocus()
{
}
protected internal float innerX = 0f;
protected internal float innerY = 0f;
protected internal float innerWidth = 160f;
protected internal float innerHeight = 100f;
}
}