aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/cpp/WorldScene.cpp
blob: 973c6e6aeac0eeedbef80a87fd98e2a5fbcf782f (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)
{
    _tileSize = DEFAULT_TILE_SIZE_PX;
}

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

    rect.setSize(sf::Vector2f(_tileSize, _tileSize));
    rect.setFillColor(sf::Color::Green);

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

    _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)
{}