mirror of
				https://github.com/hedge-dev/UnleashedRecomp.git
				synced 2025-10-30 07:11:05 +00:00 
			
		
		
		
	window: fix abnormal window states erroneously saving dimensions
This commit is contained in:
		
							parent
							
								
									9e2edfe8cd
								
							
						
					
					
						commit
						fabc1ffbc7
					
				
					 3 changed files with 29 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -38,7 +38,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
 | 
			
		|||
                // Restore original window dimensions on F2.
 | 
			
		||||
                case SDLK_F2:
 | 
			
		||||
                    Config::Fullscreen = Window::SetFullscreen(false);
 | 
			
		||||
                    Window::SetDimensions(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, DEFAULT_WIDTH, DEFAULT_HEIGHT);
 | 
			
		||||
                    Window::SetDimensions(DEFAULT_WIDTH, DEFAULT_HEIGHT);
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                // Recentre window on F3.
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,7 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
 | 
			
		|||
                    if (Window::IsFullscreen())
 | 
			
		||||
                        break;
 | 
			
		||||
 | 
			
		||||
                    Window::SetDimensions(SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, Window::s_width, Window::s_height);
 | 
			
		||||
                    Window::SetDimensions(Window::s_width, Window::s_height);
 | 
			
		||||
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
| 
						 | 
				
			
			@ -82,42 +82,22 @@ int Window_OnSDLEvent(void*, SDL_Event* event)
 | 
			
		|||
                    break;
 | 
			
		||||
 | 
			
		||||
                case SDL_WINDOWEVENT_RESTORED:
 | 
			
		||||
                case SDL_WINDOWEVENT_MAXIMIZED:
 | 
			
		||||
                {
 | 
			
		||||
                    Config::WindowState = Window::IsMaximised()
 | 
			
		||||
                        ? EWindowState::Maximised
 | 
			
		||||
                        : EWindowState::Normal;
 | 
			
		||||
 | 
			
		||||
                    Config::WindowState = EWindowState::Normal;
 | 
			
		||||
                    break;
 | 
			
		||||
 | 
			
		||||
                case SDL_WINDOWEVENT_MAXIMIZED:
 | 
			
		||||
                    Config::WindowState = EWindowState::Maximised;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                case SDL_WINDOWEVENT_RESIZED:
 | 
			
		||||
                {
 | 
			
		||||
                    Window::s_width = event->window.data1;
 | 
			
		||||
                    Window::s_height = event->window.data2;
 | 
			
		||||
 | 
			
		||||
                    if (!Window::IsFullscreen())
 | 
			
		||||
                    {
 | 
			
		||||
                        Config::WindowWidth = Window::s_width;
 | 
			
		||||
                        Config::WindowHeight = Window::s_height;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                case SDL_WINDOWEVENT_MOVED:
 | 
			
		||||
                {
 | 
			
		||||
                    Window::s_x = event->window.data1;
 | 
			
		||||
                    Window::s_y = event->window.data2;
 | 
			
		||||
 | 
			
		||||
                    if (!Window::IsFullscreen())
 | 
			
		||||
                    {
 | 
			
		||||
                        Config::WindowX = Window::s_x;
 | 
			
		||||
                        Config::WindowY = Window::s_y;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
| 
						 | 
				
			
			@ -157,7 +137,7 @@ void Window::Init()
 | 
			
		|||
 | 
			
		||||
    s_pWindow = SDL_CreateWindow("SWA", s_x, s_y, s_width, s_height, GetWindowFlags());
 | 
			
		||||
 | 
			
		||||
    if (Config::Fullscreen)
 | 
			
		||||
    if (IsFullscreen())
 | 
			
		||||
        SDL_ShowCursor(SDL_DISABLE);
 | 
			
		||||
 | 
			
		||||
    SetIcon();
 | 
			
		||||
| 
						 | 
				
			
			@ -171,6 +151,17 @@ void Window::Init()
 | 
			
		|||
    s_handle = info.info.win.window;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Window::Update()
 | 
			
		||||
{
 | 
			
		||||
    if (!Window::IsFullscreen() && !Window::IsMaximised())
 | 
			
		||||
    {
 | 
			
		||||
        Config::WindowWidth = Window::s_width;
 | 
			
		||||
        Config::WindowHeight = Window::s_height;
 | 
			
		||||
        Config::WindowX = Window::s_x;
 | 
			
		||||
        Config::WindowY = Window::s_y;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CApplication::Update
 | 
			
		||||
PPC_FUNC_IMPL(__imp__sub_822C1130);
 | 
			
		||||
PPC_FUNC(sub_822C1130)
 | 
			
		||||
| 
						 | 
				
			
			@ -178,5 +169,7 @@ PPC_FUNC(sub_822C1130)
 | 
			
		|||
    SDL_PumpEvents();
 | 
			
		||||
    SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);
 | 
			
		||||
 | 
			
		||||
    Window::Update();
 | 
			
		||||
 | 
			
		||||
    __imp__sub_822C1130(ctx, base);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -106,12 +106,12 @@ public:
 | 
			
		|||
        return rect;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void SetDimensions(int x, int y, int w, int h)
 | 
			
		||||
    static void SetDimensions(int w, int h, int x = SDL_WINDOWPOS_CENTERED, int y = SDL_WINDOWPOS_CENTERED)
 | 
			
		||||
    {
 | 
			
		||||
        s_x = x;
 | 
			
		||||
        s_y = y;
 | 
			
		||||
        s_width = w;
 | 
			
		||||
        s_height = h;
 | 
			
		||||
        s_x = x;
 | 
			
		||||
        s_y = y;
 | 
			
		||||
 | 
			
		||||
        SDL_SetWindowSize(s_pWindow, w, h);
 | 
			
		||||
        SDL_ResizeEvent(s_pWindow, w, h);
 | 
			
		||||
| 
						 | 
				
			
			@ -151,6 +151,9 @@ public:
 | 
			
		|||
                auto x = s_x;
 | 
			
		||||
                auto y = s_y;
 | 
			
		||||
 | 
			
		||||
                if (!Config::Fullscreen && s_width == bounds.w && s_height == bounds.h)
 | 
			
		||||
                    return false;
 | 
			
		||||
 | 
			
		||||
                if (x == SDL_WINDOWPOS_CENTERED)
 | 
			
		||||
                    x = bounds.w / 2 - s_width / 2;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -169,4 +172,5 @@ public:
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    static void Init();
 | 
			
		||||
    static void Update();
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue