public Geometry CreateGeometryEx(SvgPathElement element) { PathGeometry geometry = new PathGeometry(); string pathScript = element.PathScript; if (string.IsNullOrWhiteSpace(pathScript)) { return(geometry); } var comparer = StringComparison.OrdinalIgnoreCase; string fillRule = element.GetPropertyValue("fill-rule"); string clipRule = element.GetAttribute("clip-rule"); if (!string.IsNullOrWhiteSpace(clipRule) && string.Equals(clipRule, "evenodd", comparer) || string.Equals(clipRule, CssConstants.ValNonzero, comparer)) { fillRule = clipRule; } if (string.Equals(fillRule, "evenodd", comparer)) { geometry.FillRule = FillRule.EvenOdd; } else if (string.Equals(fillRule, CssConstants.ValNonzero, comparer)) { geometry.FillRule = FillRule.Nonzero; } try { geometry.Figures = PathFigureCollection.Parse(pathScript); if (_flattenClosedPath && element.IsClosed && geometry.MayHaveCurves() == element.MayHaveCurves) { int closedCount = 0; foreach (var figure in geometry.Figures) { if (figure.IsClosed) { closedCount++; } } if (geometry.Figures.Count == closedCount) { return(geometry.GetFlattenedPathGeometry(_flattenTolerance, _flattenToleranceType)); } } return(geometry); } catch (FormatException ex) { Trace.TraceError(ex.GetType().Name + ": " + ex.Message); //return null; return(CreateGeometry(element)); } }
private Boolean DrawContent(int width, int height, int alpha) { try { var path = this.GetTemplateChild(Part_BorderPath) as Path; var pathTriangle = this.GetTemplateChild(PART_TrianglePath) as Path; if (path == null || pathTriangle == null) { return(false); } var figureString = String.Format("M {0},0 H {1} V {3} L {4},{2} H 0 V {0} Z", alpha, width, height, height - alpha, width - alpha); // Zehong: the following line doesn't support Transform //path.Data = PathGeometry.Parse(figureString); path.Data = new PathGeometry() { Figures = PathFigureCollection.Parse(figureString) }; // draw border path.Data.Transform = this._shapeTransform; // draw lower-right triangle var triangleFigures = String.Format("M {0},{5} v {1} l {4},{2} h {3} Z", width, LicenseThickness, alpha, -LicenseThickness, -alpha, height - alpha - LicenseThickness); pathTriangle.Data = new PathGeometry() { Figures = PathFigureCollection.Parse(triangleFigures) }; pathTriangle.Data.Transform = this._shapeTransform; return(true); } catch (Exception) { return(false); } }
public void Visit(ISvgPathElement element) { if (!(element is SvgPathElement pe) || String.IsNullOrEmpty(pe.PathScript)) { return; } var geometry = new PathGeometry(); if (TryGetFillRule(pe, out FillRule fillRule)) { geometry.FillRule = fillRule; } try { geometry.Figures = PathFigureCollection.Parse(pe.PathScript); } catch { return; } var shape = WrapGeometry(geometry, element); DisplayShape(shape, element); }
private static PathFigureCollection CreateOuterPathFigures(double tabWidth) { int length = ((int)tabWidth); string outerPathFormat = "m 0,27 c 0,0 0,0 4,0 4,0 8,-12 8,-12 0,0 4,-12 8,-12 l {0},0 c 4,0 8,12 8,12 0,0 4,12 8,12 4,0 4,0 4,0 z"; return(PathFigureCollection.Parse(string.Format(outerPathFormat, length))); }
private static PathFigureCollection CreateInnerPathFigures(double tabWidth) { int length = ((int)tabWidth); string innerPathFormat = "m 0,27 c 0,0 1,0 5,0 4,0 8,-12 8,-12 0,0 3,-11 7,-11 l {0},0 c 4,0 7,11 7,11 0,0 4,12 8,12 4,0 5,0 5,0 z"; return(PathFigureCollection.Parse(string.Format(innerPathFormat, length))); }
private PathGeometry Build(string text, IList <Rect> textBounds, bool measureSpaces) { if (string.IsNullOrEmpty(text)) { return(new PathGeometry()); } var textPath = new PathGeometry(); SvgGlyphElement prevGlyph = null; double xPos = 0; var ascent = this.Ascent; for (int i = 0; i < text.Length; i++) { if (!_glyphs.TryGetValue(text.Substring(i, 1), out SvgGlyphElement glyph)) { glyph = _missingGlyph; } if (prevGlyph != null && _kerning.TryGetValue(prevGlyph.GlyphName + "|" + glyph.GlyphName, out SvgKernElement kern)) { xPos -= kern.Kerning * _emScale; } PathGeometry glyphPath = new PathGeometry(); glyphPath.Figures = PathFigureCollection.Parse(glyph.D); var groupTransform = new TransformGroup(); groupTransform.Children.Add(new ScaleTransform(_emScale, -1 * _emScale)); groupTransform.Children.Add(new TranslateTransform(xPos, ascent)); glyphPath.Transform = groupTransform; if (textBounds != null) { Rect bounds = glyphPath.Bounds; if (measureSpaces && bounds == Rect.Empty) { textBounds.Add(new Rect(xPos, 0, glyph.HorizAdvX * _emScale, ascent)); } else { textBounds.Add(bounds); } } if (glyphPath.Figures != null && glyphPath.Figures.Count > 0) { textPath.AddGeometry(glyphPath); } xPos += glyph.HorizAdvX * _emScale; prevGlyph = glyph; } return(textPath); }
public Geometry CreateGeometryEx(SvgPathElement element) { PathGeometry geometry = new PathGeometry(); string pathScript = element.PathScript; if (string.IsNullOrWhiteSpace(pathScript)) { return(geometry); } string fillRule = element.GetPropertyValue("fill-rule"); string clipRule = element.GetAttribute("clip-rule"); if (!string.IsNullOrWhiteSpace(clipRule) && string.Equals(clipRule, "evenodd") || string.Equals(clipRule, "nonzero")) { fillRule = clipRule; } if (fillRule == "evenodd") { geometry.FillRule = FillRule.EvenOdd; } else if (fillRule == "nonzero") { geometry.FillRule = FillRule.Nonzero; } try { geometry.Figures = PathFigureCollection.Parse(pathScript); if (_flattenClosedPath && element.IsClosed && geometry.MayHaveCurves() == element.MayHaveCurves) { int closedCount = 0; foreach (var figure in geometry.Figures) { if (figure.IsClosed) { closedCount++; } } if (geometry.Figures.Count == closedCount) { return(geometry.GetFlattenedPathGeometry(_flattenTolerance, _flattenToleranceType)); } } return(geometry); } catch { return(CreateGeometry(element)); } }
/// <summary> /// Converts a string into a PathFigureCollection. /// </summary> public override object ConvertFromString(string value, IValueSerializerContext context) { if (value != null) { return(PathFigureCollection.Parse(value)); } else { return(base.ConvertFromString(value, context)); } }
//========================================================================== public override Geometry GetBaseGeometry() { var pfc = PathFigureCollection.Parse(Data); if (this.Fill == null) { foreach (var pf in pfc) { pf.IsFilled = false; } } var geo = new PathGeometry(pfc); //var geo = SvgGeometryParser.ParseGeometry(Data, this.Fill != null); //var geo = Geometry.Parse(Data).Clone(); return(geo); }
private static PathFigureCollection CreateButtonPathFigures() { return(PathFigureCollection.Parse("m 0,12 -8,8 m 0,-8 8,8")); }
public void AnimatingControl_Loaded() { var imageToLoad = Int32.Parse(Application.Current.Properties["CurrentMovement"].ToString()); if (imageToLoad >= _positionImageList.Count) { MainWindow window = new MainWindow(); window.Show(); Window.GetWindow(this).Close(); return; } _currentImage = _allImages[_positionImageList[imageToLoad]]; switch (_sizeValue) { case 0: //big _currentImage.Source = _currentImage.SourceBig; break; case 1: //mid _currentImage.Source = _currentImage.SourceMid; break; case 2: //small _currentImage.Source = _currentImage.SourceSmall; break; } var bitmap = new BitmapImage(new Uri(_currentImage.Source, UriKind.Relative)); ImageToMove.Source = bitmap; ImageBehavior.SetAnimatedSource(ImageToMove, bitmap); Controller = ImageBehavior.GetAnimationController(ImageToMove); ImageMovement = new Storyboard(); GameWindow = Window.GetWindow(this); var timeToMove = Convert.ToInt32(Application.Current.Properties["Speed"].ToString()); var movementToComplete = Int32.Parse(Application.Current.Properties["CurrentMovement"].ToString()); var currentMovement = _allMovementObjects[_positionList[movementToComplete]]; if (currentMovement.Active) { DoubleAnimation horizontalMovement; DoubleAnimation verticalMovement; double xStart; double yStart; double xEnd; double yEnd; ImageToMove.Width = bitmap.Width; ImageToMove.Height = bitmap.Height; ImageToMove.Visibility = Visibility.Visible; switch (currentMovement.Type) { case MovementType.HorizontalLeftToRight: FaceDirection(true); xStart = 0; xEnd = GameWindow.ActualWidth + ImageToMove.Width; yStart = (GameWindow.ActualHeight - ImageToMove.Height) / 2; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); ImageMovement.Children.Add(horizontalMovement); break; case MovementType.HorizontalRightToLeft: FaceDirection(false); yStart = (GameWindow.ActualHeight - ImageToMove.Height) / 2; xStart = GameWindow.ActualWidth - ImageToMove.Width; xEnd = 0 - ImageToMove.Width - 10; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); ImageMovement.Children.Add(horizontalMovement); break; case MovementType.DiagonalUpLeftToDownRight: FaceDirection(true); xStart = 0; yStart = 0; xEnd = GameWindow.ActualWidth; yEnd = GameWindow.ActualHeight; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(horizontalMovement); ImageMovement.Children.Add(verticalMovement); break; case MovementType.DiagonalDownRightToUpLeft: FaceDirection(false); xStart = GameWindow.ActualWidth - ImageToMove.Width; yStart = GameWindow.ActualHeight - ImageToMove.Height; xEnd = 0 - ImageToMove.Width; yEnd = 0 - ImageToMove.Height; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(horizontalMovement); ImageMovement.Children.Add(verticalMovement); break; case MovementType.VerticalUpToDown: xStart = (GameWindow.ActualWidth - ImageToMove.Width) / 2; yStart = 0; yEnd = GameWindow.ActualHeight; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(verticalMovement); break; case MovementType.VerticalDownToUp: xStart = (GameWindow.ActualWidth - ImageToMove.Width) / 2; yStart = GameWindow.ActualHeight - ImageToMove.Height; yEnd = 0 - ImageToMove.Height; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(verticalMovement); break; case MovementType.DiagonalDownLeftToUpRight: FaceDirection(true); xStart = 0; yStart = GameWindow.ActualHeight - ImageToMove.Height; xEnd = GameWindow.ActualWidth; yEnd = 0 - ImageToMove.Height; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(horizontalMovement); ImageMovement.Children.Add(verticalMovement); break; case MovementType.DiagonalUpRightToDownLeft: FaceDirection(false); xStart = GameWindow.ActualWidth - ImageToMove.Width; yStart = 0; xEnd = 0 - ImageToMove.Width; yEnd = GameWindow.ActualHeight; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); horizontalMovement = new DoubleAnimation(xStart, xEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); verticalMovement = new DoubleAnimation(yStart, yEnd, new Duration(new TimeSpan(0, 0, 0, timeToMove))); Storyboard.SetTarget(horizontalMovement, ImageToMove); Storyboard.SetTarget(verticalMovement, ImageToMove); Storyboard.SetTargetProperty(horizontalMovement, new PropertyPath("(Canvas.Left)")); Storyboard.SetTargetProperty(verticalMovement, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(horizontalMovement); ImageMovement.Children.Add(verticalMovement); break; case MovementType.Circular: FaceDirection(true); xStart = 0; yStart = (GameWindow.ActualHeight - ImageToMove.Height) / 2; Canvas.SetTop(ImageToMove, yStart); Canvas.SetLeft(ImageToMove, xStart); System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone(); customCulture.NumberFormat.NumberDecimalSeparator = "."; System.Threading.Thread.CurrentThread.CurrentCulture = customCulture; var xMid = (GameWindow.ActualWidth - ImageToMove.Width) / 2; var yMid = (GameWindow.ActualHeight - ImageToMove.Height) / 2; var path = $"M 0,{yStart} A {xMid},{yMid} 0 1 1 0,{yStart + 0.0001}"; var pathUpperHalf = new PathGeometry(); pathUpperHalf.Figures = PathFigureCollection.Parse(path); var circularMovement1 = new DoubleAnimationUsingPath(); circularMovement1.PathGeometry = pathUpperHalf; circularMovement1.Duration = new Duration(new TimeSpan(0, 0, 0, timeToMove)); circularMovement1.Source = PathAnimationSource.X; var circularMovement2 = new DoubleAnimationUsingPath(); circularMovement2.PathGeometry = pathUpperHalf; circularMovement2.Duration = new Duration(new TimeSpan(0, 0, 0, timeToMove)); circularMovement2.Source = PathAnimationSource.Y; Storyboard.SetTarget(circularMovement1, ImageToMove); Storyboard.SetTargetProperty(circularMovement1, new PropertyPath("(Canvas.Left)")); Storyboard.SetTarget(circularMovement2, ImageToMove); Storyboard.SetTargetProperty(circularMovement2, new PropertyPath("(Canvas.Top)")); ImageMovement.Children.Add(circularMovement1); ImageMovement.Children.Add(circularMovement2); break; default: break; } Controller.Pause(); ImageToMove.Visibility = Visibility.Visible; var t = int.Parse(Application.Current.Properties["InteractionTime"].ToString()); InteractionTimer.Interval = t * 1000; SoundTimer.Interval = 5000; InteractionTimer.Start(); SoundNeeded = false; } else { Application.Current.Properties["CurrentMovement"] = Int32.Parse(Application.Current.Properties["CurrentMovement"].ToString()) + 1; AnimatingControl_Loaded(); } }