WohlSoft / LunaLua

LunaLua - LunaDLL with Lua, is a free extension mod for SMBX 1.3 game engine, core of the X2 project.
https://codehaus.moe/
GNU General Public License v3.0
33 stars 12 forks source link

Added LunaLuaSetWindowScale and LunaLuaGetWindowSize #57

Open MrDoubleA232 opened 1 year ago

MrDoubleA232 commented 1 year ago

Adds two FFI functions:

If there are any issues with this implementation or a better way to go about things, let me know!

Bluenaxela commented 1 year ago

I've been thinking about this topic a bit.

Some things I had in mind, that you accounted for and I'm glad to see:

Some things I think it's missing:

In addition. I was thinking about the idea of implementing a Graphics.adjustWindowScale() function which accepts no arguments, and bundles together what I'd consider the "best practice" for what to do following a change in framebuffer size:

  1. Read the window's size (true, not DPI adjusted, this is important... and rcNormalPosition size rather than current size so you get the restore size if it's fullscreen currently)
  2. Divide that by the height of the current main framebuffer to get the current scale according to height (Alternatively, could use the square root of the ratio of area? Undecided if area-preserving or height-preserving is better)
  3. Round to the nearest multiple of 0.5
  4. Limit to maximum scale allowed by the monitor (rounded down to nearest 0.5, accounting for both height and width)
  5. Then set the window scale accordingly

This method tries to combine respecting whatever the player has done with window size already, with rounding to a clean-looking window size of the appropriate aspect ratio.

MrDoubleA232 commented 1 year ago

This is really helpful feedback! I'll try to implement the points that you mentioned into this once I get the chance.