| Summary: | Add API to set aspect ratio window constraints | ||
|---|---|---|---|
| Product: | SDL | Reporter: | David <david> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | ASSIGNED --- | QA Contact: | Sam Lantinga <slouken> |
| Severity: | API change | ||
| Priority: | P2 | CC: | david, pabs3, x414e54 |
| Version: | HG 2.1 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: | Patch to constrain the window size by aspect ratio | ||
I just reimplemented this for X11 before finding this bug :( Personally I would suggest basing the API on width/height integers instead of aspect floats, because that is what the underlying APIs seem to be based on, at least the X11 one is. Thoughts Sam? The patch doesn't apply in hg because it modifies generated files which were regenerated since 2.0.3. I note there is some trailing whitespace in the patch and an unnessecary whitespace change, those should be removed. Once this gets merged, I'll be happy to provide an implementation for X11 as I want to use it in Chromium BSU. http://chromium-bsu.sourceforge.net/ I think this is a very useful API and would save applications having to disable resizing completely or having to call SetWindowSize after every resize event. I am also think it should be two integers for the ratio/fraction numerator and denominator, it seems more cross-platform and easier than passing a float around. I would probably stay away from labelling it "width" and "height" as it is a ratio so this is initially confusing. I do have a question/ideas though: What happens if the system cannot support the functionality or the window is maximized/fullscreen? Does SDL report a failure? Is the application expected to scale/resize or letterbox the content itself? Does SDL handle the letterboxing or scaling internally somehow? For example currently if you fullscreen a GL application and the monitor is a different aspect ratio and you do not want a stretched image, you would need to use glClear around the area. Some cards/drivers on larger resolution monitors this can be an expensive operation. Some systems however may not require the glClear because it allows a different GL surface size and shape to the window or some may allow SDL to place the inner content on a large static black background. You could do this by fixing SDL_GL_GetDrawableSize to the aspect ratio even if the window geometry cannot be fixed. The application would then render the correct aspect ratio to the framebuffer and SDL could internally do whatever the platform supports. It think it would also be useful to be able to provide a list of aspect ratios. Incase the application can only support a discrete set. Something such as: SDL_SetWindowAspectRatios(const SDL_Point *ratios, uint len); Also if the application can only support a discrete set of resolutions: SDL_SetWindowSizes(const SDL_Point *sizes, uint len); Marked for consideration for SDL 2.1, thanks! Any chance this could get added for the next SDL version? |
Created attachment 1771 [details] Patch to constrain the window size by aspect ratio It is useful in some applications to lock or constrain the aspect ratio of the window. This patch introduces four new APIs to set/get minimum and maximum aspect ratio window constraints. Games often want to constrain the window dimension because the UI is built to work for certain aspect ratios or because a window with a large aspect ratio can affect gameplay. The common use case, the programmer will set minimum window aspect ratio to 4/3 and maximum to 16/9. The user will then be allowed to resize the window as long as the dimensions are within the aspect ratio bounds. Another common use case is programming a movie player. The programmer may want the window size to lock to the aspect ratio of the movie. For this case, the programmer will set the minimum and maximum aspect ratio to the same value. When the window is resized the aspect ratio will remain fixed. This feature is backwards compatible because the default disables aspect ratio constraining by initializing the minimum and maximum values to 0. This enhancement was implemented for Windows and Mac.