diff --git a/CGame.h b/CGame.h index f1e74eb..20e66c8 100644 --- a/CGame.h +++ b/CGame.h @@ -42,6 +42,7 @@ class CGame CFont lastFps; Uint32 lastFrameTime = 0; + unsigned suppressResizeEvents_ = 0; // structure for mouse cursor struct @@ -65,6 +66,7 @@ class CGame std::unique_ptr MapObj; void SetAppIcon(); + void RecreateDisplayResources(); public: CGame(Extent GameResolution_, bool fullscreen_); @@ -74,6 +76,7 @@ class CGame bool Init(); bool ReCreateWindow(); + void UpdateDisplaySize(const Extent& newSize); void EventHandling(SDL_Event* Event); diff --git a/CGame_Event.cpp b/CGame_Event.cpp index 8799fcd..2292f5d 100644 --- a/CGame_Event.cpp +++ b/CGame_Event.cpp @@ -63,7 +63,11 @@ void CGame::EventHandling(SDL_Event* Event) switch(Event->key.keysym.sym) { - case SDLK_F2: fullscreen = !fullscreen; break; + case SDLK_RETURN: + case SDLK_KP_ENTER: + if(Event->key.keysym.mod & KMOD_ALT) + fullscreen = !fullscreen; + break; #ifdef _ADMINMODE case SDLK_F3: // if CTRL and ALT are pressed @@ -377,6 +381,20 @@ void CGame::EventHandling(SDL_Event* Event) break; } + case SDL_WINDOWEVENT: + { + if(Event->window.event == SDL_WINDOWEVENT_RESIZED) + { + if(suppressResizeEvents_ > 0) + { + suppressResizeEvents_--; + break; // Skip stale event from our own window recreation + } + UpdateDisplaySize(Extent(Event->window.data1, Event->window.data2)); + } + break; + } + case SDL_QUIT: Running = false; break; default: break; diff --git a/CGame_Init.cpp b/CGame_Init.cpp index 8c86271..8341fa9 100644 --- a/CGame_Init.cpp +++ b/CGame_Init.cpp @@ -5,6 +5,8 @@ #include "CGame.h" #include "CIO/CFile.h" +#include "CIO/CMenu.h" +#include "CIO/CWindow.h" #include "CMap.h" #include "CSurface.h" #include "SGE/sge_blib.h" @@ -17,20 +19,19 @@ bool CGame::ReCreateWindow() { + suppressResizeEvents_ = 3; displayTexture_.reset(); renderer_.reset(); window_.reset(); window_.reset(SDL_CreateWindow("Return to the Roots Map editor [BETA]", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, GameResolution.x, GameResolution.y, - fullscreen ? SDL_WINDOW_FULLSCREEN : 0)); + fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE)); if(!window_) return false; renderer_.reset(SDL_CreateRenderer(window_.get(), -1, 0)); if(!renderer_) return false; - displayTexture_ = makeSdlTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, GameResolution.x, - GameResolution.y); - Surf_Display = makeRGBSurface(GameResolution.x, GameResolution.y, true); + RecreateDisplayResources(); if(!displayTexture_ || !Surf_Display) return false; @@ -38,6 +39,24 @@ bool CGame::ReCreateWindow() return true; } +void CGame::RecreateDisplayResources() +{ + displayTexture_.reset(); + displayTexture_ = makeSdlTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, GameResolution.x, + GameResolution.y); + Surf_Display = makeRGBSurface(GameResolution.x, GameResolution.y, true); +} + +void CGame::UpdateDisplaySize(const Extent& newSize) +{ + GameResolution = newSize; + RecreateDisplayResources(); + for(auto& menu : Menus) + menu->resetSurface(); + for(auto& wnd : Windows) + wnd->resetSurface(); +} + bool CGame::Init() { std::cout << "Return to the Roots Map editor\n"; diff --git a/CGame_Render.cpp b/CGame_Render.cpp index d4c0bfd..a8ff988 100644 --- a/CGame_Render.cpp +++ b/CGame_Render.cpp @@ -39,6 +39,7 @@ void CGame::SetAppIcon() void CGame::Render() { + suppressResizeEvents_ = 0; if(Extent(Surf_Display->w, Surf_Display->h) != GameResolution || fullscreen != ((SDL_GetWindowFlags(window_.get()) & SDL_WINDOW_FULLSCREEN) != 0)) { diff --git a/CIO/CControlContainer.h b/CIO/CControlContainer.h index 6b23dbb..1f3f64a 100644 --- a/CIO/CControlContainer.h +++ b/CIO/CControlContainer.h @@ -68,6 +68,11 @@ class CControlContainer } void setWaste() { waste = true; } bool isWaste() const { return waste; } + void resetSurface() + { + surface.reset(); + needRender = true; + } // Methods CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 w = 20, Uint16 h = 20, int color = BUTTON_GREY, const char* text = nullptr, int picture = -1); diff --git a/callbacks.cpp b/callbacks.cpp index 31ede4d..6cde216 100644 --- a/callbacks.cpp +++ b/callbacks.cpp @@ -611,7 +611,7 @@ void callback::EditorHelpMenu(int Param) "..............................F1"); SelectBoxHelp->addOption( "Window/" - "Fullscreen........................................................................................F2"); + "Fullscreen...................................................................................Alt+Enter"); SelectBoxHelp->addOption( "Zoom in/normal/out......................................................................F5/F6/" "F7");