Sign in to follow this  

SDL window positioning

This topic is 4140 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

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

This topic is 4140 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this