在SDL 2中获取连续的窗口调整大小事件 [英] Getting Contiunous Window Resize Event in SDL 2

查看:108
本文介绍了在SDL 2中获取连续的窗口调整大小事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

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可以解决该问题.

use SDL's EventWatch can resolve it.

这篇关于在SDL 2中获取连续的窗口调整大小事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