예제 #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);
            }
        }
예제 #2
0
        public RectangleValidator(
            RECT bounds,
            Color penColor,
            Color brushColor,
            int penWidth                = 1,
            Gdi32.PS penStyle           = default,
            Gdi32.R2 rop2               = Gdi32.R2.COPYPEN,
            Gdi32.BKMODE backgroundMode = Gdi32.BKMODE.TRANSPARENT,
            Gdi32.BS brushStyle         = default,
            Flags validate              = default)
        {
            _bounds         = bounds;
            _brushColor     = brushColor;
            _brushStyle     = brushStyle;
            _penWidth       = penWidth;
            _penColor       = penColor;
            _penStyle       = penStyle;
            _rop2           = rop2;
            _backgroundMode = backgroundMode;

            if (validate != default)
            {
                _validate = validate;
                return;
            }

            // Default values for all of these are valid expectations so we always turn them on.
            _validate = Flags.Bounds | Flags.PenStyle | Flags.BrushStyle;

            if (penWidth != 0)
            {
                _validate |= Flags.PenWidth;
            }

            if (!penColor.IsEmpty)
            {
                _validate |= Flags.PenColor;
            }

            if (!brushColor.IsEmpty)
            {
                _validate |= Flags.BrushColor;
            }

            if (backgroundMode != default)
            {
                _validate |= Flags.BackgroundMode;
            }

            if (_rop2 != default)
            {
                _validate |= Flags.RopMode;
            }
        }
예제 #3
0
        public LineToValidator(
            Point from,
            Point to,
            Color penColor,
            int penWidth                = 1,
            Gdi32.PS penStyle           = default,
            Gdi32.R2 rop2               = Gdi32.R2.COPYPEN,
            Gdi32.BKMODE backgroundMode = Gdi32.BKMODE.TRANSPARENT,
            Flags validate              = default)
        {
            _from           = from;
            _to             = to;
            _penWidth       = penWidth;
            _penColor       = penColor;
            _penStyle       = penStyle;
            _rop2           = rop2;
            _backgroundMode = backgroundMode;

            if (validate != default)
            {
                _validate = validate;
                return;
            }

            // Default values for all of these are valid expectations so we always turn them on.
            _validate = Flags.From | Flags.To | Flags.PenStyle;

            if (penWidth != 0)
            {
                _validate |= Flags.PenWidth;
            }

            if (!penColor.IsEmpty)
            {
                _validate |= Flags.PenColor;
            }

            if (backgroundMode != default)
            {
                _validate |= Flags.BackgroundMode;
            }

            if (_rop2 != default)
            {
                _validate |= Flags.RopMode;
            }
        }
예제 #4
0
 internal static IEmfValidator LineTo(
     EasyPoint from,
     EasyPoint to,
     Color penColor,
     int penWidth                   = 1,
     Gdi32.PS penStyle              = default,
     Gdi32.R2 rop2Mode              = Gdi32.R2.COPYPEN,
     Gdi32.BKMODE backgroundMode    = Gdi32.BKMODE.TRANSPARENT,
     LineToValidator.Flags validate = default) => new LineToValidator(
     from,
     to,
     penColor,
     penWidth,
     penStyle,
     rop2Mode,
     backgroundMode,
     validate);
예제 #5
0
 internal static IEmfValidator Rectangle(
     RECT bounds,
     Color penColor,
     Color brushColor,
     int penWidth                      = 1,
     Gdi32.PS penStyle                 = default,
     Gdi32.R2 rop2                     = Gdi32.R2.COPYPEN,
     Gdi32.BKMODE backgroundMode       = Gdi32.BKMODE.TRANSPARENT,
     Gdi32.BS brushStyle               = default,
     RectangleValidator.Flags validate = default) => new RectangleValidator(
     bounds,
     penColor,
     brushColor,
     penWidth,
     penStyle,
     rop2,
     backgroundMode,
     brushStyle,
     validate);
예제 #6
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);
        }
예제 #7
0
 public static Gdi32.R2 SetROP2(IHandle hdc, R2 rop2)
 {
     Gdi32.R2 result = SetROP2(hdc.Handle, rop2);
     GC.KeepAlive(hdc);
     return(result);
 }
 public Rop2Validator(Gdi32.R2 rop2Mode) => _rop2Mode = rop2Mode;
예제 #9
0
파일: State.cs 프로젝트: hughbe/winforms
 internal static IStateValidator Rop2(Gdi32.R2 rop2Mode) => new Rop2Validator(rop2Mode);