示例#1
0
        public override void DrawImage(ITexture image, Rect rectangle, Point uvMin, Point uvMax)
        {
            if (image == null)
            {
                return;
            }
            EnsureContent();

            unsafe
            {
                if (!this.content.ReadRecord(out DrawImageCommand record))
                {//different record type: append new record
                    record.ImageSourceIndex = this.content.AddDependentResource(image);
                    record.rectangle        = rectangle;
                    record.UVMin            = uvMin;
                    record.UVMax            = uvMax;
                    this.content.WriteRecord(RecordType.DrawImage, (byte *)&record, sizeof(DrawImageCommand));
                    return;
                }

                //same type: update record if different
                bool recordNeedOverwrite = false;
                if (this.content.ReadDependentResource(record.ImageSourceIndex, out ITexture oldImage))
                {
                    if (!image.Equals(oldImage))
                    {
                        record.ImageSourceIndex = this.content.AddDependentResource(image);
                        recordNeedOverwrite     = true;
                    }
                }
                else
                {
                    record.ImageSourceIndex = this.content.AddDependentResource(image);
                    recordNeedOverwrite     = true;
                }

                if (!Point.AlmostEqual(record.UVMin, uvMin))
                {
                    record.UVMin        = uvMin;
                    recordNeedOverwrite = true;
                }
                if (!Point.AlmostEqual(record.UVMax, uvMax))
                {
                    record.UVMax        = uvMax;
                    recordNeedOverwrite = true;
                }


                if (recordNeedOverwrite)
                {
                    content.WriteRecord(RecordType.DrawImage, (byte *)&record, sizeof(DrawImageCommand));
                }
            }
        }
示例#2
0
        public override void DrawLine(Pen pen, Point point0, Point point1)
        {
            if (pen == null)
            {
                throw new ArgumentNullException(nameof(pen));
            }

            unsafe
            {
                EnsureContent();

                if (!this.content.ReadRecord(out DrawLineCommand record))
                {//different record type: append new record
                    record.PenIndex   = this.content.AddDependentResource(pen);
                    record.StartPoint = point0;
                    record.EndPoint   = point1;
                    this.content.WriteRecord(RecordType.DrawLine, (byte *)&record, sizeof(DrawLineCommand));
                    return;
                }

                //same type: update record if different
                bool recordNeedOverwrite = false;
                if (!Point.AlmostEqual(record.StartPoint, point0))
                {
                    record.StartPoint   = point0;
                    recordNeedOverwrite = true;
                }

                if (!Point.AlmostEqual(record.EndPoint, point1))
                {
                    record.EndPoint     = point0;
                    recordNeedOverwrite = true;
                }

                if (this.content.ReadDependentResource(record.PenIndex, out Pen oldPen))
                {
                    if (!Equals(oldPen, pen))
                    {
                        record.PenIndex     = this.content.AddDependentResource(pen);
                        recordNeedOverwrite = true;
                    }
                }
                else
                {
                    record.PenIndex     = this.content.AddDependentResource(pen);
                    recordNeedOverwrite = true;
                }

                if (recordNeedOverwrite)
                {
                    content.WriteRecord(RecordType.DrawLine, (byte *)&record, sizeof(DrawLineCommand));
                }
            }
        }
示例#3
0
        public override void DrawEllipse(Brush brush, Pen pen, Point center, double radiusX, double radiusY)
        {
            if (brush == null && pen == null || radiusX <= 0 || radiusY <= 0)
            {
                return;
            }
            EnsureContent();

            unsafe
            {
                if (!this.content.ReadRecord(out DrawEllipseCommand record))
                {//different record type: append new record
                    record.BrushIndex = this.content.AddDependentResource(brush);
                    record.PenIndex   = this.content.AddDependentResource(pen);
                    record.Center     = center;
                    record.RadiusX    = radiusX;
                    record.RadiusY    = radiusY;
                    this.content.WriteRecord(RecordType.DrawEllipse, (byte *)&record, sizeof(DrawEllipseCommand));
                    return;
                }

                //same type: update record if different
                bool recordNeedOverwrite = false;
                if (!Point.AlmostEqual(record.Center, center))
                {
                    record.Center       = center;
                    recordNeedOverwrite = true;
                }
                if (!MathEx.AmostEqual(record.RadiusX, radiusX))
                {
                    record.RadiusX      = radiusX;
                    recordNeedOverwrite = true;
                }
                if (!MathEx.AmostEqual(record.RadiusY, radiusY))
                {
                    record.RadiusY      = radiusY;
                    recordNeedOverwrite = true;
                }

                if (this.content.ReadDependentResource(record.PenIndex, out Pen oldPen))
                {
                    if (!oldPen.Equals(pen))
                    {
                        record.PenIndex     = this.content.AddDependentResource(pen);
                        recordNeedOverwrite = true;
                    }
                }
                else
                {
                    record.PenIndex     = this.content.AddDependentResource(pen);
                    recordNeedOverwrite = true;
                }

                if (this.content.ReadDependentResource(record.BrushIndex, out Brush oldBrush))
                {
                    if (!oldBrush.Equals(brush))
                    {
                        record.BrushIndex   = this.content.AddDependentResource(brush);
                        recordNeedOverwrite = true;
                    }
                }
                else
                {
                    record.BrushIndex   = this.content.AddDependentResource(brush);
                    recordNeedOverwrite = true;
                }

                if (recordNeedOverwrite)
                {
                    content.WriteRecord(RecordType.DrawEllipse, (byte *)&record, sizeof(DrawEllipseCommand));
                }
            }
        }
 public static bool AlmostEqual(this Point point, Point other)
 {
     return point.AlmostEqual(other.X, other.Y);
 }
 public static bool Contains(this Line line, Point point)
 {
     return(point.AlmostEqual(line.X1, line.Y1) || point.AlmostEqual(line.X2, line.Y2));
 }