public static void ApplyRotate(TransformGroup t, Duration duration) { var rotateT = new RotateTransform (); t.Children.Add(rotateT); var storyboard = CreateDPAnimation(rotateT, "Angle", duration, 0, 360, false, false, new BounceEase { Bounces = 2, Bounciness = 5 }); storyboard.Begin(); }
private void ChangeDirections() { RotateTransform rt = new RotateTransform(); rt.CenterX = 0;//-gridView.Margin.Right*2; rt.CenterY = 0;//-gridView.Margin.Bottom*2; switch (UserViewDirection) { case ViewDirection.Up: rt.Angle = 270; image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LightTableRotation1.png")); break; case ViewDirection.Down: rt.Angle = 90; image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LightTableRotation3.png")); break; case ViewDirection.Left: rt.Angle = 180; image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LightTableRotation.png")); break; case ViewDirection.Right: rt.Angle = 0; image.Source = new BitmapImage(new Uri("ms-appx:///Assets/LightTableRotation2.png")); break; } gridView.RenderTransform = rt; }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); _topRotator = GetTemplateChild(TopRotator) as RotateTransform; _botRotator = GetTemplateChild(BotRotator) as RotateTransform; PropertyChangedCallback(); }
public static void ApplyJiggle(TransformGroup t, Duration duration) { var rotateT = new RotateTransform (); t.Children.Add(rotateT); var storyboard = CreateDPAnimation(rotateT, "Angle", duration, 0, 20, false, false, new ElasticEase { Oscillations = 5 }); storyboard.Begin(); }
/// <summary> /// Converts the source data (value) that represents an angle measured in degrees to a RotateTransform /// before passing it to the target of a data binding for display in the UI. /// </summary> /// <param name="value"> /// The source data being passed to the target. /// This represents an angle measured in degrees. /// </param> /// <param name="targetType"> /// The type of data expected by the target dependency property. /// </param> /// <param name="parameter"> /// It will be ignored by this converter. /// </param> /// <param name="language"> /// The culture of the conversion. Ignored by this converter. /// </param> /// <returns> /// Returns a RotateTransform with an angle corresponding to value. /// </returns> public object Convert(object value, Type targetType, object parameter, string language) { double? angle = (double?)value; RotateTransform rotateTransform = new RotateTransform(); rotateTransform.Angle = angle.Value; return rotateTransform; }
// --- Methods of the class --- public VisualIndicator(Canvas canvasToPaintOn, Point topLeftCorner, int width, int height, bool rotateImage) { _topLeftCorner = topLeftCorner; _width = width; _height = height; _visualIndicatorOn = new Image { Source = new BitmapImage(new Uri("ms-appx:/" + ThemeHandler.I.GetCurrentThemesDir() + "/" + KalahaResources.I.GetIndicatorOnFileName())), Width = PSTScreen.I.ToScreenX(_width), Height = PSTScreen.I.ToScreenY(_height), }; // Define the angle of the visual indicator: _visualIndicatorOn.RenderTransformOrigin = new Point(0.5, 0.5); // Rotate around the center RotateTransform myRotateTransformOn = new RotateTransform(); // Put the name upside down if we are told to do so: myRotateTransformOn.Angle = (rotateImage ? 180 : 0); _visualIndicatorOn.RenderTransform = myRotateTransformOn; Canvas.SetLeft(_visualIndicatorOn, PSTScreen.I.ToScreenX(_topLeftCorner.X)); Canvas.SetTop(_visualIndicatorOn, PSTScreen.I.ToScreenY(_topLeftCorner.Y)); Canvas.SetZIndex(_visualIndicatorOn, _zIndexOfVisualIndicator); // Add the image to the canvas: canvasToPaintOn.Children.Add(_visualIndicatorOn); _visualIndicatorOff = new Image { Source = new BitmapImage(new Uri("ms-appx:/" + ThemeHandler.I.GetCurrentThemesDir() + "/" + KalahaResources.I.GetIndicatorOffFileName())), Width = PSTScreen.I.ToScreenX(_width), Height = PSTScreen.I.ToScreenY(_height), }; // Define the angle of the visual indicator: _visualIndicatorOff.RenderTransformOrigin = new Point(0.5, 0.5); // Rotate around the center RotateTransform myRotateTransformOff = new RotateTransform(); // Put the name upside down if we are told to do so: myRotateTransformOff.Angle = (rotateImage ? 180 : 0); _visualIndicatorOff.RenderTransform = myRotateTransformOff; Canvas.SetLeft(_visualIndicatorOff, PSTScreen.I.ToScreenX(_topLeftCorner.X)); Canvas.SetTop(_visualIndicatorOff, PSTScreen.I.ToScreenY(_topLeftCorner.Y)); Canvas.SetZIndex(_visualIndicatorOff, _zIndexOfVisualIndicator); // Add the image to the canvas: canvasToPaintOn.Children.Add(_visualIndicatorOff); // Show the indicator to be switched off initially: SwitchOff(); }
private void RotateEllipse(Ellipse elli, Windows.UI.Input.ManipulationDelta delta) { //check if rotate transform var oldTransform = (elli.RenderTransform as RotateTransform); if (oldTransform == null) { oldTransform = new RotateTransform(); } var angle = oldTransform.Angle; angle += delta.Rotation; var rotateTransform = new RotateTransform(); rotateTransform.Angle = angle; rotateTransform.CenterX = 150; rotateTransform.CenterY = 150; elli.RenderTransform = rotateTransform; }
void MainPage_Loaded(object sender, RoutedEventArgs e) { _compass = Compass.GetDefault(); if (_compass == null) { HelpShow.Show("亲,您的手机不支持指南针!"); return; } uint v = _compass.MinimumReportInterval; uint Interval = 20; _compass.ReportInterval = (Interval <= v) ? v : Interval; _compass.ReadingChanged += _compass_ReadingChanged; rotatTransform = new RotateTransform(); ge.RenderTransform = rotatTransform; }
public TestLineupPage() { this.InitializeComponent(); TransformGroup tg = new TransformGroup(); ScaleTransform st = new ScaleTransform(); tg.Children.Add(st); RotateTransform rt = new RotateTransform(); tg.Children.Add(rt); TranslateTransform tl = new TranslateTransform(); tg.Children.Add(tl); _viewbox.RenderTransform = tg; }
// Show commandbar //or close, depending on current state private void CommandBarClick(object sender, RoutedEventArgs e) { var rt = new RotateTransform(); if (commandBar.Visibility == Visibility.Collapsed) { commandBar.Visibility = Visibility.Visible; rt.Angle = -90; commandBarActivationButton.RenderTransform = rt; } else if(commandBar.Visibility == Visibility.Visible) { commandBar.Visibility = Visibility.Collapsed; rt.Angle = 90; commandBarActivationButton.RenderTransform = rt; } }
protected override Size ArrangeOverride(Size finalSize) { // Clip to ensure items dont override container this.Clip = new RectangleGeometry { Rect = new Rect(0, 0, finalSize.Width, finalSize.Height) }; // Size and position the child elements int i = 0; double degreesOffset = 360.0 / this.Children.Count; foreach (FrameworkElement element in this.Children) { double centerX = element.DesiredSize.Width / 2.0; double centerY = element.DesiredSize.Height / 2.0; // calculate the good angle double degreesAngle = degreesOffset * i++; RotateTransform transform = new RotateTransform(); transform.CenterX = centerX; transform.CenterY = centerY; // must be degrees. It's a shame it's not in radian :) transform.Angle = degreesAngle; element.RenderTransform = transform; // calculate radian angle var radianAngle = (Math.PI*degreesAngle)/180.0; // get x and y double x = this.Radius * Math.Cos(radianAngle); double y = this.Radius * Math.Sin(radianAngle); // get real X and Y (because 0;0 is on top left and not middle of the circle) var rectX = x + (finalSize.Width / 2.0) - centerX; var rectY = y + (finalSize.Height / 2.0) - centerY; // arrange element element.Arrange(new Rect(rectX, rectY, element.DesiredSize.Width, element.DesiredSize.Height)); } return finalSize; }
void MainPage_Loaded(object sender, RoutedEventArgs e) { Duration duration = new Duration(TimeSpan.FromSeconds(100)); Storyboard storyBoard = new Storyboard(); storyBoard.RepeatBehavior = RepeatBehavior.Forever; storyBoard.Duration = duration; DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.Duration = duration; storyBoard.Children.Add(doubleAnimation); RotateTransform rotateTransform = new RotateTransform(); Storyboard.SetTarget(doubleAnimation, rotateTransform); Storyboard.SetTargetProperty(doubleAnimation, "Angle"); doubleAnimation.To = 360; LogoImage.RenderTransform = rotateTransform; storyBoard.Begin(); }
public static void PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { int half = 30; int arc = 5; if (e.OldValue == null) { return; } FrameworkElement fe = d as FrameworkElement; fe.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotate = fe.RenderTransform as RotateTransform; if (rotate == null) { rotate = new RotateTransform(); rotate.CenterX = 0.5; rotate.CenterY = 0.5; fe.RenderTransform = rotate; } DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames(); da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0)), Value = 0 }); da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half)), Value = arc }); da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half * 3)), Value = -arc }); da.KeyFrames.Add(new EasingDoubleKeyFrame() { KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(half * 4)), Value = 0 }); Storyboard sb = new Storyboard(); Storyboard.SetTarget(da, rotate); Storyboard.SetTargetProperty(da, "Angle"); sb.Children.Add(da); sb.Begin(); }
// Sets the render transform of the indicator private void SetIndicatorTransforms() { if (RenderTransform is MatrixTransform) { TransformGroup tg = new TransformGroup(); TranslateTransform tt = new TranslateTransform(); RotateTransform rt = new RotateTransform(); tg.Children.Add(rt); tg.Children.Add(tt); this.RenderTransformOrigin = new Point(0.5, 0.5); this.RenderTransform = tg; } }
// Create the Ellipse, the TextBox, and display it on the Canvas. private void createShapes(string display, Point p, Canvas c) { // Create the Ellipse around the point // Set the point to the passed in point. // The width and the height will be the radius size (thus a Circle) // Create a default color - CornflowerBlue // Add the Ellipse to the Canvas e = new Ellipse(); e.Width = size; e.Height = size; e.Margin = new Thickness(p.X, p.Y, 0,0); e.Stroke = new SolidColorBrush(Colors.Black); e.Fill = new SolidColorBrush(Colors.CornflowerBlue); e.StrokeThickness = 3.0; c.Children.Add(e); // Create a TextBox inside the Ellipse // The text should display either a number or a character text = new TextBlock(); text.Text = display; // If the length of the text is greater than one, I need to move // the location of the TextBlock inside the Ellipse to the left some. // If the text should be rotated, I need to move it up instead. if (text.Text.Length > 1) { // The top left corner of the TextBlock should actually be above and to the // right of the center of the ellipse because we want to rotate the text. if (rotate) text.Margin = new Thickness(p.X + size / 3 + size / 2, p.Y + size / 4 - 5, 0, 0); // Correction factor - must add another size/2 to account for rotation else text.Margin = new Thickness(p.X + size / 3, p.Y + size / 4 - 5, 0, 0); } else { if (rotate) text.Margin = new Thickness(p.X + size / 3 + size / 2, p.Y + size / 4, 0, 0); // Correction factor - must add another size/2 to account for rotation else text.Margin = new Thickness(p.X + size / 3, p.Y + size / 4, 0, 0); } // Set the font size, width, and height of the TextBlock text.FontSize = 30; text.Width = size; text.Height = size; text.HorizontalAlignment = HorizontalAlignment.Right; if (rotate) { // Rotate the text 90 degree RotateTransform r = new RotateTransform(); r.Angle = 90.0; text.RenderTransform = r; } // Do not allow the user to hit the text and have anything happen. text.IsHitTestVisible = false; // Add the text to the Canvas. c.Children.Add(text); }
private void drawTickBar() { _verticalTick.Children.Clear(); int verTickCount = 10; double verTickLength = _roundAreaLength / 8; double verTickHeight = _roundAreaLength * 0.33 / verTickCount; for (int i = 0; i < verTickCount; ++i) { Rectangle r = new Rectangle(); r.Fill = Stroke; r.Width = verTickLength; r.Height = verTickHeight; r.RadiusX = r.Width / 5; r.RadiusY = r.Height / 5; double x = (ActualWidth-(1- Math.Sqrt(2) / 4) * _roundAreaLength) + i * verTickHeight * 2; double y = (1 - Math.Sqrt(2) / 4) * _roundAreaLength - i * verTickHeight * 2+_roundAreaBaseY; r.Margin = new Thickness(x- verTickLength / 2, y-verTickHeight/2, x+ verTickLength / 2, y+verTickHeight/2); RotateTransform rotate = new RotateTransform(); rotate.Angle = 45; r.RenderTransform = rotate; _verticalTick.Children.Add(r); } _slideCenter = new Point(ActualWidth - _roundAreaLength, _roundAreaLength + _roundAreaBaseY); if (RudderBtnSliderRadius == 0) RudderBtnSliderRadius = Math.Sqrt(2) * _roundAreaLength / 2; double horTickLength = verTickLength; double horTickHeight = verTickHeight; int horTickCount = 8; for (int i = 0; i < horTickCount; i++) { double angle = Math.PI / 2 * i / horTickCount+5*DEG2RAD; Rectangle r = new Rectangle(); r.Fill = Stroke; r.Width = horTickLength; r.Height = horTickHeight; r.RadiusX = r.Width / 5; r.RadiusY = r.Height / 5; double x = _slideCenter.X+Math.Sin(angle)*RudderBtnSliderRadius; double y = _slideCenter.Y-Math.Cos(angle)*RudderBtnSliderRadius; r.Margin = new Thickness(x+r.Width/2, y - r.Height/2,0,0); RotateTransform rotate = new RotateTransform(); rotate.Angle = angle*RAD2DEG+90; r.RenderTransform = rotate; _arcTick.Children.Add(r); } }
private void populateNodes(char kind, List<TrailNode> nodes) { #region TrailsA if (kind == 'A') { nodes.Add(new TrailNode(1, new Point(485, 503), MyCanvas, passer.trailsVertical)); TextBlock begin = new TextBlock() { Text = "Begin", Margin = new Thickness(485, 473, 0, 0), Foreground = new SolidColorBrush(Colors.Black), FontSize = 25 }; RotateTransform r = new RotateTransform(); r.Angle = 90; if (passer.trailsVertical) { begin.Margin = new Thickness(575, 503, 0, 0); begin.RenderTransform = r; } MyCanvas.Children.Add(begin); nodes.Add(new TrailNode(2, new Point(375, 341), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(3, new Point(277, 549), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(4, new Point(693, 547), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(5, new Point(677, 287), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(6, new Point(589, 423), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(7, new Point(495, 273), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(8, new Point(301, 151), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(9, new Point(111, 187), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(10, new Point(343, 251), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(11, new Point(81, 447), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(12, new Point(47, 65), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(13, new Point(593, 151), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(14, new Point(455, 61), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(15, new Point(1085, 55), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(16, new Point(861, 157), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(17, new Point(1089, 383), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(18, new Point(813, 343), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(19, new Point(955, 581), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(20, new Point(967, 455), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(21, new Point(1087, 673), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(22, new Point(697, 675), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(23, new Point(47, 685), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(24, new Point(503, 603), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(25, new Point(79, 573), MyCanvas, passer.trailsVertical)); TextBlock end = new TextBlock() { Text = "End", Margin = new Thickness(79, 543, 0, 0), Foreground = new SolidColorBrush(Colors.Black), FontSize = 25 }; if (passer.trailsVertical) { end.RenderTransform = r; end.Margin = new Thickness(169, 573, 0, 0); } MyCanvas.Children.Add(end); } #endregion #region TrailsB else if (kind == 'B') { nodes.Add(new TrailNode(1, new Point(607, 369), MyCanvas, passer.trailsVertical)); TextBlock begin = new TextBlock() { Text = "Begin", Margin = new Thickness(607, 339, 0, 0), Foreground = new SolidColorBrush(Colors.Black), FontSize = 25 }; RotateTransform r = new RotateTransform(); r.Angle = 90; if (passer.trailsVertical) { begin.Margin = new Thickness(697, 369, 0, 0); begin.RenderTransform = r; } MyCanvas.Children.Add(begin); nodes.Add(new TrailNode('A', new Point(333, 509), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(2, new Point(251, 195), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('B', new Point(859, 317), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(3, new Point(717, 331), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('C', new Point(501, 491), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(4, new Point(881, 401), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('D', new Point(905, 587), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(5, new Point(571, 575), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('E', new Point(181, 571), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(6, new Point(243, 317), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('F', new Point(153, 137), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(7, new Point(625, 223), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('G', new Point(419, 135), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(8, new Point(917, 109), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('H', new Point(547, 149), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(9, new Point(919, 231), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('I', new Point(927, 479), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(10, new Point(1059, 661), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('J', new Point(325, 607), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(11, new Point(63, 649), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('K', new Point(65, 69), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(12, new Point(459, 69), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode('L', new Point(219, 101), MyCanvas, passer.trailsVertical)); nodes.Add(new TrailNode(13, new Point(1057, 63), MyCanvas, passer.trailsVertical)); TextBlock end = new TextBlock() { Text = "End", Margin = new Thickness(nodes[nodes.Count - 1].getLocation().X + 10, nodes[nodes.Count - 1].getLocation().Y - 30, 0, 0), Foreground = new SolidColorBrush(Colors.Black), FontSize = 25 }; if (passer.trailsVertical) { end.Margin = new Thickness(nodes[nodes.Count - 1].getLocation().X + 80, nodes[nodes.Count - 1].getLocation().Y, 0, 0); end.RenderTransform = r; } MyCanvas.Children.Add(end); } #endregion }
private void DivideGrid(int countGamers) { try { double angle = 360.0 / countGamers; double transformAngleLine = -90; double transformAngleNumber = 0; for (int i = 0; i < countGamers; i++) { Line myLine = new Line(); transformAngleLine += angle; transformAngleNumber = transformAngleLine - angle / 2; string nameLine = "myLine" + i.ToString(); myLine.Stroke = new SolidColorBrush(colorLine); myLine.X1 = LayoutRoot.ActualWidth / 2; myLine.X2 = LayoutRoot.ActualWidth; myLine.Y1 = LayoutRoot.ActualHeight / 2; myLine.Y2 = LayoutRoot.ActualHeight / 2; myLine.StrokeThickness = 3; myLine.SetValue(Grid.RowProperty, 0); myLine.SetValue(Grid.RowSpanProperty, 2); myLine.Name = nameLine; RotateTransform MyTransform = new RotateTransform(); myLine.RenderTransform = MyTransform; myLine.RenderTransformOrigin = new Point(0.5, 0.5); MyTransform.Angle = transformAngleLine; LayoutRoot.Children.Add(myLine); TextBlock numberGamer = new TextBlock(); numberGamer.Name = "number" + i.ToString(); numberGamer.Text = (i + 1).ToString(); numberGamer.HorizontalAlignment = HorizontalAlignment.Center; numberGamer.VerticalAlignment = VerticalAlignment.Center; numberGamer.FontSize = GridNumberGamer.ActualHeight * 80 / 100; numberGamer.TextWrapping = TextWrapping.NoWrap; numberGamer.FontFamily = new FontFamily("Comic Sans MS"); Border b = new Border(); Border b2 = new Border(); b.BorderThickness = b2.BorderThickness = new Thickness(3); b.CornerRadius = b2.CornerRadius = new CornerRadius(20); b.BorderBrush = b2.BorderBrush = new SolidColorBrush(colorLine); b.Child = numberGamer; b.Height = b.Width = b2.Height = b2.Width = GridNumberGamer.ActualHeight; if (GridNumberGamer.ActualHeight > GridNumberGamer.ColumnDefinitions[1].ActualWidth) { b.Margin = b2.Margin = new Thickness(0, 0, -GridNumberGamer.ActualHeight + GridNumberGamer.ColumnDefinitions[1].ActualWidth, 0); } b2.Background = new SolidColorBrush(Colors.Black); b2.Opacity = 0.4; var radius = LayoutRoot.ActualHeight / 2 * 84 / 100; var y0 = LayoutRoot.ActualHeight / 2 * 84 / 100; var х1 = (Math.Cos(Math.PI * transformAngleNumber / 180) * radius); var у1 = y0 + (Math.Sin(Math.PI * transformAngleNumber / 180) * radius); MatrixTransform matrixTransform = new MatrixTransform(); b.RenderTransform = b2.RenderTransform = matrixTransform; matrixTransform.Matrix = new Matrix(1, 0, 0, 1, х1, у1); b2.SetValue(Grid.ColumnProperty, 1); b.SetValue(Grid.ColumnProperty, 1); GridNumberGamer.Children.Add(b2); GridNumberGamer.Children.Add(b); backButton.Height = GridNumberGamer.ActualHeight; } BottleImage = new Image(); BottleImage.Name = "bottleImage"; BottleImage.Source = new BitmapImage(new Uri(bottleRepository.GetBottle(numberBottle).Path, UriKind.RelativeOrAbsolute)); BottleImage.RenderTransformOrigin = new Point(0.5, 0.5); RotateTransform rotateBottle = new RotateTransform(); rotateBottle.Angle = 10; BottleImage.RenderTransform = rotateBottle; BottleImage.SetValue(Grid.RowProperty, 0); BottleImage.SetValue(Grid.RowSpanProperty, 2); BottleImage.Tapped += bottleImage_Start; BottleImage.PointerPressed += bottleImage_PointerPressed; BottleImage.Height = GridBottle.ActualHeight; BottleImage.HorizontalAlignment = HorizontalAlignment.Center; BottleImage.VerticalAlignment = VerticalAlignment.Center; LayoutRoot.Children.Add(BottleImage); } catch (Exception ex) { var a = ex.Message; } }
private void rotate(double degrees) { Storyboard MyStory = new Storyboard(); MyStory.Duration = TimeSpan.FromMilliseconds(degrees); DoubleAnimation My_Double = new DoubleAnimation(); My_Double.To = degrees; My_Double.Duration = TimeSpan.FromMilliseconds(degrees); MyStory.Children.Add(My_Double); RotateTransform MyTransform = new RotateTransform(); Storyboard.SetTarget(My_Double, MyTransform); Storyboard.SetTargetProperty(My_Double, "Angle"); BottleImage.RenderTransform = MyTransform; BottleImage.RenderTransformOrigin = new Point(0.5, 0.5); mediaElement.Play(); MyStory.Begin(); GridLabelCurrentGamer.Visibility = Visibility.Collapsed; MyStory.Completed += animationRotateBottle_Completed; }
public ElementAdapter(FrameworkElement el) { element_ = el; /** * copy default property */ if(!double.IsNaN(Element.Width)){ Width = Element.Width; } if (!double.IsNaN(Element.Height)) { Height = Element.Height; } X = Canvas.GetLeft(Element); Y = Canvas.GetTop(Element); Alpha = Element.Opacity; /** * Transform */ ScaleTransform myScaleTransform = new ScaleTransform(); myScaleTransform.ScaleX = 1.0; myScaleTransform.ScaleY = 1.0; RotateTransform myRotateTransform = new RotateTransform(); myRotateTransform.Angle = 0; TranslateTransform myTranslate = new TranslateTransform(); myTranslate.X = 0; myTranslate.X = 0; SkewTransform mySkew = new SkewTransform(); mySkew.AngleX = 0; mySkew.AngleY = 0; transformGroup_ = new TransformGroup(); transformGroup_.Children.Add(myScaleTransform); transformGroup_.Children.Add(myRotateTransform); transformGroup_.Children.Add(myTranslate); transformGroup_.Children.Add(mySkew); element_.RenderTransform = transformGroup_; }
private TransformGroup TransformGroup(double Angle, double X, double Y) { TransformGroup transformGroup = new TransformGroup(); TranslateTransform firstTranslate = new TranslateTransform(); firstTranslate.X = X; firstTranslate.Y = Y; transformGroup.Children.Add(firstTranslate); RotateTransform rotateTransform = new RotateTransform(); rotateTransform.Angle = Angle; transformGroup.Children.Add(rotateTransform); TranslateTransform secondTranslate = new TranslateTransform(); secondTranslate.X = diameter / 2; secondTranslate.Y = diameter / 2; transformGroup.Children.Add(secondTranslate); return transformGroup; }
//! @brief sets up the rotation transform private void SetupRotation() { m_rotation = new RotateTransform(); m_calibrateRotationRoot.RenderTransform = m_rotation; m_rotation.CenterX = m_calibrateRotationRoot.ActualWidth / 2; m_rotation.CenterY = m_calibrateRotationRoot.ActualHeight / 2; }
/// <summary> /// rotates the Image object defined in xaml. /// visual shortcut to avoid calling Rotate(MemoryStream stream), a time costly method /// </summary> public void rotatePreviewImage() { var ScreenHeight = Window.Current.Bounds.Height; var ScreenWidth = Window.Current.Bounds.Width; RotateTransform rotate = new RotateTransform(); double rotation = 0; if (currentRotation.Equals(VideoRotation.Clockwise90Degrees)) { rotation = 90; } else if (currentRotation.Equals(VideoRotation.Clockwise180Degrees)) { rotation = 180; } else if (currentRotation.Equals(VideoRotation.Clockwise270Degrees)) { rotation = 270; } else { rotation = 0; } rotate.Angle = rotation; imagePreview.RenderTransformOrigin = new Point(.5, .5); imagePreview.RenderTransform = rotate; }
/// <summary> /// Uses the current device orientation in space and page orientation on the screen to calculate the rotation /// transformation to apply to the controls /// </summary> private void UpdateButtonOrientation() { // Rotate the buttons in the UI to match the rotation of the device var angle = CameraRotationHelper.ConvertSimpleOrientationToClockwiseDegrees(_rotationHelper.GetUIOrientation()); var transform = new RotateTransform { Angle = angle }; // The RenderTransform is safe to use (i.e. it won't cause layout issues) in this case, because these buttons have a 1:1 aspect ratio PhotoButton.RenderTransform = transform; VideoButton.RenderTransform = transform; }
/// <summary> /// Rotate the UI arrow image to point up, adjusting for the accelerometer and screen rotation. /// </summary> private void UpdateArrowForRotation() { double screenRotation = 0; // Adjust the UI steering angle to account for screen rotation. switch (DisplayInformation.GetForCurrentView().CurrentOrientation) { case DisplayOrientations.Landscape: screenRotation = 0; break; case DisplayOrientations.Portrait: screenRotation = 270; break; case DisplayOrientations.LandscapeFlipped: screenRotation = 180; break; case DisplayOrientations.PortraitFlipped: screenRotation = 90; break; default: screenRotation = 0; break; } double steeringAngle = m_rotationAngle - screenRotation; // Ensure the steering angle is positive. if (steeringAngle < 0) { steeringAngle += 360; } // Update the UI based on steering action. RotateTransform transform = new RotateTransform(); transform.Angle = steeringAngle; transform.CenterX = scenario1Image.ActualWidth / 2; transform.CenterY = scenario1Image.ActualHeight / 2; scenario1Image.RenderTransform = transform; }
private void ArrangeExpandElement(int idx, UIElement element, double panelCenterX, double panelCenterY, double elementCenterX, double elementCenterY, double destX, double destY) { element.Arrange(new Rect(panelCenterX, panelCenterY, element.DesiredSize.Width, element.DesiredSize.Height)); var transGroup = element.RenderTransform as TransformGroup; Transform translateTransform, rotateTransform; if (transGroup == null) { element.RenderTransform = transGroup = new TransformGroup(); translateTransform = new TranslateTransform(); rotateTransform = new RotateTransform() { CenterX = elementCenterX, CenterY = elementCenterY }; transGroup.Children.Add(translateTransform); transGroup.Children.Add(rotateTransform); } else { translateTransform = transGroup.Children[0] as TranslateTransform; rotateTransform = transGroup.Children[1] as RotateTransform; } element.RenderTransformOrigin = new Point(0.5, 0.5); //if (i != 0) continue; var aniDuration = AnimationDuration + TimeSpan.FromSeconds(AnimationDurationStep * idx); var storySpin = new Storyboard(); var translateXAnimation = new DoubleAnimation() { From = 0, To = destX - panelCenterX, Duration = aniDuration }; var translateYAnimation = new DoubleAnimation() { From = 0, To = destY - panelCenterY, Duration = aniDuration }; var transparentAnimation = new DoubleAnimation() { From = 0, To = 1, Duration = aniDuration }; var rotateXAnimation = new DoubleAnimation() { From = 0, To = destX - panelCenterX, Duration = aniDuration }; var rotateYAnimation = new DoubleAnimation() { From = 0, To = destY - panelCenterY, Duration = aniDuration }; var rotateAngleAnimation = new DoubleAnimation() { From = 0, To = 720, Duration = aniDuration }; storySpin.Children.Add(translateXAnimation); storySpin.Children.Add(translateYAnimation); storySpin.Children.Add(transparentAnimation); storySpin.Children.Add(rotateXAnimation); storySpin.Children.Add(rotateYAnimation); storySpin.Children.Add(rotateAngleAnimation); Storyboard.SetTargetProperty(translateXAnimation, "(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)"); Storyboard.SetTargetProperty(translateYAnimation, "(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)"); Storyboard.SetTargetProperty(transparentAnimation, "UIElement.Opacity"); Storyboard.SetTargetProperty(rotateXAnimation, "(UIElement.RenderTransform).(TransformGroup.Children)[1].(RotateTransform.CenterX)"); Storyboard.SetTargetProperty(rotateYAnimation, "(UIElement.RenderTransform).(TransformGroup.Children)[1].(RotateTransform.CenterY)"); Storyboard.SetTargetProperty(rotateAngleAnimation, "(UIElement.RenderTransform).(TransformGroup.Children)[1].(RotateTransform.Angle)"); Storyboard.SetTarget(translateXAnimation, element); Storyboard.SetTarget(translateYAnimation, element); Storyboard.SetTarget(transparentAnimation, element); Storyboard.SetTarget(rotateXAnimation, element); Storyboard.SetTarget(rotateYAnimation, element); Storyboard.SetTarget(rotateAngleAnimation, element); storySpin.Begin(); }
protected override Size ArrangeOverride(Size finalSize) { foreach (UIElement child in Children) { double x = 0; double y = 0; double angle = 0.0; var pos = GetPosition(child); if(!double.IsNaN(pos.X) && !double.IsNaN(pos.Y)) { x = pos.X; y = pos.Y; } else { var posx = (double)child.GetValue(XPositionProperty); if (!double.IsNaN(posx)) x = posx; var posy = (double)child.GetValue(YPositionProperty); if (!double.IsNaN(posy)) y = posy; } var a = GetAngle(child); if (!double.IsNaN(a)) angle = a; var t = new RotateTransform(); t.Angle = angle;t.CenterX = 50.0; t.CenterY = 70.0; child.RenderTransform = t; child.Arrange(new Rect(new Point(x, y), child.DesiredSize)); } return finalSize; // Returns the final Arranged size }
/// <summary> /// Uses the current display orientation to calculate the rotation transformation to apply to the face detection bounding box canvas /// and mirrors it if the preview is being mirrored /// </summary> private void SetFacesCanvasRotation() { // Calculate how much to rotate the canvas int rotationDegrees = ConvertDisplayOrientationToDegrees(_displayOrientation); // The rotation direction needs to be inverted if the preview is being mirrored, just like in SetPreviewRotationAsync if (_mirroringPreview) { rotationDegrees = (360 - rotationDegrees) % 360; } // Apply the rotation var transform = new RotateTransform { Angle = rotationDegrees }; FacesCanvas.RenderTransform = transform; var previewArea = GetPreviewStreamRectInControl(_previewProperties as VideoEncodingProperties, PreviewControl); // For portrait mode orientations, swap the width and height of the canvas after the rotation, so the control continues to overlap the preview if (_displayOrientation == DisplayOrientations.Portrait || _displayOrientation == DisplayOrientations.PortraitFlipped) { FacesCanvas.Width = previewArea.Height; FacesCanvas.Height = previewArea.Width; // The position of the canvas also needs to be adjusted, as the size adjustment affects the centering of the control Canvas.SetLeft(FacesCanvas, previewArea.X - (previewArea.Height - previewArea.Width) / 2); Canvas.SetTop(FacesCanvas, previewArea.Y - (previewArea.Width - previewArea.Height) / 2); } else { FacesCanvas.Width = previewArea.Width; FacesCanvas.Height = previewArea.Height; Canvas.SetLeft(FacesCanvas, previewArea.X); Canvas.SetTop(FacesCanvas, previewArea.Y); } // Also mirror the canvas if the preview is being mirrored FacesCanvas.FlowDirection = _mirroringPreview ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; }
/// <summary> /// Uses the current device orientation in space and page orientation on the screen to calculate the rotation /// transformation to apply to the controls /// </summary> private void UpdateButtonOrientation() { int device = ConvertDeviceOrientationToDegrees(_deviceOrientation); int display = ConvertDisplayOrientationToDegrees(_displayOrientation); if (_displayInformation.NativeOrientation == DisplayOrientations.Portrait) { device -= 90; } // Combine both rotations and make sure that 0 <= result < 360 var angle = (360 + display + device) % 360; // Rotate the buttons in the UI to match the rotation of the device var transform = new RotateTransform { Angle = angle }; // The RenderTransform is safe to use (i.e. it won't cause layout issues) in this case, because these buttons have a 1:1 aspect ratio PhotoButton.RenderTransform = transform; VideoButton.RenderTransform = transform; }
/// <summary> /// Uses the current device orientation in space and page orientation on the screen to calculate the rotation /// transformation to apply to the controls /// </summary> private void UpdateControlOrientation() { int device = ConvertDeviceOrientationToDegrees(_deviceOrientation); int display = ConvertDisplayOrientationToDegrees(_displayOrientation); if (_displayInformation.NativeOrientation == DisplayOrientations.Portrait) { device -= 90; } // Combine both rotations and make sure that 0 <= result < 360 var angle = (360 + display + device) % 360; // Rotate the buttons in the UI to match the rotation of the device var transform = new RotateTransform { Angle = angle }; // The RenderTransform is safe to use (i.e. it won't cause layout issues) in this case, because these buttons have a 1:1 aspect ratio PhotoButton.RenderTransform = transform; HdrToggleButton.RenderTransform = transform; // Adjust which way the progress bar fills so it's always from the user's left->right or bottom->top HdrImpactBar.FlowDirection = (angle == 180 || angle == 270) ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; }