#include #include #include #include #include #include #include #include #include #include #include "editor.hpp" #include "floor.hpp" #include "nfd.hpp" #include "tileset.hpp" int main() { NFD::Guard nfdGuard; sf::RenderWindow window(sf::VideoMode({800, 600}), "sillyeditor"); window.setFramerateLimit(60); ImGui::SFML::Init(window); silly::editor::Tileset tileset; silly::editor::TileFloor tileFloor(30, 30); silly::editor::Editor editor(tileset, tileFloor); sf::Clock deltaClock; while (window.isOpen()) { // zoom size float size = 16.0f; while (const std::optional 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()) { // 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()) { window.close(); } } editor.update(window); ImGui::SFML::Update(window, deltaClock.restart()); window.clear(); tileFloor.render(window); // rendering grid for (int x = 0; x < tileFloor.get_width(); x++) { for (int y = 0; y < tileFloor.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; }