Dynamic window resize

Hello,

I’m trying to get rid of the ugly blue that appears (on Windows, at least) when I try to resize a window (the window isn’t updated until the mouse is released).
Brian Barrett gave me a solution using SDL_SetEventFilter (see here (http://www.gamedev.net/community/forums/topic.asp?topic_id=428022)) in another post, but as he said it’s not pretty.

I see at least two problems with this solution :

  • I’ve set up a minimal height and width for my window and the drawing gets weird when I go under these values.
  • My draw() function uses a lot of parameters, which seems logical unless you want to always draw the same thing, but the eventFilter() function (the parameter SDL_SetEventFilter) of is of fixed type so I can’t give parameters to my draw() function unless I use global variables, which I want to avoid.

Can you help me to improve this solution or to find a better one please ?

Thanks.

Nobody has a solution to this “bug” ?
I suppose I’m not the first one ever trying to resize a SDL window on Windows…

If you’re using C++, you could put your SDL_EventFilter function in a
class as a static member, then use other static members to store the
parameters. Or just use a namespace.On 6 May 2010 16:01, Lilly wrote:

  • My draw() function uses a lot of parameters, which seems logical unless
    you want to always draw the same thing, but the eventFilter() function (the
    parameter SDL_SetEventFilter) of is of fixed type so I can’t give parameters
    to my draw() function unless I use global variables, which I want to avoid.

What language are you working with? This could be solved pretty easily
with a closure, if you have support for them…> ----- Original Message -----

From: lilly@yopmail.com (Lilly)
Subject: Re: [SDL] dynamic window resize

  • My draw() function uses a lot of parameters, which seems logical unless
    you want to always draw the same thing, but the eventFilter() function (the
    parameter SDL_SetEventFilter) of is of fixed type so I can’t give parameters
    to my draw() function unless I use global variables, which I want to avoid.

Actually, you might be able to do something similar in C depending on
what compiler you’re using. If you nest one function inside another,
you can access local variables in the outer function, provided they
were declared before the inner function and not overridden in the
inner function. But again, this depends on the compiler. If you’re
trying to write portable code, don’t do this.

There is apparently some support for closures in some C++ compilers
(VC 2010 and GCC 4.5):

For details, look here:
http://val.samko.info/lambda/
http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2006/n1968.pdfOn 10 May 2010 16:44, Mason Wheeler wrote:

What language are you working with? ?This could be solved pretty easily
with a closure, if you have support for them…

Oh, does C allow Pascal-style nested functions? I’ve never heard
of that being available. Which compilers can do that?>----- Original Message ----

From: Kenneth Bull
Subject: Re: [SDL] dynamic window resize

On 10 May 2010 16:44, Mason Wheeler <@Mason_Wheeler> wrote:

What language are you working with? This could be solved pretty easily
with a closure, if you have support for them…

Actually, you might be able to do something similar in C depending on
what compiler you’re using. If you nest one function inside another,
you can access local variables in the outer function, provided they
were declared before the inner function and not overridden in the
inner function. But again, this depends on the compiler. If you’re
trying to write portable code, don’t do this.

I don’t think this works, in C or in Pascal. SDL_SetEventFilter
requires a plain function pointer as an argument, not a closure.On 5/10/2010 15:15, Kenneth Bull wrote:

On 10 May 2010 16:44, Mason Wheeler wrote:

What language are you working with? This could be solved pretty easily
with a closure, if you have support for them…

Actually, you might be able to do something similar in C depending on
what compiler you’re using. If you nest one function inside another,
you can access local variables in the outer function, provided they
were declared before the inner function and not overridden in the
inner function. But again, this depends on the compiler. If you’re
trying to write portable code, don’t do this.


Rainer Deyke - rainerd at eldwood.com

What language are you working with? This could be solved pretty easily
with a closure, if you have support for them…

Actually, you might be able to do something similar in C depending on
what compiler you’re using. If you nest one function inside another,
you can access local variables in the outer function, provided they
were declared before the inner function and not overridden in the
inner function. But again, this depends on the compiler. If you’re
trying to write portable code, don’t do this.

I don’t think this works, in C or in Pascal. SDL_SetEventFilter
requires a plain function pointer as an argument, not a closure.

Sure, but if the plain callback you send it invokes a closure on your end,
that closure can contain extra data that the function’s signature won’t
allow you to pass in directly. ;)>----- Original Message ----

From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize
On 5/10/2010 15:15, Kenneth Bull wrote:

On 10 May 2010 16:44, Mason Wheeler <@Mason_Wheeler> wrote:

It’s been a while since I used it. I don’t think it’s standard. It
works in GCC.

http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

Pointers to nested functions are ordinary function pointers, so
passing them as callbacks is no problem as long as you don’t end up
referring to a local variable after the parent function returns or
something like that.On 10 May 2010 17:25, Mason Wheeler wrote:

Oh, does C allow Pascal-style nested functions? ?I’ve never heard
of that being available. ?Which compilers can do that?

Oh, does C allow Pascal-style nested functions? I’ve never heard
of that being available. Which compilers can do that?

It’s been a while since I used it. I don’t think it’s standard. It
works in GCC.

http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

Pointers to nested functions are ordinary function pointers, so
passing them as callbacks is no problem as long as you don’t end up
referring to a local variable after the parent function returns or
something like that.

…which makes them useless as closures. That’s why Pascal doesn’t
let you take the address of a nested function and use it as a function
pointer, (you’d end up with undefined behavior,) and why the Delphi team
had to come up with a new syntax when they added closures to the
language a couple years ago.>----- Original Message ----

From: Kenneth Bull
Subject: Re: [SDL] dynamic window resize
On 10 May 2010 17:25, Mason Wheeler <@Mason_Wheeler> wrote:

could still use them from main() or whereever your main loop is.On 10 May 2010 19:15, Mason Wheeler wrote:

…which makes them useless as closures. ?That’s why Pascal doesn’t
let you take the address of a nested function and use it as a function
pointer, (you’d end up with undefined behavior,) and why the Delphi team
had to come up with a new syntax when they added closures to the
language a couple years ago.

I don’t think this works, in C or in Pascal. SDL_SetEventFilter
requires a plain function pointer as an argument, not a closure.

Sure, but if the plain callback you send it invokes a closure on your end,
that closure can contain extra data that the function’s signature won’t
allow you to pass in directly. :wink:

You could, but the closure would have to be stored in a variable of
static duration, and the question was about avoiding such variables. In
essence, you are suggesting the use of a global variable to avoid global
variables.On 5/10/2010 15:47, Mason Wheeler wrote:

----- Original Message ----
From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize


Rainer Deyke - rainerd at eldwood.com

I don’t think this works, in C or in Pascal. SDL_SetEventFilter
requires a plain function pointer as an argument, not a closure.

Sure, but if the plain callback you send it invokes a closure on your end,
that closure can contain extra data that the function’s signature won’t
allow you to pass in directly. :wink:

You could, but the closure would have to be stored in a variable of
static duration, and the question was about avoiding such variables. In
essence, you are suggesting the use of a global variable to avoid global
variables.

…or you could use the Userdata parameter.>----- Original Message ----

From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize
On 5/10/2010 15:47, Mason Wheeler wrote:

----- Original Message ----
From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize

You could, but the closure would have to be stored in a variable of
static duration, and the question was about avoiding such variables. In
essence, you are suggesting the use of a global variable to avoid global
variables.

…or you could use the Userdata parameter.

…then again, with the Userdata parameter you could just make it a pointer
to an object or struct containing all the extra data you need anyway, and
avoid the need for a closure.>----- Original Message ----

From: Mason Wheeler <@Mason_Wheeler>
Subject: Re: [SDL] dynamic window resize

You could, but the closure would have to be stored in a variable of
static duration, and the question was about avoiding such variables. In
essence, you are suggesting the use of a global variable to avoid global
variables.

…or you could use the Userdata parameter.

You could, if SDL_SetEventFilter had one. But then you wouldn’t need
closures.

Avoiding global variables here is somewhat silly anyway.
SDL_SetEventFilter already specifies a global behavior. Adding more
global variables into the mix won’t make things worse.

(I would suggest placing those variables in an anonymous namespace in
C++. This gives the static duration, but hides them from the rest of
the program. The equivalent in C is file-scope static variables.)On 5/10/2010 19:53, Mason Wheeler wrote:

----- Original Message ----
From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize


Rainer Deyke - rainerd at eldwood.com

…or you could use the Userdata parameter.

You could, if SDL_SetEventFilter had one. But then you wouldn’t need
closures.

It does, at least in SDL 1.3. I’ve got the source right in front of me.

extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
void *userdata);

