summaryrefslogtreecommitdiff
path: root/src/editor.hpp
blob: 13f9cac8c7b6aeef0ab6030169692f3b6babcea5 (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
#pragma once

#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Event.hpp>
#include <memory>
#include <optional>
#include <string>

#include "floor.hpp"
#include "tileset.hpp"

namespace silly::editor {
  struct NewTileState {
      std::string path;
      sf::Texture texture;
      TilesetTileType type;
  };

  class Editor {
    public:
      Editor(Tileset &tileset, TileFloor &floor)
          : tileset(tileset), floor(floor) {}

      void update(sf::RenderWindow &window);
      void update(const sf::Event &event, sf::RenderWindow &window);
      void render(const sf::RenderWindow &window);
      const float get_zoom() const;

    private:
      Tileset &tileset;
      TileFloor &floor;
      float rotation;

      // need for world movement and zoom
      sf::Vector2f lastMousePosition;
      float zoom = 1.0f;
      bool isDragging = false;

      std::optional<std::shared_ptr<TilesetTile>> selectedTile;
      std::optional<NewTileState> newTileState;
  };
}