Add fullscreen support
This commit is contained in:
parent
6a6dad4cdb
commit
b700ed3111
1 changed files with 19 additions and 0 deletions
19
src/main.cpp
19
src/main.cpp
|
@ -33,6 +33,7 @@ int windowX = SDL_WINDOWPOS_CENTERED;
|
|||
int windowY = SDL_WINDOWPOS_CENTERED;
|
||||
int windowWidth = 640;
|
||||
int windowHeight = 480;
|
||||
int windowFullscreen = 0;
|
||||
|
||||
int toInt(const std::string &str) {
|
||||
std::stringstream ss(str);
|
||||
|
@ -62,6 +63,8 @@ void readConfig() {
|
|||
windowWidth = toInt(value);
|
||||
} else if(key == "height") {
|
||||
windowHeight = toInt(value);
|
||||
} else if(key == "fullscreen") {
|
||||
windowFullscreen = toInt(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +84,8 @@ void writeConfig() {
|
|||
|
||||
file << "width=" << w << "\n";
|
||||
file << "height=" << h << "\n";
|
||||
|
||||
file << "fullscreen=" << windowFullscreen << "\n";
|
||||
}
|
||||
|
||||
int main(int, char*[]) {
|
||||
|
@ -95,6 +100,8 @@ int main(int, char*[]) {
|
|||
SDL_WINDOW_RESIZABLE);
|
||||
if(!window)
|
||||
return -1;
|
||||
|
||||
SDL_SetWindowFullscreen(window, windowFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
|
||||
Renderer* renderer = new Renderer();
|
||||
|
||||
|
@ -139,6 +146,18 @@ int main(int, char*[]) {
|
|||
if(event.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||
target = renderer->createSurfaceRenderTarget(surface, target);
|
||||
}
|
||||
|
||||
if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_F11) {
|
||||
if(windowFullscreen == 1) {
|
||||
SDL_SetWindowFullscreen(window, 0);
|
||||
windowFullscreen = 0;
|
||||
} else {
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
windowFullscreen = 1;
|
||||
}
|
||||
|
||||
target = renderer->createSurfaceRenderTarget(surface, target);
|
||||
}
|
||||
}
|
||||
|
||||
renderer->render(world, target);
|
||||
|
|
Reference in a new issue