blob: 3eb444c9a77d1034f3739d645bff32100223086b (
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
|
#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 "floor.hpp"
int main() {
sf::RenderWindow window(sf::VideoMode({800, 600}), "sillyeditor");
window.setFramerateLimit(60);
ImGui::SFML::Init(window);
silly::editor::Floor floor(30, 30);
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);
}
// (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));
window.setView(sf::View(visibleArea));
}
if (event->is<sf::Event::Closed>()) {
window.close();
}
}
ImGui::SFML::Update(window, deltaClock.restart());
window.clear();
// 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);
}
}
ImGui::SFML::Render(window);
window.display();
}
return 0;
}
|