Skip to main content
GameDev.net gamedev.net
🔒 Locked

SDL window positioning

Started by minamur Aug 17, 2006 at 6:35 PM 2 replies 1.6k views
Original Post
minamur
minamur
when you create a window in sdl, is there any way to set the position at wich it will be created?
basement
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>voidCenterWindow(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   }}

minamur
minamur
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>voidCenterWindow(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.
rip-off
rip-off
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.