public void DrawRectangle(Rect frame, Size corner, Pen pen = null, Brush brush = null)
        {
            if (corner.Width > 0 || corner.Height > 0)
            {
                var geometry = new StreamGeometry();
                using (var context = geometry.Open())
                {
                    bool       isStroked    = pen != null;
                    const bool isSmoothJoin = true;

                    var diag         = corner.Diagonal;
                    var cornerRadius = new {
                        TopLeft     = diag,
                        TopRight    = diag,
                        BottomRight = diag,
                        BottomLeft  = diag
                    };

                    var rect = frame.GetRect();

                    context.BeginFigure(rect.TopLeft + new Vector(0, cornerRadius.TopLeft), brush != null, true);
                    context.ArcTo(new System.Windows.Point(rect.TopLeft.X + cornerRadius.TopLeft, rect.TopLeft.Y),
                                  new System.Windows.Size(cornerRadius.TopLeft, cornerRadius.TopLeft),
                                  90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);

                    context.LineTo(rect.TopRight - new Vector(cornerRadius.TopRight, 0), isStroked, isSmoothJoin);
                    context.ArcTo(new System.Windows.Point(rect.TopRight.X, rect.TopRight.Y + cornerRadius.TopRight),
                                  new System.Windows.Size(cornerRadius.TopRight, cornerRadius.TopRight),
                                  90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);

                    context.LineTo(rect.BottomRight - new Vector(0, cornerRadius.BottomRight), isStroked, isSmoothJoin);
                    context.ArcTo(new System.Windows.Point(rect.BottomRight.X - cornerRadius.BottomRight, rect.BottomRight.Y),
                                  new System.Windows.Size(cornerRadius.BottomRight, cornerRadius.BottomRight),
                                  90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);

                    context.LineTo(rect.BottomLeft + new Vector(cornerRadius.BottomLeft, 0), isStroked, isSmoothJoin);
                    context.ArcTo(new System.Windows.Point(rect.BottomLeft.X, rect.BottomLeft.Y - cornerRadius.BottomLeft),
                                  new System.Windows.Size(cornerRadius.BottomLeft, cornerRadius.BottomLeft),
                                  90, false, SweepDirection.Clockwise, isStroked, isSmoothJoin);

                    context.Close();
                }
                dc.DrawGeometry(brush?.GetBrush(), pen?.GetPen(), geometry);
            }
            else
            {
                dc.DrawRectangle(brush?.GetBrush(), pen?.GetPen(), frame.GetRect());
            }
        }
예제 #2
0
        public void DrawImage(IImage image, Rect frame, double alpha = 1)
        {
            if (alpha != 1)
            {
                throw new NotImplementedException();
            }

            var isImage = image as ImageSourceImage;

            dc.DrawImage(isImage.BitmapSource, frame.GetRect());
        }
예제 #3
0
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
     dc.DrawRectangle(brush?.GetBrush(), pen?.GetPen(), frame.GetRect());
 }
 public void DrawRectangle(Rect frame, Pen pen = null, Brush brush = null)
 {
     dc.DrawRectangle(brush?.GetBrush(), pen?.GetPen(), frame.GetRect());
 }
        public void DrawImage(IImage image, Rect frame, double alpha = 1)
        {
            if (alpha != 1)
            {
                throw new NotImplementedException();
            }

            var isImage = image as ImageSourceImage;
            dc.DrawImage(isImage.BitmapSource, frame.GetRect());
        }