Beispiel #1
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(TransformOperation.Identity);
            }
            var r = TransformOperations.Parse(value.ToString());

            return(r);
        }
        public void Can_Parse_Rotation(string data, double angleDeg)
        {
            var transform = TransformOperations.Parse(data);

            var operations = transform.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Rotate, operations[0].Type);
            Assert.Equal(MathUtilities.Deg2Rad(angleDeg), operations[0].Data.Rotate.Angle, 4);
        }
        public void Can_Parse_Skew(string data, double x, double y)
        {
            var transform = TransformOperations.Parse(data);

            var operations = transform.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Skew, operations[0].Type);
            Assert.Equal(MathUtilities.Deg2Rad(x), operations[0].Data.Skew.X, 4);
            Assert.Equal(MathUtilities.Deg2Rad(y), operations[0].Data.Skew.Y, 4);
        }
        public void Can_Parse_Scale(string data, double x, double y)
        {
            var transform = TransformOperations.Parse(data);

            var operations = transform.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Scale, operations[0].Type);
            Assert.Equal(x, operations[0].Data.Scale.X);
            Assert.Equal(y, operations[0].Data.Scale.Y);
        }
        public void Can_Interpolate_Rotation(double progress, double angle)
        {
            var from = TransformOperations.Parse("rotate(10deg)");
            var to   = TransformOperations.Parse("rotate(20deg)");

            var interpolated = TransformOperations.Interpolate(from, to, progress);

            var operations = interpolated.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Rotate, operations[0].Type);
            Assert.Equal(MathUtilities.Deg2Rad(angle), operations[0].Data.Rotate.Angle);
        }
        public void Interpolation_Fallback_To_Matrix()
        {
            double progress = 0.5d;

            var from = TransformOperations.Parse("rotate(45deg)");
            var to   = TransformOperations.Parse("translate(100px, 100px) rotate(1215deg)");

            var interpolated = TransformOperations.Interpolate(from, to, progress);

            var operations = interpolated.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Matrix, operations[0].Type);
        }
        public void Can_Interpolate_Skew(double progress, double x, double y)
        {
            var from = TransformOperations.Parse("skewX(10deg)");
            var to   = TransformOperations.Parse("skewY(20deg)");

            var interpolated = TransformOperations.Interpolate(from, to, progress);

            var operations = interpolated.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Skew, operations[0].Type);
            Assert.Equal(MathUtilities.Deg2Rad(x), operations[0].Data.Skew.X);
            Assert.Equal(MathUtilities.Deg2Rad(y), operations[0].Data.Skew.Y);
        }
        public void Can_Interpolate_Scale(double progress, double x, double y)
        {
            var from = TransformOperations.Parse("scaleX(10)");
            var to   = TransformOperations.Parse("scaleY(20)");

            var interpolated = TransformOperations.Interpolate(from, to, progress);

            var operations = interpolated.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Scale, operations[0].Type);
            Assert.Equal(x, operations[0].Data.Scale.X);
            Assert.Equal(y, operations[0].Data.Scale.Y);
        }
        public void Can_Parse_Matrix_Operation()
        {
            var data = "matrix(1,2,3,4,5,6)";

            var transform = TransformOperations.Parse(data);

            var operations = transform.Operations;

            Assert.Single(operations);
            Assert.Equal(TransformOperation.OperationType.Matrix, operations[0].Type);

            var expectedMatrix = new Matrix(1, 2, 3, 4, 5, 6);

            Assert.Equal(expectedMatrix, operations[0].Matrix);
        }
        public void Order_Of_Operations_Is_Preserved_One_Prefix()
        {
            var from = TransformOperations.Parse("scale(1)");
            var to   = TransformOperations.Parse("scale(0.5,0.5) translate(50px,50px)");

            var interpolated_0 = TransformOperations.Interpolate(from, to, 0);

            Assert.True(interpolated_0.IsIdentity);

            var interpolated_50 = TransformOperations.Interpolate(from, to, 0.5);

            AssertMatrix(interpolated_50.Value, scaleX: 0.75, scaleY: 0.75, translateX: 25.0, translateY: 25);

            var interpolated_100 = TransformOperations.Interpolate(from, to, 1);

            AssertMatrix(interpolated_100.Value, scaleX: 0.5, scaleY: 0.5, translateX: 50, translateY: 50);
        }
        public void Can_Parse_Compound_Operations()
        {
            var data = "scale(1,2) translate(3px,4px) rotate(5deg) skew(6deg,7deg)";

            var transform = TransformOperations.Parse(data);

            var operations = transform.Operations;

            Assert.Equal(TransformOperation.OperationType.Scale, operations[0].Type);
            Assert.Equal(1, operations[0].Data.Scale.X);
            Assert.Equal(2, operations[0].Data.Scale.Y);

            Assert.Equal(TransformOperation.OperationType.Translate, operations[1].Type);
            Assert.Equal(3, operations[1].Data.Translate.X);
            Assert.Equal(4, operations[1].Data.Translate.Y);

            Assert.Equal(TransformOperation.OperationType.Rotate, operations[2].Type);
            Assert.Equal(MathUtilities.Deg2Rad(5), operations[2].Data.Rotate.Angle);

            Assert.Equal(TransformOperation.OperationType.Skew, operations[3].Type);
            Assert.Equal(MathUtilities.Deg2Rad(6), operations[3].Data.Skew.X);
            Assert.Equal(MathUtilities.Deg2Rad(7), operations[3].Data.Skew.Y);
        }
Beispiel #12
0
 public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
 {
     return(TransformOperations.Parse((string)value));
 }
