aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-02-12 19:31:45 +0100
committerNao Pross <naopross@thearcway.org>2018-02-12 19:31:45 +0100
commit43d0e11b4c9cd601f23cfe99a188ede598be418c (patch)
tree6a31fffae507997c0038177cbbccc984a468be04 /src
parentUpdate gitignore to ignore ctags (diff)
downloadSubconscious-old-43d0e11b4c9cd601f23cfe99a188ede598be418c.tar.gz
Subconscious-old-43d0e11b4c9cd601f23cfe99a188ede598be418c.zip
Fix zoom bug, add Scene.type member
Diffstat (limited to '')
-rw-r--r--src/main/cpp/Subconscious.cpp9
-rw-r--r--src/main/cpp/WorldScene.cpp18
-rw-r--r--src/main/headers/Scene.hpp13
-rw-r--r--src/main/headers/WorldScene.hpp4
4 files changed, 28 insertions, 16 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)
-{}
+{
+
+}
diff --git a/src/main/headers/Scene.hpp b/src/main/headers/Scene.hpp
index 757202c..2183d63 100644
--- a/src/main/headers/Scene.hpp
+++ b/src/main/headers/Scene.hpp
@@ -6,21 +6,26 @@
class Scene
{
public:
- constexpr static float MAX_ZOOM = 10;
- constexpr static float MIN_ZOOM = .1;
+ enum Type
+ {
+ WORLD, MENU
+ };
+
+ const Type type;
+
+ Scene() = delete;
virtual void render() = 0;
virtual void resize(const sf::Event::SizeEvent &size) = 0;
virtual void click(const sf::Event::MouseButtonEvent &click) {}
virtual void keyPress(const sf::Event::KeyEvent &event) {}
- virtual void zoom(float factor) {}
protected:
float _zoom = 1;
sf::RenderWindow &_window;
- Scene(sf::RenderWindow &window) : _window(window) {}
+ Scene(sf::RenderWindow &window, Type _type) : type(_type), _window(window) {}
};
#endif
diff --git a/src/main/headers/WorldScene.hpp b/src/main/headers/WorldScene.hpp
index 09f3120..ec12930 100644
--- a/src/main/headers/WorldScene.hpp
+++ b/src/main/headers/WorldScene.hpp
@@ -10,8 +10,8 @@
class WorldScene : public Scene
{
public:
- constexpr static int ZOOM_MIN = 1;
- constexpr static int ZOOM_MAX = 100;
+ constexpr static float MAX_ZOOM = 10;
+ constexpr static float MIN_ZOOM = 1/2.0;
constexpr static int DEFAULT_TILE_SIZE_PX = 20;
WorldScene(sf::RenderWindow &window);