internal static Geometry MarkersAsGeometry(Curve curve, MatrixTransform graphToCanvas, MarkersType markersType, double markersSize) { double xScale = graphToCanvas.Matrix.M11; double xOffset = graphToCanvas.Matrix.OffsetX; double yScale = graphToCanvas.Matrix.M22; double yOffset = graphToCanvas.Matrix.OffsetY; GeometryGroup markers = new GeometryGroup(); double width = Math.Abs(markersSize); double height = Math.Abs(markersSize); Geometry markerGeometry = LegendMarkerGeometry(markersType, markersSize); if (markerGeometry == null) { return(null); } markerGeometry.Freeze(); for (int i = 0; i < curve.xTransformed.Length; ++i) { if (!curve.includeMarker[i]) { continue; } double xCanvas = curve.xTransformed[i] * xScale + xOffset; double yCanvas = curve.yTransformed[i] * yScale + yOffset; Geometry newMarker = markerGeometry.Clone(); newMarker.Transform = new TranslateTransform(xCanvas, yCanvas); markers.Children.Add(newMarker); } markers.Freeze(); return(markers); }
public FleetRender(Fleet fleet, bool?lines) { LineGeometry line; FormattedText text; Geometry textGeom; double x = fleet.SourcePlanet.X + ((fleet.DestinationPlanet.X - fleet.SourcePlanet.X) * ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength)); double y = fleet.SourcePlanet.Y + ((fleet.DestinationPlanet.Y - fleet.SourcePlanet.Y) * ((double)(fleet.TotalTripLength - fleet.TurnsRemaining) / fleet.TotalTripLength)); if (lines ?? false) { line = new LineGeometry(new Point(x, y), new Point(fleet.DestinationPlanet.X, fleet.DestinationPlanet.Y)); m_gg.Children.Add(line); } text = new FormattedText( fleet.ShipCount.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 0.8, Brushes.Black); textGeom = text.BuildGeometry(new Point(x - text.Width / 2, y - text.Height / 2)); m_gg.Children.Add(textGeom); m_gg.Freeze(); }
private void DrawLongitudeAxis(Canvas c) { int VTICKNUM = Properties.Settings.Default.StorygraphVerticalTicks; c.Children.Clear(); double x = 0; double increment = _drawingHeight / VTICKNUM; double tincrement = ((double)_meta["maxLng"] - (double)_meta["minLng"]) / VTICKNUM; GeometryGroup grp = new GeometryGroup(); double j = c.ActualHeight; double k = (double)_meta["minLng"]; while ((c.ActualHeight - j) < c.ActualHeight) { grp.Children.Add(new LineGeometry(new Point(x, j), new Point(x + Properties.Settings.Default.StorygraphTickLength, j))); c.Children.Add(GraphText(x + 8, j - 8, String.Format("{0:0.0000}", k), Properties.Settings.Default.StorygraphFontSize, HorizontalAlignment.Left)); j -= increment; k += tincrement; } grp.Freeze(); Path tickPath = new Path() { Stroke = Brushes.Black, StrokeThickness = 1.0 }; tickPath.Data = grp; c.Children.Add(tickPath); }
private void DrawFrequencyAxis(Canvas c) { int VTICKNUM = Properties.Settings.Default.TimelineVerticalTicks; c.Children.Clear(); double x = c.ActualWidth - Properties.Settings.Default.StorygraphTickLength; double increment = _drawingHeight / VTICKNUM; double tincrement = (_storyTable.MaxFrequency - _storyTable.MinFrequency) / VTICKNUM; GeometryGroup grp = new GeometryGroup(); double j = c.ActualHeight; double k = _storyTable.MinFrequency; while ((c.ActualHeight - j) < c.ActualHeight) { grp.Children.Add(new LineGeometry(new Point(x, j), new Point(x + Properties.Settings.Default.StorygraphTickLength, j))); c.Children.Add(GraphText(x - 38, j - 8, String.Format("{0:0.0000}", k), Properties.Settings.Default.StorygraphFontSize, HorizontalAlignment.Right)); j -= increment; k += tincrement; } grp.Freeze(); Path tickPath = new Path() { Stroke = Brushes.Black, StrokeThickness = 1.0 }; tickPath.Data = grp; c.Children.Add(tickPath); }
public FrameworkElement Plot(params Geometry[] geometries) { // compute values needed for constructing the visual tree of the plot var combinedGeometry = new GeometryGroup { Children = new GeometryCollection(geometries.Select(x => x.Clone())) }; combinedGeometry.Freeze(); var transform = ComputeTransform(combinedGeometry.Bounds); // construct the plot's visual stree. var canvas = new Canvas { Width = width, Height = height, Background = Brushes.White, Children = { new Path { Data = combinedGeometry, LayoutTransform = transform, Stroke = Brushes.Black, StrokeThickness = 1, } } }; return(canvas); }
private void DrawTimeAxis(Canvas c) { int HTICKNUM = Properties.Settings.Default.StorygraphHorizontalTicks; c.Children.Clear(); double increment = c.ActualWidth / HTICKNUM; DateTime maxd = (DateTime)_meta["maxDate"]; DateTime mind = (DateTime)_meta["minDate"]; double tincrement = (maxd.Subtract(mind)).TotalDays / HTICKNUM; GeometryGroup grp = new GeometryGroup(); double j = 0.0; DateTime k = (DateTime)_meta["minDate"]; while (j <= c.ActualWidth + 1) { grp.Children.Add(new LineGeometry(new Point(j, 0), new Point(j, Properties.Settings.Default.StorygraphTickLength))); //c.Children.Add(GraphText(j - 12, 8.0, k.ToString("HH:mm"), Properties.Settings.Default.StorygraphFontSize, HorizontalAlignment.Center)); c.Children.Add(GraphText(j - 12, 8.0, k.ToString("MM/yy"), Properties.Settings.Default.StorygraphFontSize, HorizontalAlignment.Center)); j += increment; k = k.AddDays(tincrement); } grp.Freeze(); Path tickPath = new Path() { Stroke = Brushes.Black, StrokeThickness = 1.0 }; tickPath.Data = grp; c.Children.Add(tickPath); }
private static GeometryGroup CreatePathGeometry(TriangleMesh mesh) { var geometryGroup = new GeometryGroup(); foreach (var e in mesh.Edges) { var p0 = 256 * e.Vertex0.Traits.Position; var p1 = 256 * e.Vertex1.Traits.Position; var lineGeometry = new LineGeometry(new Point(p0.X, p0.Y), new Point(p1.X, p1.Y)); lineGeometry.Freeze(); geometryGroup.Children.Add(lineGeometry); } foreach (var v in mesh.Vertices)//.Where(x => x.OnBoundary)) { var p = new Point(256 * v.Traits.Position.X, 256 * v.Traits.Position.Y); //var elli = new EllipseGeometry(p, 2, 2); //geometryGroup.Children.Add(elli); /// text geometry & drawing var text = new FormattedText(v.Index.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), 2, Brushes.Black); var textGeometry = text.BuildGeometry(p); textGeometry.Freeze(); geometryGroup.Children.Add(textGeometry); } geometryGroup.Freeze(); return(geometryGroup); }
public void DrawIrregularPolygon(int numSides, int[] r) { GeometryGroup gg = new GeometryGroup(); gg.Children.Add(BuildIrregularPolygon(numSides, r)); gg.Freeze(); path2.Data = gg; }
public void DrawregularPolygon(int numSides, int r) { GeometryGroup gg = new GeometryGroup(); gg.Children.Add(BuildregularPolygon(numSides, r));//添加图形 gg.Freeze(); path1.Data = gg; }
private void RefreshDrawing(DrawingVisual drawingVisual = null) { var geometryGroup = new GeometryGroup(); var rect = new Rect(50, 50, VisualWidth, 50); var rectGeom = new RectangleGeometry(rect); geometryGroup.Children.Add(rectGeom); geometryGroup.Freeze(); drawingVisual = drawingVisual ?? (DrawingVisual)GetVisualChild(0); using (var dc = drawingVisual.RenderOpen()) { dc.DrawGeometry(Brushes.Blue, null, geometryGroup); } }
private Path GeneratePoinsCloud(IEnumerable <Point> points) { var geometry = new GeometryGroup { Children = new GeometryCollection(from pnt in points select new EllipseGeometry(pnt, 1, 1)), }; geometry.Freeze(); var path = new Path { Data = geometry }; return(path); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (!(value is IEnumerable <Point>)) { Trace.TraceError("value is not of the correct type"); return(Binding.DoNothing); } var enumerable = value as IEnumerable <Point>; var result = new GeometryGroup(); foreach (var point in enumerable) { var ellipseGeometry = new EllipseGeometry(point, 0.5, 0.5); result.Children.Add(ellipseGeometry); } result.Freeze(); return(result); }
private void renderColumns(List <int> columns, Brush brush, Image image) { GeometryGroup group = new GeometryGroup(); group.Children.Add(new RectangleGeometry(new Rect(0, 0, 0, 0))); renderColumnsForLines(group, columns, _view.TextViewLines); group.Freeze(); Drawing drawing = new GeometryDrawing(brush, _emptyPen, group); drawing.Freeze(); DrawingImage drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); image.Source = drawingImage; Canvas.SetLeft(image, _view.ViewportLeft + group.Bounds.Left); Canvas.SetTop(image, _view.ViewportTop + group.Bounds.Top); }
public void CreateDotChartGeometry(ICollection dt, double _maxData, double chartHeight, double chartWidth) { _children.Clear(); stopWatch.Restart(); var barWidth = SetBarWidth(dt.Count, chartWidth); var ellipses = new GeometryGroup(); // For each row in the datasource double centerX = _axis_start; foreach (var el in dt) { // Calculate bar value. var height = Convert.ToDouble(el) * (chartHeight - _axis_start) / _maxData; centerX += barWidth; ellipses.Children.Add( new EllipseGeometry(new Point(centerX, chartHeight - height - _axis_start), 1, 1) ); } ellipses.Freeze(); var visual = new DrawingVisual(); using (var dc = visual.RenderOpen()) { dc.DrawGeometry(null, _chartPen, ellipses); stopWatch.Stop(); var elapsedTime = String.Format("{0} - {1} - {2}", MethodBase.GetCurrentMethod().Name, dt.Count, stopWatch.ElapsedTicks); dc.DrawText( new FormattedText(elapsedTime, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 12, Brushes.LightGreen), new Point(10, 10)); } _children.Add(visual); }
public override Geometry GetHilightGeometry(TextRange range) { Geometry result = Geometry.Empty; if (range != null) { IEnumerable <Rect> rects = GetHighlightRects(range, this.textBlock); IEnumerable <Geometry> rectGeometries = from rect in rects select FrozenGeometryFromRect(rect); GeometryCollection collection = new GeometryCollection(rectGeometries); collection.Freeze(); result = new GeometryGroup() { Children = collection }; result.Freeze(); } return(result); }
public PlanetRender(Planet planet) { EllipseGeometry planetGeom; FormattedText text; Geometry textGeom; double radius = Math.Sqrt(planet.GrowthRate) / c_RadiusScale; /* Area proportional to growth rate */ planetGeom = new EllipseGeometry(new Point(planet.X, planet.Y), radius, radius); m_gg.Children.Add(planetGeom); text = new FormattedText( planet.ShipCount.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Tahoma"), radius < 0.6 ? 0.6 : radius, Brushes.Black); textGeom = text.BuildGeometry(new Point(planet.X - text.Width / 2, planet.Y - text.Height / 2)); m_gg.Children.Add(textGeom); m_gg.Freeze( ); }
/// <summary> /// <see cref="ChartItemCollection.Draw(IDrawingContext)"/> /// </summary> public override void Draw(IDrawingContext dc) { if (points == null || !points.Any()) { return; } if (ItemStyle == StockItemStyle.Linear) { base.Draw(dc); return; } double halfItemWidth = ItemXDistance / 2; if (halfItemWidth + ItemXSpan < 1) { DrawDenseChart(dc); return; } int i = -1; do { i++; } while (i < points.Length && !IsPointValid(points[i])); GeometryGroup groupLineRaise = new GeometryGroup(), groupLineFall = new GeometryGroup(); GeometryGroup groupRectRaise = new GeometryGroup(), groupRectFall = new GeometryGroup(); Point p1 = new Point(); Point p2 = new Point(); List <Point> PtList = new List <Point>(); for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var yC = points[i].Y; var yH = verticalLines[i].YHigh; var yL = verticalLines[i].YLow; var yO = verticalLines[i].YOpen; bool isRaise = yC <= yO; if (yC == yO) { isRaise = Items[i + iStartPosition].ValueChange >= 0; } GeometryGroup groupLine, groupRect = null; var xMid = PointSnapper.SnapValue(x + halfItemWidth); if (ItemStyle == StockItemStyle.Candle) { if (ItemXDistance >= 3) { p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); double yNext = 0; if (isRaise) { p2.Y = PointSnapper.SnapValue(yC); groupLine = groupLineRaise; groupRect = groupRectRaise; yNext = PointSnapper.SnapValue(yO); } else { p2.Y = PointSnapper.SnapValue(yO); groupLine = groupLineFall; groupRect = groupRectFall; yNext = PointSnapper.SnapValue(yC); } if (p1.Y != p2.Y) { LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); } p1.X = PointSnapper.SnapValue(x); p1.Y = p2.Y; p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1; p2.Y = yNext; if (p1.Y == p2.Y) { LineGeometry rLine = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else rLine.Freeze(); #endif groupLine.Children.Add(rLine); } else { RectangleGeometry rect = new RectangleGeometry() { Rect = new Rect(p1, p2) }; #if USINGCANVAS #else rect.Freeze(); #endif groupRect.Children.Add(rect); } p1.X = p2.X = xMid; p1.Y = yNext; p2.Y = PointSnapper.SnapValue(yL); if (p1.Y != p2.Y) { LineGeometry line2 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line2.Freeze(); #endif groupLine.Children.Add(line2); } } else { if (isRaise) { groupLine = groupLineRaise; } else { groupLine = groupLineFall; } p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); if (p1.Y == p2.Y) { p2.Y++; } LineGeometry line1 = new LineGeometry { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); } } else { if (isRaise) { groupLine = groupLineRaise; } else { groupLine = groupLineFall; } p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); if (p1.Y == p2.Y) { p2.Y++; } LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif groupLine.Children.Add(line1); p1.X = PointSnapper.SnapValue(x); p1.Y = p2.Y = PointSnapper.SnapValue(yO); p2.X = xMid; if (p1.X != p2.X) { LineGeometry line2 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line2.Freeze(); #endif groupLine.Children.Add(line2); } p1.X = p2.X; p1.Y = p2.Y = PointSnapper.SnapValue(yC); p2.X = PointSnapper.SnapValue(x + ItemXDistance); if (p1.X != p2.X) { LineGeometry line3 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line3.Freeze(); #endif groupLine.Children.Add(line3); } } } #if USINGCANVAS #else groupLineRaise.Freeze(); groupLineFall.Freeze(); groupRectRaise.Freeze(); groupRectFall.Freeze(); #endif dc.DrawGeometry(null, lineRaisePen, groupLineRaise); dc.DrawGeometry(null, lineFallPen, groupLineFall); dc.DrawGeometry(null, rectRaisePen, groupRectRaise); dc.DrawGeometry(rectFallPen.Brush, rectFallPen, groupRectFall); }
/// <summary> /// Draw the hatches and the transparent area where isn't covering the elements. /// </summary> /// <param name="drawingContext"></param> private void DrawBackgound(DrawingContext drawingContext) { PathGeometry hatchGeometry = null; Geometry rectGeometry = null; int count = _elementsBounds.Count; if (count != 0) { // Create a union collection of the element regions. for (int i = 0; i < count; i++) { Rect hatchRect = _elementsBounds[i]; if (hatchRect.IsEmpty) { continue; } hatchRect.Inflate(HatchBorderMargin / 2, HatchBorderMargin / 2); if (hatchGeometry == null) { PathFigure path = new PathFigure(); path.StartPoint = new Point(hatchRect.Left, hatchRect.Top); PathSegmentCollection segments = new PathSegmentCollection(); PathSegment line = new LineSegment(new Point(hatchRect.Right, hatchRect.Top), true); line.Freeze(); segments.Add(line); line = new LineSegment(new Point(hatchRect.Right, hatchRect.Bottom), true); line.Freeze(); segments.Add(line); line = new LineSegment(new Point(hatchRect.Left, hatchRect.Bottom), true); line.Freeze(); segments.Add(line); line = new LineSegment(new Point(hatchRect.Left, hatchRect.Top), true); line.Freeze(); segments.Add(line); segments.Freeze(); path.Segments = segments; path.IsClosed = true; path.Freeze(); hatchGeometry = new PathGeometry(); hatchGeometry.Figures.Add(path); } else { rectGeometry = new RectangleGeometry(hatchRect); rectGeometry.Freeze(); hatchGeometry = Geometry.Combine(hatchGeometry, rectGeometry, GeometryCombineMode.Union, null); } } } // Then, create a region which equals to "SelectionFrame - element1 bounds - element2 bounds - ..." GeometryGroup backgroundGeometry = new GeometryGroup(); GeometryCollection geometryCollection = new GeometryCollection(); // Add the entile rectanlge to the group. rectGeometry = new RectangleGeometry(new Rect(0, 0, RenderSize.Width, RenderSize.Height)); rectGeometry.Freeze(); geometryCollection.Add(rectGeometry); // Add the union of the element rectangles. Then the group will do oddeven operation. Geometry outlineGeometry = null; if (hatchGeometry != null) { hatchGeometry.Freeze(); outlineGeometry = hatchGeometry.GetOutlinedPathGeometry(); outlineGeometry.Freeze(); if (count == 1 && ((InkCanvasInnerCanvas)AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0) { geometryCollection.Add(outlineGeometry); } } geometryCollection.Freeze(); backgroundGeometry.Children = geometryCollection; backgroundGeometry.Freeze(); // Then, draw the region which may contain holes so that the elements cannot be covered. // After that, the underneath elements can receive the messages. #if DEBUG_OUTPUT // Draw the debug feedback drawingContext.DrawGeometry(new SolidColorBrush(Color.FromArgb(128, 255, 255, 0)), null, backgroundGeometry); #else drawingContext.DrawGeometry(Brushes.Transparent, null, backgroundGeometry); #endif // At last, draw the hatch borders if (outlineGeometry != null) { drawingContext.DrawGeometry(null, _hatchPen, outlineGeometry); } }
private void DrawBar(IDrawingContext dc) { int i = -1; do { i++; } while (!IsPointValid(points[i])); GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup(); Point p1 = new Point(); Point p2 = new Point(); List <Point> PtList = new List <Point>(); double halfItemWidth = ItemXDistance / 2; for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var y = points[i].Y; GeometryGroup group = null; bool isRaise = (Items[iStartPosition + i] as VolumnItem).IsRaise; if (isRaise) { group = groupRaise; } else { group = groupFall; } if (ItemXDistance >= 3 && volumnItemStyle == VolumnItemStyle.Fat) { p1.X = PointSnapper.SnapValue(x); p1.Y = PointSnapper.SnapValue(y); p2.X = PointSnapper.SnapValue(x + ItemXDistance) - 1; p2.Y = collectRect.Bottom; RectangleGeometry rect = new RectangleGeometry() { Rect = new Rect(p1, p2) }; #if USINGCANVAS #else rect.Freeze(); #endif group.Children.Add(rect); } else { p1.X = p2.X = PointSnapper.SnapValue(x + halfItemWidth); p1.Y = PointSnapper.SnapValue(y); p2.Y = collectRect.Bottom; LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif group.Children.Add(line1); } } #if USINGCANVAS #else (RaisePen as DrawingPen).Freeze(); (FallPen as DrawingPen).Freeze(); groupRaise.Freeze(); groupFall.Freeze(); #endif dc.DrawGeometry(null, RaisePen, groupRaise); dc.DrawGeometry(FallPen.Brush, FallPen, groupFall); }
// Token: 0x060077BC RID: 30652 RVA: 0x00222C78 File Offset: 0x00220E78 private void DrawBackgound(DrawingContext drawingContext) { PathGeometry pathGeometry = null; int count = this._elementsBounds.Count; Geometry geometry; if (count != 0) { for (int i = 0; i < count; i++) { Rect rect = this._elementsBounds[i]; if (!rect.IsEmpty) { rect.Inflate(3.0, 3.0); if (pathGeometry == null) { PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(rect.Left, rect.Top); PathSegmentCollection pathSegmentCollection = new PathSegmentCollection(); PathSegment pathSegment = new LineSegment(new Point(rect.Right, rect.Top), true); pathSegment.Freeze(); pathSegmentCollection.Add(pathSegment); pathSegment = new LineSegment(new Point(rect.Right, rect.Bottom), true); pathSegment.Freeze(); pathSegmentCollection.Add(pathSegment); pathSegment = new LineSegment(new Point(rect.Left, rect.Bottom), true); pathSegment.Freeze(); pathSegmentCollection.Add(pathSegment); pathSegment = new LineSegment(new Point(rect.Left, rect.Top), true); pathSegment.Freeze(); pathSegmentCollection.Add(pathSegment); pathSegmentCollection.Freeze(); pathFigure.Segments = pathSegmentCollection; pathFigure.IsClosed = true; pathFigure.Freeze(); pathGeometry = new PathGeometry(); pathGeometry.Figures.Add(pathFigure); } else { geometry = new RectangleGeometry(rect); geometry.Freeze(); pathGeometry = Geometry.Combine(pathGeometry, geometry, GeometryCombineMode.Union, null); } } } } GeometryGroup geometryGroup = new GeometryGroup(); GeometryCollection geometryCollection = new GeometryCollection(); geometry = new RectangleGeometry(new Rect(0.0, 0.0, base.RenderSize.Width, base.RenderSize.Height)); geometry.Freeze(); geometryCollection.Add(geometry); Geometry geometry2 = null; if (pathGeometry != null) { pathGeometry.Freeze(); geometry2 = pathGeometry.GetOutlinedPathGeometry(); geometry2.Freeze(); if (count == 1 && ((InkCanvasInnerCanvas)base.AdornedElement).InkCanvas.GetSelectedStrokes().Count == 0) { geometryCollection.Add(geometry2); } } geometryCollection.Freeze(); geometryGroup.Children = geometryCollection; geometryGroup.Freeze(); drawingContext.DrawGeometry(Brushes.Transparent, null, geometryGroup); if (geometry2 != null) { drawingContext.DrawGeometry(null, this._hatchPen, geometry2); } }
private void DrawDenseChart(IDrawingContext dc) { int i = -1; do { i++; } while (i < points.Length && !IsPointValid(points[i])); GeometryGroup groupRaise = new GeometryGroup(), groupFall = new GeometryGroup(); Point p1 = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA); Point p2 = new Point(ChartItemCollection.valueNA, ChartItemCollection.valueNA); double open = ChartItemCollection.valueNA; double close = open; List <Point> PtList = new List <Point>(); double halfItemWidth = ItemXDistance / 2; int iStart = i; for (; i < points.Length; i++) { if (!IsPointValid(points[i])) { continue; } var x = points[i].X; var yC = points[i].Y; var yH = verticalLines[i].YHigh; var yL = verticalLines[i].YLow; var yO = verticalLines[i].YOpen; GeometryGroup group = null; var xMid = PointSnapper.SnapValue(x + halfItemWidth); if (p1.X != xMid) { if (i != iStart) { if (p1.Y == p2.Y) { p2.Y++; } bool isRaise = close <= open; if (isRaise) { group = groupRaise; } else { group = groupFall; } LineGeometry line1 = new LineGeometry() { StartPoint = p1, EndPoint = p2 }; #if USINGCANVAS #else line1.Freeze(); #endif group.Children.Add(line1); } open = yO; close = yC; p1.X = p2.X = xMid; p1.Y = PointSnapper.SnapValue(yH); p2.Y = PointSnapper.SnapValue(yL); } else { var YH = PointSnapper.SnapValue(yH); if (YH < p1.Y) { p1.Y = YH; } var YL = PointSnapper.SnapValue(yL); if (YL > p2.Y) { p2.Y = YL; } close = yC; } } #if USINGCANVAS #else groupRaise.Freeze(); groupFall.Freeze(); #endif dc.DrawGeometry(null, lineRaisePen, groupRaise); dc.DrawGeometry(null, lineFallPen, groupFall); }
private void SetCursor(CursorT t) { Task.Run(() => { if (CurrentCursor == t) { return; } CurrentCursor = t; switch (t) { case CursorT.Paint: { Correcting = true; Dispatcher.Invoke(() => { using var dc = CursorVisual.RenderOpen(); }); } break; case CursorT.Standart: { Correcting = true; Dispatcher.Invoke(() => { using var dc = CursorVisual.RenderOpen(); dc.DrawLine(LinesPen, new Point(-15, 0), new Point(15, 0)); dc.DrawLine(LinesPen, new Point(0, -15), new Point(0, 15)); }); } break; case CursorT.Select: { Correcting = false; var geo = new PathGeometry(new[] { new PathFigure(new Point(0, 0), new[] { new LineSegment(new Point(0, 75), true), new LineSegment(new Point(75, 0), true) }, true) }); geo.Freeze(); var clip = new GeometryGroup(); #region Clip Geometry clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(150, 235), RadiusX = 65, RadiusY = 65 }, Geometry2 = new RectangleGeometry(new Rect( new Point(60, 100), new Size(180, 135))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(150, 235), RadiusX = 50, RadiusY = 50 }, Geometry2 = new RectangleGeometry(new Rect( new Point(60, 100), new Size(180, 135))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(135, 50), RadiusX = 50, RadiusY = 50 }, Geometry2 = new RectangleGeometry(new Rect( new Point(85, 50), new Size(180, 150))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(135, 50), RadiusX = 35, RadiusY = 35 }, Geometry2 = new RectangleGeometry(new Rect( new Point(85, 50), new Size(180, 150))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(150, 200), RadiusX = 35, RadiusY = 35 }, Geometry2 = new RectangleGeometry(new Rect( new Point(85, 100), new Size(100, 100))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Exclude, Geometry1 = new EllipseGeometry() { Center = new Point(150, 200), RadiusX = 20, RadiusY = 20 }, Geometry2 = new RectangleGeometry(new Rect( new Point(85, 100), new Size(100, 100))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Union, Geometry1 = new EllipseGeometry() { Center = new Point(122.5, 80), RadiusX = 7.5, RadiusY = 7.5 }, Geometry2 = new RectangleGeometry(new Rect( new Point(115, 80), new Size(15, 120))) }); clip.Children.Add(new CombinedGeometry { GeometryCombineMode = GeometryCombineMode.Union, Geometry1 = new EllipseGeometry() { Center = new Point(207.5, 80), RadiusX = 7.5, RadiusY = 7.5 }, Geometry2 = new RectangleGeometry(new Rect( new Point(200, 80), new Size(15, 155))) }); clip.Children.Add(new RectangleGeometry(new Rect(new Point(85, 50), new Size(15, 185)))); clip.Children.Add(new RectangleGeometry(new Rect(new Point(170, 50), new Size(15, 150)))); #endregion clip.Freeze(); Dispatcher.Invoke(() => { using var dc = CursorVisual.RenderOpen(); //dc.PushTransform(new TranslateTransform(-4, 3)); //dc.PushTransform(new RotateTransform(-30)); //dc.PushTransform(new ScaleTransform(1.5, 1.5)); //dc.DrawGeometry(LinesPen.Brush, null, geo); //dc.Pop(); //dc.Pop(); //dc.Pop(); //dc.PushTransform(new TranslateTransform(0, 0)); dc.PushTransform(new ScaleTransform(0.10, 0.10)); dc.DrawGeometry(LinesPen.Brush, null, geo); dc.DrawGeometry(LinesPen.Brush, null, clip); }); } break; case CursorT.Hook: { Correcting = false; var geo = new PathGeometry(new[] { new PathFigure(new Point(4, 0), new[] { new LineSegment(new Point(8, 12), true), new LineSegment(new Point(6, 13), true), new LineSegment(new Point(5, 10), true), new LineSegment(new Point(5, 18), true), new LineSegment(new Point(3, 18), true), new LineSegment(new Point(3, 10), true), new LineSegment(new Point(2, 13), true), new LineSegment(new Point(0, 12), true) }, true) }); geo.Freeze(); Dispatcher.Invoke(() => { using var dc = CursorVisual.RenderOpen(); dc.PushTransform(new TranslateTransform(-4, 3)); dc.PushTransform(new RotateTransform(-30)); dc.PushTransform(new ScaleTransform(1.5, 1.5)); dc.DrawGeometry(LinesPen.Brush, null, geo); }); } break; case CursorT.None: { Correcting = true; Dispatcher.Invoke(() => { using var dc = CursorVisual.RenderOpen(); }); } break; } if (MagnetState) { MagnetAdd(); } if (t == CursorT.Hook || t == CursorT.Select) { Hide = true; Dispatcher.Invoke(() => { CursorPriceVisual.RenderOpen().Close(); CursorTimeVisual.RenderOpen().Close(); CursorLinesVisual.RenderOpen().Close(); }); } else { Hide = false; SetCursorLines(); } }); }
protected virtual Geometry GetDefiningGeometry() { bool isStartVisible = IsStartVisible; bool isEndVisible = IsEndVisible; double radius = Radius; double thickness = GetThickness(); double sx = X1; double sy = Y1; double ex = X2; double ey = Y2; double zet = LineUtil.Zet(sx, sy, ex, ey); double width = LineUtil.Width(radius, thickness, zet); double height = LineUtil.Height(radius, thickness, zet); bool shortenStart = GetShortenStart(this); bool shortenEnd = GetShortenEnd(this); bool isStartIO = GetStartIO(); bool isEndIO = GetEndIO(); // shorten start if (isStartIO == true && isEndIO == false && shortenStart == true) { if (Math.Round(sy, 1) == Math.Round(ey, 1)) { sx = ex - ShortenLineSize; } } // shorten end if (isStartIO == false && isEndIO == true && shortenEnd == true) { if (Math.Round(sy, 1) == Math.Round(ey, 1)) { ex = sx + ShortenLineSize; } } // get ellipse position IPoint ellipseStart = LineUtil.EllipseStart(sx, sy, width, height, isStartVisible); IPoint ellipseEnd = LineUtil.EllipseEnd(ex, ey, width, height, isEndVisible); // get line position IPoint lineStart = LineUtil.LineStart(sx, sy, width, height, isStartVisible); IPoint lineEnd = LineUtil.LineEnd(ex, ey, width, height, isEndVisible); var g = new GeometryGroup() { FillRule = FillRule.Nonzero }; if (isStartVisible == true) { var startEllipse = new EllipseGeometry( new Point(ellipseStart.X, ellipseStart.Y), radius, radius); g.Children.Add(startEllipse); } if (isEndVisible == true) { var endEllipse = new EllipseGeometry( new Point(ellipseEnd.X, ellipseEnd.Y), radius, radius); g.Children.Add(endEllipse); } var line = new LineGeometry( new Point(lineStart.X, lineStart.Y), new Point(lineEnd.X, lineEnd.Y)); g.Children.Add(line); g.Freeze(); return(g); }
private static Geometry CreateStrokedLineGeometry(Geometry lineGeometry, double strokeWidth, LineCap2 startCap, LineCap2 endCap, PaintDotNet.UI.Media.DashStyle dashStyle) { Geometry geometry; Geometry geometry2; Geometry geometry3; Geometry geometry4; Geometry geometry5; double length = lineGeometry.GetLength(flatteningTolerance); StrokeStyle strokeStyle = new StrokeStyle { DashStyle = dashStyle, LineJoin = PenLineJoin.Round }; double num2 = 0.0; switch (startCap) { case LineCap2.Flat: geometry = null; break; case LineCap2.Arrow: geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>(); num2 = 0.5; break; case LineCap2.ArrowFilled: geometry = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>(); num2 = 1.5; break; case LineCap2.Rounded: strokeStyle.StartLineCap = PenLineCap.Round; geometry = null; break; default: throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(startCap, "startCap"); } double num3 = 0.0; switch (endCap) { case LineCap2.Flat: geometry2 = null; break; case LineCap2.Arrow: geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, false, false).EnsureFrozen <Geometry>(); num3 = 0.5; break; case LineCap2.ArrowFilled: geometry2 = CreateArrowGeometry(5.0, 5.0, strokeWidth, 1.0, true, true).EnsureFrozen <Geometry>(); num3 = 1.5; break; case LineCap2.Rounded: strokeStyle.EndLineCap = PenLineCap.Round; geometry2 = null; break; default: throw ExceptionUtil.InvalidEnumArgumentException <LineCap2>(endCap, "endCap"); } strokeStyle.Freeze(); if (geometry == null) { geometry3 = null; } else { PointAndTangentDouble pointAtLength = lineGeometry.GetPointAtLength(0.0, flatteningTolerance); double radians = Math.Atan2(pointAtLength.Tangent.Y, pointAtLength.Tangent.X) + 3.1415926535897931; Matrix3x2Double num9 = Matrix3x2Double.RotationByRadians(radians); Matrix3x2Double num10 = Matrix3x2Double.Translation(pointAtLength.Point.X, pointAtLength.Point.Y); Matrix3x2Double matrix = num9 * num10; geometry3 = geometry.GetTransformedGeometry(matrix).EnsureFrozen <Geometry>(); } if (geometry2 == null) { geometry4 = null; } else { double num14 = lineGeometry.GetLength(flatteningTolerance); PointAndTangentDouble num15 = lineGeometry.GetPointAtLength(num14, flatteningTolerance); Matrix3x2Double num18 = Matrix3x2Double.RotationByRadians(Math.Atan2(num15.Tangent.Y, num15.Tangent.X)); Matrix3x2Double num19 = Matrix3x2Double.Translation(num15.Point.X, num15.Point.Y); Matrix3x2Double num20 = num18 * num19; geometry4 = geometry2.GetTransformedGeometry(num20).EnsureFrozen <Geometry>(); } double startLength = 0.0; double endLength = length; if (num2 != 0.0) { startLength = strokeWidth * num2; } if (num3 != 0.0) { endLength = length - (strokeWidth * num3); } if ((startLength != 0.0) || (endLength != length)) { geometry5 = GetTrimmedGeometry(lineGeometry, startLength, endLength).EnsureFrozen <Geometry>(); } else { geometry5 = lineGeometry; } Geometry item = new WidenedGeometry(geometry5, strokeWidth, strokeStyle) { FlatteningTolerance = flatteningTolerance }.EnsureFrozen <WidenedGeometry>(); GeometryGroup group = new GeometryGroup { FillRule = FillRule.Nonzero }; group.Children.Add(item); if (geometry3 != null) { group.Children.Add(geometry3); } if (geometry4 != null) { group.Children.Add(geometry4); } group.Freeze(); return(group); }
/// <summary> /// Adds the markers. /// </summary> /// <param name="pts">The points.</param> private void AddMarkers(IList <Point> pts) { var grp = new GeometryGroup { FillRule = FillRule.Nonzero }; double sz = this.MarkerSize; double sz2 = sz / 2; switch (this.LineMarker) { case MarkerType.Square: foreach (var pt in pts) { grp.Children.Add(new RectangleGeometry(new Rect(pt.X - sz2, pt.Y - sz2, sz, sz))); } break; case MarkerType.Circle: foreach (var pt in pts) { grp.Children.Add(new EllipseGeometry(new Rect(pt.X - sz2, pt.Y - sz2, sz, sz))); } break; case MarkerType.Diamond: foreach (var pt in pts) { grp.Children.Add(new RectangleGeometry(new Rect(pt.X - sz2, pt.Y - sz2, sz, sz)) { Transform = new RotateTransform(45, pt.X, pt.Y) }); } break; } grp.Freeze(); var path = new Path { Data = grp, Fill = this.Background }; this.Canvas.Children.Add(path); for (int i = 0; i < pts.Count; i++) { var pt = pts[i]; var tb = new TextBox { Text = string.Format(this.TextFormat, this.points[i].Y), FontSize = this.FontSize, Foreground = Brushes.Black, BorderBrush = this.AnnotationBrush }; Canvas.SetLeft(tb, pt.X + this.OffsetX); Canvas.SetTop(tb, pt.Y + this.OffsetY); this.Canvas.Children.Add(tb); this.Canvas.Children.Add( new Line { Stroke = this.AnnotationBrush, StrokeThickness = 1, X1 = pt.X, Y1 = pt.Y, X2 = pt.X + this.OffsetX, Y2 = pt.Y + this.OffsetY }); } }