Exemplo n.º 1
0
        private void GetPlatformWindowSize(out int w, out int h)
        {
#if WIN32
            UnmanagedMethods.RECT rc;
            UnmanagedMethods.GetClientRect(_hwnd.Handle, out rc);
            w = rc.right - rc.left;
            h = rc.bottom - rc.top;
#else
            throw new NotImplementedException();
#endif
        }
Exemplo n.º 2
0
        public ILockedFramebuffer Lock()
        {
            UnmanagedMethods.RECT rc;
            UnmanagedMethods.GetClientRect(_hwnd, out rc);
            var width  = rc.right - rc.left;
            var height = rc.bottom - rc.top;

            if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height) && width > 0 && height > 0)
            {
                _fb?.Deallocate();
                _fb = null;
                _fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height));
            }
            return(_fb);
        }
Exemplo n.º 3
0
        private void GetPlatformWindowSize(IntPtr hwnd, out int w, out int h)
        {
#if __IOS__
            var bounds = GetApplicationFrame();
            w = (int)bounds.Width;
            h = (int)bounds.Height;
#elif WIN32
            UnmanagedMethods.RECT rc;
            UnmanagedMethods.GetClientRect(_hwnd, out rc);
            w = rc.right - rc.left;
            h = rc.bottom - rc.top;
#else
            throw new NotImplementedException();
#endif
        }
Exemplo n.º 4
0
        public ILockedFramebuffer Lock()
        {
            UnmanagedMethods.GetClientRect(_hwnd, out var rc);

            var width  = Math.Max(1, rc.right - rc.left);
            var height = Math.Max(1, rc.bottom - rc.top);

            if ((_fb == null || _fb.Size.Width != width || _fb.Size.Height != height))
            {
                _fb?.Deallocate();
                _fb = null;
                _fb = new WindowFramebuffer(_hwnd, new PixelSize(width, height));
            }

            return(_fb);
        }
Exemplo n.º 5
0
        public void Resize(Size value)
        {
            int requestedClientWidth  = (int)(value.Width * Scaling);
            int requestedClientHeight = (int)(value.Height * Scaling);

            UnmanagedMethods.RECT clientRect;
            UnmanagedMethods.GetClientRect(_hwnd, out clientRect);

            // do comparison after scaling to avoid rounding issues
            if (requestedClientWidth != clientRect.Width || requestedClientHeight != clientRect.Height)
            {
                UnmanagedMethods.RECT windowRect;
                UnmanagedMethods.GetWindowRect(_hwnd, out windowRect);

                UnmanagedMethods.SetWindowPos(
                    _hwnd,
                    IntPtr.Zero,
                    0,
                    0,
                    requestedClientWidth + (windowRect.Width - clientRect.Width),
                    requestedClientHeight + (windowRect.Height - clientRect.Height),
                    UnmanagedMethods.SetWindowPosFlags.SWP_RESIZE);
            }
        }
        public ILockedFramebuffer Lock()
        {
            Monitor.Enter(_lock);

            LockedFramebuffer?fb = null;

            try
            {
                UnmanagedMethods.GetClientRect(_hwnd, out var rc);

                var width  = Math.Max(1, rc.right - rc.left);
                var height = Math.Max(1, rc.bottom - rc.top);

                if (_framebufferData is null || _framebufferData?.Size.Width != width || _framebufferData?.Size.Height != height)
                {
                    _framebufferData?.Dispose();

                    _framebufferData = AllocateFramebufferData(width, height);
                }

                var framebufferData = _framebufferData.Value;

                return(fb = new LockedFramebuffer(
                           framebufferData.Data.Address, framebufferData.Size, framebufferData.RowBytes,
                           GetCurrentDpi(), _format, _onDisposeAction));
            }
            finally
            {
                // We free the lock when for whatever reason framebuffer was not created.
                // This allows for a potential retry later.
                if (fb is null)
                {
                    Monitor.Exit(_lock);
                }
            }
        }
Exemplo n.º 7
0
 protected override Size2 GetWindowSize()
 {
     UnmanagedMethods.RECT rc;
     UnmanagedMethods.GetClientRect(_window.Handle, out rc);
     return(new Size2(rc.right - rc.left, rc.bottom - rc.top));
 }
Exemplo n.º 8
0
 Size2 GetWindowSize()
 {
     UnmanagedMethods.RECT rc;
     UnmanagedMethods.GetClientRect(_hwnd, out rc);
     return(new Size2(rc.right - rc.left, rc.bottom - rc.top));
 }