gpt4 book ai didi

c++ - 在 SDL 2 中获取连续的窗口调整大小事件

转载 作者:IT老高 更新时间:2023-10-28 22:41:27 26 4
gpt4 key购买 nike

我使用以下结构来获取调整大小的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com