Jump to content
  • Advertisement
Sign in to follow this  
minamur

SDL window positioning

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Not in any SDL version so far. However I think in SDL 1.3 this will finally be fixed. Best thing you can do for now is using native functions for your platform, for example use this to center the window:


#include <SDL_syswm.h>
void
CenterWindow(int w, int h)
{
int x,y;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if(SDL_GetWMInfo(&info) > 0)
{
# if defined(WIN32)
x = GetSystemMetrics(SM_CXSCREEN) / 2 - w / 2;
y = GetSystemMetrics(SM_CYSCREEN) / 2 - h / 2;
MoveWindow(info.window, x, y, w, h, TRUE);
#else
/* other platforms */
#endif
}
}

Share this post


Link to post
Share on other sites
Quote:
Original post by basement
Not in any SDL version so far. However I think in SDL 1.3 this will finally be fixed. Best thing you can do for now is using native functions for your platform, for example use this to center the window:


#include <SDL_syswm.h>
void
CenterWindow(int w, int h)
{
int x,y;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if(SDL_GetWMInfo(&info) > 0)
{
# if defined(WIN32)
x = GetSystemMetrics(SM_CXSCREEN) / 2 - w / 2;
y = GetSystemMetrics(SM_CYSCREEN) / 2 - h / 2;
MoveWindow(info.window, x, y, w, h, TRUE);
#else
/* other platforms */
#endif
}
}



nice, i wasn't aware of SDL_GetWMInfo. thanks.

Share this post


Link to post
Share on other sites
See near the bottom of this:

Quote:

Note: If you want to control the position on the screen when creating a windowed surface, you may do so by setting the environment variables "SDL_VIDEO_CENTERED=center" or "SDL_VIDEO_WINDOW_POS=x,y". You can set them via SDL_putenv.


More info on SDL's enviornmental variables can be found here and here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!