Beispiel #1
0
        public void DrawRectangle(WindowsPen pen, int x, int y, int width, int height)
        {
            Debug.Assert(pen != null, "pen == null");

            HandleRef hdc = new HandleRef(DeviceContext, DeviceContext.Hdc);

            if (pen != null)
            {
                DeviceContext.SelectObject(pen.HPen, GdiObjectType.Pen);
            }

            Gdi32.R2 rasterOp = DeviceContext.BinaryRasterOperation;

            if (rasterOp != Gdi32.R2.COPYPEN)
            {
                rasterOp = DeviceContext.SetRasterOperation(Gdi32.R2.COPYPEN);
            }

            Gdi32.SelectObject(hdc, Gdi32.GetStockObject(Gdi32.StockObject.HOLLOW_BRUSH));

            // Add 1 to width and height to create the 'bounding box' (convert from point to size).
            IntUnsafeNativeMethods.Rectangle(hdc, x, y, x + width, y + height);

            if (rasterOp != Gdi32.R2.COPYPEN)
            {
                DeviceContext.SetRasterOperation(rasterOp);
            }
        }
Beispiel #2
0
        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(DeviceContext, DeviceContext.Hdc);

            DeviceContextBinaryRasterOperationFlags rasterOp = DeviceContext.BinaryRasterOperation;
            DeviceContextBackgroundMode             bckMode  = DeviceContext.BackgroundMode;

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                rasterOp = DeviceContext.SetRasterOperation(DeviceContextBinaryRasterOperationFlags.CopyPen);
            }

            if (bckMode != DeviceContextBackgroundMode.Transparent)
            {
                bckMode = DeviceContext.SetBackgroundMode(DeviceContextBackgroundMode.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 != DeviceContextBackgroundMode.Transparent)
            {
                DeviceContext.SetBackgroundMode(bckMode);
            }

            if (rasterOp != DeviceContextBinaryRasterOperationFlags.CopyPen)
            {
                DeviceContext.SetRasterOperation(rasterOp);
            }

            IntUnsafeNativeMethods.MoveToEx(hdc, oldPoint.X, oldPoint.Y, &oldPoint);
        }