Mouse Position edge case

Hello,

When creating a backbuffer with the same size as the native resolution in windowed mode the mouse miss aligns using Mouse.GetState().Y etc.

This is likely due too AdjustClinetRect doing something funky too keep the max screen size set and xna forcing the back buffer to be still the full resoloution.

the most basic way of fixing it on the user side is scaling the mouse position too the ratio of the actual window resolution and the incorrect back buffer size.

mousePos.Y = (mousePos.Y / Window.Height) * BackBuffer.Y;

However when working with Pixel art games with indepednent resolution scaling and viewport manipulation (black bars) this added calculation makes things a little more complicated. Does anyone know if this is intended or a bug?

I ran into this same problem. You need to use the hardware mode switch.

Read here.

Ah great i’ll check this out, I had a look through monogame source and it seemed that hardware switch mostly only effected fullscreen state by finding closest resolution. I saw some suggestions it affects stretching of the back buffer so that could be where this title bar offset is getting messed up from.

Unfortunatly HardwareModeSwitch has no effect on this as i suspected as HardwareModeSwitch only rally effects the swapchain and fullscreen mode. This particular edge case is windowed mode at native resolution. What Monogame should do for windowed mode is force the back buffer too fit the clinet window size. For instance i could request 1920x1080 but the window with a boarder cannot accomidate that so it should force the back buffer to be 1920x1050 matching the window clinet size and keeping mouse in sync.

[Edited]
there are 2 options, monogame internally fixes the window to go above max, or force the back buffer to client rect .

But the best solution for right now is too manually check for this case and force the window to be borderless like so:

    private void ApplySettings()
    {
        if(m_IsFullscreen == false)
        {
            if (m_ScreenWidth < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width &&
             m_ScreenHeight < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height)
            {
                Engine.Instance.Window.IsBorderless = false;
                Engine.Instance.Window.Position = new Point((int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - m_ScreenWidth) * 0.5f), 
                                                            (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - m_ScreenHeight) * 0.5f));
                m_GraphicsManager.PreferredBackBufferWidth  = m_ScreenWidth;
                m_GraphicsManager.PreferredBackBufferHeight = m_ScreenHeight;
                m_GraphicsManager.IsFullScreen              = m_IsFullscreen;
                m_GraphicsManager.ApplyChanges();
            }
            else
            {
                // Gotta use borderless
                Engine.Instance.Window.IsBorderless = true;
                Engine.Instance.Window.Position = new Point(0, 0);
                m_GraphicsManager.PreferredBackBufferWidth = m_ScreenWidth;
                m_GraphicsManager.PreferredBackBufferHeight = m_ScreenHeight;
                m_GraphicsManager.IsFullScreen = m_IsFullscreen;
                m_GraphicsManager.ApplyChanges();
            }
        }
        else
        {
            m_GraphicsManager.PreferredBackBufferWidth  = m_ScreenWidth;
            m_GraphicsManager.PreferredBackBufferHeight = m_ScreenHeight;
            m_GraphicsManager.IsFullScreen              = m_IsFullscreen;
            m_GraphicsManager.ApplyChanges();
        }
    }