Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [al5] Setting the minimum and maximum window size?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
[al5] Setting the minimum and maximum window size?
jmasterx
Member #11,410
October 2009

In the game that I will be planning to make, it will use Layouts and a few other things and I would like to make it so that the window can be no smaller than 320x240.

Is it possible to do this?

By this I mean, when you drag a corner of a window to re-size it, the window will stop becoming smaller when it hits a certain threshold.

I'm aware of al_resize_display() but I was wondering if there was a way to prevent the window from resizing in the first place.

Thanks

Edgar Reynaldo
Member #8,592
May 2007
avatar

I would also like to see support for (at least) minimum and (maybe) maximum window size, without the window temporarily appearing smaller than the minimum or larger than the maximum. It would be a really nice feature.

Elias
Member #358
May 2000

I'd like it as well. I'll do the X11 version of it if someone makes the Windows version. Since we have al_set_new_window_position already, I guess a function similar to that would fit well into the API.

--
"Either help out or stop whining" - Evert

Evert
Member #794
November 2000
avatar

The OS X version does this internally anyway (otherwise you can resize the window to something that's smaller than the titlebar and weirdness happens).

Thomas Fjellstrom
Member #476
June 2000
avatar

I half expected you could implement this yourself by just not acknowledging resizes once it gets too small or large..

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Evert
Member #794
November 2000
avatar

I half expected you could implement this yourself by just not acknowledging resizes once it gets too small or large..

That's not quite the same thing though, isn't it?
All that does is make the size of the drawing area not agree with the size of the window frame. The window frame itself is still resized. Or is that not the case in X11?

Matthew Leverton
Supreme Loser
January 1999
avatar

I half expected you could implement this yourself by just not acknowledging resizes once it gets too small or large..

The window is still resized, even if you don't acknowledge it.

There needs to be a function al_set_window_constraints(display, minw, minh, maxw, maxh). It doesn't need to affect explicit resizes.

(Edit: maybe even an optional ratio parameter... Not sure what is easily supported by the underlying OS.)

Thomas Fjellstrom
Member #476
June 2000
avatar

Or maybe allegro shouldn't allow the resize if it isn't acknowledged. But either way works.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Matthew Leverton
Supreme Loser
January 1999
avatar

Or maybe allegro shouldn't allow the resize if it isn't acknowledged. But either way works.

That doesn't really work very well with events.

Plus, you need to have the ability to clamp to the constraints. If the minimum width is 300, you wouldn't want an attempt to resize to 295 to be ignored completely... you'd want it to clamp to 300.

Evert
Member #794
November 2000
avatar

Or maybe allegro shouldn't allow the resize if it isn't acknowledged.

That would be nice, but unfortunately the way it works (at least on OS X) is that the Window is resized, we get a "window resized" message, which Allegro passes on to the user, who then calls a function to synchronise the size of the backbuffer with whatever size it should be.

jmasterx
Member #11,410
October 2009

Turns out this is dead easy in Windows:

In the message loop, just handle the:

WM_GETMINMAXINFO

message

and just fill out the MINMAXINFO structure.

http://msdn.microsoft.com/en-us/library/ms632626%28v=vs.85%29.aspx

Matthew Leverton
Supreme Loser
January 1999
avatar

One of the comments says:

Quote:

It should be noted, that the values specified in the MINMAXINFO structure are the client plus non-client (including the caption and borders) size of the window. Most Windows programmers know this, but it isn't really noted here.

But that's not how Allegro should work if at all possible. The value specified should be the internal (buffer) size.

Thomas Fjellstrom
Member #476
June 2000
avatar

Evert said:

That would be nice, but unfortunately the way it works (at least on OS X) is that the Window is resized, we get a "window resized" message, which Allegro passes on to the user, who then calls a function to synchronise the size of the backbuffer with whatever size it should be.

That's odd. I expected it to give you a "Begin Resize" event that you can ignore, or call a function, or return a special variable to cancel the resize (or clamp it).

But that's not how Allegro should work if at all possible. The value specified should be the internal (buffer) size.

It's not that hard to do the math, just fetch the non-client border size, and combine it with the numbers specified by the user with the new function.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

But can't you just use:

GetSystemMetrics(SM_CYBORDER); // get the border width
GetSystemMetrics (SM_CYCAPTION); //get title bar height

and then do the math so the struct is correct?

Evert
Member #794
November 2000
avatar

I expected it to give you a "Begin Resize" event that you can ignore, or call a function, or return a special variable to cancel the resize (or clamp it).

Well, ok, you do get viewWillStartLiveResize`/`viewDidEndLiveResize, but you can't cancel the resize.

jmasterx
Member #11,410
October 2009

For OSX can't you simply do:

[theWindow setMaxSize:windowMaxSize];
[theWindow setMinSize:windowMinSize];

Evert
Member #794
November 2000
avatar

jmasterx said:

[theWindow setMaxSize:windowMaxSize];
[theWindow setMinSize:windowMinSize];

Yes. I didn't mean to imply it'd be in any way difficult.

jmasterx
Member #11,410
October 2009

Okay great! Looks like the only one that would be left is Linux!

It would be nice if this feature could make it into 5.03 ; it feels like it should be part of 5 and not just >= 5.1 .

Thomas Fjellstrom
Member #476
June 2000
avatar

As long as it can be done without breaking Binary Compatibility, it could be added to 5.0.x

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Arthur Kalliokoski
Second in Command
February 2005
avatar

jmasterx said:

Looks like the only one that would be left is Linux!

xdisplay.c already has

      hints->min_width  = hints->max_width  = hints->base_width  = d->w;
      hints->min_height = hints->max_height = hints->base_height = d->h;

“Throughout history, poverty is the normal condition of man. Advances which permit this norm to be exceeded — here and there, now and then — are the work of an extremely small minority, frequently despised, often condemned, and almost always opposed by all right-thinking people. Whenever this tiny minority is kept from creating, or (as sometimes happens) is driven out of a society, the people then slip back into abject poverty. This is known as "bad luck.”

― Robert A. Heinlein

Thomas Fjellstrom
Member #476
June 2000
avatar

Yeah, it wouldn't be that hard to support.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

jmasterx
Member #11,410
October 2009

Evert said:

Well, ok, you do get viewWillStartLiveResize`/`viewDidEndLiveResize, but you can't cancel the resize.

I think that Allegro should still integrate the resize begin and resize end though. Not for the min max size, but to add consistency when resizing. What I mean is, right now in OSX and I think Linux, the Window resizes in real time, but in Windows it just awkwardly stretches what was there until you let go of the mouse.

What this could allow is to blit a black rectangle before the resize begins so that while it is resizing the screen is black across all platforms.

Evert
Member #794
November 2000
avatar

jmasterx said:

I think that Allegro should still integrate the resize begin and resize end though.

What do you mean?
Allegro generates a "display resized" message when it receives a "resize done" message.

Quote:

What I mean is, right now in OSX and I think Linux, the Window resizes in real time, but in Windows it just awkwardly stretches what was there until you let go of the mouse.

On OS X, I think there's a flag that controls the behaviour of the window while it resizes. Not sure though, but it would make sense. Would then also make sense to have the same on other platforms.

jmasterx
Member #11,410
October 2009

What I mean is that, for example, in Windows, I can drag around the Window for 8 hours, but I will not get a single ALLEGRO_EVENT_DISPLAY_RESIZED event until I let go my mouse. So I have no way to blit that black rectangle.

My biggest issue is that in Windows the old contents is stretched while resizing which I find ugly, I'd rather have control of what I see when it is resizing and that I can make it consistent across all platforms.

Elias
Member #358
May 2000

In X11 it's up to the window manager how to resize. E.g. in compiz I can set it to only show a transparent rectangle while resizing then send a single resize message to the application when I let go, or I can set it to stretch, or to constantly send 100ds of messages to the application during the resize. The application itself doesn't know which way is being used (at least not by default, possibly there's a way to override it somehow).

Anyway, I agree that the Windows behavior should be changed and if we can have three events for resize_start, resize_in_progress and resize_done (or a flag in the ALLEGRO_EVENT_DISPLAY_RESIZED event indicating which of the three it is), all the better.

--
"Either help out or stop whining" - Evert

 1   2 


Go to: