How to limit window size when resized

Hello,

I’m trying to limit the size of the window that a user can resize it to.
Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

Thanks,

Aaron

#include
#include <stdlib.h>
#include <SDL/SDL.h>
using namespace std;

int
main (int argc, char *argv[])
{ //Our main program
SDL_Surface *screen;
SDL_Event event; //Events
bool done = false; //Not done before we’ve started…

if (SDL_Init (SDL_INIT_VIDEO) < 0)
{ //Could we start SDL_VIDEO?
std::cerr << “Couldn’t init SDL”; //Nope, output to stderr and quit
exit (1);
}

atexit (SDL_Quit); //Now that we’re enabled, make sure we cleanup

screen = SDL_SetVideoMode (640, 480, 32, SDL_HWSURFACE |
SDL_RESIZABLE); //Create
a 640x480x32 resizable window

if (!screen)
{ //Couldn’t create window?
std::cerr << “Couldn’t create screen”; //Output to stderr and quit
exit (1);
}

while (!done)
{ //While program isn’t done
while (SDL_PollEvent (&event))
{ //Poll events
switch (event.type)
{ //Check event type
case SDL_QUIT: //User hit the X (or equivelent)
done = true; //Make the loop end
break; //We handled the event
case SDL_VIDEORESIZE: //User resized window
if(event.resize.w < 800 && event.resize.h < 800) {
screen = SDL_SetVideoMode (event.resize.w, event.resize.h, 32,
SDL_HWSURFACE | SDL_RESIZABLE); // Create new window
}else {
screen = SDL_SetVideoMode (800, 800, 32, SDL_HWSURFACE |
SDL_RESIZABLE); // Create new window
cout << " request to big!" << endl;
}
break; //Event handled, fetch next :slight_smile:
} //Finished with current event
} //Done with all events for now
} //Program done, exited
}–
Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel

I’m trying to limit the size of the window that a user can resize it to.
Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

Linux using libsdl-1.2.14-r6

Thanks,

AaronOn Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it to.

Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel

Anyone know anything more about this? Could this be a bug?

Thanks,

