aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/WorldScene.cpp
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-02-12 00:13:39 +0100
committerNao Pross <naopross@thearcway.org>2018-02-12 00:13:39 +0100
commitd3e8495212f9008f0c2650fb5ee628b464ca5ac0 (patch)
treee45ef935e17e24184cce7a75d5a281133d49b271 /src/main/cpp/WorldScene.cpp
parentUpdate README to add dependencies (diff)
downloadSubconscious-old-d3e8495212f9008f0c2650fb5ee628b464ca5ac0.tar.gz
Subconscious-old-d3e8495212f9008f0c2650fb5ee628b464ca5ac0.zip
Handle WindowResize event and add zoom
Diffstat (limited to 'src/main/cpp/WorldScene.cpp')
-rw-r--r--src/main/cpp/WorldScene.cpp37
1 files changed, 32 insertions, 5 deletions
diff --git a/src/main/cpp/WorldScene.cpp b/src/main/cpp/WorldScene.cpp
index ab1c4d0..973c6e6 100644
--- a/src/main/cpp/WorldScene.cpp
+++ b/src/main/cpp/WorldScene.cpp
@@ -1,11 +1,11 @@
#include "WorldScene.hpp"
-WorldScene::WorldScene()
+WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window)
{
_tileSize = DEFAULT_TILE_SIZE_PX;
}
-void WorldScene::render(sf::RenderWindow &window)
+void WorldScene::render()
{
sf::RectangleShape rect;
@@ -17,12 +17,39 @@ void WorldScene::render(sf::RenderWindow &window)
for (const Tile &tile : map.tiles()) {
rect.setPosition(tile.x * _tileSize, tile.y * _tileSize);
- window.draw(rect);
+ _window.draw(rect);
}
}
-void WorldScene::zoom(int value)
-{}
+void WorldScene::resize(const sf::Event::SizeEvent &size)
+{
+ auto oldView = _window.getView();
+ sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height));
+
+ _window.setView(resizedView);
+}
+
+void WorldScene::zoom(float factor)
+{
+ _zoom += factor;
+
+ if (_zoom < MIN_ZOOM) {
+ _zoom = MIN_ZOOM;
+ }
+
+ if (_zoom > MAX_ZOOM) {
+ _zoom = MAX_ZOOM;
+ }
+
+ sf::View view = _window.getView();
+
+ view.setSize(
+ _window.getSize().x * 1 / _zoom,
+ _window.getSize().y * 1 / _zoom
+ );
+
+ _window.setView(view);
+}
void WorldScene::pan(int dx, int dy)
{}