예제 #1
0
        public Vector2 GetPosTan(float distance)
        {
            if (distance < 0)
            {
                distance = 0;
            }

            var length = Length;

            if (distance > length)
            {
                distance = length;
            }

            return(_geometry.ComputePointOnPath(distance));
        }
예제 #2
0
        private void Canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            if (needsToRecreateResources)
            {
                RecreateGeometry(sender);
                needsToRecreateResources = false;
            }

            if (CurrentContourTracingAnimation != ContourTracingAnimationOption.None)
            {
                float animationDistanceThisFrame = CurrentContourTracingAnimation == ContourTracingAnimationOption.Slow ? 1.0f : 20.0f;
                currentDistanceOnContourPath = (currentDistanceOnContourPath + animationDistanceThisFrame) % totalDistanceOnContourPath;

                pointOnContourPath = combinedGeometry.ComputePointOnPath(currentDistanceOnContourPath, out tangentOnContourPath);
            }
        }
예제 #3
0
        private void Canvas_Update(ICanvasAnimatedControl sender, CanvasAnimatedUpdateEventArgs args)
        {
            if (needsToRecreateResources)
            {
                RecreateGeometry(sender);
                needsToRecreateResources = false;
            }

            if (CurrentContourTracingAnimation != ContourTracingAnimationOption.None)
            {
                float animationDistanceThisFrame = CurrentContourTracingAnimation == ContourTracingAnimationOption.Slow ? 1.0f : 20.0f;
                currentDistanceOnContourPath = (currentDistanceOnContourPath + animationDistanceThisFrame) % totalDistanceOnContourPath;

#if WINDOWS_UAP
                Vector2 outTangent;
#else
                Microsoft.Graphics.Canvas.Numerics.Vector2 outTangent;
#endif
                pointOnContourPath   = combinedGeometry.ComputePointOnPath(currentDistanceOnContourPath, out outTangent);
                tangentOnContourPath = outTangent;
            }
        }
