Getting Contiunous Window Resize Event in SDL 2

2020-06-01 06:34发布

问题:

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;
  }
}

回答1:

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.



回答2:

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.



标签: c++ sdl-2