Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class CGame
CFont lastFps;

Uint32 lastFrameTime = 0;
unsigned suppressResizeEvents_ = 0;

// structure for mouse cursor
struct
Expand All @@ -65,6 +66,7 @@ class CGame
std::unique_ptr<CMap> MapObj;

void SetAppIcon();
void RecreateDisplayResources();

public:
CGame(Extent GameResolution_, bool fullscreen_);
Expand All @@ -74,6 +76,7 @@ class CGame

bool Init();
bool ReCreateWindow();
void UpdateDisplaySize(const Extent& newSize);

void EventHandling(SDL_Event* Event);

Expand Down
20 changes: 19 additions & 1 deletion CGame_Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
27 changes: 23 additions & 4 deletions CGame_Init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,27 +19,44 @@

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;

SetAppIcon();
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unify the duplicated code here and above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved into RecreateDisplayResources()

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";
Expand Down
1 change: 1 addition & 0 deletions CGame_Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
5 changes: 5 additions & 0 deletions CIO/CControlContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down