4

We recently ported Bitfighter from GLUT to SDL. There were numerous benefits to doing this, but a few drawbacks as well, especially in the area of window management.

Bitfighter runs in a fixed-aspect-ratio window (800x600 pixels). Users can make their window any size they want, but we capture the resize event and make adjustments to the requested size to ensure the window keeps the correct proportions (using SDL_SetVideoMode).

(The following problem applies to Windows, but has not yet been tested on other platforms. What I describe below refers specifically to Windows, though I am looking for a platform-independent solution.)

Ordinarily, this works great, except when users maximze their window by double clicking on the title bar or using the maximize button. In that case, the window resize event is called with the a window size approximating the screen size (minus some pixels for window ornamentation). Unfortunately, when the window is maximized, SDL_SetVideoMode has no effect (unlike GLUT which was able to resize a maximized window). Furthermore, subsequent calls to SDL_GetVideoInfo report the size we requested, not the actual current size of the window, so it is hard to tell if the attempted resizing worked.

I am looking for a platform independent way to do any of the following (in descending order of preference):

  1. Resize a window after it's been maximized
  2. Detect when a window has been maximized so that, knowing I can't resize it, I can at least adjust the video to be centered
  3. Prevent a window from being maximized (block double clicks on window title bar, use of the maximize button, and dragging the window to the top of the screen)

Bitfighter is written in C++, and we're using the latest official release of SDL.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Watusimoto
  • 1,773
  • 1
  • 23
  • 38

2 Answers2

1

Migrate to SDL 2.0 (which it seems you already have)

SDL 2.0 provides a better API to window management (it actually provides one). While there are still many bugs in Windows management in SDL 2.0 (especially on the Linux side), it has vastly improved since the 1.2 days.

faffy
  • 351
  • 3
  • 14
0

I assume, that you use OpenGL with SDL, because you used GLUT before. I don't know any solutions for that problem, exept point 2. If you want the Video to have a specific size, just leave the SDL-Window like it is, and call

glViewport(0, 0, width, height);

with the right size with the right proportions. With that solutions you will still have a black border in your window, but It only shows as much, as you want. (with the first 2 arguments you can also set the position of the Viewport in the window ;) )

matheus23
  • 74
  • 1
  • 10