diff options
Diffstat (limited to 'src/main/cpp')
-rw-r--r-- | src/main/cpp/Subconscious.cpp | 9 | ||||
-rw-r--r-- | src/main/cpp/WorldScene.cpp | 18 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/main/cpp/Subconscious.cpp b/src/main/cpp/Subconscious.cpp index b53a38b..a4f6128 100644 --- a/src/main/cpp/Subconscious.cpp +++ b/src/main/cpp/Subconscious.cpp @@ -55,7 +55,11 @@ void Subconscious::run() // // std::cout << std::fixed << std::setprecision(3) // << event.mouseWheelScroll.delta << std::endl; - _currentScene->zoom(event.mouseWheelScroll.delta/10.0); + + if (_currentScene->type == Scene::Type::WORLD) { + static_cast<WorldScene*>(_currentScene)->zoom(event.mouseWheelScroll.delta/10.0); + } + break; /*** Window Events ***/ @@ -66,6 +70,9 @@ void Subconscious::run() case sf::Event::Resized: _currentScene->resize(event.size); break; + + default: + break; } } diff --git a/src/main/cpp/WorldScene.cpp b/src/main/cpp/WorldScene.cpp index 973c6e6..209596b 100644 --- a/src/main/cpp/WorldScene.cpp +++ b/src/main/cpp/WorldScene.cpp @@ -1,6 +1,6 @@ #include "WorldScene.hpp" -WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window) +WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window, Scene::Type::WORLD) { _tileSize = DEFAULT_TILE_SIZE_PX; } @@ -12,6 +12,7 @@ void WorldScene::render() rect.setSize(sf::Vector2f(_tileSize, _tileSize)); rect.setFillColor(sf::Color::Green); + // negative thickness to make the outline toward inside rect.setOutlineThickness(-.5); rect.setOutlineColor(sf::Color::Black); @@ -24,7 +25,7 @@ void WorldScene::render() void WorldScene::resize(const sf::Event::SizeEvent &size) { auto oldView = _window.getView(); - sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height)); + sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height) / _zoom); _window.setView(resizedView); } @@ -35,21 +36,20 @@ void WorldScene::zoom(float factor) if (_zoom < MIN_ZOOM) { _zoom = MIN_ZOOM; + return; } if (_zoom > MAX_ZOOM) { _zoom = MAX_ZOOM; + return; } sf::View view = _window.getView(); - - view.setSize( - _window.getSize().x * 1 / _zoom, - _window.getSize().y * 1 / _zoom - ); - + view.setSize(static_cast<sf::Vector2f>(_window.getSize()) / _zoom); _window.setView(view); } void WorldScene::pan(int dx, int dy) -{} +{ + +} |