/// <summary> /// Update location of object according given x/y offset /// </summary> /// <param name="_pane"></param> /// <param name="dx">x offset in screen</param> /// <param name="dy">y offset in screen</param> virtual public void UpdateLocation(PaneBase _pane, float dx, float dy) { GraphPane pane = _pane as GraphPane; // convert location to screen coordinate PointF ptPix1 = pane.GeneralTransform(_location.X1, _location.Y1, _location.CoordinateFrame); PointF ptPix2 = pane.GeneralTransform(_location.X2, _location.Y2, _location.CoordinateFrame); // calc new position ptPix1.X += (float)dx; ptPix1.Y += (float)dy; ptPix2.X += (float)dx; ptPix2.Y += (float)dy; // convert to user coordinate PointD pt1 = pane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame); PointD pt2 = pane.GeneralReverseTransform(ptPix2, _location.CoordinateFrame); _location.X = pt1.X; _location.Y = pt1.Y; _location.Width = pt2.X - pt1.X; _location.Height = pt2.Y - pt1.Y; OnLocationChanged(pane, dx, dy); }
/// <summary> /// Render this object to the specified <see cref="Graphics"/> device /// This method is normally only called by the Draw method /// of the parent <see cref="ArrowList"/> collection object. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public void Draw(Graphics g, GraphPane pane, double scaleFactor) { // Convert the arrow coordinates from the user coordinate system // to the screen coordinate system PointF pix1 = pane.GeneralTransform(new PointF(this.x1, this.y1), this.coordinateFrame); PointF pix2 = pane.GeneralTransform(new PointF(this.x2, this.y2), this.coordinateFrame); // get a scaled size for the arrowhead float scaledSize = (float)(this.size * scaleFactor); // calculate the length and the angle of the arrow "vector" double dy = pix2.Y - pix1.Y; double dx = pix2.X - pix1.X; float angle = (float)Math.Atan2(dy, dx) * 180.0F / (float)Math.PI; float length = (float)Math.Sqrt(dx * dx + dy * dy); // Save the old transform matrix Matrix transform = g.Transform; // Move the coordinate system so it is located at the starting point // of this arrow g.TranslateTransform(pix1.X, pix1.Y); // Rotate the coordinate system according to the angle of this arrow // about the starting point g.RotateTransform(angle); // get a pen according to this arrow properties Pen pen = new Pen(this.color, this.penWidth); // Draw the line segment for this arrow g.DrawLine(pen, 0, 0, length, 0); // Only show the arrowhead if required if (this.isArrowHead) { SolidBrush brush = new SolidBrush(this.color); // Create a polygon representing the arrowhead based on the scaled // size PointF[] polyPt = new PointF[4]; float hsize = scaledSize / 3.0F; polyPt[0].X = length; polyPt[0].Y = 0; polyPt[1].X = length - size; polyPt[1].Y = hsize; polyPt[2].X = length - size; polyPt[2].Y = -hsize; polyPt[3] = polyPt[0]; // render the arrowhead g.FillPolygon(brush, polyPt); } // Restore the transform matrix back to its original state g.Transform = transform; }
public override RectangleF BoundingRect(PaneBase pane) { GraphPane gPane = pane as GraphPane; float x1 = 100000; float y1 = 100000; float x2 = -100000; float y2 = -100000; foreach (PointD pt in _points) { // Convert the coordinates from the user coordinate system // to the screen coordinate system // Offset the points by the location value //PointF pixPt = SafeTransform(pt, gPane, _location.CoordinateFrame); PointF pixPt = gPane.GeneralTransform(pt.X, pt.Y, _location.CoordinateFrame); x1 = Math.Min(x1, pixPt.X); y1 = Math.Min(y1, pixPt.Y); x2 = Math.Max(x2, pixPt.X); y2 = Math.Max(y2, pixPt.Y); } return(new RectangleF(x1, y1, x2 - x1, y2 - y1)); }
override public GraphicsPath MakePath(PaneBase pane) { GraphicsPath path = new GraphicsPath(); //PointF pix1 = this.Location.TransformTopLeft(pane); //PointF pix2 = this.Location.TransformBottomRight(pane); GraphPane gPane = pane as GraphPane; PointF pix1 = gPane.GeneralTransform(_location.TopLeft, _location.CoordinateFrame); PointF pix2 = gPane.GeneralTransform(_location.BottomRight, _location.CoordinateFrame); RectangleF pixRect = new RectangleF(Math.Min(pix1.X, pix2.X), Math.Min(pix1.Y, pix2.Y), Math.Abs(pix2.X - pix1.X), Math.Abs(pix2.Y - pix1.Y)); path.AddRectangle(pixRect); return(path); }
internal PointF SafeTransform(PointD pt, GraphPane pane, CoordType coord) { PointF pixPt = new PointF(); if (pt.X != 0) // for first point { pixPt = pane.GeneralTransform(pt.X, pt.Y, coord); } return(pixPt); }
/// <summary> /// Render this <see cref="TextItem"/> object to the specified <see cref="Graphics"/> device /// This method is normally only called by the Draw method /// of the parent <see cref="TextList"/> collection object. /// </summary> /// <param name="g"> /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// </param> /// <param name="pane"> /// A reference to the <see cref="GraphPane"/> object that is the parent or /// owner of this object. /// </param> /// <param name="scaleFactor"> /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent <see cref="GraphPane"/> object using the /// <see cref="GraphPane.CalcScaleFactor"/> method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// </param> public void Draw(Graphics g, GraphPane pane, double scaleFactor) { // transform the x,y location from the user-defined // coordinate frame to the screen pixel location PointF pix = pane.GeneralTransform(new PointF(this.x, this.y), this.coordinateFrame); // Draw the text on the screen, including any frame and background // fill elements this.FontSpec.Draw(g, this.text, pix.X, pix.Y, this.alignH, this.alignV, scaleFactor); }
override public RectangleF[] EdgeRects(PaneBase pane) { RectangleF[] rects = new RectangleF[_points.Count]; GraphPane gPane = pane as GraphPane; for (int i = 0; i < rects.Length; i++) { //PointF pixPt = SafeTransform(_points[i], gPane, _location.CoordinateFrame); PointF pixPt = gPane.GeneralTransform(_points[i].X, _points[i].Y, _location.CoordinateFrame); rects[i] = new RectangleF(pixPt.X - 4, pixPt.Y - 4, 8, 8); } return(rects); }
override public PointF[] ScreenPoints(PaneBase pane) { PointF[] points = new PointF[_points.Count]; GraphPane gPane = pane as GraphPane; for (int i = 0; i < points.Length; i++) { PointF pixPt = gPane.GeneralTransform(_points[i].X, _points[i].Y, _location.CoordinateFrame); points[i] = pixPt; } return(points); }
override public GraphicsPath MakePath(PaneBase pane) { GraphicsPath path = new GraphicsPath(); bool first = true; PointF lastPt = new PointF(); GraphPane gPane = pane as GraphPane; foreach (PointD pt in _points) { // Convert the coordinates from the user coordinate system // to the screen coordinate system // Offset the points by the location value //PointF pixPt = SafeTransform(pt, gPane, _location.CoordinateFrame); PointF pixPt = gPane.GeneralTransform(pt.X, pt.Y, _location.CoordinateFrame); if (Math.Abs(pixPt.X) < 100000 && Math.Abs(pixPt.Y) < 100000) { if (first) { first = false; } else { path.AddLine(lastPt, pixPt); } lastPt = pixPt; } } if (_isClosedFigure) { path.CloseFigure(); } return(path); }
public override void UpdateLocation(PaneBase _pane, float dx, float dy) { GraphPane pane = _pane as GraphPane; // update each points for (int i = 0; i < _points.Count; i++) { // convert location to screen coordinate PointF ptPix1 = pane.GeneralTransform(_points[i].X, _points[i].Y, _location.CoordinateFrame); // calc new position ptPix1.X += (float)dx; ptPix1.Y += (float)dy; // convert to user coordinate PointD pt1 = pane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame); _points[i] = pt1; } OnLocationChanged(pane, dx, dy); }
string zedGraphControl1_PointValueEvent(ZedGraphControl sender, GraphPane pane, CurveItem curve, int iPt) { if (curve[iPt] != ppHover) { ppHover = curve[iPt]; if (pictureBox1.Visible) { pictureBox1.Visible = false; } if (curve.Label.Text == "photos") { PointF pf = pane.GeneralTransform(curve[iPt].X, curve[iPt].Y, CoordType.AxisXYScale); string[] split = curve[iPt].Tag.ToString().Split(','); pictureBox1.Image = Image.FromFile(split[1]); pictureBox1.Location = new Point(Convert.ToInt32(pf.X), Convert.ToInt32(pf.Y) - pictureBox1.Height); pictureBox1.BringToFront(); pictureBox1.Visible = true; return split[0]; } else if (curve.Label.Text.StartsWith("Anno")) { HighlightGraphs(curve[iPt].Z, curve[iPt].X - curve[iPt].Z); } } else if (curve.Label.Text == "photos") { string[] split = curve[iPt].Tag.ToString().Split(','); return split[0]; } if (curve[iPt].Tag != null) return curve[iPt].Tag.ToString(); else return curve[iPt].ToString(); }
override public void ResizeEdge(int edge, PointF pt, PaneBase pane) { // set edget to right-bottom edge when edget is -1 if (edge == int.MaxValue) { edge = 4; } // do nothing if edge is invalid if (edge < 0 || edge > 8) { return; } RectangleF[] edges = EdgeRects(pane); //RectangleF s = edges[edge]; GraphPane gPane = pane as GraphPane; // convert location to screen coordinate PointF ptPix1 = gPane.GeneralTransform(_location.X1, _location.Y1, _location.CoordinateFrame); PointF ptPix2 = gPane.GeneralTransform(_location.X2, _location.Y2, _location.CoordinateFrame); /* * // calc new position * ptPix1.X += (mousePt.X - _dragStartPt.X); * ptPix1.Y += (mousePt.Y - _dragStartPt.Y); * * ptPix2.X += (mousePt.X - _dragStartPt.X); * ptPix2.Y += (mousePt.Y - _dragStartPt.Y); * * // convert to user coordinate * PointD pt1 = pane.GeneralReverseTransform(ptPix1, obj.Location.CoordinateFrame); * PointD pt2 = pane.GeneralReverseTransform(ptPix2, obj.Location.CoordinateFrame); * * obj.Location.X = pt1.X; * obj.Location.Y = pt1.Y; * obj.Location.Width = pt2.X - pt1.X; * obj.Location.Height = pt2.Y - pt1.Y; */ //float dx = (pt.X - s.X) / pane.Rect.Width; //float dy = (pt.Y - s.Y) / pane.Rect.Height; //float dx = (pt.X - s.X - 2) ; //float dy = (pt.Y - s.Y - 2) ; /* * 0 1 2 +---------------+ | | | 7 | | 3 | | +---------------+ | 6 5 4 */ switch (edge) { case 0: //_location.X += dx; //_location.Y += dy; //_location.Width -= dx; //_location.Height -= dy; // calc new position //ptPix1.X += dx; //ptPix1.Y += dy; ptPix1.X = pt.X; ptPix1.Y = pt.Y; break; case 1: //_location.Y += dy; //_location.Height -= dy; // calc new position //ptPix1.Y += dy; ptPix1.Y = pt.Y; break; case 2: //_location.Y += dy; //_location.Width += dx; //_location.Height -= dy; // calc new position //ptPix1.Y += dy; //ptPix2.X += dx; ptPix1.Y = pt.Y; ptPix2.X = pt.X; break; case 3: //_location.Width += dx; // calc new position //ptPix2.X += dx; ptPix2.X = pt.X; break; case 4: //_location.Width += dx; //_location.Height += dy; // calc new position //ptPix2.X += dx; //ptPix2.Y += dy; ptPix2.X = pt.X; ptPix2.Y = pt.Y; break; case 5: //_location.Height += dy; // calc new position //ptPix2.Y += dy; ptPix2.Y = pt.Y; break; case 6: //_location.X += dx; //_location.Width -= dx; //_location.Height += dy; // calc new position //ptPix1.X += dx; //ptPix2.Y += dy; ptPix1.X = pt.X; ptPix2.Y = pt.Y; break; case 7: //_location.X += dx; //_location.Width -= dx; // calc new position //ptPix1.X += dx; ptPix1.X = pt.X; break; } //System.Diagnostics.Debug.WriteLine(string.Format("resize edget {4} pt1 {0} pt2 {1} s {2} pt {3} ", // ptPix1, ptPix2, s, pt, edge)); // convert to user space coordinate PointD pt1 = gPane.GeneralReverseTransform(ptPix1, _location.CoordinateFrame); PointD pt2 = gPane.GeneralReverseTransform(ptPix2, _location.CoordinateFrame); _location.X = pt1.X; _location.Y = pt1.Y; _location.Width = pt2.X - pt1.X; _location.Height = pt2.Y - pt1.Y; }
internal PointF SafeTransform(PointD pt, GraphPane pane, CoordType coord) { PointF pixPt = new PointF(); if (pt.X != 0) // for first point pixPt = pane.GeneralTransform(pt.X, pt.Y, coord); return pixPt; }