protected override void OnMouseDown(MouseEventArgs e) { isMouseDown = true; Focused = true; MousePoint = PointToClient(MousePosition); base.OnMouseDown(e); Invalidate(Needs.Select | Needs.Mouse); }
void draw_bar(Graphics g, decimal value, double wedge) { FloatRect r = Ren.ui.ClientRect; FloatPoint p = ClientMouse; p.X = Convert.ToSingle((double)value * wedge) + r.Left; using (Pen pn = new Pen(SystemColors.HotTrack, 3)) g.DrawLine(pn, p.X, r.Top, p.X, r.Bottom); }
protected override void OnMouseUp(MouseEventArgs e) { // MousePoint = MousePosition; isMouseDown = false; MouseTrail = new FloatPoint(0); base.OnMouseUp(e); Invalidate(Needs.Deselect | Needs.Mouse); }
protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); if (AutoScale) { PSIZ = ClientSize; } }
static public void ElipseToPath(GraphicsPath gp, FloatPoint xp, double radius) { FloatPoint rp = new FloatPoint(radius), hp = rp * .5f, dp = rp * 2f; FloatPoint p = xp - rp; gp.AddEllipse(p.X, p.Y, dp.X, dp.Y); }
static public FloatPoint Limit(this FloatPoint input, FloatPoint min, FloatPoint max) { var result = input.Clone(); result.X = result.X.MinMax(min.X, max.X).ToSingle(); result.Y = result.Y.MinMax(min.Y, max.Y).ToSingle(); return(result); }
static public FloatPoint[] MeasureRange(string str, Font fnt) { FloatPoint[] hp = new FloatPoint[str.Length]; for (int i = 0; i < str.Length; i++) { hp[i] = Measure(char_str(str[i]), fnt); } return(hp); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (SC == null || SC.HasRenderError) { return; } SC.CalculateRows(this.ClientSize, data); float y = 0; int RB = 0; int[] a = SC.RowsAndCollumns.KeyArray; foreach (int i in a) { List <long> ll = SC.RowsAndCollumns[i]; FloatPoint rs = SC.GetRowMaxHeight(data, ll.ToArray()); float xBegin = 0; foreach (long lX in SC.RowsAndCollumns[i]) { RectangleF rf = new RectangleF(xBegin, y + AutoScrollPosition.Y, data[lX].Width, data[lX].Height); RectangleF rx = rf; rx.Inflate(-1, -1); e.Graphics.DrawRectangle(SystemPens.WindowFrame, rx.X, rx.Y, rx.Width, rx.Height); { // begin: render image if (IsFileMode && ilx.Thumbnails.ContainsKey(ilx.Files[RB])) { e.Graphics.DrawImage(ilx.Thumbnails[ilx.Files[RB]], rx.X, rx.Y); } } // end: render image if (!DrawText) { string strout = !IsFileMode? string.Format("{0}.{1}", i, RB) : string.Format("{0}.{1}\rHas: {2}", ilx.Files[RB], RB, ilx.Thumbnails.ContainsKey(ilx.Files[RB])) ; fsettings.RenderString(e.Graphics, strout, rx); } xBegin += data[lX].Width; RB++; } y += rs.Y; } a = null; AutoScrollMinSize = new FloatPoint(0, y + 1); }
public bool HitTestText(FloatPoint test) { GraphicsPath tp = GP; Region reg = new Region(tp); bool ht = reg.IsVisible(test); reg.Dispose(); tp.Dispose(); return(ht); }
FloatPoint GetBiggerY(params FloatPoint[] value) { FloatPoint tvalue = FloatPoint.Empty; foreach (FloatPoint f in value) { tvalue.Y = (tvalue.Y > f.Y) ? tvalue.Y : f.Y; } return(tvalue); }
public void AlighToBottom() { if (ParentElement == null) { return; } Location = new FloatPoint { X = Location.X, Y = ParentElement.Size.Y - Size.Y }; }
public void AlignToTop() { if (ParentElement == null) { return; } Location = new FloatPoint { X = Location.X, Y = 0 }; }
FloatPoint GetBiggerX(params FloatPoint[] value) { FloatPoint tvalue = FloatPoint.Empty; foreach (FloatPoint f in value) { tvalue.X = (tvalue.X > f.X) ? tvalue.X : f.X; } return(tvalue); }
public FloatPoint GetRowMaxHeight(DICT <long, FloatRect> basis, params long[] items) { FloatPoint point = new FloatPoint(0, 0); foreach (long i in items) { point.Y = GetBigger(basis[i].X, (float)basis[i].Size.Y, point.Y); } return(point); }
public void AlignToLeft() { if (ParentElement == null) { return; } Location = new FloatPoint { X = 0, Y = Location.Y }; }
static public FloatPoint[] CirclePoints(float phase, FloatPoint box_dimension, FloatPoint size, int _count) { List <FloatPoint> points = new List <FloatPoint>(); for (float i = 0; i < _count; i++) { points.Add(CirclePoint(i, _count, phase)); } return(points.ToArray()); }
public void AlignToRight() { if (ParentElement == null) { return; } Location = new FloatPoint { X = ParentElement.Size.X - Size.X, Y = Location.Y }; }
public void Draw(FloatPoint center, Vector2 size) { Sb.Draw(Texture, destinationRectangle: new Rectangle((int)center.X, (int)center.Y, (int)size.X, (int)size.Y), sourceRectangle: new Rectangle(0, 0, (int)SizeX, (int)SizeY), color: Color.White, rotation: (MathHelper.PiOver2 / 3.0f) + (MathHelper.PiOver2 / 1.5f) * Rotation, origin: new Vector2(size.X / 2, size.Y / 2) ); }
public void SetControlPoint(int index, FloatPoint p) { if (index == 0) { controlLeft = p; } else { controlRight = p; } }
static public FloatPoint Measure(int index, Graphics fx) { if (index == -1) { return(FloatPoint.Empty); } FloatPoint hp = FloatPoint.Empty; using (Font fnt = CreateFont(index)) { hp = fx.MeasureString(fnt.Name, fnt); } return(hp); }
static public FloatPoint[] ScalePoints(FloatPoint box, FloatPoint size, int _count, float scale_by) { List <FloatPoint> points = new List <FloatPoint>(); FloatPoint scale = FloatPoint.FlattenPoint(box, false); for (float i = -_count; i < _count; i++) { points.Add(scale * scale_by * 0.5f); } return(points.ToArray()); }
static public FloatPoint Measure(int index) { if (index == -1) { return(FloatPoint.Empty); } FloatPoint hp = FloatPoint.Empty; using (Font fnt = CreateFont(index)) { hp = Measure(fnt); } return(hp); }
static public bool HitTest(FloatPoint Center, float CircleRadius, FloatPoint TestPoint) { FloatPoint newPoint = Center - TestPoint, maxPoint = HitTestMaxPoint(Center, CircleRadius), minPoint = HitTestMinPoint(Center, CircleRadius); return(newPoint.Slope <= new FloatPoint(CircleRadius).Slope); //double Slope = newPoint.Slope; // return ( TestPoint.IsLEq(maxPoint) ) && ( TestPoint.IsGEq(minPoint) ); }
public void drawRelativeLine(FloatPoint pos1, FloatPoint pos2, Brush color, int width) { double widthHalf = CanvasGrid.ActualWidth / 2; double heightHalf = CanvasGrid.ActualHeight / 2; Debug.WriteLine("FloatPos1: {0}, FloatPos2: {1}", pos1, pos2); drawLine(new Point { X = pos1.X * widthHalf + widthHalf, Y = pos1.Y * heightHalf + heightHalf }, new Point { X = pos2.X * widthHalf + widthHalf, Y = pos2.Y * heightHalf + heightHalf }, Brushes.White, 10); }
public DICT <long, FloatRect> Imagine(ImageLoader il, FloatPoint TSiz) { IsFileMode = true; ilx = il; DICT <long, FloatRect> items = new DICT <long, FloatRect>(); long incr = 0; foreach (FileInfo fi in il.Files) { items.Add(incr++, new FloatRect(0, 0, TSiz.X, TSiz.Y)); } return(data = items); }
void drawdot(Graphics g, FloatRect clientrect, int wedge) { float line1 = GetLineHeight(g, big, 1); NoteTransport s = NoteSegment; FloatPoint f = s.ClientInput; f += clientrect.Location; f.Y -= line1; f.Y -= line1; g.DrawString(s.Human, big, SystemBrushes.WindowText, f); s = null; }
void Render(Graphics g) { FloatPoint h = HalfPoint; string value = string.Format("{0:N0}x{1:N0}", ClientSize.Width, ClientSize.Height); FloatPoint posText = new FloatPoint(0, HalfPoint.Y); posText.Y -= HalfLineHeight; using (Pen line = new Pen(LineColor, 1)) g.DrawLine(line, 0, h.Y, ClientSize.Width, h.Y); using (Brush fg = new SolidBrush(BackColor)) g.DrawString(value, Font, fg, posText + -2); using (Brush fg = new SolidBrush(BackColor)) g.DrawString(value, Font, fg, posText + 2); using (Brush fg = new SolidBrush(LineColor)) g.DrawString(value, Font, fg, posText); }
public void AlignCenterHorizontaly() { if (ParentElement == null) { return; } var deltaX = ParentElement.Size.X - Size.X; Location = new FloatPoint { X = deltaX / 2, Y = Location.Y }; }
public void AlignCenterVerticaly() { if (ParentElement == null) { return; } var deltaY = ParentElement.Size.Y - Size.Y; Location = new FloatPoint { X = Location.X, Y = deltaY / 2 }; }
protected override void OnMouseMove(MouseEventArgs e) { if (!IsMouseDown) { base.OnMouseMove(e); Invalidate(Needs.Mouse); return; } MouseTrail = (new FloatPoint(PointToClient(MousePosition)) - MousePoint); base.OnMouseMove(e); Invalidate(Needs.Select | Needs.Mouse); }
/// <summary> /// Load an array of locations (FloatPoint instances) from a binary file. /// The file format includes 8 bytes (unused), then a point count (int32), then each location as a pair /// of floats. /// </summary> public static FloatPoint[] LoadLocations(string filePath) { if (!File.Exists(filePath)) { string cFilePath = filePath.Replace("locs", "clocs"); if (File.Exists(cFilePath)) return LoadAndConvertCompressedLocs(cFilePath); return new FloatPoint[0]; } FloatPoint[] Locations = new FloatPoint[0]; using (Stream inputStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (BinaryReader reader = new BinaryReader(inputStream)) { reader.ReadInt32(); reader.ReadInt32(); int pointCount = reader.ReadInt32(); Locations = new FloatPoint[pointCount]; byte[] buffer = reader.ReadBytes(pointCount*sizeof (float)*2); float[] tempFloatBuffer = new float[pointCount*2]; System.Buffer.BlockCopy(buffer, 0, tempFloatBuffer, 0, buffer.Length); for (int pointIndex = 0; pointIndex < pointCount; pointIndex++) { Locations[pointIndex] = new FloatPoint { X = tempFloatBuffer[pointIndex*2], Y = tempFloatBuffer[pointIndex*2 + 1] }; } } } return Locations; }
/// <summary> /// Write out locations to a .locs file. /// </summary> public static void SaveLocations(FloatPoint[] locs, string outputPath) { using (FileStream outputStream = new FileStream(outputPath, FileMode.Create)) { using (BinaryWriter locsWriter = new BinaryWriter(outputStream)) { locsWriter.Write(1); locsWriter.Write(1.0f); if (locs == null) { locsWriter.Write(0); } else { locsWriter.Write(locs.Length); for (int pointIndex = 0; pointIndex < locs.Length; pointIndex++) { locsWriter.Write(locs[pointIndex].X); locsWriter.Write(locs[pointIndex].Y); } } } } }
public static byte[] CompressLocs(FloatPoint[] locs, out byte[] bins, out uint[] origIndexMap) { int maxXbins = (int) Math.Ceiling(ImageWidth/(double) blockSize); int maxYbins = (int) Math.Ceiling(ImageHeight/(double) blockSize); bins = new byte[maxXbins*maxYbins]; List<byte>[] binLocs = new List<byte>[bins.Length]; List<uint>[] origLocsIndex = new List<uint>[bins.Length]; int totalLocs = 0; // bin locs for (int clusterIndex = 0; clusterIndex < locs.Length; clusterIndex++) { if (locs[clusterIndex].X < 0 || locs[clusterIndex].Y < 0) continue; // out of defined range, can throw away these outliers // determine bin index int xbin = (int) Math.Floor(locs[clusterIndex].X/blockSize); int ybin = (int) Math.Floor(locs[clusterIndex].Y/blockSize); int binIndex = ybin*maxXbins + xbin; if (xbin >= maxXbins) continue; if (ybin >= maxYbins) continue; // add locs to bin bins[binIndex]++; totalLocs++; if (binLocs[binIndex] == null) binLocs[binIndex] = new List<byte>(blockSize*blockSize); if (origLocsIndex[binIndex] == null) origLocsIndex[binIndex] = new List<uint>(blockSize*blockSize); binLocs[binIndex].Add(Convert.ToByte((locs[clusterIndex].X%blockSize)*10f)); binLocs[binIndex].Add(Convert.ToByte((locs[clusterIndex].Y%blockSize)*10f)); origLocsIndex[binIndex].Add((uint) clusterIndex); } // combine all binned locs into one big array byte[] clocs = new byte[totalLocs*2]; origIndexMap = new uint[totalLocs]; int offset = 0; int origOffset = 0; for (int binIndex = 0; binIndex < binLocs.Length; binIndex++) { if (binLocs[binIndex] == null) continue; // no locs in bin, move on foreach (byte locByte in binLocs[binIndex]) { clocs[offset] = locByte; offset++; } foreach (uint origIndexVal in origLocsIndex[binIndex]) { origIndexMap[origOffset] = origIndexVal; origOffset++; } } return clocs; }
//draws the co-ordinates on x and y axes. void DrawPoints(Graphics g) { float xDiff = xAxis.X - origin.X; float yDiff = origin.Y - yAxis.Y; float xStep = xDiff/GRAPHSTRUCT.PointsOnXAxis; float yStep = yDiff/GRAPHSTRUCT.PointsOnYAxis; var fpt = new FloatPoint(origin.X, origin.Y) {Value = 0}; graphPointsX.Add(fpt); graphPointsY.Add(fpt); var p = new Pen(textColor); Brush b = new SolidBrush(textColor); var f = new Font(Font.FontFamily, Font.Size); for (int i = 1; i <= GRAPHSTRUCT.PointsOnXAxis; i++) { float xAxisX = origin.X + (i*xStep); float xAxisY = origin.Y; g.DrawLine(p, xAxisX, xAxisY - 2, xAxisX, xAxisY + 2); float val = GRAPHSTRUCT.StartValueXAxis + ((i - 1)*GRAPHSTRUCT.StepXAxis); g.DrawString(val.ToString(), f, b, xAxisX - 5, xAxisY + 3); fpt.X = xAxisX; fpt.Y = 0; fpt.Value = val; graphPointsX.Add(fpt); } for (int j = 1; j <= GRAPHSTRUCT.PointsOnYAxis; j++) { float yAxisX = origin.X; float yAxisY = origin.Y - (j*yStep); g.DrawLine(p, yAxisX - 2, yAxisY, yAxisX + 2, yAxisY); float val = GRAPHSTRUCT.StartValueYAxis + ((j - 1)*GRAPHSTRUCT.StepYAxis); g.DrawString(val.ToString(), f, b, yAxisX - 15, yAxisY); fpt.X = 0; fpt.Y = yAxisY; fpt.Value = val; graphPointsY.Add(fpt); } f.Dispose(); b.Dispose(); p.Dispose(); }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="fp"></param> /// <returns></returns> public static bool OffsetFilterAntiAlias(Bitmap b, FloatPoint[,] fp) { Bitmap bSrc = (Bitmap)b.Clone(); // GDI+ still lies to us - the return format is BGR, NOT RGB. BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); BitmapData bmSrc = bSrc.LockBits(new Rectangle(0, 0, bSrc.Width, bSrc.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int scanline = bmData.Stride; System.IntPtr Scan0 = bmData.Scan0; System.IntPtr SrcScan0 = bmSrc.Scan0; unsafe { byte* p = (byte*)(void*)Scan0; byte* pSrc = (byte*)(void*)SrcScan0; int nOffset = bmData.Stride - b.Width * 3; int nWidth = b.Width; int nHeight = b.Height; double xOffset, yOffset; double fraction_x, fraction_y, one_minus_x, one_minus_y; int ceil_x, ceil_y, floor_x, floor_y; Byte p1, p2; for (int y = 0; y < nHeight; ++y) { for (int x = 0; x < nWidth; ++x) { xOffset = fp[x, y].X; yOffset = fp[x, y].Y; // Setup floor_x = (int)Math.Floor(xOffset); floor_y = (int)Math.Floor(yOffset); ceil_x = floor_x + 1; ceil_y = floor_y + 1; fraction_x = xOffset - floor_x; fraction_y = yOffset - floor_y; one_minus_x = 1.0 - fraction_x; one_minus_y = 1.0 - fraction_y; if (floor_y >= 0 && ceil_y < nHeight && floor_x >= 0 && ceil_x < nWidth) { // Blue p1 = (Byte)(one_minus_x * (double)(pSrc[floor_y * scanline + floor_x * 3]) + fraction_x * (double)(pSrc[floor_y * scanline + ceil_x * 3])); p2 = (Byte)(one_minus_x * (double)(pSrc[ceil_y * scanline + floor_x * 3]) + fraction_x * (double)(pSrc[ceil_y * scanline + 3 * ceil_x])); p[x * 3 + y * scanline] = (Byte)(one_minus_y * (double)(p1) + fraction_y * (double)(p2)); // Green p1 = (Byte)(one_minus_x * (double)(pSrc[floor_y * scanline + floor_x * 3 + 1]) + fraction_x * (double)(pSrc[floor_y * scanline + ceil_x * 3 + 1])); p2 = (Byte)(one_minus_x * (double)(pSrc[ceil_y * scanline + floor_x * 3 + 1]) + fraction_x * (double)(pSrc[ceil_y * scanline + 3 * ceil_x + 1])); p[x * 3 + y * scanline + 1] = (Byte)(one_minus_y * (double)(p1) + fraction_y * (double)(p2)); // Red p1 = (Byte)(one_minus_x * (double)(pSrc[floor_y * scanline + floor_x * 3 + 2]) + fraction_x * (double)(pSrc[floor_y * scanline + ceil_x * 3 + 2])); p2 = (Byte)(one_minus_x * (double)(pSrc[ceil_y * scanline + floor_x * 3 + 2]) + fraction_x * (double)(pSrc[ceil_y * scanline + 3 * ceil_x + 2])); p[x * 3 + y * scanline + 2] = (Byte)(one_minus_y * (double)(p1) + fraction_y * (double)(p2)); } } } } b.UnlockBits(bmData); bSrc.UnlockBits(bmSrc); return true; }
public static FloatPoint[] DecompressLocs(byte[] bins, byte[] clocs) { int maxXbins = (int) Math.Ceiling(ImageWidth/(double) blockSize); int numLocs = 0; // get number of locs for (int binIndex = 0; binIndex < bins.Length; binIndex++) numLocs += bins[binIndex]; if (numLocs <= 0) return new FloatPoint[0]; FloatPoint[] locations = new FloatPoint[numLocs]; float xoffset = 0; // x offset for bin float yoffset = 0; // y offset for bin int locsoffset = 0; int locsIndex = 0; for (int binIndex = 0; binIndex < bins.Length; binIndex++) { ushort numberLocs = Convert.ToUInt16(bins[binIndex]); for (int clocsIndex = 0; clocsIndex < numberLocs; clocsIndex++) { FloatPoint point = new FloatPoint { X = Convert.ToSingle(clocs[(clocsIndex*2) + locsoffset])/10f + xoffset, Y = Convert.ToSingle(clocs[(clocsIndex*2) + locsoffset + 1])/ 10f + yoffset }; locations[locsIndex] = point; locsIndex++; } locsoffset += (numberLocs*2); // update x, y bin offsets for bin if (binIndex > 0 && (binIndex + 1)%maxXbins == 0) { xoffset = 0; yoffset += blockSize; } else xoffset += blockSize; } return locations; }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="fDegree"></param> /// <param name="bSmoothing"></param> /// <returns></returns> public static bool Swirl(Bitmap b, double fDegree, bool bSmoothing /* default fDegree to .05 */) { int nWidth = b.Width; int nHeight = b.Height; FloatPoint[,] fp = new FloatPoint[nWidth, nHeight]; Point[,] pt = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double theta, radius; double newX, newY; for (int x = 0; x < nWidth; ++x) for (int y = 0; y < nHeight; ++y) { int trueX = x - mid.X; int trueY = y - mid.Y; theta = Math.Atan2((trueY), (trueX)); radius = Math.Sqrt(trueX * trueX + trueY * trueY); newX = mid.X + (radius * Math.Cos(theta + fDegree * radius)); if (newX > 0 && newX < nWidth) { fp[x, y].X = newX; pt[x, y].X = (int)newX; } else fp[x, y].X = pt[x, y].X = x; newY = mid.Y + (radius * Math.Sin(theta + fDegree * radius)); if (newY > 0 && newY < nHeight) { fp[x, y].Y = newY; pt[x, y].Y = (int)newY; } else fp[x, y].Y = pt[x, y].Y = y; } if (bSmoothing) OffsetFilterAntiAlias(b, fp); else OffsetFilterAbs(b, pt); return true; }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="factor"></param> /// <param name="bSmoothing"></param> /// <returns></returns> public static bool TimeWarp(Bitmap b, Byte factor, bool bSmoothing) { int nWidth = b.Width; int nHeight = b.Height; FloatPoint[,] fp = new FloatPoint[nWidth, nHeight]; Point[,] pt = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double theta, radius; double newX, newY; for (int x = 0; x < nWidth; ++x) for (int y = 0; y < nHeight; ++y) { int trueX = x - mid.X; int trueY = y - mid.Y; theta = Math.Atan2((trueY), (trueX)); radius = Math.Sqrt(trueX * trueX + trueY * trueY); double newRadius = Math.Sqrt(radius) * factor; newX = mid.X + (newRadius * Math.Cos(theta)); if (newX > 0 && newX < nWidth) { fp[x, y].X = newX; pt[x, y].X = (int)newX; } else { fp[x, y].X = 0.0; pt[x, y].X = 0; } newY = mid.Y + (newRadius * Math.Sin(theta)); if (newY > 0 && newY < nHeight) { fp[x, y].Y = newY; pt[x, y].Y = (int)newY; } else { fp[x, y].Y = 0.0; pt[x, y].Y = 0; } } if (bSmoothing) OffsetFilterAbs(b, pt); else OffsetFilterAntiAlias(b, fp); return true; }
/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="nWave"></param> /// <param name="bSmoothing"></param> /// <returns></returns> public static bool Water(Bitmap b, short nWave, bool bSmoothing) { int nWidth = b.Width; int nHeight = b.Height; FloatPoint[,] fp = new FloatPoint[nWidth, nHeight]; Point[,] pt = new Point[nWidth, nHeight]; Point mid = new Point(); mid.X = nWidth / 2; mid.Y = nHeight / 2; double newX, newY; double xo, yo; for (int x = 0; x < nWidth; ++x) for (int y = 0; y < nHeight; ++y) { xo = ((double)nWave * Math.Sin(2.0 * 3.1415 * (float)y / 128.0)); yo = ((double)nWave * Math.Cos(2.0 * 3.1415 * (float)x / 128.0)); newX = (x + xo); newY = (y + yo); if (newX > 0 && newX < nWidth) { fp[x, y].X = newX; pt[x, y].X = (int)newX; } else { fp[x, y].X = 0.0; pt[x, y].X = 0; } if (newY > 0 && newY < nHeight) { fp[x, y].Y = newY; pt[x, y].Y = (int)newY; } else { fp[x, y].Y = 0.0; pt[x, y].Y = 0; } } if (bSmoothing) OffsetFilterAbs(b, pt); else OffsetFilterAntiAlias(b, fp); return true; }
//draws the X and Y axes and also set the origin and x and y axes points //This method should be called before any other drawing method. void DrawAxes(Graphics g) { //get the bounds of our region.We will draw within the region RectangleF rect = Region.GetBounds(g); float xOrigin = rect.Left + 20; float yOrigin = rect.Bottom - 70; origin = new FloatPoint(xOrigin, yOrigin); xAxis = new FloatPoint(rect.Right - 20, origin.Y); yAxis = new FloatPoint(origin.X, rect.Top); var axisPen = new Pen(axesColor); g.DrawLine(axisPen, origin.X, origin.Y, xAxis.X, xAxis.Y); g.DrawLine(axisPen, origin.X, origin.Y, yAxis.X, yAxis.Y); axisPen.Dispose(); }
//Given a display point, this function will point the actual co-ordinates //for this point on our graph. It acts like the ScreenToClient function in Windows FloatPoint FindLocationOnGraph(Point pt) { float diffValue, finalYValue; float finalXValue = finalYValue = 0; for (int i = 0; i < graphPointsX.Count; i++) { //store the current point var current = (FloatPoint) graphPointsX[i]; //if points X is lesser that current points Value if (pt.X < current.Value) { var previous = (FloatPoint) graphPointsX[i - 1]; //store diff between current X and previous X coordinate float diffX = current.X - previous.X; //store difference between values of current and prev points diffValue = current.Value - previous.Value; float unitsPerCoordinate = diffValue/diffX; finalXValue = ((pt.X - previous.Value)/unitsPerCoordinate) + previous.X; break; } if (pt.X == current.Value) { finalXValue = current.X; } } for (int j = 0; j < graphPointsY.Count; j++) { var current = (FloatPoint) graphPointsY[j]; if (pt.Y < current.Value) { var previous = (FloatPoint) graphPointsY[j - 1]; float diffY = current.Y - previous.Y; diffValue = current.Value - previous.Value; float unitsPerCoordinate = diffValue/diffY; finalYValue = ((pt.Y - previous.Value)/unitsPerCoordinate) + previous.Y; break; } if (pt.Y == current.Value) { finalYValue = current.Y; } } var fpNew = new FloatPoint(finalXValue, finalYValue); return fpNew; }