Not sure about 1.2, though.>----- Original Message ----

From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize
On 5/10/2010 19:53, Mason Wheeler wrote:

You could, if SDL_SetEventFilter had one. But then you wouldn’t need
closures.

It does, at least in SDL 1.3. I’ve got the source right in front of me.

extern DECLSPEC void SDLCALL SDL_SetEventFilter(SDL_EventFilter filter,
void *userdata);

Not sure about 1.2, though.

It doesn’t in 1.2. I checked before posting.On 5/10/2010 20:10, Mason Wheeler wrote:

----- Original Message ----
From: Rainer Deyke
Subject: Re: [SDL] dynamic window resize


Rainer Deyke - rainerd at eldwood.com

Thanks a lot for all these answers.
I’m programming in C, and I’d like my application to be portable.
Does that mean there’s no solution for me?

Which SDL version are you using? 1.3 provides the Userdata parameter, which you can use to get around the whole problem. But apparently you don’t have that option in 1.2. If you’re on 1.2, with no access to closures, you may have to use a global or something like that.>From: Lilly

Subject: Re: [SDL] dynamic window resize

Thanks a lot for all these answers.
I’m programming in C, and I’d like my application to be portable.
Does that mean there’s no solution for me?

Hello guys,

I just verified this solution on MacOSX with SDL 1.3 and it works perfect. My application event queue was stopped, well basically the main thread was stopped (other threads were running) when I entered Cocoa menu or started window resizing. Now it works perfect, except it’s not a good idea to do the animation stuff from event filter before event enters the queue. Is there any way to get the state of main thread and in case it’s frozen by window resize or something else, I would process few events from the filter, otherwise they would be handled normally from main thread.

thanks,
PavelOn 11.5.2010, at 22:57, Mason Wheeler wrote:

Which SDL version are you using? 1.3 provides the Userdata parameter, which you can use to get around the whole problem. But apparently you don’t have that option in 1.2. If you’re on 1.2, with no access to closures, you may have to use a global or something like that.

From: Lilly
Subject: Re: [SDL] dynamic window resize

Thanks a lot for all these answers.
I’m programming in C, and I’d like my application to be portable.
Does that mean there’s no solution for me?


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