예제 #1
0
        public void Draw(AreaBase area, ref AreaDrawParams param)
        {
            _brush = Brushes.White;
            _path  = new Path(FillMode.Winding);
            _path.AddRectangle(0d, 0d, param.AreaWidth, param.AreaHeight);
            _path.End();
            param.Context.Fill(_path, _brush);
            _path.Free();

            double graphWidth;
            double graphHeight;

            GraphSize(param.AreaWidth, param.AreaHeight, out graphWidth, out graphHeight);

            _strokeParams = new StrokeParams()
            {
                LineCap    = LineCap.Flat,
                LineJoin   = LineJoin.Miter,
                Thickness  = 2,
                MiterLimit = 10.0
            };

            _brush = Brushes.Black;
            _path  = new Path(FillMode.Winding);
            _path.NewFigure(xoffLeft, yoffTop);
            _path.LineTo(xoffLeft, yoffTop + graphHeight);
            _path.LineTo(xoffLeft + graphWidth, yoffTop + graphHeight);
            _path.End();
            param.Context.Stroke(_path, _brush, _strokeParams);
            _path.Free();

            var matrix = Matrix.SetIdentity();

            matrix.Translate(xoffLeft, yoffTop);
            param.Context.Transform(matrix);

            _brush = (SolidColorBrush)_colorPicker.Color;
            var a = _brush.A;

            _brush.A = _brush.A / 2;
            _path    = ConstructGraph(graphWidth, graphHeight, true);
            param.Context.Fill(_path, _brush);
            _path.Free();

            _path    = ConstructGraph(graphWidth, graphHeight, false);
            _brush.A = a;
            param.Context.Stroke(_path, _brush, _strokeParams);
            _path.Free();

            if (_currentPoint != -1)
            {
                double[] xs, ys;
                PointLocations(graphWidth, graphHeight, out xs, out ys);
                _path = new Path(FillMode.Winding);
                _path.NewFigureWithArc(xs[_currentPoint], ys[_currentPoint], 5, 0, 6.23, false);
                _path.End();
                param.Context.Fill(_path, _brush);
                _path.Free();
            }
        }
예제 #2
0
        private static void DrawGradient(ref AreaDrawParams param)
        {
            var areaSize     = 250d;
            var padding      = 30d;
            var circleRadius = (areaSize - padding) / 2;

            var path = new Path(FillMode.Winding);

            path.AddRectangle(-50, -50, areaSize + 100, areaSize + 100);
            path.End();
            var brush = Brushes.Lime;

            param.Context.Fill(path, brush);
            path.Free();

            path = new Path(FillMode.Winding);
            path.AddRectangle(0, 0, areaSize, areaSize);
            path.End();
            brush = Brushes.White;
            param.Context.Fill(path, brush);
            brush = Brushes.Red;
            var sp = new StrokeParams()
            {
                Thickness = 1
            };

            param.Context.Stroke(path, brush, sp);
            path.Free();

            path = new Path(FillMode.Winding);
            path.NewFigureWithArc(areaSize / 2, areaSize / 2, circleRadius, 0, 2 * Math.PI, false);
            path.End();
            var stops = new GradientStop[2];

            stops[0] = new GradientStop()
            {
                Pos = 0, R = 0, G = 1, B = 1, A = 1
            };
            stops[1] = new GradientStop()
            {
                Pos = 1, R = 0, G = 0, B = 1, A = 1
            };
            var linear = new LinearGradientBrush
            {
                StartPoint = new Point(areaSize / 2, padding),
                EndPoint   = new Point(areaSize / 2, areaSize - padding),
                Stops      = stops
            };

            param.Context.Fill(path, linear);
            path.Free();
        }
예제 #3
0
        private static void DrawDashes(ref AreaDrawParams param)
        {
            var offset = -50;
            var dashes = new double[] { 50d, 10d, 10d, 10d };
            var brush  = Brushes.Black;
            var sp     = new StrokeParams();

            sp.Dashes    = dashes;
            sp.DashPhase = offset;
            sp.Thickness = 10;

            var path = new Path(FillMode.Winding);

            path.NewFigure(128.0, 25.6);
            path.LineTo(230.4, 230.4);
            path.LineTo(230.4 - 102.4, 230.4 + 0.0);
            path.BezierTo(51.2, 230.4, 51.2, 128.0, 128.0, 128.0);
            path.End();
            param.Context.Stroke(path, brush, sp);
            path.Free();
        }
예제 #4
0
        private static void DrawOriginal(ref AreaDrawParams param)
        {
            var sp = new StrokeParams()
            {
                Thickness = 1
            };
            var brush = Brushes.Red;
            var path  = new Path(FillMode.Winding);

            path.NewFigure(param.ClipX + 5, param.ClipY + 5);
            path.LineTo(param.ClipX + param.ClipWidth - 5, param.ClipY + param.ClipHeight - 5);
            path.End();
            param.Context.Stroke(path, brush, sp);
            path.Free();

            brush   = Brushes.Blue;
            brush.B = 0.75;
            path    = new Path(FillMode.Winding);
            path.NewFigure(param.ClipX, param.ClipY);
            path.LineTo(param.ClipX + param.ClipWidth, param.ClipY);
            path.LineTo(50, 150);
            path.LineTo(50, 50);
            path.CloseFigure();
            path.End();
            sp.Thickness = 5;
            sp.LineJoin  = LineJoin.Round;
            param.Context.Stroke(path, brush, sp);
            path.Free();

            brush   = Brushes.Green;
            brush.G = 0.75;
            brush.A = 0.5;
            path    = new Path(FillMode.Winding);
            path.AddRectangle(120, 80, 50, 50);
            path.End();
            param.Context.Fill(path, brush);
            path.Free();

            brush.G = 0.5;
            brush.A = 1;
            path    = new Path(FillMode.Winding);
            path.NewFigure(5.5, 10.5);
            path.LineTo(5.5, 50.5);
            path.End();
            sp.LineJoin  = LineJoin.Miter;
            sp.Thickness = 1;
            param.Context.Stroke(path, brush, sp);
            path.Free();

            brush.R = 0.5;
            brush.G = 0.75;
            path    = new Path(FillMode.Winding);
            path.NewFigure(400, 100);
            path.ArcTo(400, 100, 50, 30 * (Math.PI / 180), 300 * (Math.PI / 180), false);
            path.LineTo(400, 100);
            path.NewFigureWithArc(510, 100, 50, 30 * (Math.PI / 180), 300 * (Math.PI / 180), false);
            path.CloseFigure();
            path.NewFigure(400, 210);
            path.ArcTo(400, 210, 50, 30 * (Math.PI / 180), 330 * (Math.PI / 180), false);
            path.LineTo(400, 210);
            path.NewFigureWithArc(510, 210, 50, 30 * (Math.PI / 180), 330 * (Math.PI / 180), false);
            path.CloseFigure();
            path.End();
            param.Context.Stroke(path, brush, sp);
            path.Free();

            brush.R = 0;
            brush.G = 0.5;
            brush.B = 0.75;
            path    = new Path(FillMode.Winding);
            path.NewFigure(300, 300);
            path.BezierTo(350, 320, 310, 390, 435, 372);
            path.End();
            param.Context.Stroke(path, brush, sp);
            path.Free();
        }