目前,我的程序在最小化和最小化(恢复/重新曝光)窗口后失去焦点而不是处理。
我已经在我的代码中添加了调试代码,以便在恢复最小化后的窗口后搜索出现的情况。
似乎正在发生的事件是SDL_WINDOWEVENT_EXPOSED
。
之后,窗口重新曝光我尝试处理它;但没有任何反应。在我恢复恢复之前,窗口没有响应。
这是我的代码:
void GPE_Renderer::handle_events(SDL_Event& e)
{
//Window event occured
if( e.type == SDL_WINDOWEVENT )
{
//Caption update flag
switch( e.window.event )
{
//Get new dimensions and repaint on window size change
case SDL_WINDOWEVENT_SIZE_CHANGED:
case SDL_WINDOWEVENT_RESIZED:
if( isMinimized)
{
SDL_RestoreWindow(gpeWindow);
//SDL_SetWindowSize(gpeWindow,mWidth,mHeight);
rWidth = mWidth;
rHeight = mHeight;
isMinimized = false;
clear_renderer();
record_error("Window unminimized");
}
else
{
if( e.window.data1>0 && e.window.data2 > 0)
{
mWidth = rWidth = e.window.data1;
mHeight = rHeight = e.window.data2;
isMinimized = false;
record_error("Window reiszed with proper data");
}
else
{
rWidth = mWidth;
rHeight = mHeight;
record_error("Window resize with improper data");
}
}
WINDOW_WAS_JUST_RESIZED = true;
break;
case SDL_WINDOWEVENT_MINIMIZED:
isMinimized = true;
isResized = true;
mWidth = rWidth;
mHeight = rHeight;
WINDOW_WAS_JUST_RESIZED = true;
record_error("Window minimized");
break;
case SDL_WINDOWEVENT_ENTER:
break;
case SDL_WINDOWEVENT_EXPOSED:
if( isMinimized)
{
isMinimized = false;
WINDOW_WAS_JUST_RESIZED = true;
SDL_SetWindowSize(gpeWindow,mWidth,mHeight);
SCREEN_WIDTH = rWidth = mWidth;
SCREEN_HEIGHT = rHeight = mHeight;
clear_renderer();
record_error("Window unminimized from being exposed!");
}
else
{
record_error("Window exposed!!!!");
}
break;
case SDL_WINDOWEVENT_LEAVE:
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
SDL_SetWindowTitle(gpeWindow,"[Game Pencil Engine]");
break;
case SDL_WINDOWEVENT_FOCUS_LOST:
SDL_SetWindowTitle(gpeWindow,"*Out of Focus*Game Pencil Engine");
break;
case SDL_WINDOWEVENT_CLOSE:
break;
case SDL_WINDOWEVENT_RESTORED:
if( isMinimized)
{
//SDL_SetWindowSize(gpeWindow,mWidth,mHeight);
rWidth = mWidth;
rHeight = mHeight;
isMinimized = false;
record_error("Window restored and unminimized");
}
else
{
rWidth = mWidth = MIN_WINDOW_WIDTH;
rHeight = mHeight = MIN_WINDOW_HEIGHT;
record_error("Window restored.");
}
isResized = true;
WINDOW_WAS_JUST_RESIZED = true;
break;
case SDL_WINDOWEVENT_NONE:
break;
default:
break;
}
}
}
答案 0 :(得分:0)
因此,此时似乎必须手动恢复窗口(并且最大化以获得正常效果)。
这是我在检查屏幕是否最小化后在SDL_WindowEvent_Exposed案例中添加的内容:
我修好了。
显然我必须恢复窗口。
我在expose事件中添加了这些行(在检查miniimize之后),这有效:
SDL_RestoreWindow(gpeWindow);
SDL_MaximizeWindow(gpeWindow);
SDL_GetWindowSize(gpeWindow,&mWidth,&mHeight);