|
|
|
@ -6,18 +6,60 @@ |
|
|
|
#include "slides_ui.hpp" |
|
|
|
#include "slides_ui.hpp" |
|
|
|
#include "control_ui.hpp" |
|
|
|
#include "control_ui.hpp" |
|
|
|
#include "parser.hpp" |
|
|
|
#include "parser.hpp" |
|
|
|
|
|
|
|
#include <filesystem> |
|
|
|
|
|
|
|
#include <chrono> |
|
|
|
|
|
|
|
#include <SFML/System/Clock.hpp> |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
using namespace std::chrono_literals; |
|
|
|
dbc::check(argc >= 2, "USAGE: bezos my_fucking_slides.md"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto backend = std::make_shared<gui::Backend>(); |
|
|
|
std::optional<SlidesUI> load_slides(const std::string& input_md, std::shared_ptr<gui::Backend> backend) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
auto data = parse_slides(input_md, [&](nlohmann::json& config) { |
|
|
|
|
|
|
|
backend->set_font(config["font_file"]); |
|
|
|
|
|
|
|
guecs::init(backend.get()); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
auto data = parse_slides(argv[1], [&](nlohmann::json& config) { |
|
|
|
fmt::println("FONT FILE: {}", backend->$font_file); |
|
|
|
backend->set_font(config["font_file"]); |
|
|
|
|
|
|
|
guecs::init(backend.get()); |
|
|
|
SlidesUI slides(data); |
|
|
|
}); |
|
|
|
slides.init(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return slides; |
|
|
|
|
|
|
|
} catch(...) { |
|
|
|
|
|
|
|
fmt::println("ERROR!"); |
|
|
|
|
|
|
|
return std::nullopt; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ChangeDetector { |
|
|
|
|
|
|
|
std::string input_md; |
|
|
|
|
|
|
|
sf::Clock timer{}; |
|
|
|
|
|
|
|
std::filesystem::file_time_type last_mod_time = std::filesystem::last_write_time(input_md); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool check_changed() { |
|
|
|
|
|
|
|
if(timer.getElapsedTime().toDuration() > 500ms) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
auto mod_time = std::filesystem::last_write_time(input_md); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(last_mod_time < mod_time) { |
|
|
|
|
|
|
|
last_mod_time = mod_time; |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch(const std::filesystem::filesystem_error& err) { |
|
|
|
|
|
|
|
fmt::println("failed to open {}: {}", err.path1().string(), err.what()); |
|
|
|
|
|
|
|
timer.restart(); |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
fmt::println("FONT FILE: {}", backend->$font_file); |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
dbc::check(argc >= 2, "USAGE: bezos my_fucking_slides.md"); |
|
|
|
|
|
|
|
|
|
|
|
auto& modes = sf::VideoMode::getFullscreenModes(); |
|
|
|
auto& modes = sf::VideoMode::getFullscreenModes(); |
|
|
|
auto screen_mode = std::find_if(modes.begin(), modes.end(), [=](const auto& a) -> bool { |
|
|
|
auto screen_mode = std::find_if(modes.begin(), modes.end(), [=](const auto& a) -> bool { |
|
|
|
@ -32,25 +74,26 @@ int main(int argc, char *argv[]) { |
|
|
|
presenter.setFramerateLimit(FRAME_LIMIT); |
|
|
|
presenter.setFramerateLimit(FRAME_LIMIT); |
|
|
|
presenter.setVerticalSyncEnabled(VSYNC); |
|
|
|
presenter.setVerticalSyncEnabled(VSYNC); |
|
|
|
|
|
|
|
|
|
|
|
SlidesUI slides(data); |
|
|
|
auto backend = std::make_shared<gui::Backend>(); |
|
|
|
slides.init(); |
|
|
|
|
|
|
|
|
|
|
|
auto new_slides = load_slides(argv[1], backend); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!new_slides) { |
|
|
|
|
|
|
|
fmt::println("ERROR in your .md file"); |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SlidesUI slides = *new_slides; |
|
|
|
ControlUI control_ui(presenter); |
|
|
|
ControlUI control_ui(presenter); |
|
|
|
control_ui.init(); |
|
|
|
control_ui.init(); |
|
|
|
|
|
|
|
|
|
|
|
dbc::check(control_ui.$status != nullptr, "bad ptr"); |
|
|
|
dbc::check(control_ui.$status != nullptr, "bad ptr"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChangeDetector reloader{argv[1]}; |
|
|
|
|
|
|
|
|
|
|
|
while(controller.isOpen()) { |
|
|
|
while(controller.isOpen()) { |
|
|
|
while (const auto event = presenter.pollEvent()) { |
|
|
|
while (const auto event = presenter.pollEvent()) { |
|
|
|
if(const auto* mouse = event->getIf<sf::Event::MouseButtonPressed>()) { |
|
|
|
if(event) slides.handle_events(presenter, *event); |
|
|
|
sf::Vector2f pos = presenter.mapPixelToCoords(mouse->position); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(mouse->button == sf::Mouse::Button::Left) { |
|
|
|
|
|
|
|
slides.mouse(pos.x, pos.y, {1 << guecs::ModBit::left}); |
|
|
|
|
|
|
|
} else if(mouse->button == sf::Mouse::Button::Right) { |
|
|
|
|
|
|
|
slides.mouse(pos.x, pos.y, {1 << guecs::ModBit::right}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
while (const auto event = controller.pollEvent()) { |
|
|
|
while (const auto event = controller.pollEvent()) { |
|
|
|
@ -62,5 +105,14 @@ int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
|
|
presenter.display(); |
|
|
|
presenter.display(); |
|
|
|
controller.display(); |
|
|
|
controller.display(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(reloader.check_changed()) { |
|
|
|
|
|
|
|
auto new_slides = load_slides(argv[1], backend); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(new_slides) { |
|
|
|
|
|
|
|
new_slides->set_slide(slides.$current); |
|
|
|
|
|
|
|
slides = *new_slides; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|