Ejemplo n.º 1
0
        private void DrawTimer(SKCanvas canvas, SKImageInfo info)
        {
            canvas.Clear();
            canvas.DrawPaint(new SKPaint {
                Color = new SKColor(96, 96, 96)
            });


            SKPoint center = new SKPoint(info.Width / 2 - 15, info.Height / 2);
            float   radius = Math.Min(info.Width / 2, info.Height / 2) - 10;
            SKRect  rect   = new SKRect(center.X - radius, center.Y - radius,
                                        center.X + radius, center.Y + radius);

            var surroundCircle = new YCircle(center, radius + 2, new SKColor(48, 48, 48), 4, SKPaintStyle.Stroke);

            surroundCircle.Draw(canvas);

            var backgroundCircle = new YCircle(center, radius, new SKColor(80, 80, 80), 1, SKPaintStyle.Fill);

            backgroundCircle.Draw(canvas);

            float startAngle = 270;



            var path = new YPath(new SKPath(), new SKColor(245, 222, 179), 5);

            path.DrawingPath.MoveTo(center);
            path.Paint.Style = SKPaintStyle.Fill;
            path.DrawingPath.ArcTo(rect, startAngle, _sweepAngle, false);
            path.DrawingPath.Close();

            path.Draw(canvas);
        }
Ejemplo n.º 2
0
        private void skElement_MouseMove(object sender, MouseEventArgs e)
        {
            var pixelPosition = e.GetPosition(sender as Canvas);
            var x             = (float)(pixelPosition.X * DpiScale.DpiScaleX - 350 * DpiScale.DpiScaleX);
            var y             = (float)(pixelPosition.Y * DpiScale.DpiScaleY - 150 * DpiScale.DpiScaleY);

            /*if(!(x < _winInf.Width && x > 0 && y < _winInf.Height && y > 0))
             * {
             *  _isMouseDown = false;
             * }*/
            if (_isMouseDown)
            {
                var skPoint = new SKPoint(x, y);

                var color = GetCurrentColor();

                YFigure currentFigure = null;

                switch (_state)
                {
                case State.pen:
                    _yPath.DrawingPath.LineTo(skPoint);
                    currentFigure = _yPath;
                    break;

                case State.rubber:
                    _yPath.DrawingPath.LineTo(skPoint);
                    currentFigure = _yPath;
                    break;

                case State.square:
                    currentFigure = new YRect(_skPoint.X, _skPoint.Y, x - _skPoint.X, y - _skPoint.Y, color, _strokeWidth, SKPaintStyle.Stroke);
                    break;

                case State.circle:
                    float radius = (float)Math.Sqrt(Math.Pow(x - _skPoint.X, 2) + Math.Pow(y - _skPoint.Y, 2));
                    currentFigure = new YCircle(_skPoint, radius, color, _strokeWidth, SKPaintStyle.Stroke);
                    break;

                case State.squareFilled:
                    currentFigure = new YRect(_skPoint.X, _skPoint.Y, x - _skPoint.X, y - _skPoint.Y, color, _strokeWidth, SKPaintStyle.Fill);
                    break;

                case State.circleFilled:
                    float radiusFilled = (float)Math.Sqrt(Math.Pow(x - _skPoint.X, 2) + Math.Pow(y - _skPoint.Y, 2));
                    currentFigure = new YCircle(_skPoint, radiusFilled, color, _strokeWidth, SKPaintStyle.Fill);
                    break;

                case State.line:
                    currentFigure = new YLine(_skPoint, new SKPoint(x, y), color, _strokeWidth);
                    break;
                }

                if (currentFigure != null)
                {
                    _history.Pop();
                    _history.Push(currentFigure);
                    skElement.InvalidateVisual();
                }
            }
        }