blob: 74c14fadd83d788acc3b038d1fddb541bbadd540 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
#include <imgui-SFML.h>
#include <imgui.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/RectangleShape.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/System/Clock.hpp>
#include <SFML/System/Vector2.hpp>
#include <SFML/Window/Event.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <optional>
#include "editor.hpp"
#include "level.hpp"
#include "nfd.hpp"
#include "package.hpp"
int main() {
NFD::Guard nfdGuard;
sf::RenderWindow window(sf::VideoMode({800, 600}), "sillyeditor");
window.setFramerateLimit(60);
ImGui::SFML::Init(window);
silly::editor::LevelPackage package;
silly::editor::Editor editor(package);
sf::Clock deltaClock;
while (window.isOpen()) {
// zoom size
float size = 16.0f;
while (const std::optional<sf::Event> event = window.pollEvent()) {
if (event.has_value()) {
sf::Event e = event.value();
ImGui::SFML::ProcessEvent(window, e);
editor.update(e, window);
}
// (cv pasted from
// https://www.sfml-dev.org/tutorials/3.0/graphics/view/#showing-more-when-the-window-is-resized)
// catch the resize events
if (const auto *resized = event->getIf<sf::Event::Resized>()) {
// update the view to the new size of the window
sf::FloatRect visibleArea({0.f, 0.f}, sf::Vector2f(resized->size));
sf::View view(visibleArea);
view.setCenter(window.getView().getCenter());
view.zoom(editor.get_zoom());
window.setView(view);
}
if (event->is<sf::Event::Closed>()) {
window.close();
}
}
editor.update(window);
ImGui::SFML::Update(window, deltaClock.restart());
window.clear();
if (!package.get_levels().empty() &&
!package.get_current_level().get_floors().empty()) {
silly::editor::TileLevel &level = package.get_current_level();
silly::editor::TileFloor &floor = level.get_current_floor();
floor.render(window);
// rendering grid
for (int x = 0; x < floor.get_width(); x++) {
for (int y = 0; y < floor.get_height(); y++) {
sf::RectangleShape shape({size, size});
shape.setFillColor(sf::Color::Transparent);
shape.setOutlineColor(sf::Color(80, 80, 80));
shape.setOutlineThickness(1.0f);
shape.setPosition({x * size, y * size});
window.draw(shape);
}
}
}
editor.render(window);
ImGui::SFML::Render(window);
window.display();
}
return 0;
}
|