parent
6a6382ec74
commit
e33d989b9e
@ -0,0 +1,72 @@ |
|||||||
|
#include "app.hpp" |
||||||
|
#include <fmt/xchar.h> |
||||||
|
#include "parser.hpp" |
||||||
|
#include "dbc.hpp" |
||||||
|
|
||||||
|
void App::init() { |
||||||
|
presenter.setPosition({0,0}); |
||||||
|
presenter.setFramerateLimit(FRAME_LIMIT); |
||||||
|
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"]); |
||||||
|
} |
||||||
|
|
||||||
|
void App::change_slides() { |
||||||
|
// save the current slide
|
||||||
|
auto current_slide = slides->$deck->current; |
||||||
|
// load the new one
|
||||||
|
auto new_slides = load_slides(); |
||||||
|
|
||||||
|
if(new_slides) { |
||||||
|
new_slides->set_slide(current_slide); |
||||||
|
slides = new_slides; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void App::update() { |
||||||
|
if(reloader.changed()) { |
||||||
|
change_slides(); |
||||||
|
} |
||||||
|
|
||||||
|
slides->update(presenter); |
||||||
|
control_ui->update(slides); |
||||||
|
} |
||||||
|
|
||||||
|
void App::render() { |
||||||
|
slides->render(presenter); |
||||||
|
control_ui->render(controller, *slides->$deck); |
||||||
|
|
||||||
|
presenter.display(); |
||||||
|
controller.display(); |
||||||
|
} |
||||||
|
|
||||||
|
bool App::open() { |
||||||
|
return controller.isOpen(); |
||||||
|
} |
||||||
|
|
||||||
|
std::shared_ptr<SlidesUI> App::load_slides() { |
||||||
|
try { |
||||||
|
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); |
||||||
|
|
||||||
|
auto slides = std::make_shared<SlidesUI>(deck, options.pres_size); |
||||||
|
slides->init(); |
||||||
|
|
||||||
|
return slides; |
||||||
|
} catch(...) { |
||||||
|
fmt::println("ERROR!"); |
||||||
|
return nullptr; |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,27 @@ |
|||||||
|
#pragma once |
||||||
|
#include "backend.hpp" |
||||||
|
#include "constants.hpp" |
||||||
|
#include "slides_ui.hpp" |
||||||
|
#include "control_ui.hpp" |
||||||
|
#include <memory> |
||||||
|
#include "changes.hpp" |
||||||
|
#include "options.hpp" |
||||||
|
|
||||||
|
struct App { |
||||||
|
Options options; |
||||||
|
gui::Backend backend{}; |
||||||
|
sf::RenderWindow presenter{sf::VideoMode(options.pres_size), |
||||||
|
"Bezos Loves Slides", sf::Style::None, sf::State::Windowed}; |
||||||
|
|
||||||
|
sf::RenderWindow controller{sf::VideoMode(options.control_size), "Bezos Loves Control"}; |
||||||
|
std::shared_ptr<ControlUI> control_ui = nullptr; |
||||||
|
std::shared_ptr<SlidesUI> slides = nullptr; |
||||||
|
ChangeDetector reloader{}; |
||||||
|
|
||||||
|
void init(); |
||||||
|
void change_slides(); |
||||||
|
void update(); |
||||||
|
void render(); |
||||||
|
bool open(); |
||||||
|
std::shared_ptr<SlidesUI> load_slides(); |
||||||
|
}; |
||||||
@ -0,0 +1,38 @@ |
|||||||
|
#include "options.hpp" |
||||||
|
#include <fmt/core.h> |
||||||
|
#include <unistd.h> |
||||||
|
|
||||||
|
void print_usage() { |
||||||
|
fmt::println("USAGE: bezos [-p PORT] [-h] -d deck.md"); |
||||||
|
} |
||||||
|
|
||||||
|
Options parse_options(int argc, char* argv[]) { |
||||||
|
int opt = 0; |
||||||
|
Options result; |
||||||
|
|
||||||
|
while((opt = getopt(argc, argv, "hp:d:")) != -1) { |
||||||
|
switch(opt) { |
||||||
|
case 'h': |
||||||
|
print_usage(); |
||||||
|
return {.help=true}; |
||||||
|
break; |
||||||
|
case 'p': |
||||||
|
result.port = std::stoi(optarg); |
||||||
|
break; |
||||||
|
case 'd': |
||||||
|
result.deck_given=true; |
||||||
|
result.deck_file = optarg; |
||||||
|
break; |
||||||
|
default: |
||||||
|
print_usage(); |
||||||
|
return {.error=true}; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if(!result.deck_given) { |
||||||
|
print_usage(); |
||||||
|
result.error = true; |
||||||
|
} |
||||||
|
|
||||||
|
return result; |
||||||
|
} |
||||||
@ -0,0 +1,17 @@ |
|||||||
|
#pragma once |
||||||
|
#include <SFML/System/Vector2.hpp> |
||||||
|
#include <string> |
||||||
|
#include "constants.hpp" |
||||||
|
|
||||||
|
struct Options { |
||||||
|
std::string deck_file{}; |
||||||
|
bool deck_given{false}; |
||||||
|
bool help{false}; |
||||||
|
sf::Vector2u pres_size{WINDOW_WIDTH, WINDOW_HEIGHT}; |
||||||
|
sf::Vector2u control_size{CONTROL_WIDTH, CONTROL_HEIGHT}; |
||||||
|
bool error{false}; |
||||||
|
unsigned short port=9898; |
||||||
|
}; |
||||||
|
|
||||||
|
void print_usage(); |
||||||
|
Options parse_options(int argc, char* argv[]); |
||||||
Loading…
Reference in new issue