raycrasher / Fell-Sky

2d space combat simulator like EV Nova and Transcendence.
MIT License
2 stars 1 forks source link

Mouse position scales differently than graphics #13

Closed markgarcia closed 8 years ago

markgarcia commented 8 years ago

Steps to reproduce bug:

Note that I've tested this in a 1366x768 sized window. Resizing the window to something smaller like 800x600 seem to lessen the problem, i.e. the mouse cursor is just very slightly off. This suggests some resolution-dependent scaling issue.

Note that the bug is exhibited even when DPI-awareness is off, i.e. using default-generated manifest. Also exhibited both on 100% and 125% scaling.

raycrasher commented 8 years ago

So far I cannot duplicate the issue in my side.

Try looking into the IMouseService implementations (one each for game and editor), and also Camera.ScreenToCameraSpace. We should also check BoundingBoxSelectionSystem for the bounding box drag logic, and also for BoundingBoxRendererSystem.

markgarcia commented 8 years ago

After much debugging, I've uncovered the source of the bug, which happens when the graphics device back buffer's size doesn't match the window's client size (the part of the window that is drawn unto and interacted with). This happens either when the buffer size exceeds your desktop resolution in which Windows limits your window size to your desktop resolution, or when the buffer size is larger than the client size still because of the the reason of Windows limiting the window size to your desktop resolution and because the title bar and perhaps other window elements ultimately reduce the client size making it smaller than the back buffer's size.

In my case the back buffer's height is equal to my desktop height, and because the title bar occupies some space on the window, the client size is reduced resulting in a mismatch with the back buffer's size. The scaling issue happens because Mono uses window client coordinates rather than screen-space/back-buffer-space coordinates, hence the input scaling issue.

A fix is coming, with a caveat which I think is a bug in Mono itself.

raycrasher commented 8 years ago

Ahhhh, so thats why I cannot duplicate, since I am currently at 1080p resolution.

Off the top of my head, some fixes would be:

  1. Use borderless window when desktop resolution < 1366x768
  2. Set backbufffer size to actual client area size (difficult, i think, and platform-dependent too).
  3. Modify IMouseService and compensate for the mismatch.

Aside from the mouse issue, this would be problematic when aligning UI elements on the right/bottom side of the screen.