I'm having a rather strange issue involving my game window and its resolution.
I have a function in my Engine that sets the resolution (with the appropriate checks to make sure the resolution is supported, etc) using:
CurrentScreenResolution = new Vector2(width, height); GraphicsManager.PreferredBackBufferWidth = width; GraphicsManager.PreferredBackBufferHeight = height; GraphicsManager.IsFullScreen = fullscreen; GraphicsManager.ApplyChanges();
The input width and height are applied to a "CurrentScreenResolution" variable which is what my game uses to position and scale GUI elements appropriately.
Problem: When the resolution is set to the primary screen's resolution using the above code, there is a strange offset (GUI elements are rendered and located in a position 17 pixels below where they should be).
The problem occurs only in specific circumstances. It only occurs when the game window's resolution is set to the native resolution, no matter what that resolution is. (Click on images and read the title of the game window, and notice the mouse and whether or not the button detects the mouse (by moving outwards) ):
Resolution: 1280X720 Windowed, Clientbounds: 1280X720, Viewport: 1280X720, Target resolution: 1280X720 Result: No problems, the button detects the mouse at the very edge of its upper side as expected.
Resolution: 1280X720 Fullscreen, Clientbounds: N/A, Viewport: 1280X720, Target resolution: 1280X720 Result: No problems, the button detects the mouse at the very edge of its upper side as expected.
Resolution: 1920X1080 Windowed, Clientbounds: 1920X1080, Viewport: 1920X1080, Target resolution: 1920X1080 Result: Problem: The button does not detect the mouse, it's as if the actual position of every GUI element were moved up exactly 17 pixels.
Resolution: 1920X1080 Windowed, Clientbounds: 1920 X 1063 , Viewport: 1920X1080, Target resolution: 1920X1080 Result: The problem is now fixed, all GUI elements are now acting as they normally should, however, this occurs only AFTER the user moves the window any amount with the mouse. After the 1080P window is moved, it snaps (resizes), and the ClientBounds changes to 1920 X 1063, which is exactly 17 pixels less than the viewport and backbuffer.
Resolution: 1920X1080 Fullscreen, Clientbounds: N/A, Viewport: 1920X1080, Target resolution: 1920X1080 Result: Strangely enough, there are no problems (in fullscreen), the button detects the mouse at the very edge of its upper side. This functions as expected.
As I said, this issue occurs on the native resolution. To summarize, here is how the issue takes places: Resolution is set by default to 1280X710 windowed. Everything is normal. Resolution is changed to native resolution, in this case 1920X1080 windowed (but it doesn't matter, I tested this with 1600X900, and 1600X1024, it only occurs when the game's resolution is set to the primary screen's set (native) resolution). ALL GUI elements appear exactly where they should be, but the actual area that they should be detected in is moved down 17 pixels. When the window is moved by the user, the ClientBounds (and ONLY the clientbounds) are resized to 1920X1063 (native resolution - 17 height pixels). The GUI elements then function as normally expected, and the backbuffer remains 1920X1080 as it should the whole time.
I have tried setting the program to fullscreen and back, and moving the window programmically when the resolution is set, but the ONLY way that the issue is solved when the game is set to the native resolution of the primary panel is for the USER to move the window's position, and have the ClientBounds snap (resize) to 17 pixels less in Height.
Sorry for the long post, but I felt that there wasn't a good way to explain this without pictures and a detailed description. Thanks for any help!