Skip to content

Commit 7114ec3

Browse files
Allow window resizing
1 parent 4a2d0df commit 7114ec3

5 files changed

Lines changed: 41 additions & 3 deletions

File tree

CGame.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class CGame
7474

7575
bool Init();
7676
bool ReCreateWindow();
77+
void UpdateDisplaySize(unsigned width, unsigned height);
7778

7879
void EventHandling(SDL_Event* Event);
7980

CGame_Event.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ void CGame::EventHandling(SDL_Event* Event)
6363

6464
switch(Event->key.keysym.sym)
6565
{
66-
case SDLK_F2: fullscreen = !fullscreen; break;
66+
case SDLK_RETURN:
67+
case SDLK_KP_ENTER:
68+
if(Event->key.keysym.mod & KMOD_ALT)
69+
fullscreen = !fullscreen;
70+
break;
6771

6872
#ifdef _ADMINMODE
6973
case SDLK_F3: // if CTRL and ALT are pressed
@@ -377,6 +381,19 @@ void CGame::EventHandling(SDL_Event* Event)
377381
break;
378382
}
379383

384+
case SDL_WINDOWEVENT:
385+
{
386+
switch(Event->window.event)
387+
{
388+
case SDL_WINDOWEVENT_RESIZED:
389+
{
390+
UpdateDisplaySize(Event->window.data1, Event->window.data2);
391+
}
392+
break;
393+
}
394+
break;
395+
}
396+
380397
case SDL_QUIT: Running = false; break;
381398

382399
default: break;

CGame_Init.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "CGame.h"
77
#include "CIO/CFile.h"
8+
#include "CIO/CMenu.h"
9+
#include "CIO/CWindow.h"
810
#include "CMap.h"
911
#include "CSurface.h"
1012
#include "SGE/sge_blib.h"
@@ -22,7 +24,7 @@ bool CGame::ReCreateWindow()
2224
window_.reset();
2325
window_.reset(SDL_CreateWindow("Return to the Roots Map editor [BETA]", SDL_WINDOWPOS_CENTERED,
2426
SDL_WINDOWPOS_CENTERED, GameResolution.x, GameResolution.y,
25-
fullscreen ? SDL_WINDOW_FULLSCREEN : 0));
27+
fullscreen ? SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE));
2628
if(!window_)
2729
return false;
2830
renderer_.reset(SDL_CreateRenderer(window_.get(), -1, 0));
@@ -38,6 +40,19 @@ bool CGame::ReCreateWindow()
3840
return true;
3941
}
4042

43+
void CGame::UpdateDisplaySize(unsigned width, unsigned height)
44+
{
45+
GameResolution.x = width;
46+
GameResolution.y = height;
47+
displayTexture_.reset();
48+
displayTexture_ = makeSdlTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
49+
Surf_Display = makeRGBSurface(width, height, true);
50+
for(auto& menu : Menus)
51+
menu->resetSurface();
52+
for(auto& wnd : Windows)
53+
wnd->resetSurface();
54+
}
55+
4156
bool CGame::Init()
4257
{
4358
std::cout << "Return to the Roots Map editor\n";

CIO/CControlContainer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ class CControlContainer
6868
}
6969
void setWaste() { waste = true; }
7070
bool isWaste() const { return waste; }
71+
void resetSurface()
72+
{
73+
surface.reset();
74+
needRender = true;
75+
}
7176
// Methods
7277
CButton* addButton(void callback(int), int clickedParam, Uint16 x = 0, Uint16 y = 0, Uint16 w = 20, Uint16 h = 20,
7378
int color = BUTTON_GREY, const char* text = nullptr, int picture = -1);

callbacks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ void callback::EditorHelpMenu(int Param)
611611
"..............................F1");
612612
SelectBoxHelp->addOption(
613613
"Window/"
614-
"Fullscreen........................................................................................F2");
614+
"Fullscreen...................................................................................Alt+Enter");
615615
SelectBoxHelp->addOption(
616616
"Zoom in/normal/out......................................................................F5/F6/"
617617
"F7");

0 commit comments

Comments
 (0)