private static PathGeometry CreateGeometry(Size contentDesiredSize) { //TODO Make better :) do some funky beziers or summit const double cheapRadiusBig = 6.0; const double cheapRadiusSmall = cheapRadiusBig / 2; const int angle = 20; const double radians = angle * (Math.PI / 180); var startPoint = new Point(0, contentDesiredSize.Height + cheapRadiusSmall + cheapRadiusSmall); //clockwise starting at bottom left var bottomLeftSegment = new ArcSegment(new Point(startPoint.X + cheapRadiusSmall, startPoint.Y - cheapRadiusSmall), new Size(cheapRadiusSmall, cheapRadiusSmall), 315, false, SweepDirection.Counterclockwise, true); var triangleX = Math.Tan(radians) * (contentDesiredSize.Height); var leftSegment = new LineSegment(new Point(bottomLeftSegment.Point.X + triangleX, bottomLeftSegment.Point.Y - contentDesiredSize.Height), true); var topLeftSegment = new ArcSegment(new Point(leftSegment.Point.X + cheapRadiusBig, leftSegment.Point.Y - cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 120, false, SweepDirection.Clockwise, true); var topSegment = new LineSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig, 0), true); var topRightSegment = new ArcSegment(new Point(contentDesiredSize.Width + cheapRadiusBig + cheapRadiusBig + cheapRadiusBig, cheapRadiusSmall), new Size(cheapRadiusBig, cheapRadiusBig), 40, false, SweepDirection.Clockwise, true); triangleX = Math.Tan(radians) * (contentDesiredSize.Height); //triangleX = Math.Tan(radians)*(contentDesiredSize.Height - topRightSegment.Point.Y); var rightSegment = new LineSegment(new Point(topRightSegment.Point.X + triangleX, topRightSegment.Point.Y + contentDesiredSize.Height), true); var bottomRightPoint = new Point(rightSegment.Point.X + cheapRadiusSmall, rightSegment.Point.Y + cheapRadiusSmall); var bottomRightSegment = new ArcSegment(bottomRightPoint, new Size(cheapRadiusSmall, cheapRadiusSmall), 25, false, SweepDirection.Counterclockwise, true); var bottomLeftPoint = new Point(0, bottomRightSegment.Point.Y); var bottomSegment = new LineSegment(bottomLeftPoint, true); var pathSegmentCollection = new PathSegmentCollection { bottomLeftSegment, leftSegment, topLeftSegment, topSegment, topRightSegment, rightSegment, bottomRightSegment, bottomSegment }; var pathFigure = new PathFigure(startPoint, pathSegmentCollection, true) { IsFilled = true }; var pathFigureCollection = new PathFigureCollection { pathFigure }; var geometryGroup = new PathGeometry(pathFigureCollection); geometryGroup.Freeze(); return(geometryGroup); }
private static Geometry ApplyTransform(Geometry geometry, double bt, Size renderSize) { var pathGeometry = new PathGeometry(); pathGeometry.AddGeometry(geometry); var hbt = bt * 0.5; //var scaleY = ((hbt * 100) / renderSize.Height) / 100; var scaleY = hbt / renderSize.Height; pathGeometry.Transform = new ScaleTransform(1, scaleY + 1, renderSize.Width * 0.5, 0); pathGeometry.Freeze(); return(pathGeometry); }
// currently not in use... private void AnimatePutCard2(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y); pBezierSegment.Points.Add(pFigure.StartPoint); pBezierSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(1); // Set the animation's DoesRotateWithTangent property // to true so that rotates the card in addition to moving it. matrixAnimation.DoesRotateWithTangent = true; matrixAnimation.Completed += delegate { // the cards get reversed - there for need animation to flip it... DoubleAnimation da = new DoubleAnimation(180, 0, TimeSpan.FromSeconds(0.34)); RotateTransform rt = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight); targetCanves.RenderTransform = rt; rt.BeginAnimation(RotateTransform.AngleProperty, da); }; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
// Creates a border geometry used to render complex border brushes private static Geometry GenerateBorderGeometry(Rect rect, Thickness borderThickness) { PathGeometry geometry = new PathGeometry(); // Add outer rectangle figure geometry.Figures.Add(GenerateRectFigure(rect)); // Subtract inner rectangle figure geometry.Figures.Add(GenerateRectFigure(HelperDeflateRect(rect, borderThickness))); geometry.Freeze(); return geometry; }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } if (!(value is EnvelopeCore.StepCollection)) { throw new ArgumentException("EnvPhaseToGeometryConverter requires a value of type StepCollection"); } double totalSeconds = 0; EnvelopeCore.StepCollection coll = value as EnvelopeCore.StepCollection; Point[] points = coll.Select(s => new Point(totalSeconds += s.Seconds, 1 - s.TargetValue)).ToArray(); double startingValue = GetStartingValue(coll); // The units don't matter here -- just that the projection is independently proportional on each axis. // For display, the path objects of related stepcollections eill need to have the same scaling as each other to line up correctly. PathFigure figure = new PathFigure(); figure.StartPoint = new Point(0, 1 - startingValue); if (coll.Any()) { points.Execute(p => figure.Segments.Add(new LineSegment(p, true))); if (coll.Phase == EnvelopePhase.Release && coll.Last().TargetValue != 0) { figure.Segments.Add(new LineSegment(new Point(totalSeconds, 1), true)); } AddFrame(figure, coll.TotalSeconds); } else if (coll.Phase == EnvelopePhase.Loop) { figure.Segments.Add(new LineSegment(new Point(coll.TotalSeconds, 1 - startingValue), true)); AddFrame(figure, coll.TotalSeconds); } PathGeometry geo = new PathGeometry(); geo.Figures.Add(figure); geo.Freeze(); return(geo); }
/// <summary> /// Creates the geometry. /// Returns null when the geometry is empty! /// </summary> public Geometry CreateGeometry() { CloseFigure(); if (figures.Count != 0) { PathGeometry g = new PathGeometry(figures); g.Freeze(); return(g); } else { return(null); } }
private PathGeometry CreatePathForAnimation(int x1, int y1, int x2, int y2) { PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); pFigure.IsClosed = false; pFigure.StartPoint = new Point(x1, y1); PolyLineSegment pLineSegment = new PolyLineSegment(); pLineSegment.Points.Add(new Point(x2, y2)); pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); animationPath.Freeze(); // Замораживаем для производительности return(animationPath); }
private void AnimatePutCard(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); Point pointWindowCorner = PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyLineSegment pLineSegment = new PolyLineSegment(); Point pointStart = new Point(); pointStart.X = pointWindowCorner.X - pointCanvasCorner.X + this.ActualWidth / 2 - targetCanves.ActualHeight / 4; pointStart.Y = pointWindowCorner.Y - pointCanvasCorner.Y - targetCanves.ActualWidth; pFigure.StartPoint = pointStart; pLineSegment.Points.Add(pFigure.StartPoint); pLineSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationPutCardTime); DoubleAnimation doubleAnimation = new DoubleAnimation(90, 360, TimeSpan.FromSeconds(iAnimationPutCardTime)); RotateTransform renderTransform = new RotateTransform(0, targetCanves.ActualWidth / 2, targetCanves.ActualHeight / 2);//targetCanves.ActualHeight); targetCanves.Children[0].RenderTransform = renderTransform; renderTransform.BeginAnimation(RotateTransform.AngleProperty, doubleAnimation); //matrixAnimation.DoesRotateWithTangent = true; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
internal static Geometry CreateGeometry(PointCollection pointCollection) { PathGeometry path_geometry = new PathGeometry(); PolyLineSegment aa = new PolyLineSegment(); aa.Points = pointCollection; PathFigure figure = new PathFigure(); figure.Segments.Add(aa); path_geometry.Figures.Add(figure); path_geometry.Freeze(); return(path_geometry); }
/// <summary> /// Funkja przygotowywująca animację na podstawie rozmiaru obiektu canvas /// </summary> /// <param name="geometry">Aktualny obiekt geometry</param> private void PrepareAnimation(EllipseGeometry geometry) { double space = playField.ActualWidth / baloons; j += (int)space + 50; if (j > playField.ActualWidth) { j = Convert.ToInt32(j % playField.ActualWidth); } geometry.Center = new Point(j, -50); up = new PointAnimationUsingPath(); pBezierSegment = new PolyBezierSegment(); animationPath = new PathGeometry(); pFigure = new PathFigure(); pFigure.StartPoint = new Point(j, -50); for (int i = 0; (i < playField.ActualHeight); i += 25) { int randomSign = random.Next(1); if (randomSign == 0) { pBezierSegment.Points.Add(new Point(j - random.Next(30), i)); } else if (randomSign == 1) { pBezierSegment.Points.Add(new Point(j + random.Next(30), i)); } } pBezierSegment.Points.Add(new Point(j, playField.ActualHeight + 50)); pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); up.PathGeometry = animationPath; if (timesIndex != times.Count) { up.BeginTime = TimeSpan.FromSeconds(Convert.ToInt32(times[timesIndex])); timesIndex++; } up.Duration = TimeSpan.FromSeconds(10); up.SpeedRatio = 0.5; up.RepeatBehavior = RepeatBehavior.Forever; animationPath.Freeze(); geometry.BeginAnimation(EllipseGeometry.CenterProperty, up); }
public PathGeometry CreatePath(Distance distance, int lane) { var segments = new List <PathSegment>(); var lapCount = Calculator.Laps(distance); for (var lap = 1; lap <= lapCount; lap++, lane ^= 1) { segments.AddRange(Rounds[lane]); } var startPoint = StartPoints[lane]; var figure = new PathFigure(startPoint, segments, false); var path = new PathGeometry(new[] { figure }); path.Freeze(); return(path); }
PathGeometry GetAnimationPathGeometry(Point offset) { PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); var points = Connection.GetBezierPoints(); for (int i = 0; i < points.Count; i++) { Point p = points[i]; p.Offset(offset.X, offset.Y); points[i] = p; } PolyBezierSegment pBezierSegment = new PolyBezierSegment(); if (From == Connection.From) { pFigure.StartPoint = points[0]; pBezierSegment.Points.Add(points[1]); pBezierSegment.Points.Add(points[2]); pBezierSegment.Points.Add(points[3]); } else if (From == Connection.To) { pFigure.StartPoint = points[3]; pBezierSegment.Points.Add(points[2]); pBezierSegment.Points.Add(points[1]); pBezierSegment.Points.Add(points[0]); } foreach (Point p in pBezierSegment.Points) { p.Offset(4, 4); } pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); return(animationPath); }
// 旗帜 public void CreateDrawingVisualFlag(Brush gBrush, Pen gPen, Point startPoint, Size flagSize) { //旗 M0,20 C50,-20 100,40 150,0 L150,100 C100,120 50,80 0,120 PathGeometry flaggeo = new PathGeometry(); PathFigure ffg = new PathFigure(); ffg.StartPoint = new Point(startPoint.X, startPoint.Y + 20); ffg.Segments.Add(new BezierSegment(new Point(startPoint.X + flagSize.Width / 3, startPoint.Y - 20), new Point(startPoint.X + flagSize.Width * 2 / 3, startPoint.Y + 20), new Point(startPoint.X + flagSize.Width, startPoint.Y), true)); ffg.Segments.Add(new LineSegment(new Point(startPoint.X + flagSize.Width, startPoint.Y + flagSize.Height), true)); ffg.Segments.Add(new BezierSegment(new Point(startPoint.X + flagSize.Width * 2 / 3, startPoint.Y + flagSize.Height + 20), new Point(startPoint.X + flagSize.Width / 3, startPoint.Y + flagSize.Height - 20), new Point(startPoint.X, startPoint.Y + flagSize.Height + 20), true)); flaggeo.Figures.Add(ffg); flaggeo.Freeze(); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawGeometry(gBrush, gPen, flaggeo); drawingContext.Close(); _children.Add(drawingVisual); }
// 倒三角形 public void CreateDrawingTriangle2(Brush rBrush, Pen rPen, Point rCenter, double rWidth, double rHeight) { PathGeometry flaggeo = new PathGeometry(); PathFigure ffg = new PathFigure { StartPoint = new Point(rCenter.X - rWidth / 2, rCenter.Y - rHeight) }; ffg.Segments.Add(new LineSegment(new Point(rCenter.X, rCenter.Y), true)); ffg.Segments.Add(new LineSegment(new Point(rCenter.X + rWidth / 2, rCenter.Y - rHeight), true)); ffg.Segments.Add(new LineSegment(new Point(rCenter.X - rWidth / 2, rCenter.Y - rHeight), true)); flaggeo.Figures.Add(ffg); flaggeo.Freeze(); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawGeometry(rBrush, rPen, flaggeo); drawingContext.Close(); _children.Add(drawingVisual); }
/// <summary> /// Creates the triangle's geometry. /// </summary> private static void CreateTriangle() { const int triangleSize = 5; var firstLine = new LineSegment(new Point(0, -triangleSize), false); firstLine.Freeze(); var secondLine = new LineSegment(new Point(0, triangleSize), false); secondLine.Freeze(); var figure = new PathFigure { StartPoint = new Point(triangleSize, 0) }; figure.Segments.Add(firstLine); figure.Segments.Add(secondLine); figure.Freeze(); s_Triangle = new PathGeometry(); s_Triangle.Figures.Add(figure); s_Triangle.Freeze(); }
private void AnimateMoveCard(int iLocationFrom, int iLocationTo) { Canvas canvesFrom = GetCanvas(iLocationFrom); Point pointCanvasCornerFrom = canvesFrom.PointToScreen(new Point(0, 0)); Canvas canvesTo = GetCanvas(iLocationTo); Point pointCanvasCornerTo = canvesTo.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyLineSegment pLineSegment = new PolyLineSegment(); pFigure.StartPoint = new Point(0, 0); pLineSegment.Points.Add(pFigure.StartPoint); pLineSegment.Points.Add(new Point(pointCanvasCornerTo.X - pointCanvasCornerFrom.X, pointCanvasCornerTo.Y - pointCanvasCornerFrom.Y)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationRemoveCardTime); canvesFrom.Children[0].RenderTransform = matrixTransform; matrixAnimation.Completed += delegate { MoveCard(iLocationFrom, iLocationTo); }; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
private void AnimatePutCardMiddleOrRight(int iLocationIndex) { Canvas targetCanves = GetCanvas(iLocationIndex); Point pointCanvasCorner = targetCanves.PointToScreen(new Point(0, 0)); // Create the animation path. PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); PolyBezierSegment pBezierSegment = new PolyBezierSegment(); pFigure.StartPoint = new Point(-pointCanvasCorner.X + this.ActualWidth / 2, -pointCanvasCorner.Y); pBezierSegment.Points.Add(pFigure.StartPoint); pBezierSegment.Points.Add(new Point(-targetCanves.ActualWidth, 0)); pBezierSegment.Points.Add(new Point(0, 0)); // Create a MatrixTransform. This transform will be used to move the button. MatrixTransform matrixTransform = new MatrixTransform(); targetCanves.RenderTransform = matrixTransform; pFigure.Segments.Add(pBezierSegment); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); // Create a MatrixAnimationUsingPath to move the // button along the path by animating its MatrixTransform. MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(iAnimationPutCardTime); // Set the animation's DoesRotateWithTangent property // to true so that rotates the card in addition to moving it. matrixAnimation.DoesRotateWithTangent = true; matrixTransform.BeginAnimation(MatrixTransform.MatrixProperty, matrixAnimation); }
/// <summary> /// Sets the specified side length for a <see cref="MapGrid"/> polygon.</summary> /// <param name="length"> /// The new value for the <see cref="RegularPolygon.Length"/> property of an <see /// cref="PolygonGrid.Element"/> in the <see cref="MapGrid"/>.</param> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="length"/> is equal to or less than zero.</exception> /// <exception cref="PropertyValueException"> /// <see cref="MapGrid"/> is a null reference. Use <see cref="SetMapGrid"/> to initialize /// this property.</exception> /// <remarks><para> /// <b>ResizePolygon</b> sets the <see cref="PolygonGrid.Element"/> property of the current /// <see cref="MapGrid"/> to a new <see cref="RegularPolygon"/> instance with the specified /// <paramref name="length"/> and otherwise identical property values. /// </para><para> /// <b>ResizePolygon</b> also sets the <see cref="GridElementGeometry"/> property, and /// recreates the <see cref="TileCopyBuffer"/> and <see cref="TileDrawBuffer"/> bitmaps with /// the resulting <see cref="TileWidth"/> and <see cref="TileHeight"/>. Any existing bitmap /// contents are lost.</para></remarks> protected void ResizePolygon(double length) { if (MapGrid == null) { ThrowHelper.ThrowPropertyValueException("MapGrid", Tektosyne.Strings.PropertyNull); } // create identical but resized polygon this._mapGrid.Element = MapGrid.Element.Resize(length); // create element outline, starting at top left corner GridElementGeometry = new PathGeometry() { Figures = { MapGrid.Element.ToFigure() } }; GridElementGeometry.Freeze(); // create tile buffers for one grid element TileCopyBuffer = CreateTileCopyBuffer(0, 0); TileDrawBuffer = CreateTileDrawBuffer(0, 0); }
Geometry GetMarkerGeometry(HexBufferSpan bufferSpan, HexSpanSelectionFlags flags, bool clipToViewport, Thickness padding, bool isLineGeometry) { if (bufferSpan.Buffer != hexView.Buffer) { throw new ArgumentException(); } bool createOutlinedPath = false; PathGeometry geo = null; var textBounds = GetNormalizedTextBounds(bufferSpan, flags); HexMarkerHelper.AddGeometries(hexView, textBounds, isLineGeometry, clipToViewport, padding, 0, ref geo, ref createOutlinedPath); if (createOutlinedPath) { geo = geo.GetOutlinedPathGeometry(); } if (geo != null && geo.CanFreeze) { geo.Freeze(); } return(geo); }
Geometry GetMarkerGeometry(SnapshotSpan bufferSpan, bool clipToViewport, Thickness padding, bool isLineGeometry) { if (bufferSpan.Snapshot != snapshot) { throw new ArgumentException(); } bool createOutlinedPath = false; PathGeometry geo = null; var textBounds = GetNormalizedTextBounds(bufferSpan); MarkerHelper.AddGeometries(textView, textBounds, isLineGeometry, clipToViewport, padding, 0, ref geo, ref createOutlinedPath, false); if (createOutlinedPath) { geo = geo.GetOutlinedPathGeometry(); } if (geo != null && geo.CanFreeze) { geo.Freeze(); } return(geo); }
/// <summary> /// Generate a path from actors current position to the extent of the Codespace in given direction /// </summary> /// <param name="ord"></param> /// <param name="a"></param> /// <returns></returns> public static PathGeometry OrdinalPath(Codespace.Ordinal ord, DynamicElement el) { PathFigure pFigure = new PathFigure(); pFigure.StartPoint = el.MidPoint; Point endpoint = el.MidPoint; switch (ord) { case Codespace.Ordinal.Right: endpoint.Offset(el.Parent.Right, 0); break; case Codespace.Ordinal.Left: endpoint.Offset(el.Parent.Left, 0); break; case Codespace.Ordinal.Up: endpoint.Offset(0, el.Parent.Top); break; case Codespace.Ordinal.Down: endpoint.Offset(0, el.Parent.Bottom); break; } pFigure.Segments.Add(new LineSegment(endpoint, true)); PathGeometry animationPath = new PathGeometry(); animationPath.Figures.Add(pFigure); // Freeze the PathGeometry for performance benefits. animationPath.Freeze(); return(animationPath); }
private DrawingVisual GetFaceDrawingVisual() { RadialGradientBrush radialGradientBrush = new RadialGradientBrush(Colors.Yellow, Colors.Orange); radialGradientBrush.RadiusX = 0.8; radialGradientBrush.RadiusY = 0.8; radialGradientBrush.Freeze(); Pen outerPen = new Pen(Brushes.Black, 5.25); outerPen.Freeze(); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawEllipse(radialGradientBrush, outerPen, new Point(75, 75), 72.375, 72.375); drawingContext.DrawEllipse(Brushes.Black, null, new Point(44.25, 49.5), 10.125, 12.75); drawingContext.DrawEllipse(Brushes.Black, null, new Point(105.75, 49.5), 10.125, 12.75); ArcSegment arcSegment = new ArcSegment(new Point(115.5, 93.75), new Size(61.5, 61.5), 0, false, SweepDirection.Counterclockwise, true); PathFigure pathFigure = new PathFigure(new Point(34.5, 93.75), new List <PathSegment>() { arcSegment }, false); PathGeometry pathGeometry = new PathGeometry(new List <PathFigure>() { pathFigure }); pathGeometry.Freeze(); Pen smilePen = new Pen(Brushes.Black, 10.5); smilePen.StartLineCap = PenLineCap.Round; smilePen.EndLineCap = PenLineCap.Round; smilePen.Freeze(); drawingContext.DrawGeometry(null, smilePen, pathGeometry); drawingContext.Close(); return(drawingVisual); }
internal static Geometry CreateGeometry(Point[] points, bool isClosed = false) { PathGeometry path_geometry = new PathGeometry(); PolyLineSegment polyLineSegment = new PolyLineSegment(); polyLineSegment.Points = new PointCollection(points); PathFigure figure = new PathFigure(); figure.Segments.Add(polyLineSegment); if (isClosed) { figure.IsClosed = true; figure.IsFilled = true; } path_geometry.Figures.Add(figure); path_geometry.Freeze(); return(path_geometry); }
/// <summary> /// Calibration method. /// </summary> private void StartCalibration(object sender, EventArgs e) { if (CalibrationStarted) { return; } CalibrationStarted = true; pipeline.RunAsync(); var segment = new PolyLineSegment(); allCalibrationLines.ForEach(line => segment.Points.Add(new Point(line.X2, line.Y2))); var pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(allCalibrationLines.First().X1, allCalibrationLines.First().Y1); pathFigure.Segments.Add(segment); var animationPath = new PathGeometry(); animationPath.Figures.Add(pathFigure); animationPath.Freeze(); var centerPointAnimation = new PointAnimationUsingPath(); centerPointAnimation.PathGeometry = animationPath; centerPointAnimation.Duration = Duration; Storyboard.SetTargetName(centerPointAnimation, nameof(EllipseGeometryCalibrationCircle));//Storyboard.SetTarget method not working Storyboard.SetTargetProperty(centerPointAnimation, new PropertyPath(EllipseGeometry.CenterProperty)); pathAnimationStoryboard.Children.Add(centerPointAnimation); //pathAnimationStoryboard.Completed += CalibrationCompleted; pathAnimationStoryboard.AutoReverse = true; pathAnimationStoryboard.RepeatBehavior = RepeatBehavior.Forever; pathAnimationStoryboard.Begin(this); CompositionTarget.Rendering += CaptureCalibrationCircleCoordinate; }
/// <summary> /// Draws the <see cref="Catalog"/> tile with the specified index.</summary> /// <param name="context"> /// The <see cref="DrawingContext"/> for the drawing.</param> /// <param name="index"> /// The tile index in the <see cref="Catalog"/> bitmap whose contents to draw.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="context"/> is a null reference.</exception> /// <exception cref="ObjectDisposedException"> /// The <see cref="CatalogManager"/> object has been disposed of.</exception> /// <remarks><para> /// <b>DrawTile</b> draws the <see cref="Catalog"/> tile at the specified <paramref /// name="index"/> to pixel location (1,1) within the specified <paramref name="context"/>. /// </para><para> /// The tile is clipped by and surrounded with the <see cref="RegularPolygon"/> outline of /// an <see cref="PolygonGrid.Element"/> in the current <see cref="MapGrid"/>. /// </para></remarks> public void DrawTile(DrawingContext context, int index) { if (IsDisposed) { ThrowHelper.ThrowObjectDisposedException(null); } if (context == null) { ThrowHelper.ThrowArgumentNullException("context"); } // compute source & target rectangles RectI source = GetTileBounds(index); Rect target = new Rect(1, 1, source.Width, source.Height); // copy catalog tile to buffer TileCopyBuffer.Lock(); TileCopyBuffer.Read(0, 0, Catalog, source); TileCopyBuffer.Unlock(); // get scaled polygonal outline, centered on tile PointD offset = new PointD((source.Width + 2) / 2.0, (source.Height + 2) / 2.0); var geometry = new PathGeometry() { Figures = { MapGrid.Element.ToFigure(offset) } }; geometry.Freeze(); // draw catalog tile, clipped to polygonal region context.PushClip(geometry); context.DrawImage(TileCopyBuffer, target); context.Pop(); // draw black polygon outline context.DrawGeometry(null, new Pen(Brushes.Black, 1.0), geometry); }
//Convert points[] to storyboard private Storyboard CreateStoryBoard(Point[] points) { MatrixTransform buttonMatrixTransform = new MatrixTransform(); BusImage.RenderTransform = buttonMatrixTransform; Parent.RegisterName("MatrixTransform" + BusLineNo, buttonMatrixTransform); PathGeometry animationPath = new PathGeometry(); PathFigure pFigure = new PathFigure(); pFigure.StartPoint = points[0]; PolyLineSegment pLineSegment = new PolyLineSegment(); for (int i = 1; i < points.Length; i++) { pLineSegment.Points.Add(points[i]); } pFigure.Segments.Add(pLineSegment); animationPath.Figures.Add(pFigure); animationPath.Freeze(); MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath(); matrixAnimation.PathGeometry = animationPath; matrixAnimation.Duration = TimeSpan.FromSeconds(Duration(SPEED, points)); matrixAnimation.DoesRotateWithTangent = true; Storyboard.SetTargetName(matrixAnimation, "MatrixTransform" + BusLineNo); Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty)); this.pasb = new Storyboard(); this.pasb.Children.Add(matrixAnimation); this.pasb.Completed += new EventHandler(nextStop); return(pasb); }
static DropTargetInsertAdorner() { // Create the pen and triangle in a static constructor and freeze them to improve performance. const int triangleSize = 5; var firstLine = new LineSegment(new Point(0, -triangleSize), false); firstLine.Freeze(); var secondLine = new LineSegment(new Point(0, triangleSize), false); secondLine.Freeze(); var figure = new PathFigure { StartPoint = new Point(triangleSize, 0) }; figure.Segments.Add(firstLine); figure.Segments.Add(secondLine); figure.Freeze(); m_Triangle = new PathGeometry(); m_Triangle.Figures.Add(figure); m_Triangle.Freeze(); }
private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { var dpimultiplier = PresentationSource.FromVisual(Application.Current.Windows[0]).CompositionTarget.TransformToDevice.M11; var hesaplama = DataContext as Hesaplama; var x = e.GetPosition(Şekil).X; var y = e.GetPosition(Şekil).Y; hesaplama?.Noktalar.Add(new Point(x, y)); PathFigure figure = new PathFigure { StartPoint = new Point(x, y) }; PathGeometry geometry = new PathGeometry(); PolyLineSegment linesegment = new PolyLineSegment { Points = new PointCollection(hesaplama?.Noktalar) }; figure.Segments.Add(linesegment); geometry.Figures.Add(figure); geometry.Freeze(); hesaplama.GeometryData = geometry; hesaplama.Alan = geometry.GetArea() / (96 * dpimultiplier) / (96 * dpimultiplier) * 2.54 * 2.54 * 2.54 * 72 / (96 * dpimultiplier); }
private static PathGeometry CreateArrow() { PathFigure figure = new PathFigure { StartPoint = new Point(InsertionAdorner.Size, 0) }; InsertionAdorner.CreateLineSegments( figure, new Point(0, -InsertionAdorner.Size), new Point(0, -InsertionAdorner.Size / 3d), new Point(-InsertionAdorner.Size, -InsertionAdorner.Size / 3d), new Point(-InsertionAdorner.Size, InsertionAdorner.Size / 3d), new Point(0, InsertionAdorner.Size / 3d), new Point(0, InsertionAdorner.Size), new Point(InsertionAdorner.Size, 0) ); PathGeometry arrow = new PathGeometry { Figures = { figure } }; figure.Freeze(); arrow.Freeze(); return(arrow); }
private DrawingVisual GetFaceDrawingVisual() { RadialGradientBrush radialGradientBrush = new RadialGradientBrush(Colors.Yellow, Colors.Orange); radialGradientBrush.RadiusX = 0.8; radialGradientBrush.RadiusY = 0.8; radialGradientBrush.Freeze(); Pen outerPen = new Pen(Brushes.Black, 5.25); outerPen.Freeze(); DrawingVisual drawingVisual = new DrawingVisual(); DrawingContext drawingContext = drawingVisual.RenderOpen(); drawingContext.DrawEllipse(radialGradientBrush, outerPen, new Point(ActualWidth / 2, ActualHeight / 2), (ActualWidth - outerPen.Thickness) / 2, (ActualHeight - outerPen.Thickness) / 2); drawingContext.DrawEllipse(Brushes.Black, null, new Point(ActualWidth / 3.3898305084745761, ActualHeight / 3.0303030303030303), ActualWidth / 14.814814814814815, ActualHeight / 11.764705882352942); drawingContext.DrawEllipse(Brushes.Black, null, new Point(ActualWidth / 1.4184397163120568, ActualHeight / 3.0303030303030303), ActualWidth / 14.814814814814815, ActualHeight / 11.764705882352942); ArcSegment arcSegment = new ArcSegment(new Point(ActualWidth / 1.2987012987012987, ActualHeight / 1.6), new Size(ActualWidth / 2.4390243902439024, ActualHeight / 2.4390243902439024), 0, false, SweepDirection.Counterclockwise, true); PathFigure pathFigure = new PathFigure(new Point(ActualWidth / 4.3478260869565215, ActualHeight / 1.6), new List <PathSegment>() { arcSegment }, false); PathGeometry pathGeometry = new PathGeometry(new List <PathFigure>() { pathFigure }); pathGeometry.Freeze(); Pen smilePen = new Pen(Brushes.Black, 10.5); smilePen.StartLineCap = PenLineCap.Round; smilePen.EndLineCap = PenLineCap.Round; smilePen.Freeze(); drawingContext.DrawGeometry(null, smilePen, pathGeometry); drawingContext.Close(); return(drawingVisual); }