19
votes

I use the following structure to get new width and height of the resized SDL window. But with this structure I'm only able to get new data after the resizing is done that is when I finish dragging and release the mouse button. How can I get the new data continuously, that is while I'm dragging the window.

if (sdl_set->GetMainEvent()->type == SDL_WINDOWEVENT)
{
  if (sdl_set->GetMainEvent()->window.event == SDL_WINDOWEVENT_RESIZED)
  {
    ScreenWidth = sdl_set->GetMainEvent()->window.data1;
    ScreenHeight = sdl_set->GetMainEvent()->window.data2;
    cout << "Window Resized!" << endl;
  }
}
2
SDL_WINDOWEVENT_SIZE_CHANGED is NOT documented as providing continuous resizing updates. And experimentally (on mac os x) it doesn't. I also would like to know how to get continuous resize events during the user gesture! wiki.libsdl.org/SDL_WindowEventIDdavid van brink
It's actually impossible because of this bug: bugzilla.libsdl.org/show_bug.cgi?id=2077LB--
There is SDL_SetWindowsMessageHook which will call supplied function on every Windows message, before TranslateMessage.Xeverous

2 Answers

13
votes
static int resizingEventWatcher(void* data, SDL_Event* event) {
  if (event->type == SDL_WINDOWEVENT &&
      event->window.event == SDL_WINDOWEVENT_RESIZED) {
    SDL_Window* win = SDL_GetWindowFromID(event->window.windowID);
    if (win == (SDL_Window*)data) {
      printf("resizing.....\n");
    }
  }
  return 0;
}

int main() {
    SDL_Window* win = ...
    ...
    SDL_AddEventWatch(resizingEventWatcher, win);
    ...
}

use SDL's EventWatch can resolve it.

-6
votes

If you are on windows, have you tried using the windows api?

I know its not a real fix but if you are not making a cross platform application, you should give it a shot.

Use HWND to find SDL's window and return the window size.