aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/WorldScene.cpp
blob: 209596b20e37943e4785e67478c27edc8a48b919 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "WorldScene.hpp"

WorldScene::WorldScene(sf::RenderWindow &window) : Scene(window, Scene::Type::WORLD)
{
    _tileSize = DEFAULT_TILE_SIZE_PX;
}

void WorldScene::render()
{
    sf::RectangleShape rect;

    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);

    for (const Tile &tile : map.tiles()) {
        rect.setPosition(tile.x * _tileSize, tile.y * _tileSize);
        _window.draw(rect);
    }
}

void WorldScene::resize(const sf::Event::SizeEvent &size)
{
    auto oldView = _window.getView();
    sf::View resizedView(oldView.getCenter(), sf::Vector2f(size.width, size.height) / _zoom);

    _window.setView(resizedView);
}

void WorldScene::zoom(float factor)
{
    _zoom += factor;

    if (_zoom < MIN_ZOOM) {
        _zoom = MIN_ZOOM;
        return;
    }

    if (_zoom > MAX_ZOOM) {
        _zoom = MAX_ZOOM;
        return;
    }

    sf::View view = _window.getView();
    view.setSize(static_cast<sf::Vector2f>(_window.getSize()) / _zoom);
    _window.setView(view);
}

void WorldScene::pan(int dx, int dy)
{

}