diff --git a/FarOut/System.cpp b/FarOut/System.cpp index 05cc2dd..f82e35a 100644 --- a/FarOut/System.cpp +++ b/FarOut/System.cpp @@ -8,13 +8,24 @@ SystemClass System; //Constructor SystemClass::SystemClass() : - desktop(sf::VideoMode::getDesktopMode()), - window(desktop, "FarOut") + videoMode(sf::VideoMode::getDesktopMode()) { - inFocus = true; + windowTitle = "FarOut"; - addData("DesktopX", desktop.width); - addData("DesktopY", desktop.height); + std::vector modes = sf::VideoMode::getFullscreenModes(); + + for (int i = 0; i < modes.size(); ++i) { + if (modes[i].height == videoMode.height && modes[i].width == videoMode.width) { + videoMode = modes[i]; + break; + } + } + if (videoMode.isValid()) + window.create(videoMode, windowTitle, sf::Style::Fullscreen); + else window.create(videoMode, windowTitle); + + addData("DesktopX", videoMode.width); + addData("DesktopY", videoMode.height); view = window.getDefaultView(); @@ -22,13 +33,12 @@ SystemClass::SystemClass() : FPSActive = true; FPSFont.loadFromFile("Assets/AreaKilometer50.otf"); FPSText.setFont(FPSFont); - FPSText.setCharacterSize(desktop.height / 30); + FPSText.setCharacterSize(videoMode.height / 30); FPSText.setPosition(10, 0); //VSync VSyncEnabled = false; window.setVerticalSyncEnabled(VSyncEnabled); - //window.setMouseCursorVisible(false); //debug } @@ -132,20 +142,9 @@ void SystemClass::runWindow() { if (event.type == sf::Event::Closed) window.close(); - //Pauses when out of focus - if (event.type == sf::Event::LostFocus) - inFocus = false; - if (event.type == sf::Event::GainedFocus) - inFocus = true; - //Most events should only be checked when in focus - if (inFocus) { + if (window.hasFocus()) { if (event.type == sf::Event::KeyPressed) { - - //ESC - if (event.key.code == sf::Keyboard::Escape) - window.close(); - //VSync toggle if (event.key.code == sf::Keyboard::V) { if (VSyncEnabled) VSyncEnabled = false; @@ -161,7 +160,7 @@ void SystemClass::runWindow() { //time we came through this loop dt = clock.restart(); - if (inFocus) { + if (window.hasFocus()) { window.clear(); update(dt); @@ -227,8 +226,3 @@ void SystemClass::quit() { } - - - - - diff --git a/FarOut/SystemClass.h b/FarOut/SystemClass.h index 9e85c60..94806bc 100644 --- a/FarOut/SystemClass.h +++ b/FarOut/SystemClass.h @@ -33,11 +33,15 @@ class SystemClass { bool addData(std::string name, float toadd); float getData(std::string name); - //Other utility functions for developers + // Other utility functions for developers void setVSync(bool); void setFPSCounter(bool); void quit(); - + + // Window + sf::RenderWindow window; + sf::VideoMode videoMode; + private: // Basic actions to be taken each loop, including calling update // and draw functions for the active scene, and checking some key events @@ -52,11 +56,10 @@ class SystemClass { std::unordered_map dataCollection; //Window stuff - sf::VideoMode desktop; - sf::RenderWindow window; sf::View view; sf::Clock clock; bool VSyncEnabled; + std::string windowTitle; //FPS Counter void updateFPS(); @@ -66,9 +69,6 @@ class SystemClass { sf::Time FPSTime; sf::Clock FPSClock; int FPSFrames; - - //Misc - bool inFocus; }; extern SystemClass System; diff --git a/PrototypeScene.cpp b/PrototypeScene.cpp index bf8b2d0..6f63fde 100644 --- a/PrototypeScene.cpp +++ b/PrototypeScene.cpp @@ -69,6 +69,21 @@ PrototypeScene::~PrototypeScene() { // Update data members that get updated void PrototypeScene::update(sf::Time dt) { + + // Key press checks + if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { + System.quit(); + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::F3)) { + System.window.create(System.videoMode, "FarOut"); + } + + if (sf::Keyboard::isKeyPressed(sf::Keyboard::F4)) { + if(System.videoMode.isValid()) + System.window.create(System.videoMode, "FarOut", sf::Style::Fullscreen); + } + bg.update(dt); ship.update(dt); alien->update(dt, ship.getPosition());