我使用以下结构来获取调整后的SDL窗口的新宽度和高度。但是使用这种结构,我只能在调整大小后(即完成拖动并释放鼠标按钮时)获得新数据。我如何连续获取新数据,也就是拖动窗口时。

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

最佳答案

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

使用SDL的EventWatch可以解决它。

关于c++ - 在SDL 2中获取连续的窗口调整大小事件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32294913/

10-10 06:45