How to get resolution of my SDL window?

Hello,

I create my SDL window created with:

surface_screen = SDL_SetVideoMode(MAX_X, MAX_Y, BPP,
SDL_SWSURFACE|SDL_RESIZABLE);

After some resizes I want to get new X and Y resolution of my window.

I’ve tryed to do that using this Win32 function:

RECT windowRect;
GetWindowRect(hWnd, &windowRect);
//To access members
//windowRect.left
//windowRect.right
//windowRect.top
//windowRect.bottom

But this returns me the size of all the window, including window
border/title.

Is there an SDL/Win32 way to get X/Y resolution of my window?

Thanks in advance

Quoting voidstar :

Hello,

I create my SDL window created with:

surface_screen = SDL_SetVideoMode(MAX_X, MAX_Y, BPP,
SDL_SWSURFACE|SDL_RESIZABLE);

After some resizes I want to get new X and Y resolution of my window.

I’ve tryed to do that using this Win32 function:

RECT windowRect;
GetWindowRect(hWnd, &windowRect);
//To access members
//windowRect.left
//windowRect.right
//windowRect.top
//windowRect.bottom

But this returns me the size of all the window, including window
border/title.

Is there an SDL/Win32 way to get X/Y resolution of my window?

Thanks in advance

width=screen->w;

height=screen->h;

??

width=screen->w;

height=screen->h;

Yes, but in this way I can’t get the correct window resolution if I’ve
resized the window while the SDL_VIDEORESIZE was disabled.

In this case, if I resize the window, for SDL the window is not resized,
so screen->w e screen->h are unchanged… but the window is resized (not
SDL updated, but resized).

I need this check because i want to restore window resolution if the user
try to resize the window while the SDL_VIDEORESIZE event is disabled.

However, I’ve found this way to do it:

RECT windowRect;
GetClientRect(hWnd, &windowRect);
int real_w = windowRect.right-windowRect.left;
int real_h = windowRect.bottom-windowRect.top;

I think this is the only way to do it… or not?
What do you think?

Thank you for your help!

No need to use windows-specific functions…
Just use the SDL_GetVideoSurface() function. It returns a pointer to the
current display surface. you can even use it directly:
int screen_width = SDL_GetVideoSurface()->w; // this gives surface width
int screen_height = SDL_GetVideoSurface()->h; // this gives surface height

if you assign it to an existing pointer (screen = SDL_GetVideoSurface():wink: it
will only work until the screen is resized, at which point you must reassign
the pointer to the changed video surface. (similar, if not identical, to
what you have been describing.)

I hope that helps.
-Dave> ----- Original Message -----

From: voidstar@tin.it (Andrea Pintori)
To:
Sent: Wednesday, December 05, 2007 6:34 AM
Subject: Re: [SDL] How to get resolution of my SDL window?

width=screen->w;

height=screen->h;

Yes, but in this way I can’t get the correct window resolution if I’ve
resized the window while the SDL_VIDEORESIZE was disabled.

In this case, if I resize the window, for SDL the window is not resized,
so screen->w e screen->h are unchanged… but the window is resized (not
SDL updated, but resized).

I need this check because i want to restore window resolution if the user
try to resize the window while the SDL_VIDEORESIZE event is disabled.

However, I’ve found this way to do it:

RECT windowRect;
GetClientRect(hWnd, &windowRect);
int real_w = windowRect.right-windowRect.left;
int real_h = windowRect.bottom-windowRect.top;

I think this is the only way to do it… or not?
What do you think?

Thank you for your help!


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

No need to use windows-specific functions…
Just use the SDL_GetVideoSurface() function. It returns a pointer to the
current display surface. you can even use it directly:
int screen_width = SDL_GetVideoSurface()->w; // this gives surface width
int screen_height = SDL_GetVideoSurface()->h; // this gives surface height

if you assign it to an existing pointer (screen = SDL_GetVideoSurface():wink: it
will only work until the screen is resized, at which point you must reassign
the pointer to the changed video surface. (similar, if not identical, to
what you have been describing.)

I’ve tried to use GetVideoSurface() function, but it doesn’t “notice” that my
window has been resized while SDL_VIDEORESIZE events are disabled.

The situation is the following:

When the user keep space-bar pressed, I show a picture and I disable
SDL_VIDEORESIZE events (and mouse events too)

If the user (while pressing space-bar) try to resize the window with the mouse,
SDL doen’t receive the resize event, so it doesn’t update the screen, but
Windows resize the window (the window is larger/smaller)!

So, when the user release space-bar, I want the window to return to the original
resolution (because this is an invalid resize for my app), but I want to do this
only if the user resized the window while pressing space-bar.

To check is the user resized the window while pressing space-bar, I have to
check the new real window resolution, and compare it with his resolution
before pressing space-bar.

The problem with SDL_GetVideoSurface is that when the user release space-bar,
SDL_GetVideoSurface()->w and SDL_GetVideoSurface()->h return me the original
resolution, also if the user resized the window while SDL_VIDEORESIZE events
were disabled.

Instead, using GetClientRect I can obtain the new real window resolution.

Do you know if there’s another way to do this using SDL?

Thanks for you help

You know you should be calling SDL_SetVideoMode() when you get a
SDL_RESIZEEVENT (or whatever its called) ? I’ve noticed (on Windows
anyway) that even if you ignore the events the window gets resized by
the window manager. By calling SDL_SetVideoMode, your screen surface
should now contain the correct width and height.