public override void Render(DrawingContext dc, Point screenPoint) { Point dataPoint = screenPoint.ScreenToData(this.ct.Transform); Point dataPointZero = new Point(dataPoint.X, 0.0); Point screenPointZero = dataPointZero.DataToScreen(this.ct.Transform); //const double verticalShift = 5; // px //dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, 40)), screenPoint); double pointx = screenPointZero.X + 2; double pointy = screenPointZero.Y + 13; FormattedText textToDraw = new FormattedText(dataPoint.Y.ToString("0.0"), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx, pointy)); /* * string svalue = dataPoint.Y.ToString("0.000"); * foreach (var s in svalue) * { * if (s.Equals('.')) * continue; * FormattedText textToDraw = new FormattedText(s.ToString(), Thread.CurrentThread.CurrentCulture, * FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); * dc.DrawText(textToDraw, new Point(pointx,pointy)); * pointy = pointy + 10; * * } * */ }
public override void Render(DrawingContext dc, Point screenPoint) { Point dataPoint = screenPoint.ScreenToData(this.ct.Transform); Point dataPointZero = new Point(dataPoint.X,0.0); Point screenPointZero = dataPointZero.DataToScreen(this.ct.Transform); //const double verticalShift = 5; // px //dc.DrawLine(new Pen(Brushes.Black, 1), Point.Add(screenPoint, new Vector(0, 40)), screenPoint); double pointx = screenPointZero.X + 2; double pointy = screenPointZero.Y + 2; FormattedText textToDraw = new FormattedText(dataPoint.Y.ToString("0.000"), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx, pointy)); /* string svalue = dataPoint.Y.ToString("0.000"); foreach (var s in svalue) { if (s.Equals('.')) continue; FormattedText textToDraw = new FormattedText(s.ToString(), Thread.CurrentThread.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), 12, Brushes.Black); dc.DrawText(textToDraw, new Point(pointx,pointy)); pointy = pointy + 10; } * */ }
private Vector GetForces() { Vector springForce = new Vector(); if (useMouse) { Point mousePos = GetMousePosition(); if (!mousePos.IsFinite()) { } Point p1 = initialMousePos.ScreenToData(initialTransform); Point p2 = mousePos.ScreenToData(viewport.Transform); var transform = viewport.Transform; Vector diff = p2 - p1; springForce = -diff * springCoeff; } Vector frictionForce = GetFrictionForce(springForce); Vector liquidFriction = -liquidFrictionCoeff * velocity - liquidFrictionQuadraticCoeff * velocity * velocity.Length; Vector result = springForce + frictionForce + liquidFriction; return(result); }
public void UpdatePositionInData(Point mousePos, CoordinateTransform transform) { Point mousePosInData = mousePos.ScreenToData(transform); _mousePointsInData.Add(mousePosInData); _lastMousePosInData = mousePosInData; OnNearestPointUpdated(); }
public void UpdatePositionInData(Point mousePos, Vector screenDistance, CoordinateTransform transform) { Point mousePosInData = mousePos.ScreenToData(transform); _lastMousePosInData = mousePosInData; PositionAndCheckDistance pcd = new PositionAndCheckDistance(mousePos, screenDistance, transform); OnNearestPointUpdated(pcd); }
protected override void OnMouseMove(System.Windows.Input.MouseEventArgs e) { base.OnMouseMove(e); var popup = GetPopupTipWindow(); if (popup.IsOpen) { popup.Hide(); } if (bitmapInvalidated) { return; } Point p = e.GetPosition(this); Point dp = p.ScreenToData(Plotter2D.Transform); var tooltip = GetTooltipForPoint(p, completedRequest.Visible, completedRequest.Output); if (tooltip == null) { return; } popup.VerticalOffset = p.Y + 20; popup.HorizontalOffset = p.X; popup.ShowDelayed(new TimeSpan(0, 0, 1)); Grid grid = new Grid(); Rectangle rect = new Rectangle { Stroke = Brushes.Black, Fill = SystemColors.InfoBrush }; StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Vertical; sp.Children.Add(tooltip); sp.Margin = new Thickness(4, 2, 4, 2); var tb = new TextBlock(); tb.Text = String.Format("Location: {0:F2}, {1:F2}", dp.X, dp.Y); tb.Foreground = SystemColors.GrayTextBrush; sp.Children.Add(tb); grid.Children.Add(rect); grid.Children.Add(sp); grid.Measure(SizeHelper.CreateInfiniteSize()); popup.Child = grid; }
public PositionAndCheckDistance(Point screenPosition, Vector screenDistance, CoordinateTransform transform) { ScreenPosition = screenPosition; ScreenDistance = screenDistance; DataPosition = screenPosition.ScreenToData(transform); DataTopRight = (screenPosition + screenDistance).ScreenToData(transform); DataBottomLeft = (screenPosition - screenDistance).ScreenToData(transform); Transform = transform; }
private void MouseWheelZoom(Point mousePos, int wheelRotationDelta) { Point zoomTo = mousePos.ScreenToData(Viewport.Transform); double zoomSpeed = Math.Abs(wheelRotationDelta / Mouse.MouseWheelDeltaForOneLine); zoomSpeed *= wheelZoomSpeed; if (wheelRotationDelta < 0) { zoomSpeed = 1 / zoomSpeed; } Viewport.Visible = Viewport.Visible.Zoom(zoomTo, zoomSpeed); }
private void Part_Plotter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (this.ViewModel.IsManualPeakSelectionEnabled) { Point mousePos = m_cursorGraph.Position; var transform = Part_Plotter.Viewport.Transform; Point mousePosInData = mousePos.ScreenToData(transform); double timeMs = mousePosInData.X; m_mouseClickedPosition = mousePos.X; m_sampleToAddCandidateInMs = timeMs; } }
private void OnMouseMove(object sender, MouseEventArgs e) { var popup = GetPopupTipWindow(); if (popup.IsOpen) { popup.Hide(); } Point screenPoint = e.GetPosition(plotter.CentralGrid); Point viewportPoint = screenPoint.ScreenToData(plotter.Transform); var tooltip = GetTooltipForPoint(viewportPoint); if (tooltip == null) { return; } popup.VerticalOffset = screenPoint.Y + 20; popup.HorizontalOffset = screenPoint.X; popup.ShowDelayed(TimeSpan.FromSeconds(0)); Grid grid = new Grid(); Rectangle rect = new Rectangle { Stroke = Brushes.Black, Fill = SystemColors.InfoBrush }; StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Vertical; panel.Children.Add(tooltip); panel.Margin = new Thickness(4, 2, 4, 2); var textBlock = new TextBlock(); textBlock.Text = String.Format("Location: {0:F2}, {1:F2}", viewportPoint.X, viewportPoint.Y); textBlock.Foreground = SystemColors.GrayTextBrush; panel.Children.Add(textBlock); grid.Children.Add(rect); grid.Children.Add(panel); grid.Measure(SizeHelper.CreateInfiniteSize()); popup.Child = grid; }
private void CentralGrid_MouseUp(object sender, MouseButtonEventArgs e) { clickIndex++; Point mousePos = e.GetPosition(Plotter.CentralGrid); if (clickIndex % 2 == 1) { firstPoint = mousePos; } else { var transform = Plotter.Transform; Selector.SelectedRectangle = new DataRect(mousePos.ScreenToData(transform), firstPoint.ScreenToData(transform)); } }
private void Part_Plotter_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if (this.ViewModel.IsManualPeakSelectionEnabled && m_mouseClickedPosition.HasValue) { Point mousePos = m_cursorGraph.Position; if (Math.Abs(mousePos.X - m_mouseClickedPosition.Value) < 4) { var transform = Part_Plotter.Viewport.Transform; Point mousePosInData = mousePos.ScreenToData(transform); double timeMs = mousePosInData.X; this.ViewModel.AddPeakAtPosition(m_sampleToAddCandidateInMs.Value); } } m_mouseClickedPosition = null; m_sampleToAddCandidateInMs = null; }
private void UpdateUIRepresentation() { foreach (var path in addedPaths) { content.Children.Remove(path); } addedPaths.Clear(); if (DataSource == null) { labelGrid.Visibility = Visibility.Hidden; return; } Rect output = Plotter2D.Viewport.Output; Point mousePos = Mouse.GetPosition(this); if (!output.Contains(mousePos)) { return; } var transform = Plotter2D.Viewport.Transform; Point visiblePoint = mousePos.ScreenToData(transform); Rect visible = Plotter2D.Viewport.Visible; double isolineLevel; if (Search(visiblePoint, out isolineLevel)) { var collection = IsolineBuilder.Build(isolineLevel); string format = "G3"; if (Math.Abs(isolineLevel) < 1000) { format = "F"; } textBlock.Text = isolineLevel.ToString(format); double x = mousePos.X + labelShift.X; if (x + labelGrid.ActualWidth > output.Right) { x = mousePos.X - labelShift.X - labelGrid.ActualWidth; } double y = mousePos.Y - labelShift.Y - labelGrid.ActualHeight; if (y < output.Top) { y = mousePos.Y + labelShift.Y; } Canvas.SetLeft(labelGrid, x); Canvas.SetTop(labelGrid, y); foreach (LevelLine segment in collection.Lines) { StreamGeometry streamGeom = new StreamGeometry(); using (StreamGeometryContext context = streamGeom.Open()) { Point startPoint = segment.StartPoint.DataToScreen(transform); var otherPoints = segment.OtherPoints.DataToScreen(transform); context.BeginFigure(startPoint, false, false); context.PolyLineTo(otherPoints, true, true); } Path path = new Path { Stroke = new SolidColorBrush(Palette.GetColor(segment.Value01)), Data = streamGeom, Style = pathStyle }; content.Children.Add(path); addedPaths.Add(path); labelGrid.Visibility = Visibility.Visible; Binding pathBinding = new Binding { Path = new PropertyPath("StrokeThickness"), Source = this }; path.SetBinding(Path.StrokeThicknessProperty, pathBinding); } } else { labelGrid.Visibility = Visibility.Hidden; } }
//------------------------------------------------------------------------- public Point GetCursorLatLonDeg() { Point ll = Mouse.GetPosition(CentralGrid); return(ll.ScreenToData(Transform)); }
protected virtual void UpdateUIRepresentation(Point mousePos, CoordinateTransform transform) { Point mousePosInData = mousePos.ScreenToData(transform); UpdateUIRepresentation(mousePosInData, mousePosInData); }
private void UpdateUIRepresentation(Point mousePos) { if (Plotter2D == null) return; var transform = Plotter2D.Viewport.Transform; Rect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; if (!output.Contains(mousePos)) return; horizLine.X1 = output.Left; horizLine.X2 = output.Right; horizLine.Y1 = mousePos.Y; horizLine.Y2 = mousePos.Y; vertLine.X1 = mousePos.X; vertLine.X2 = mousePos.X; vertLine.Y1 = output.Top; vertLine.Y2 = output.Bottom; if (UseDashOffset) { horizLine.StrokeDashOffset = (output.Right - mousePos.X) / 2; vertLine.StrokeDashOffset = (output.Bottom - mousePos.Y) / 2; } Point mousePosInData = mousePos.ScreenToData(transform); string text = null; if (showVerticalLine) { double xValue = mousePosInData.X; m_longitude = xValue; //kda if (xTextMapping != null) text = xTextMapping(xValue); // doesnot have xTextMapping or it returned null if (text == null) text = GetRoundedValue(visible.Left, visible.Right, xValue); if (!String.IsNullOrEmpty(customXFormat)) text = String.Format(customXFormat, text); horizTextBlock.Text = text; } double width = horizGrid.ActualWidth; double x = mousePos.X + blockShift.X; if (x + width > output.Right) { x = mousePos.X - blockShift.X - width; } Canvas.SetLeft(horizGrid, x); if (showHorizontalLine) { double yValue = mousePosInData.Y; m_latitude = yValue; // kda text = null; if (yTextMapping != null) text = yTextMapping(yValue); if (text == null) text = GetRoundedValue(visible.Bottom, visible.Top, yValue); if (!String.IsNullOrEmpty(customYFormat)) text = String.Format(customYFormat, text); vertTextBlock.Text = text; } // by default vertGrid is positioned on the top of line. double height = vertGrid.ActualHeight; double y = mousePos.Y - blockShift.Y - height; if (y < output.Top) { y = mousePos.Y + blockShift.Y; } Canvas.SetTop(vertGrid, y); Position = mousePos; }
private void UpdateUIRepresentation(Point mousePos) { if (Plotter2D == null) { return; } var transform = Plotter2D.Viewport.Transform; Rect visible = Plotter2D.Viewport.Visible; Rect output = Plotter2D.Viewport.Output; if (!output.Contains(mousePos)) { return; } horizLine.X1 = output.Left; horizLine.X2 = output.Right; horizLine.Y1 = mousePos.Y; horizLine.Y2 = mousePos.Y; vertLine.X1 = mousePos.X; vertLine.X2 = mousePos.X; vertLine.Y1 = output.Top; vertLine.Y2 = output.Bottom; if (UseDashOffset) { horizLine.StrokeDashOffset = (output.Right - mousePos.X) / 2; vertLine.StrokeDashOffset = (output.Bottom - mousePos.Y) / 2; } Point mousePosInData = mousePos.ScreenToData(transform); string text = null; if (showVerticalLine) { double xValue = mousePosInData.X; if (xTextMapping != null) { text = xTextMapping(xValue); } // doesnot have xTextMapping or it returned null if (text == null) { text = GetRoundedValue(visible.Left, visible.Right, xValue); } if (!String.IsNullOrEmpty(customXFormat)) { text = String.Format(customXFormat, text); } horizTextBlock.Text = text; } double width = horizGrid.ActualWidth; double x = mousePos.X + blockShift.X; if (x + width > output.Right) { x = mousePos.X - blockShift.X - width; } Canvas.SetLeft(horizGrid, x); if (showHorizontalLine) { double yValue = mousePosInData.Y; text = null; if (yTextMapping != null) { text = yTextMapping(yValue); } if (text == null) { text = GetRoundedValue(visible.Bottom, visible.Top, yValue); } if (!String.IsNullOrEmpty(customYFormat)) { text = String.Format(customYFormat, text); } vertTextBlock.Text = text; } // by default vertGrid is positioned on the top of line. double height = vertGrid.ActualHeight; double y = mousePos.Y - blockShift.Y - height; if (y < output.Top) { y = mousePos.Y + blockShift.Y; } Canvas.SetTop(vertGrid, y); Position = mousePos; }