using System; using System.Collections.Generic; using CPF.Drawing; using CPF.ReoGrid.Drawing.Text; using CPF.ReoGrid.Graphics; using CPF.ReoGrid.Interaction; using CPF.ReoGrid.Rendering; namespace CPF.ReoGrid.Drawing { [Serializable] public class DrawingObject : SelectableFloatingObject, IDrawingObject, IFloatingObject, IUserVisual, IThumbVisualObject { public DrawingObject() { this.clientBounds = base.Bounds; this.ScaleX = 1f; this.ScaleY = 1f; this.ForeColor = Color.Black; this.LineColor = Color.Black; this.FillColor = Color.White; this.FontName = "Arial"; this.FontSize = 8.25f; this.LineWidth = 1f; } public IDrawingContainer Container { get; set; } public override void Invalidate() { bool flag = this.Container != null; if (flag) { this.Container.Invalidate(); } } public virtual Rect ClientBounds { get { return this.clientBounds; } } public virtual Point OriginPoint { get; protected set; } public virtual float ScaleX { get; set; } public virtual float ScaleY { get; set; } public virtual float RotateAngle { get; set; } public bool Visible { get { return this.visible; } set { bool flag = this.visible != value; if (flag) { this.visible = value; this.Invalidate(); } } } internal PaddingValue Padding { get; set; } public Color FillColor { get; set; } public Color ForeColor { get; set; } public Color LineColor { get; set; } public float LineWidth { get; set; } public LineStyles LineStyle { get; set; } public virtual string FontName { get; set; } public virtual float FontSize { get; set; } public virtual CPF.ReoGrid.Drawing.Text.FontStyles FontStyles { get; set; } public IDrawingObjectStyle Style { get { bool flag = this.styleProxy == null; if (flag) { this.styleProxy = new DrawingObjectStyle(this); } return this.styleProxy; } } public virtual void Draw(RDrawingContext dc) { Rect rect = this.ClientBounds; IGraphics graphics = dc.Graphics; bool flag = this.innerX != 0f || this.innerY != 0f || this.ScaleX != 1f || this.ScaleY != 1f || this.RotateAngle != 0f; if (flag) { graphics.PushTransform(); bool flag2 = this.ScaleX != 1f || this.ScaleY != 1f; if (flag2) { graphics.ScaleTransform(this.ScaleX, this.ScaleY); } bool flag3 = this.RotateAngle != 0f; if (flag3) { graphics.TranslateTransform(this.innerX + this.halfWidth, this.innerY + this.halfHeight); graphics.RotateTransform(this.RotateAngle); graphics.TranslateTransform(-this.halfWidth, -this.halfHeight); } else { graphics.TranslateTransform(this.innerX, this.innerY); } this.OnPaint(dc); graphics.PopTransform(); } else { this.OnPaint(dc); } bool isSelected = this.IsSelected; if (isSelected) { this.DrawSelection(dc); } } protected virtual void OnPaint(RDrawingContext dc) { IGraphics graphics = dc.Graphics; float num = 0f; float num2 = 0f; float width = base.Width; float height = base.Height; Rect rect = new Rect(ref num, ref num2, ref width, ref height); bool flag = !this.FillColor.IsTransparent && !this.LineColor.IsTransparent; if (flag) { graphics.DrawAndFillRectangle(rect, this.LineColor, this.FillColor, this.LineWidth, this.LineStyle); } else { bool flag2 = !this.FillColor.IsTransparent; if (flag2) { graphics.FillRectangle(rect, this.FillColor); } else { bool flag3 = this.LineColor.A > 0; if (flag3) { graphics.DrawRectangle(rect, this.LineColor, this.LineWidth, this.LineStyle); } } } } protected virtual void DrawSelection(RDrawingContext dc) { IGraphics graphics = dc.Graphics; graphics.DrawRectangle(base.Bounds, Color.DeepSkyBlue); bool flag = this.resizePoints != null && this.resizePoints.Length != 0; if (flag) { foreach (ResizeThumb resizeThumb in this.resizePoints) { Point point = resizeThumb.Point; graphics.DrawEllipse(Color.SeaGreen, point.X - 2f, point.Y - 2f, 4f, 4f); } } } protected internal override void InternalBoundsUpdate(Rect oldBounds) { float left = this.Padding.Left; float top = this.Padding.Top; float num = this.innerWidth - this.Padding.Left - this.Padding.Right; float num2 = this.innerHeight - this.Padding.Top - this.Padding.Bottom; Rect rect = new Rect(ref left, ref top, ref num, ref num2); bool flag = rect.Width < 0f; if (flag) { rect.Width = 0f; } bool flag2 = rect.Height < 0f; if (flag2) { rect.Height = 0f; } this.clientBounds = rect; this.halfWidth = this.innerWidth / 2f; this.halfHeight = this.innerHeight / 2f; this.OriginPoint = new Point(ref this.halfWidth, ref this.halfHeight); base.InternalBoundsUpdate(oldBounds); } public override void OnSelect() { this.UpdateResizeThumbPoints(); base.OnSelect(); } public override void OnDeselect() { base.OnDeselect(); } public IEnumerable ThumbPoints { get { return this.resizePoints; } } protected internal void UpdateResizeThumbPoints() { this.resizePoints[0] = new ResizeThumb(ResizeThumbPosition.TopLeft, this.innerX, this.innerY); this.resizePoints[1] = new ResizeThumb(ResizeThumbPosition.Top, this.innerX + this.halfWidth, this.innerY); this.resizePoints[2] = new ResizeThumb(ResizeThumbPosition.TopRight, base.Right, this.innerY); this.resizePoints[3] = new ResizeThumb(ResizeThumbPosition.Left, this.innerX, this.innerY + this.halfHeight); this.resizePoints[4] = new ResizeThumb(ResizeThumbPosition.Right, base.Right, this.innerY + this.halfHeight); this.resizePoints[5] = new ResizeThumb(ResizeThumbPosition.BottomLeft, this.innerX, base.Bottom); this.resizePoints[6] = new ResizeThumb(ResizeThumbPosition.Bottom, this.innerX + this.halfWidth, base.Bottom); this.resizePoints[7] = new ResizeThumb(ResizeThumbPosition.BottomRight, base.Right, base.Bottom); } private Rect clientBounds; private float halfWidth; private float halfHeight; private bool visible = true; private DrawingObjectStyle styleProxy = null; private ResizeThumb[] resizePoints = new ResizeThumb[8]; } }