Example #1
0
        private static IntPtr WindowProc(IntPtr hwnd, uint umsg,
                                         IntPtr wParam, IntPtr lParam)
        {
            var msg = (WM)umsg;

            switch (msg)
            {
            case WM.ERASEBKGND:
                return(new IntPtr(1));

            case WM.CLOSE:
            {
                User32Methods.PostQuitMessage(0);
                break;
            }

            case WM.PAINT:
            {
                PaintStruct ps;
                var         hdc = User32Methods.BeginPaint(hwnd, out ps);
                User32Methods.FillRect(hdc, ref ps.PaintRect,
                                       Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH));
                User32Methods.EndPaint(hwnd, ref ps);
                break;
            }
            }
            return(User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam));
        }
Example #2
0
        public static void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer,
                                        Action <SKSurface> handler)
        {
            var       hwnd = packet.Hwnd;
            Rectangle clientRect;

            User32Methods.GetClientRect(hwnd, out clientRect);
            var size = clientRect.Size;

            pixelBuffer.EnsureSize(size.Width, size.Height);
            PaintStruct ps;
            var         hdc       = User32Methods.BeginPaint(hwnd, out ps);
            var         skPainted = false;

            try
            {
                using (var surface = SKSurface.Create(
                           size.Width,
                           size.Height,
                           SKColorType.Bgra8888,
                           SKAlphaType.Premul,
                           pixelBuffer.Handle,
                           pixelBuffer.Stride))
                {
                    if (surface != null)
                    {
                        handler(surface);
                        skPainted = true;
                    }
                }
            }
            finally
            {
                if (skPainted)
                {
                    Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle);
                }
                User32Methods.EndPaint(hwnd, ref ps);
            }
        }
Example #3
0
            public static unsafe void ProcessPaint(ref PaintPacket packet, NativePixelBuffer pixelBuffer,
                                                   Action <SKSurface> handler)
            {
                var       hwnd = packet.Hwnd;
                Rectangle clientRect;

                User32Methods.GetClientRect(hwnd, out clientRect);
                var size = clientRect.Size;

                pixelBuffer.EnsureSize(size.Width, size.Height);
                PaintStruct ps;
                var         hdc       = User32Methods.BeginPaint(hwnd, out ps);
                var         skPainted = false;

                try
                {
                    using (var surface = SKSurface.Create(
                               size.Width,
                               size.Height,
                               SKColorType.Bgra8888,
                               SKAlphaType.Premul,
                               pixelBuffer.Handle,
                               pixelBuffer.Stride))
                    {
                        if (surface != null)
                        {
                            handler(surface);

                            /*
                             * foreach (var VARIABLE in Enumerable.Range(0, pixelBuffer.Stride * size.Height / 4))
                             * {
                             *  var value = Marshal.ReadInt32(pixelBuffer.Handle, VARIABLE*4);
                             *  // ABGR >> ARGB
                             *  unchecked
                             *  {
                             *      value = ((value & (int)0xff000000) >> 0) +
                             *          ((value & 0xff0000) >> 16 )+
                             *          ((value & 0xff00) << 0) +
                             *          ((value & 0xff) << 16);
                             *  }
                             *
                             *  Marshal.WriteInt32(pixelBuffer.Handle, VARIABLE * 4, value);
                             * }*/

                            var max = pixelBuffer.Stride * size.Height / 4;

                            int *arr = (int *)pixelBuffer.Handle.ToPointer();
                            unchecked
                            {
                                var a = 0;
                                while (a < max)
                                {/*
                                  * arr = ((*arr & (int) 0xff000000) >> 0) +
                                  *        ((*arr & 0xff0000) >> 16) +
                                  *        ((*arr & 0xff00) << 0) +
                                  *        ((*arr & 0xff) << 16);
                                  * arr++;*/
                                    a++;
                                }
                            }

                            skPainted = true;
                        }
                    }
                }
                finally
                {
                    if (skPainted)
                    {
                        Gdi32Helpers.SetRgbBitsToDevice(hdc, size.Width, size.Height, pixelBuffer.Handle);
                    }
                    User32Methods.EndPaint(hwnd, ref ps);
                }
            }
Example #4
0
        private static IntPtr WindowProc(IntPtr hwnd, uint umsg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr result = IntPtr.Zero;

            var msg = (WM)umsg;

            switch (msg)
            {
            case WM.ERASEBKGND:
                return(new IntPtr(1));

            case WM.CLOSE: User32Methods.PostQuitMessage(0);
                break;

            case WM.PAINT:
            {
                var hdc = User32Methods.BeginPaint(hwnd, out PaintStruct ps);
                User32Methods.FillRect(hdc, ref ps.PaintRect,
                                       Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH));
                User32Methods.EndPaint(hwnd, ref ps);
                break;
            }

            case WM.KEYDOWN: InputManager.Instance.KeyPressed((VirtualKey)wParam.ToInt32(), lParam.ToInt32() & 0x40000000);
                break;

            case WM.KEYUP: InputManager.Instance.KeyReleased((VirtualKey)wParam.ToInt32());
                break;

            case WM.CHAR: InputManager.Instance.KeyTyped((char)wParam.ToInt32());
                break;

            case WM.MOUSEMOVE:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseMoved(x, y);
                break;
            }

            case WM.LBUTTONDOWN:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MousePressed(MouseButton.Left, x, y);
                break;
            }

            case WM.LBUTTONUP:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseReleased(MouseButton.Left, x, y);
                break;
            }

            case WM.RBUTTONDOWN:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MousePressed(MouseButton.Right, x, y);
                break;
            }

            case WM.RBUTTONUP:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseReleased(MouseButton.Right, x, y);
                break;
            }

            default:
                result = User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam);
                break;
            }
            return(result);
        }
Example #5
0
 public void EndPaint(ref PaintStruct ps)
 {
     User32Methods.EndPaint(this.Handle, ref ps);
 }