|
|
|
@ -14,30 +14,13 @@ struct Options { |
|
|
|
std::string deck_file{}; |
|
|
|
std::string deck_file{}; |
|
|
|
bool deck_given{false}; |
|
|
|
bool deck_given{false}; |
|
|
|
bool help{false}; |
|
|
|
bool help{false}; |
|
|
|
|
|
|
|
sf::Vector2u pres_size{WINDOW_WIDTH, WINDOW_HEIGHT}; |
|
|
|
|
|
|
|
sf::Vector2u control_size{CONTROL_WIDTH, CONTROL_HEIGHT}; |
|
|
|
bool error{false}; |
|
|
|
bool error{false}; |
|
|
|
|
|
|
|
|
|
|
|
unsigned short port=9898; |
|
|
|
unsigned short port=9898; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<SlidesUI> load_slides(const std::string& input_md, std::shared_ptr<gui::Backend> backend) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
auto deck = parse_slides(input_md, [&](nlohmann::json& config) { |
|
|
|
|
|
|
|
backend->set_font(config["font_file"]); |
|
|
|
|
|
|
|
guecs::init(backend.get()); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt::println("FONT FILE: {}", backend->$font_file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto slides = std::make_shared<SlidesUI>(deck, sf::Vector2u{WINDOW_WIDTH, WINDOW_HEIGHT}); |
|
|
|
|
|
|
|
slides->init(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return slides; |
|
|
|
|
|
|
|
} catch(...) { |
|
|
|
|
|
|
|
fmt::println("ERROR!"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void print_usage() { |
|
|
|
void print_usage() { |
|
|
|
fmt::println("USAGE: bezos [-p PORT] [-h] -d deck.md"); |
|
|
|
fmt::println("USAGE: bezos [-p PORT] [-h] -d deck.md"); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -73,70 +56,101 @@ Options parse_options(int argc, char* argv[]) { |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct App { |
|
|
|
|
|
|
|
Options options; |
|
|
|
|
|
|
|
gui::Backend backend{}; |
|
|
|
|
|
|
|
sf::RenderWindow presenter{sf::VideoMode(options.pres_size), |
|
|
|
|
|
|
|
"Bezos Loves Slides", sf::Style::None, sf::State::Windowed}; |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
sf::RenderWindow controller{sf::VideoMode(options.control_size), "Bezos Loves Control"}; |
|
|
|
auto options = parse_options(argc, argv); |
|
|
|
std::shared_ptr<ControlUI> control_ui = nullptr; |
|
|
|
|
|
|
|
std::shared_ptr<SlidesUI> slides = nullptr; |
|
|
|
|
|
|
|
ChangeDetector reloader{}; |
|
|
|
|
|
|
|
|
|
|
|
if(options.help) { |
|
|
|
void init() { |
|
|
|
return 0; |
|
|
|
presenter.setPosition({0,0}); |
|
|
|
} else if(options.error) { |
|
|
|
presenter.setFramerateLimit(FRAME_LIMIT); |
|
|
|
return 1; |
|
|
|
presenter.setVerticalSyncEnabled(VSYNC); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
slides = load_slides(); |
|
|
|
|
|
|
|
dbc::check(slides != nullptr, "ERROR in your .md file"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
control_ui = std::make_shared<ControlUI>(presenter, controller, options.port); |
|
|
|
|
|
|
|
control_ui->init(); |
|
|
|
|
|
|
|
control_ui->full_screen(false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reloader.watch(options.deck_file); |
|
|
|
|
|
|
|
reloader.watch(slides->$deck->config["layouts"]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto& modes = sf::VideoMode::getFullscreenModes(); |
|
|
|
void change_slides() { |
|
|
|
auto screen_mode = std::find_if(modes.begin(), modes.end(), [=](const auto& a) -> bool { |
|
|
|
// save the current slide
|
|
|
|
return a.size.x == WINDOW_WIDTH && a.size.y == WINDOW_HEIGHT; |
|
|
|
auto current_slide = slides->$deck->current; |
|
|
|
}); |
|
|
|
// load the new one
|
|
|
|
|
|
|
|
auto new_slides = load_slides(); |
|
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow presenter(*screen_mode, |
|
|
|
if(new_slides) { |
|
|
|
"Bezos Loves Slides", sf::Style::None, sf::State::Windowed); |
|
|
|
new_slides->set_slide(current_slide); |
|
|
|
|
|
|
|
slides = new_slides; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
presenter.setPosition({0,0}); |
|
|
|
void update() { |
|
|
|
presenter.setFramerateLimit(FRAME_LIMIT); |
|
|
|
if(reloader.changed()) { |
|
|
|
presenter.setVerticalSyncEnabled(VSYNC); |
|
|
|
change_slides(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow controller(sf::VideoMode({CONTROL_WIDTH, CONTROL_HEIGHT}), "Bezos Loves Control"); |
|
|
|
slides->update(presenter); |
|
|
|
|
|
|
|
control_ui->update(slides); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
auto backend = std::make_shared<gui::Backend>(); |
|
|
|
void render() { |
|
|
|
|
|
|
|
slides->render(presenter); |
|
|
|
|
|
|
|
control_ui->render(controller, *slides->$deck); |
|
|
|
|
|
|
|
|
|
|
|
auto slides = load_slides(options.deck_file, backend); |
|
|
|
presenter.display(); |
|
|
|
|
|
|
|
controller.display(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if(!slides) { |
|
|
|
bool open() { |
|
|
|
fmt::println("ERROR in your .md file"); |
|
|
|
return controller.isOpen(); |
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ControlUI control_ui{presenter, controller, options.port}; |
|
|
|
std::shared_ptr<SlidesUI> load_slides() { |
|
|
|
control_ui.init(); |
|
|
|
try { |
|
|
|
control_ui.full_screen(false); |
|
|
|
auto deck = parse_slides(options.deck_file, [&](nlohmann::json& config) { |
|
|
|
|
|
|
|
backend.set_font(config["font_file"]); |
|
|
|
|
|
|
|
guecs::init(&backend); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fmt::println("FONT FILE: {}", backend.$font_file); |
|
|
|
|
|
|
|
|
|
|
|
ChangeDetector reloader; |
|
|
|
auto slides = std::make_shared<SlidesUI>(deck, options.pres_size); |
|
|
|
reloader.watch(options.deck_file); |
|
|
|
slides->init(); |
|
|
|
reloader.watch(slides->$deck->config["layouts"]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(controller.isOpen()) { |
|
|
|
return slides; |
|
|
|
while(const auto event = presenter.pollEvent()) { |
|
|
|
} catch(...) { |
|
|
|
if(event) slides->handle_events(presenter, *event); |
|
|
|
fmt::println("ERROR!"); |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
control_ui.update(slides); |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
auto options = parse_options(argc, argv); |
|
|
|
|
|
|
|
|
|
|
|
slides->render(presenter); |
|
|
|
if(options.help) { |
|
|
|
control_ui.render(controller, *slides->$deck); |
|
|
|
return 0; |
|
|
|
|
|
|
|
} else if(options.error) { |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
presenter.display(); |
|
|
|
auto app = std::make_shared<App>(options); |
|
|
|
controller.display(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(reloader.changed()) { |
|
|
|
app->init(); |
|
|
|
// save the current slide
|
|
|
|
|
|
|
|
auto current_slide = slides->$deck->current; |
|
|
|
while(app->open()) { |
|
|
|
// load the new one
|
|
|
|
app->update(); |
|
|
|
auto new_slides = load_slides(options.deck_file, backend); |
|
|
|
app->render(); |
|
|
|
|
|
|
|
|
|
|
|
if(new_slides) { |
|
|
|
|
|
|
|
new_slides->set_slide(current_slide); |
|
|
|
|
|
|
|
slides = new_slides; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|