/// Drawing methods. public unsafe void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); if (pen != null) { // 1. Select the pen in the DC Gdi32.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } // 2. call the functions // we first draw a path that goes : // from center of pie, draw arc (this draw the line to the beginning of the arc // then, draw the closing line. // paint the path with the pen int sideLength = Math.Min(bounds.Width, bounds.Height); Point p = new Point(bounds.X + sideLength / 2, bounds.Y + sideLength / 2); int radius = sideLength / 2; IntUnsafeNativeMethods.BeginPath(hdc); Point oldPoint = default; IntUnsafeNativeMethods.MoveToEx(hdc, p.X, p.Y, &oldPoint); IntUnsafeNativeMethods.AngleArc(hdc, p.X, p.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, p.X, p.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
public void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); DeviceContextBinaryRasterOperationFlags binaryRasterOperation = this.dc.BinaryRasterOperation; DeviceContextBackgroundMode backgroundMode = this.dc.BackgroundMode; if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen) { binaryRasterOperation = this.dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen); } if (backgroundMode != DeviceContextBackgroundMode.Transparent) { backgroundMode = this.dc.SetBackgroundMode(DeviceContextBackgroundMode.Transparent); } if (pen != null) { this.dc.SelectObject(pen.HPen, GdiObjectType.Pen); } IntNativeMethods.POINT pt = new IntNativeMethods.POINT(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, pt); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (backgroundMode != DeviceContextBackgroundMode.Transparent) { this.dc.SetBackgroundMode(backgroundMode); } if (binaryRasterOperation != DeviceContextBinaryRasterOperationFlags.CopyPen) { this.dc.SetRasterOperation(binaryRasterOperation); } IntUnsafeNativeMethods.MoveToEx(hdc, pt.x, pt.y, null); }
public void DrawPie(WindowsPen pen, Rectangle bounds, float startAngle, float sweepAngle) { HandleRef hdc = new HandleRef(this.dc, this.dc.Hdc); if (pen != null) { IntUnsafeNativeMethods.SelectObject(hdc, new HandleRef(pen, pen.HPen)); } int num = Math.Min(bounds.Width, bounds.Height); Point point = new Point(bounds.X + (num / 2), bounds.Y + (num / 2)); int radius = num / 2; IntUnsafeNativeMethods.BeginPath(hdc); IntUnsafeNativeMethods.MoveToEx(hdc, point.X, point.Y, null); IntUnsafeNativeMethods.AngleArc(hdc, point.X, point.Y, radius, startAngle, sweepAngle); IntUnsafeNativeMethods.LineTo(hdc, point.X, point.Y); IntUnsafeNativeMethods.EndPath(hdc); IntUnsafeNativeMethods.StrokePath(hdc); }
public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc); Gdi32.R2 rasterOp = DeviceContext.BinaryRasterOperation; Gdi32.BKMODE bckMode = DeviceContext.BackgroundMode; if (rasterOp != Gdi32.R2.COPYPEN) { rasterOp = DeviceContext.SetRasterOperation(Gdi32.R2.COPYPEN); } if (bckMode != Gdi32.BKMODE.TRANSPARENT) { bckMode = DeviceContext.SetBackgroundMode(Gdi32.BKMODE.TRANSPARENT); } if (pen != null) { DeviceContext.SelectObject(pen.HPen, GdiObjectType.Pen); } Point oldPoint = new Point(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != Gdi32.BKMODE.TRANSPARENT) { DeviceContext.SetBackgroundMode(bckMode); } if (rasterOp != Gdi32.R2.COPYPEN) { DeviceContext.SetRasterOperation(rasterOp); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint); }
public unsafe void DrawLine(WindowsPen pen, int x1, int y1, int x2, int y2) { HandleRef hdc = new HandleRef(dc, dc.Hdc); DeviceContextBinaryRasterOperationFlags rasterOp = dc.BinaryRasterOperation; DeviceContextBackgroundMode bckMode = dc.BackgroundMode; if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { rasterOp = dc.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen); } if (bckMode != DeviceContextBackgroundMode.Transparent) { bckMode = dc.SetBackgroundMode(DeviceContextBackgroundMode.Transparent); } if (pen != null) { dc.SelectObject(pen.HPen, GdiObjectType.Pen); } Point oldPoint = new Point(); IntUnsafeNativeMethods.MoveToEx(hdc, x1, y1, &oldPoint); IntUnsafeNativeMethods.LineTo(hdc, x2, y2); if (bckMode != DeviceContextBackgroundMode.Transparent) { dc.SetBackgroundMode(bckMode); } if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen) { dc.SetRasterOperation(rasterOp); } IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint); }