Beispiel #13
0
        private void SetStyles()
        {
            Style arrowColor = new Style(x => x.OfType <ToggleButton>().Class("ContentButton").Child().OfType <Grid>().Child().OfType <Canvas>().Class("ArrowCanvas").Child().OfType <Path>());

            arrowColor.Setters.Add(new Setter(Path.FillProperty, Application.Current.FindResource("ThemeForegroundBrush")));
            this.Styles.Add(arrowColor);

            Style arrowColorPressed = new Style(x => x.OfType <ToggleButton>().Class("ContentButton").Class(":pressed").Child().OfType <Grid>().Child().OfType <Canvas>().Class("ArrowCanvas").Child().OfType <Path>());

            arrowColorPressed.Setters.Add(new Setter(Path.FillProperty, Application.Current.FindResource("ThemeControlHighlightLowBrush")));
            this.Styles.Add(arrowColorPressed);

            Style arrowColorActive = new Style(x => x.OfType <ToggleButton>().Class("ContentButton").Class(":checked").Child().OfType <Grid>().Child().OfType <Canvas>().Class("ArrowCanvas").Child().OfType <Path>());

            arrowColorActive.Setters.Add(new Setter(Path.FillProperty, Application.Current.FindResource("ThemeControlHighlightLowBrush")));
            this.Styles.Add(arrowColorActive);

            Style canvasRotationActive = new Style(x => x.OfType <ToggleButton>().Class("ContentButton").Class(":checked").Child().OfType <Grid>().Child().OfType <Canvas>().Class("ArrowCanvas"));

            canvasRotationActive.Setters.Add(new Setter(Canvas.RenderTransformProperty, new RotateTransform(180)));
            this.Styles.Add(canvasRotationActive);

            if (!ColorPicker.TransitionsDisabled)
            {
                Transitions transformTransitions = new Transitions
                {
                    new TransformOperationsTransition()
                    {
                        Property = Path.RenderTransformProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };

                Transitions strokeTransitions = new Transitions
                {
                    new DoubleTransition()
                    {
                        Property = Path.StrokeThicknessProperty, Duration = new TimeSpan(0, 0, 0, 0, 100)
                    }
                };

                Style HexagonLeft = new Style(x => x.OfType <Path>().Class("HexagonLeftButton"));
                HexagonLeft.Setters.Add(new Setter(Path.TransitionsProperty, transformTransitions));
                this.Styles.Add(HexagonLeft);

                Style HexagonRight = new Style(x => x.OfType <Path>().Class("HexagonRightButton"));
                HexagonRight.Setters.Add(new Setter(Path.TransitionsProperty, transformTransitions));
                this.Styles.Add(HexagonRight);

                Style HexagonCenter = new Style(x => x.OfType <Path>().Class("HexagonCenterButton"));
                HexagonCenter.Setters.Add(new Setter(Path.StrokeProperty, Application.Current.FindResource("ThemeBackgroundBrush")));
                HexagonCenter.Setters.Add(new Setter(Path.TransitionsProperty, strokeTransitions));
                this.Styles.Add(HexagonCenter);
            }

            Style HexagonLeftOver = new Style(x => x.OfType <Path>().Class("HexagonLeftButton").Class(":pointerover"));

            HexagonLeftOver.Setters.Add(new Setter(Path.RenderTransformProperty, TransformOperations.Parse("translate(-4.33px, 0)")));
            this.Styles.Add(HexagonLeftOver);

            Style HexagonRightOver = new Style(x => x.OfType <Path>().Class("HexagonRightButton").Class(":pointerover"));

            HexagonRightOver.Setters.Add(new Setter(Path.RenderTransformProperty, TransformOperations.Parse("translate(4.33px, 0)")));
            this.Styles.Add(HexagonRightOver);

            Style HexagonCenterOver = new Style(x => x.OfType <Path>().Class("HexagonCenterButton").Class(":pointerover"));

            HexagonCenterOver.Setters.Add(new Setter(Path.StrokeThicknessProperty, 3.0));
            this.Styles.Add(HexagonCenterOver);

            Style rightOverBlurring = new Style(x => x.OfType <Path>().Class("rightOverBlurring"));

            rightOverBlurring.Setters.Add(new Setter(Path.ZIndexProperty, 9));
            this.Styles.Add(rightOverBlurring);

            Style leftOverBlurring = new Style(x => x.OfType <Path>().Class("leftOverBlurring"));

            leftOverBlurring.Setters.Add(new Setter(Path.ZIndexProperty, 9));
            this.Styles.Add(leftOverBlurring);

            Style centerOverBlurring = new Style(x => x.OfType <Path>().Class("centerOverBlurring"));

            centerOverBlurring.Setters.Add(new Setter(Path.ZIndexProperty, 9));
            this.Styles.Add(centerOverBlurring);

            Style rightOver = new Style(x => x.OfType <Path>().Class("rightOver"));

            rightOver.Setters.Add(new Setter(Path.ZIndexProperty, 10));
            this.Styles.Add(rightOver);

            Style leftOver = new Style(x => x.OfType <Path>().Class("leftOver"));

            leftOver.Setters.Add(new Setter(Path.ZIndexProperty, 10));
            this.Styles.Add(leftOver);

            Style centerOver = new Style(x => x.OfType <Path>().Class("centerOver"));

            centerOver.Setters.Add(new Setter(Path.ZIndexProperty, 10));
            this.Styles.Add(centerOver);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var r = TransformOperations.Parse(value.ToString());

            return(r);
        }
Beispiel #15
0
 public override object?ConvertFrom(ITypeDescriptorContext?context, CultureInfo?culture, object?value)
 {
     return(value is string s?TransformOperations.Parse(s) : null);
 }