gpt4 book ai didi

c++ - SDL_WINDOWEVENT_SIZE_CHANGED 和 SDL_WINDOWEVENT_RESIZED 不工作?

转载 作者:行者123 更新时间:2023-11-30 03:14:48 30 4
gpt4 key购买 nike

我正在尝试检测 SDL2 窗口的大小何时发生变化。但是 SDL_WINDOWEVENT_RESIZED 和 SDL_WINDOWEVENT_SIZE_CHANGED 都不起作用,至少在 MacOS 上是这样。这是我的代码:

SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 100, 100, SDL_WINDOW_RESIZABLE);
SDL_Renderer *ren = SDL_CreateRenderer(win, 0, 0);

bool running = true;
SDL_Event event;
while (running) {
while(SDL_PollEvent(&event) != 0) {
if(event.type == SDL_QUIT) {
running = false;
}

if(event.type == SDL_WINDOWEVENT_SIZE_CHANGED) {
return 3;
}

if(event.type == SDL_WINDOWEVENT_RESIZED) {
return 4;
}
}

SDL_RenderClear(ren);
}
SDL_DestroyRenderer(ren);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;

运行程序和调整窗口大小时没有任何反应。我做错了什么还是错误?

编辑:我查阅了有关窗口事件的文档(https://wiki.libsdl.org/SDL_WindowEvent)。它说要写这样的东西:

event.window.type == SDL_WINDOWEVENT_SIZE_CHANGED 

但这也行不通。

最佳答案

SDL_WINDOWEVENT_* 不是事件类型,而是 SDL_WindowEventID .也就是说,如果您的 event.typeSDL_WINDOWEVENT,您可以访问 window union 字段以获取额外数据,包括 event,例如

while(SDL_PollEvent(&event)) {
if(event.type == SDL_WINDOWEVENT) {
if(event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
// ...
}
}
}

关于c++ - SDL_WINDOWEVENT_SIZE_CHANGED 和 SDL_WINDOWEVENT_RESIZED 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57492243/

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