diff options
author | Nao Pross <naopross@thearcway.org> | 2018-02-12 00:13:39 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2018-02-12 00:13:39 +0100 |
commit | d3e8495212f9008f0c2650fb5ee628b464ca5ac0 (patch) | |
tree | e45ef935e17e24184cce7a75d5a281133d49b271 /src/main/cpp/Subconscious.cpp | |
parent | Update README to add dependencies (diff) | |
download | Subconscious-old-d3e8495212f9008f0c2650fb5ee628b464ca5ac0.tar.gz Subconscious-old-d3e8495212f9008f0c2650fb5ee628b464ca5ac0.zip |
Handle WindowResize event and add zoom
Diffstat (limited to '')
-rw-r--r-- | src/main/cpp/Subconscious.cpp | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp index 942b0b4..8e1bd02 100644 --- a/src/main/cpp/Subconscious.cpp +++ b/src/main/cpp/Subconscious.cpp @@ -3,6 +3,10 @@ #include <SFML/Graphics.hpp> +// TODO remove (needed for mousewheel debug) +#include <iostream> +#include <iomanip> + /*** public methods ***/ Subconscious::Subconscious() @@ -19,6 +23,35 @@ void Subconscious::run() { _running = true; while (_running && _window.isOpen()) { + + sf::Event event; + + while (_window.pollEvent(event)) { + switch (event.type) { + /*** Keyboard Events ***/ + /*** Mouse Events ***/ + case sf::Event::MouseWheelScrolled: + // my mouse always outputs +/- 1.0000, so the zoom speed + // is by 1/10.0 => .1 + // TODO make this a setting that chan be changed + // (mousewheel sensibility + // + // std::cout << std::fixed << std::setprecision(3) + // << event.mouseWheelScroll.delta << std::endl; + _currentScene->zoom(event.mouseWheelScroll.delta/10.0); + break; + + /*** Window Events ***/ + case sf::Event::Closed: + _window.close(); + break; + + case sf::Event::Resized: + _currentScene->resize(event.size); + break; + } + } + gameUpdate(); gameRender(); } @@ -26,7 +59,7 @@ void Subconscious::run() void Subconscious::demo() { - Scene *demoScene = new WorldScene(); + Scene *demoScene = new WorldScene(_window); _currentScene = demoScene; _scenes.push_back(demoScene); @@ -39,13 +72,6 @@ void Subconscious::demo() void Subconscious::gameUpdate() { - sf::Event event; - - while (_window.pollEvent(event)) { - if (event.type == sf::Event::Closed) { - _window.close(); - } - } } void Subconscious::gameRender() @@ -53,7 +79,7 @@ void Subconscious::gameRender() _window.clear(); if (_currentScene != nullptr) { - _currentScene->render(_window); + _currentScene->render(); } _window.display(); |