コード例 #1
0
 private void Rotation_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
 {
     if (inkCanvas != null)
     {
         InkDrawingAttributes drawingAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes();
         float radians = Utils.DegreesToRadians((float)e.NewValue);
         drawingAttributes.PenTipTransform = Matrix3x2.CreateRotation(radians);
         inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(drawingAttributes);
     }
 }
コード例 #2
0
 private void Rotation_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
 {
     if (inkCanvas != null)
     {
         // Rotation only applies to ink rendering (not pencil).
         float radians = Utils.DegreesToRadians((float)e.NewValue);
         inkAttributes.PenTipTransform = Matrix3x2.CreateRotation(radians);
         inkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(inkAttributes);
     }
 }
コード例 #3
0
        // PickRandomDirection is overriden so we can make the particles always have an initial velocity pointing up.
        protected override Vector2 PickRandomDirection()
        {
            // Point the particles somewhere between 80 and 100 degrees.
            // Tweak this to make the smoke have more or less spread.
            float angle = Utils.RandomBetween(Utils.DegreesToRadians(80), Utils.DegreesToRadians(100));

            // From the unit circle, cosine is the x coordinate and sine is the y coordinate.
            // We're negating y because on the screen increasing y moves down the display.
            return(new Vector2((float)Math.Cos(angle),
                               -(float)Math.Sin(angle)));
        }
コード例 #4
0
        bool IsArcRadiusTooSmall()
        {
            // Get the distance between the arc start/end points.
            Vector2 arc = arcPoints[1] - arcPoints[0];

            // Compensate for any ellipse rotation.
            arc = Vector2.Transform(arc, Matrix3x2.CreateRotation(-Utils.DegreesToRadians(ArcRotation)));

            // Normalize to a unit circle.
            arc /= new Vector2(ArcRadiusX, ArcRadiusY);

            // If the length is greater than 2, there is no possible way to fit an arc of
            // the specified radius between the specified endpoints. D2D will compensate
            // by scaling up the radius, but the result may not be what was intended.
            return(arc.Length() > 2);
        }
コード例 #5
0
        void Canvas_Draw(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            var centerPoint = (arcPoints[0] + arcPoints[1]) / 2;

            // Draw the end point markers.
            if (!ThumbnailGenerator.IsDrawingThumbnail)
            {
                for (int i = 0; i < 2; i++)
                {
                    ds.DrawCircle(arcPoints[i], hitTestRadius, (i == activeDrag) ? Colors.White : Colors.Gray);
                }
            }

            switch (CurrentOverload)
            {
            case AddArcOverload.AroundEllipse:
                // Compute positions.
                var ellipseRadius = (arcPoints[1] - arcPoints[0]) / 2;

                ellipseRadius.X = Math.Abs(ellipseRadius.X);
                ellipseRadius.Y = Math.Abs(ellipseRadius.Y);

                float startAngle = Utils.DegreesToRadians(ArcStartAngle);
                float sweepAngle = Utils.DegreesToRadians(ArcSweepAngle);

                var startPoint = centerPoint + Vector2.Transform(Vector2.UnitX, Matrix3x2.CreateRotation(startAngle)) * ellipseRadius;

                // Draw the bounding rectangle.
                if (!ThumbnailGenerator.IsDrawingThumbnail)
                {
                    ds.DrawRectangle(new Rect(arcPoints[0].ToPoint(), arcPoints[1].ToPoint()), Color.FromArgb(255, 64, 64, 64));
                }

                // Draw the arc.
                using (var builder = new CanvasPathBuilder(sender))
                {
                    builder.BeginFigure(startPoint);
                    builder.AddArc(centerPoint, ellipseRadius.X, ellipseRadius.Y, startAngle, sweepAngle);
                    builder.EndFigure(CanvasFigureLoop.Open);

                    using (var geometry = CanvasGeometry.CreatePath(builder))
                    {
                        ds.DrawGeometry(geometry, Colors.Yellow, strokeWidth, strokeStyle);
                    }
                }
                break;

            case AddArcOverload.PointToPoint:
                // Display a warning if this is an invalid arc configuration.
                bool isRadiusTooSmall = IsArcRadiusTooSmall();

                if (isRadiusTooSmall)
                {
                    ds.DrawText("Radius is less than the\ndistance between the\nstart and end points", centerPoint, Colors.Red, textFormat);
                }

                // Draw the arc.
                using (var builder = new CanvasPathBuilder(sender))
                {
                    builder.BeginFigure(arcPoints[0]);
                    builder.AddArc(arcPoints[1], ArcRadiusX, ArcRadiusY, Utils.DegreesToRadians(ArcRotation), ArcSweepDirection, ArcSize);
                    builder.EndFigure(CanvasFigureLoop.Open);

                    using (var geometry = CanvasGeometry.CreatePath(builder))
                    {
                        ds.DrawGeometry(geometry, isRadiusTooSmall ? Colors.Red : Colors.Yellow, strokeWidth, strokeStyle);
                    }
                }
                break;
            }
        }