private void _data_Change(object sender, EventArgs e) { if (PlotterControl != null) { PlotterControl.Invalidate(); } }
public override void Paint(Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } if (_function == null) { return; } int clientWidth = PlotterControl.ClientRectangle.Width; if (_linesToDraw == null || _linesToDraw.Length != PlotterControl.ClientRectangle.Width) { _linesToDraw = new Point[PlotterControl.ClientRectangle.Width]; } for (int screenX = 0; screenX < clientWidth; screenX++) { double spaceX = PlotterControl.ScreenX2SpaceX(screenX); double spaceY = _function(spaceX); int screenY = PlotterControl.SpaceY2ScreenY(spaceY); _linesToDraw[screenX] = new Point(screenX, screenY); } using (Pen pen = new Pen(ForeColor, LineWidth)) { pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; gr.DrawLines(pen, _linesToDraw); } }
private void _buffer_Change(object sender, EventArgs e) { // Check this to avoid infinite recursion. if (_bufferTrimming) { return; } CheckBufferLength(); if (PlotterControl != null) { PlotterControl.Invalidate(); } }
public override void Paint(Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } if (_data.Count < 2) { return; } using (Pen pen = new Pen(ForeColor, LineWidth)) { pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; if (_continuousLine) { if (_linesToDraw == null || _linesToDraw.Length != _data.Count) { _linesToDraw = new Point[_data.Count]; } for (int i = 0; i < _data.Count; i++) { _linesToDraw[i] = LimitPoint(PlotterControl.Space2Screen(_data[i])); } gr.DrawLines(pen, _linesToDraw); } else { for (int i = 1; i < _data.Count; i += 2) { Point p1 = LimitPoint(PlotterControl.Space2Screen(_data[i - 1])); Point p2 = LimitPoint(PlotterControl.Space2Screen(_data[i])); gr.DrawLine(pen, p1, p2); } } } }
public override void Paint(System.Drawing.Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } if (_buffer.Count < 2) { return; } int linesCount = 0; switch (_stepLengthMode) { case LengthMode.Space: linesCount = (int)Math.Ceiling( PlotterControl.VisibleRectangle.Width / _stepLength) + 1; break; case LengthMode.Screen: linesCount = (int)Math.Ceiling( PlotterControl.ClientRectangle.Width / _stepLength) + 1; break; } if (linesCount > _buffer.Count) { linesCount = _buffer.Count; } using (Pen pen = new Pen(ForeColor, LineWidth)) { pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round; if (_linesToDraw == null || _linesToDraw.Length != linesCount) { _linesToDraw = new Point[linesCount]; } float vRectRight = PlotterControl.VisibleRectangle.Right; int cRectWidth = PlotterControl.ClientRectangle.Width; for (int i = 0, bufElem = _buffer.Count - 1; i < linesCount && bufElem >= 0; i++, bufElem--) { Point chartPoint = Point.Empty; switch (_stepLengthMode) { case LengthMode.Space: chartPoint = PlotterControl.Space2Screen( new PointF(vRectRight - i * _stepLength, _buffer[bufElem])); break; case LengthMode.Screen: chartPoint = new Point( (int)(cRectWidth - i * _stepLength), PlotterControl.SpaceY2ScreenY(_buffer[bufElem])); break; } _linesToDraw[i] = LimitPoint(chartPoint); } gr.DrawLines(pen, _linesToDraw); } }
public override void Paint(System.Drawing.Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } if (_function == null) { return; } int screenWidth = PlotterControl.ClientRectangle.Width; int screenHeight = PlotterControl.ClientRectangle.Height; Bitmap bmp = new Bitmap(screenWidth, screenHeight, PixelFormat.Format32bppArgb); Rectangle wholeBitmap = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmpData = bmp.LockBits(wholeBitmap, ImageLockMode.WriteOnly, bmp.PixelFormat); try { int strideAbs = Math.Abs(bmpData.Stride); bool bottomUp = bmpData.Stride < 0; byte[] bmpBuf = new byte[strideAbs * bmpData.Height]; int scanLine = 0; int yFirst = bottomUp ? bmpData.Height - 1 : 0; int yAfterLast = bottomUp ? -1 : bmpData.Height; int dy = bottomUp ? -1 : 1; for (int screenY = yFirst; screenY != yAfterLast; screenY += dy, scanLine += strideAbs) { double y = PlotterControl.ScreenY2SpaceY(screenY); int pixelIndex = scanLine; for (int screenX = 0; screenX < bmpData.Width; screenX++) { double x = PlotterControl.ScreenX2SpaceX(screenX); Color col = _function(x, y); bmpBuf[pixelIndex++] = col.B; bmpBuf[pixelIndex++] = col.G; bmpBuf[pixelIndex++] = col.R; bmpBuf[pixelIndex++] = col.A; } } System.Runtime.InteropServices.Marshal.Copy(bmpBuf, 0, bmpData.Scan0, bmpBuf.Length); } finally { bmp.UnlockBits(bmpData); } /*for (int screenY = 0; screenY < screenHeight; screenY++) * { * double y = PlotterControl.ScreenY2SpaceY(screenY); * for (int screenX = 0; screenX < screenWidth; screenX++) * { * double x = PlotterControl.ScreenX2SpaceX(screenX); * bmp.SetPixel(screenX, screenY, _function(x, y)); * } * }*/ gr.DrawImage(bmp, 0, 0); }
public override void Paint(Graphics gr) { if (PlotterControl == null) { throw new InvalidOperationException("PlotterControl is null"); } int diameter = 2 * PointSize; Point origin = PlotterControl.Space2Screen(new PointF(0.0f, 0.0f)); using (Pen pen = new Pen(ForeColor, LineWidth)) { foreach (ChartPoint point in _points) { /* Point is a structure, so we can afford it. If it were a class, * this would be very memory-consuming. */ Point sigPoint = PlotterControl.Space2Screen(point.Coords); pen.Color = (point.Color == Color.Empty) ? ForeColor : point.Color; switch (point.Shape) { case PointShape.Circle: gr.DrawEllipse(pen, sigPoint.X - _pointSize, sigPoint.Y - _pointSize, diameter, diameter); break; case PointShape.Square: gr.DrawRectangle(pen, sigPoint.X - _pointSize, sigPoint.Y - _pointSize, diameter, diameter); break; } if (point.DrawLines) { // Draw the dashed line from the origin to the signal point. pen.DashStyle = DashStyle.Dash; gr.DrawLine(pen, origin, sigPoint); /* Draw the dotted lines from the signal point to the axes. * The line is drawn not strictly from the signal point, but * from the ellipse'point boundary. The Math.Sign method allows * us to support the both axis sides correctly. */ pen.DashStyle = DashStyle.Dot; gr.DrawLine(pen, sigPoint.X, sigPoint.Y + _pointSize * Math.Sign(point.Coords.Y), sigPoint.X, origin.Y); gr.DrawLine(pen, sigPoint.X - _pointSize * Math.Sign(point.Coords.X), sigPoint.Y, origin.X, sigPoint.Y); // Restore the original DashStyle settings. pen.DashStyle = DashStyle.Solid; } } } }