예제 #4
0
        private void canvas_RegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)
        {
            float tLineSWidth = 2;

            CanvasStrokeStyle strokeStyle = new CanvasStrokeStyle
            {
                DashStyle = CanvasDashStyle.Dot,
                DashCap   = CanvasCapStyle.Round,
                StartCap  = CanvasCapStyle.Round,
                EndCap    = CanvasCapStyle.Round,
                LineJoin  = CanvasLineJoin.Bevel,
            };

            CanvasStrokeStyle strokeStyle2 = new CanvasStrokeStyle
            {
                CustomDashStyle = new float[] { 15f, 10f }
            };

            CanvasTextFormat infoRectTextFormat = new CanvasTextFormat
            {
                FontSize     = 12.0f,
                WordWrapping = CanvasWordWrapping.NoWrap
            };

            Color infoRectBGColor   = Colors.Black;
            Color infoRectTextColor = Colors.DarkGray;

            var dir = CanvasSweepDirection.CounterClockwise;

            float cursorSize       = 50;
            float insideCursorSize = 3;

            foreach (var region in args.InvalidatedRegions)
            {
                using (var drawingSession = sender.CreateDrawingSession(region))
                {
                    #region XYZ Axis
                    //Y
                    drawingSession.DrawLine(new Vector2((float)canvas.ActualWidth / 2, 0), new Vector2((float)canvas.ActualWidth / 2, (float)canvas.ActualHeight / 2), Colors.Green, 1);

                    drawingSession.DrawLine(new Vector2((float)canvas.ActualWidth / 2, (float)canvas.ActualHeight / 2), new Vector2((float)canvas.ActualWidth / 2, ((float)canvas.ActualHeight / 2) - 50), Colors.White, 1);

                    drawingSession.DrawLine(new Vector2(((float)canvas.ActualWidth / 2), ((float)canvas.ActualHeight / 2) - 70), new Vector2(((float)canvas.ActualWidth / 2) + 7, ((float)canvas.ActualHeight / 2) - 60), Colors.White, 1);      // \
                    drawingSession.DrawLine(new Vector2(((float)canvas.ActualWidth / 2) + 14, ((float)canvas.ActualHeight / 2) - 70), new Vector2(((float)canvas.ActualWidth / 2) + 7, ((float)canvas.ActualHeight / 2) - 60), Colors.White, 1); // /
                    drawingSession.DrawLine(new Vector2(((float)canvas.ActualWidth / 2) + 7, ((float)canvas.ActualHeight / 2) - 50), new Vector2(((float)canvas.ActualWidth / 2) + 7, ((float)canvas.ActualHeight / 2) - 60), Colors.White, 1);  // |
                    //X
                    drawingSession.DrawLine(new Vector2((float)canvas.ActualWidth / 2, (float)canvas.ActualHeight / 2), new Vector2((float)canvas.ActualWidth, (float)canvas.ActualHeight / 2), Colors.Red, 1);

                    drawingSession.DrawLine(new Vector2((float)canvas.ActualWidth / 2, (float)canvas.ActualHeight / 2), new Vector2(((float)canvas.ActualWidth / 2) + 50, (float)canvas.ActualHeight / 2), Colors.White, 1);

                    drawingSession.DrawLine(new Vector2(((float)canvas.ActualWidth / 2) + 51, (float)canvas.ActualHeight / 2 - 21), new Vector2(((float)canvas.ActualWidth / 2) + 71, (float)canvas.ActualHeight / 2 - 1), Colors.White, 1);
                    drawingSession.DrawLine(new Vector2(((float)canvas.ActualWidth / 2) + 71, (float)canvas.ActualHeight / 2 - 21), new Vector2(((float)canvas.ActualWidth / 2) + 51, (float)canvas.ActualHeight / 2 - 1), Colors.White, 1);
                    //Z
                    //maybeoneday
                    #endregion

                    #region CURSOR
                    if (windowsCursor == false)
                    {
                        if (cursorMode == 0)
                        {
                            //vertical
                            drawingSession.DrawLine(new Vector2((float)aCursorPOS.X, (float)aCursorPOS.Y - cursorSize), new Vector2((float)aCursorPOS.X, (float)aCursorPOS.Y - insideCursorSize), Colors.White, 1);
                            drawingSession.DrawLine(new Vector2((float)aCursorPOS.X, (float)aCursorPOS.Y + insideCursorSize), new Vector2((float)aCursorPOS.X, (float)aCursorPOS.Y + cursorSize), Colors.White, 1);
                            //horizontal
                            drawingSession.DrawLine(new Vector2((float)aCursorPOS.X - cursorSize, (float)aCursorPOS.Y), new Vector2((float)aCursorPOS.X - insideCursorSize, (float)aCursorPOS.Y), Colors.White, 1);
                            drawingSession.DrawLine(new Vector2((float)aCursorPOS.X + insideCursorSize, (float)aCursorPOS.Y), new Vector2((float)aCursorPOS.X + cursorSize, (float)aCursorPOS.Y), Colors.White, 1);
                            //retangulo
                            drawingSession.DrawRectangle(new Rect(new Point(aCursorPOS.X - insideCursorSize, aCursorPOS.Y - insideCursorSize), new Point(aCursorPOS.X + insideCursorSize, aCursorPOS.Y + insideCursorSize)), Colors.White, 1);
                        }
                    }
                    else
                    {
                        Window.Current.CoreWindow.PointerCursor = new CoreCursor(cursorNormal, 0);
                    }
                    #endregion

                    #region LINE
                    if (drawingLine == true)
                    {
                        // Linha do desenho
                        Vector2 tLineP1 = new Vector2(tLine.x1, tLine.y1);
                        Vector2 tLineP2 = new Vector2(tLine.x2, tLine.y2);

                        drawingSession.DrawLine(tLineP1, tLineP2, Colors.White, 1);

                        // Linha paralela
                        float L            = (float)(Math.Sqrt((tLineP1.X - tLineP2.X) * (tLineP1.X - tLineP2.X) + (tLineP1.Y - tLineP2.Y) * (tLineP1.Y - tLineP2.Y)));
                        float offsetPixels = 50;
                        float radius       = Vector2.Distance(tLineP1, tLineP2);
                        float yAxis        = -180;

                        if (tLine.y2 > tLine.y1)
                        {
                            yAxis        = 180;
                            offsetPixels = -50;
                            dir          = CanvasSweepDirection.Clockwise;
                        }

                        Vector2 pLineP1 = new Vector2(tLineP1.X + offsetPixels * (tLineP2.Y - tLineP1.Y) / L, tLineP1.Y + offsetPixels * (tLineP1.X - tLineP2.X) / L);
                        Vector2 pLineP2 = new Vector2(tLineP2.X + offsetPixels * (tLineP2.Y - tLineP1.Y) / L, tLineP2.Y + offsetPixels * (tLineP1.X - tLineP2.X) / L);

                        drawingSession.DrawLine(pLineP1, pLineP2, Colors.DarkGray, tLineSWidth, strokeStyle); // diagonal
                        drawingSession.DrawLine(tLineP1, pLineP1, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 1
                        drawingSession.DrawLine(tLineP2, pLineP2, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 2

                        // linha adjacente
                        drawingSession.DrawLine(tLineP1.X, tLineP1.Y, tLineP1.X + L, tLineP1.Y, Colors.DarkGray, tLineSWidth, strokeStyle);

                        // arco
                        CanvasPathBuilder pathBuilder = new CanvasPathBuilder(sender);
                        pathBuilder.BeginFigure(new Vector2(tLineP1.X + L, tLineP1.Y));

                        pathBuilder.AddArc(
                            tLineP2,
                            radius,
                            radius,
                            0, dir, CanvasArcSize.Small
                            );

                        pathBuilder.EndFigure(CanvasFigureLoop.Open);

                        CanvasGeometry geometry = CanvasGeometry.CreatePath(pathBuilder);
                        drawingSession.DrawGeometry(geometry, Colors.DarkGray, 2, strokeStyle);

                        // InfoBox de medição do angulo
                        double angle     = Math.Abs((Math.Atan2((tLineP1.Y) - tLineP2.Y, (tLineP1.X + radius) - tLineP2.X)) * 360 / Math.PI + yAxis);
                        double arcLenght = (angle * Math.PI * radius) / 180;

                        Vector2 midPoint = geometry.ComputePointOnPath((float)arcLenght / 2);

                        CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, Math.Round(angle).ToString() + "°", infoRectTextFormat, 0.0f, 0.0f);

                        Rect infoRect = new Rect(midPoint.X - ((float)textLayout.DrawBounds.Width / 2) - 5,
                                                 midPoint.Y - ((float)textLayout.DrawBounds.Height / 2) - 5,
                                                 textLayout.DrawBounds.Width + 10,
                                                 textLayout.DrawBounds.Height + 10
                                                 );

                        drawingSession.FillRectangle(infoRect, infoRectBGColor); // fundo
                        drawingSession.DrawTextLayout(textLayout,
                                                      midPoint.X - ((float)textLayout.DrawBounds.Width / 2),
                                                      midPoint.Y - ((float)textLayout.DrawBounds.Height),
                                                      infoRectTextColor
                                                      );
                    }
                    #endregion

                    #region RECT
                    if (drawingRect == true)
                    {
                        drawingSession.DrawRectangle(new Rect(new Point(tRect.x1, tRect.y1), new Point(tRect.x2, tRect.y2)), Colors.White, 1);
                    }
                    #endregion

                    #region CIRCLE
                    if (drawingCircle == true)
                    {
                        // Linha do desenho
                        drawingSession.DrawLine(tCircle.cx1, tCircle.cy1, tCircle.rx2, tCircle.ry2, Colors.Orange, 1, strokeStyle2);

                        // Linha paralela
                        float L = (float)(Math.Sqrt((tCircle.cx1 - tCircle.rx2) * (tCircle.cx1 - tCircle.rx2) + (tCircle.cy1 - tCircle.ry2) * (tCircle.cy1 - tCircle.ry2)));

                        float offsetPixels = 50;

                        float x1p = tCircle.cx1 + offsetPixels * (tCircle.ry2 - tCircle.cy1) / L;
                        float x2p = tCircle.rx2 + offsetPixels * (tCircle.ry2 - tCircle.cy1) / L;
                        float y1p = tCircle.cy1 + offsetPixels * (tCircle.cx1 - tCircle.rx2) / L;
                        float y2p = tCircle.ry2 + offsetPixels * (tCircle.cx1 - tCircle.rx2) / L;

                        drawingSession.DrawLine(x1p, y1p, x2p, y2p, Colors.DarkGray, tLineSWidth, strokeStyle);                 // diagonal
                        drawingSession.DrawLine(tCircle.cx1, tCircle.cy1, x1p, y1p, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 1
                        drawingSession.DrawLine(tCircle.rx2, tCircle.ry2, x2p, y2p, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 2

                        drawingSession.DrawCircle(tCircle.cx1, tCircle.cy1, Vector2.Distance(new Vector2(tCircle.cx1, tCircle.cy1), new Vector2(tCircle.rx2, tCircle.ry2)), Colors.White, 1);
                    }
                    #endregion

                    #region RULER
                    if (measuring == true)
                    {
                        // Linha do desenho
                        Vector2 rLineP1 = new Vector2(tRuler.x1, tRuler.y1);
                        Vector2 rLineP2 = new Vector2(tRuler.x2, tRuler.y2);

                        drawingSession.DrawLine(rLineP1, rLineP2, Colors.Orange, 1, strokeStyle2);

                        // Linha paralela
                        float L            = Convert.ToInt16(Math.Sqrt((rLineP1.X - rLineP2.X) * (rLineP1.X - rLineP2.X) + (rLineP1.Y - rLineP2.Y) * (rLineP1.Y - rLineP2.Y)));
                        float offsetPixels = 50;

                        Vector2 pLineP1 = new Vector2(rLineP1.X + offsetPixels * (rLineP2.Y - rLineP1.Y) / L, rLineP1.Y + offsetPixels * (rLineP1.X - rLineP2.X) / L);
                        Vector2 pLineP2 = new Vector2(rLineP2.X + offsetPixels * (rLineP2.Y - rLineP1.Y) / L, rLineP2.Y + offsetPixels * (rLineP1.X - rLineP2.X) / L);

                        drawingSession.DrawLine(pLineP1, pLineP2, Colors.DarkGray, tLineSWidth, strokeStyle); // diagonal
                        drawingSession.DrawLine(rLineP1, pLineP1, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 1
                        drawingSession.DrawLine(rLineP2, pLineP2, Colors.DarkGray, tLineSWidth, strokeStyle); // ligação 2

                        // InfoBox de medição do comprimento
                        float lenght = Vector2.Distance(rLineP1, rLineP2);

                        Vector2 midPoint = new Vector2(pLineP1.X + (pLineP2.X - pLineP1.X) / 2, pLineP1.Y + (pLineP2.Y - pLineP1.Y) / 2);

                        CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, lenght.ToString("0.0000", new CultureInfo("en-US")), infoRectTextFormat, 0.0f, 0.0f);

                        Rect infoRect = new Rect(midPoint.X - (textLayout.DrawBounds.Width / 2) - 5,
                                                 midPoint.Y - (textLayout.DrawBounds.Height / 2) - 5,
                                                 textLayout.DrawBounds.Width + 10,
                                                 textLayout.DrawBounds.Height + 10
                                                 );

                        drawingSession.FillRectangle(infoRect, infoRectBGColor); // fundo
                        drawingSession.DrawTextLayout(textLayout,
                                                      midPoint.X - ((float)textLayout.DrawBounds.Width / 2),
                                                      midPoint.Y - ((float)textLayout.DrawBounds.Height),
                                                      infoRectTextColor
                                                      );
                    }
                    #endregion

                    #region SNAP
                    if (isSnapActivated == true && isDrawing == true)
                    {
                        foreach (snap s in Snaps)
                        {
                            if (s.isVisible == true)
                            {
                                int size = 5;

                                Point centerPOS = new Point(s.rect.X + near, s.rect.Y + near);

                                if (s.type == 1)
                                {
                                    drawingSession.DrawRectangle(new Rect(new Point(centerPOS.X - size, centerPOS.Y - size), new Point(centerPOS.X + size, centerPOS.Y + size)), Colors.DeepSkyBlue, 2);
                                }
                                else if (s.type == 2)
                                {
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X - size, (float)centerPOS.Y + size), new Vector2((float)centerPOS.X + size, (float)centerPOS.Y + size), Colors.DeepSkyBlue, 2); //base
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X - size, (float)centerPOS.Y + size), new Vector2((float)centerPOS.X, (float)centerPOS.Y - size), Colors.DeepSkyBlue, 2);        //lateral esq
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X + size, (float)centerPOS.Y + size), new Vector2((float)centerPOS.X, (float)centerPOS.Y - size), Colors.DeepSkyBlue, 2);        //lateral dir
                                }
                                else if (s.type == 3)
                                {
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X, (float)centerPOS.Y - size), new Vector2((float)centerPOS.X, (float)centerPOS.Y + size), Colors.Red, 1);               // |
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X - size, (float)centerPOS.Y), new Vector2((float)centerPOS.X + size, (float)centerPOS.Y), Colors.Red, 1);               // -

                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X - size, (float)centerPOS.Y - size), new Vector2((float)centerPOS.X + size, (float)centerPOS.Y + size), Colors.Red, 1); // \
                                    drawingSession.DrawLine(new Vector2((float)centerPOS.X + size, (float)centerPOS.Y - size), new Vector2((float)centerPOS.X - size, (float)centerPOS.Y + size), Colors.Red, 1); // /
                                }
                            }
                        }
                    }
                    #endregion

                    foreach (line l in Lines)
                    {
                        drawingSession.DrawLine(l.x1, l.y1, l.x2, l.y2, Colors.White, 1);
                    }

                    foreach (rect r in Rects)
                    {
                        drawingSession.DrawRectangle(new Rect(new Point(r.x1, r.y1), new Point(r.x2, r.y2)), Colors.White, 1);
                    }

                    foreach (circle c in Circles)
                    {
                        drawingSession.DrawCircle(new Vector2(c.cx1, c.cy1), c.radius, Colors.White, 1);
                    }
                }
            }
        }