AaronOn Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen <@Aaron_Rosen> wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it to.

Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be
if(event.resize.w
< 800 || event.resize.h < 800) {
?
-AlexOn Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it to.

Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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

Here’s the resize code (attached wrong file before).On Wed, Dec 14, 2011 at 10:42 AM, Aaron Rosen <@Aaron_Rosen> wrote:

Yea that’s now it. It still allows you to resize past 800. Before it was
trigged if both were greater than 800 now only one has to be greater than
800.

On Wed, Dec 14, 2011 at 9:55 AM, Alex Barry <alex.barry at gmail.com> wrote:

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be if(event.resize.w
< 800 || event.resize.h < 800) {
?
-Alex

On Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen <@Aaron_Rosen> wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen <@Aaron_Rosen> wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it

to.
Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size
desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel
-------------- next part --------------
A non-text attachment was scrubbed…
Name: resize.cpp
Type: text/x-c++src
Size: 1590 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111214/ae029e1c/attachment.cpp

Yea that’s now it. It still allows you to resize past 800. Before it was
trigged if both were greater than 800 now only one has to be greater than
800.On Wed, Dec 14, 2011 at 9:55 AM, Alex Barry <alex.barry at gmail.com> wrote:

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be if(event.resize.w
< 800 || event.resize.h < 800) {
?
-Alex

On Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen <@Aaron_Rosen> wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen <@Aaron_Rosen> wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it

to.
Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel
-------------- next part --------------
A non-text attachment was scrubbed…
Name: abc.cpp
Type: text/x-c++src
Size: 102 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111214/5e2d4221/attachment.cpp

Now that I think about it, it should be && rather than ||, and it should be
working. I’m guessing the issue here is that linux is firing a resize
event when you actually resize the window. Try changing the if statement
to this:

if(event.resize.w > 800 || event.resize.h > 800) {
screen = SDL_SetVideoMode (
( event.resize.w > 800 ) ? 800 : event.resize.w,
( event.resize.h > 800 ) ? 800 : event.resize.h,
32, SDL_HWSURFACE | SDL_RESIZABLE
);
cout << " request to big!" << endl;
}

This will only limit the resizing if it’s over the limit, as i believe the
window resize event changes the video mode internally, so when you were
setting the size, it may have just caught in an infinite loop rather than a
resize issue.

I hope that helps,
-AlexOn Wed, Dec 14, 2011 at 10:43 AM, Aaron Rosen wrote:

Here’s the resize code (attached wrong file before).

On Wed, Dec 14, 2011 at 10:42 AM, Aaron Rosen wrote:

Yea that’s now it. It still allows you to resize past 800. Before it was
trigged if both were greater than 800 now only one has to be greater than
800.

On Wed, Dec 14, 2011 at 9:55 AM, Alex Barry <@Alex_Barry> wrote:

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be if(event.resize.w
< 800 || event.resize.h < 800) {
?
-Alex

On Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it

to.
Would someone mind pointing out why the code below doesn’t seem to
do
this? The user is still able to stretch the window to any size
desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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

Nope same thing.

AaronOn Wed, Dec 14, 2011 at 10:55 AM, Alex Barry <alex.barry at gmail.com> wrote:

Now that I think about it, it should be && rather than ||, and it should
be working. I’m guessing the issue here is that linux is firing a resize
event when you actually resize the window. Try changing the if statement
to this:

if(event.resize.w > 800 || event.resize.h > 800) {
screen = SDL_SetVideoMode (
( event.resize.w > 800 ) ? 800 : event.resize.w,
( event.resize.h > 800 ) ? 800 : event.resize.h,
32, SDL_HWSURFACE | SDL_RESIZABLE
);
cout << " request to big!" << endl;
}

This will only limit the resizing if it’s over the limit, as i believe the
window resize event changes the video mode internally, so when you were
setting the size, it may have just caught in an infinite loop rather than a
resize issue.

I hope that helps,
-Alex

On Wed, Dec 14, 2011 at 10:43 AM, Aaron Rosen <@Aaron_Rosen> wrote:

Here’s the resize code (attached wrong file before).

On Wed, Dec 14, 2011 at 10:42 AM, Aaron Rosen <@Aaron_Rosen> wrote:

Yea that’s now it. It still allows you to resize past 800. Before it was
trigged if both were greater than 800 now only one has to be greater than
800.

On Wed, Dec 14, 2011 at 9:55 AM, Alex Barry <alex.barry at gmail.com>wrote:

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be if(event.resize.w
< 800 || event.resize.h < 800) {
?
-Alex

On Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen <@Aaron_Rosen>wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen <@Aaron_Rosen>wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize

it to.
Would someone mind pointing out why the code below doesn’t seem to
do
this? The user is still able to stretch the window to any size
desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel
-------------- next part --------------
A non-text attachment was scrubbed…
Name: resize.cpp
Type: text/x-c++src
Size: 1601 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20111214/a20585af/attachment.cpp

Ah, I was wrong, the SDL 1.2 documentation says that you should be calling
SDL_SetVideoMode() when handling a resize event, so try this:

case SDL_VIDEORESIZE: //User resized window
screen = SDL_SetVideoMode (
( event.resize.w > 800 ) ? 800 : event.resize.w,
( event.resize.h > 800 ) ? 800 : event.resize.h,
32, SDL_HWSURFACE | SDL_RESIZABLE
);
break; //Event handled, fetch next :slight_smile:

Hope that helps,
-AlexOn Wed, Dec 14, 2011 at 11:00 AM, Aaron Rosen wrote:

Nope same thing.

Aaron

On Wed, Dec 14, 2011 at 10:55 AM, Alex Barry <@Alex_Barry> wrote:

Now that I think about it, it should be && rather than ||, and it should
be working. I’m guessing the issue here is that linux is firing a resize
event when you actually resize the window. Try changing the if statement
to this:

if(event.resize.w > 800 || event.resize.h > 800) {
screen = SDL_SetVideoMode (
( event.resize.w > 800 ) ? 800 : event.resize.w,
( event.resize.h > 800 ) ? 800 : event.resize.h,
32, SDL_HWSURFACE | SDL_RESIZABLE
);
cout << " request to big!" << endl;
}

This will only limit the resizing if it’s over the limit, as i believe
the window resize event changes the video mode internally, so when you were
setting the size, it may have just caught in an infinite loop rather than a
resize issue.

I hope that helps,
-Alex

On Wed, Dec 14, 2011 at 10:43 AM, Aaron Rosen wrote:

Here’s the resize code (attached wrong file before).

On Wed, Dec 14, 2011 at 10:42 AM, Aaron Rosen wrote:

Yea that’s now it. It still allows you to resize past 800. Before it
was trigged if both were greater than 800 now only one has to be greater
than 800.

On Wed, Dec 14, 2011 at 9:55 AM, Alex Barry <@Alex_Barry>wrote:

Shouldnt if(event.resize.w < 800 && event.resize.h < 800) { be if(event.resize.w
< 800 || event.resize.h < 800) {
?
-Alex

On Tue, Dec 13, 2011 at 6:20 PM, Aaron Rosen wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon <icculus at icculus.org wrote:

I’m trying to limit the size of the window that a user can resize

it to.
Would someone mind pointing out why the code below doesn’t seem
to do
this? The user is still able to stretch the window to any size
desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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

I downloaded your program, and commented out the conflicting “if” statements:

if(event.resize.w < 800 || event.resize.h < 800) {
if(event.resize.w > 800 || event.resize.h > 800) {
// …
}
}

Removing these, and just using the inner call to SDL_SetVideoMode,
using the ternary operator to control the size, “works”. The logic
allows the window to grow bigger than 800x800 temporarily, but then it
snaps back once the user releases the mouse (on Ubuntu). IIRC Windows
behaves the same.

I don’t believe it is possible to prevent the user from temporarily
exceeding this limit, if that is what you want.On 14 December 2011 16:00, Aaron Rosen wrote:

Nope same thing.

Aaron

Ha, I see it was working before too. I had just never released the mouse .

Thanks guys,

AaronOn Wed, Dec 14, 2011 at 11:12 AM, Brian Barrett <brian.ripoff at gmail.com>wrote:

I downloaded your program, and commented out the conflicting "if"
statements:

if(event.resize.w < 800 || event.resize.h < 800) {
if(event.resize.w > 800 || event.resize.h > 800) {
// …
}
}

Removing these, and just using the inner call to SDL_SetVideoMode,
using the ternary operator to control the size, “works”. The logic
allows the window to grow bigger than 800x800 temporarily, but then it
snaps back once the user releases the mouse (on Ubuntu). IIRC Windows
behaves the same.

I don’t believe it is possible to prevent the user from temporarily
exceeding this limit, if that is what you want.

On 14 December 2011 16:00, Aaron Rosen <@Aaron_Rosen> wrote:

Nope same thing.

Aaron


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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel

When we talk to windows it seems like we are talking a different language.
The code there says that if windows tells me the window has gone too big
then I don’t want to update the portion of the screen that’s too large. Am
I right?
I think WM_SIZING is the size message you get and something like
WM_GETMINMAXINFO and SetWindowPos are the things you are looking for in the
windows api. Does sdl have some native way to deal with this as well so we
can stay out of the windows api mess?On Tue, Dec 13, 2011 at 5:20 PM, Aaron Rosen wrote:

Anyone know anything more about this? Could this be a bug?

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:18 PM, Aaron Rosen wrote:

Linux using libsdl-1.2.14-r6

Thanks,

Aaron

On Mon, Dec 12, 2011 at 1:13 PM, Ryan C. Gordon wrote:

I’m trying to limit the size of the window that a user can resize it to.

Would someone mind pointing out why the code below doesn’t seem to do
this? The user is still able to stretch the window to any size desired.

What platform is this on?

–ryan.

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


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


Aaron O. Rosen
Masters Student - Network Communication
306B Fluor Daniel


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

I think it would be cool if these functions were added to the SDL API:

SDL_SetWindowWidthMin(int)
SDL_SetWindowHeightMin(int)
SDL_SetWindowWidthMax(int)
SDL_SetWindowHeightMax(int)

Can you respond to a resize event by resizing to the minimum/maximum as
necessary?

Jonny D

It is my understanding that X11 window managers often have an extension where you can specify min and max size hints, which greatly improve the user experience.

So I view this as a request for enabling that hint API (in cases where it works) without non-portable code.On 08/03/2012 05:37 PM, Jonathan Dearborn wrote:

Can you respond to a resize event by resizing to the minimum/maximum as necessary?

Jonny D


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


LordHavoc
Author of DarkPlaces Quake1 engine - http://icculus.org/twilight/darkplaces
Co-designer of Nexuiz - http://alientrap.org/nexuiz
"War does not prove who is right, it proves who is left." - Unknown
"Any sufficiently advanced technology is indistinguishable from a rigged demo." - James Klass
"A game is a series of interesting choices." - Sid Meier

So the user wants to make the window sized bigger or smaller than you would
like and you want to stop him?On Fri, Aug 3, 2012 at 7:37 PM, Jonathan Dearborn wrote:

Can you respond to a resize event by resizing to the minimum/maximum as
necessary?

Jonny D


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