|
|
@ -7,24 +7,32 @@ |
|
|
|
#include <nlohmann/json.hpp> |
|
|
|
#include <nlohmann/json.hpp> |
|
|
|
#include "dbc.hpp" |
|
|
|
#include "dbc.hpp" |
|
|
|
#include <memory> |
|
|
|
#include <memory> |
|
|
|
|
|
|
|
#include <filesystem> |
|
|
|
|
|
|
|
#include <fstream> |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
|
|
|
|
|
|
|
|
constexpr const int WINDOW_WIDTH=1280; |
|
|
|
int WINDOW_WIDTH=1280; |
|
|
|
constexpr const int WINDOW_HEIGHT=720; |
|
|
|
int WINDOW_HEIGHT=720; |
|
|
|
constexpr const int FRAME_LIMIT=60; |
|
|
|
constexpr const int FRAME_LIMIT=60; |
|
|
|
constexpr const bool VSYNC=true; |
|
|
|
constexpr const bool VSYNC=true; |
|
|
|
|
|
|
|
constexpr const int TITLE_SIZE=84; |
|
|
|
|
|
|
|
constexpr const int CONTENT_SIZE=56; |
|
|
|
|
|
|
|
|
|
|
|
using std::string, std::wstring, std::shared_ptr, std::make_shared; |
|
|
|
using std::string, std::wstring, std::shared_ptr, std::make_shared; |
|
|
|
using nlohmann::json; |
|
|
|
using nlohmann::json; |
|
|
|
|
|
|
|
namespace fs = std::filesystem; |
|
|
|
|
|
|
|
|
|
|
|
struct Slide { |
|
|
|
struct Slide { |
|
|
|
guecs::UI $gui; |
|
|
|
guecs::UI $gui; |
|
|
|
wstring $title; |
|
|
|
wstring $title; |
|
|
|
wstring $content; |
|
|
|
wstring $content; |
|
|
|
|
|
|
|
json $config; |
|
|
|
bool $initialized = false; |
|
|
|
bool $initialized = false; |
|
|
|
|
|
|
|
|
|
|
|
Slide(const string& title, const string& content) : |
|
|
|
Slide(const string& title, const string& content, json& config) : |
|
|
|
$title(guecs::to_wstring(title)), |
|
|
|
$title(guecs::to_wstring(title)), |
|
|
|
$content(guecs::to_wstring(content)) |
|
|
|
$content(guecs::to_wstring(content)), |
|
|
|
|
|
|
|
$config(config) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -42,12 +50,12 @@ struct Slide { |
|
|
|
|
|
|
|
|
|
|
|
auto title = $gui.entity("title"); |
|
|
|
auto title = $gui.entity("title"); |
|
|
|
$gui.set<guecs::Text>(title, { |
|
|
|
$gui.set<guecs::Text>(title, { |
|
|
|
$title, 124}); |
|
|
|
$title, TITLE_SIZE}); |
|
|
|
|
|
|
|
|
|
|
|
auto content = $gui.entity("content"); |
|
|
|
auto content = $gui.entity("content"); |
|
|
|
$gui.set<guecs::Text>(content, { |
|
|
|
$gui.set<guecs::Text>(content, { |
|
|
|
$content, |
|
|
|
$content, |
|
|
|
56, guecs::THEME.TEXT_COLOR, 20}); |
|
|
|
CONTENT_SIZE, guecs::THEME.TEXT_COLOR, 20}); |
|
|
|
|
|
|
|
|
|
|
|
$gui.init(); |
|
|
|
$gui.init(); |
|
|
|
} |
|
|
|
} |
|
|
@ -115,6 +123,17 @@ struct SlidesUI { |
|
|
|
|
|
|
|
|
|
|
|
void show_slide() { |
|
|
|
void show_slide() { |
|
|
|
auto& slide = current(); |
|
|
|
auto& slide = current(); |
|
|
|
|
|
|
|
auto& bg = $gui.get<guecs::Background>($gui.MAIN); |
|
|
|
|
|
|
|
sf::Color color = guecs::THEME.FILL_COLOR; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(slide.$config.contains("bg_color")) { |
|
|
|
|
|
|
|
auto color_conf = slide.$config["bg_color"]; |
|
|
|
|
|
|
|
color = {color_conf[0], color_conf[1], color_conf[2], color_conf[3]}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bg.set_color(color); |
|
|
|
|
|
|
|
bg.init(); |
|
|
|
|
|
|
|
|
|
|
|
auto& cell = $gui.cell_for("slide"); |
|
|
|
auto& cell = $gui.cell_for("slide"); |
|
|
|
slide.init(cell); |
|
|
|
slide.init(cell); |
|
|
|
} |
|
|
|
} |
|
|
@ -143,24 +162,68 @@ struct SlidesUI { |
|
|
|
shared_ptr<SlideDeck> parse_slides(const string& md_file) { |
|
|
|
shared_ptr<SlideDeck> parse_slides(const string& md_file) { |
|
|
|
shared_ptr<SlideDeck> slides = make_shared<SlideDeck>(); |
|
|
|
shared_ptr<SlideDeck> slides = make_shared<SlideDeck>(); |
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < 10; i++) { |
|
|
|
dbc::check(fs::exists(md_file), "md file missing"); |
|
|
|
slides->emplace_back(fmt::format("Title {}", i),"content"); |
|
|
|
|
|
|
|
|
|
|
|
auto size = fs::file_size(md_file); |
|
|
|
|
|
|
|
string line(size, '\0'); |
|
|
|
|
|
|
|
bool started = false; |
|
|
|
|
|
|
|
json config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(std::ifstream in_file{md_file, std::ios::binary}) { |
|
|
|
|
|
|
|
while(std::getline(in_file, line)) { |
|
|
|
|
|
|
|
if(line == "{") { |
|
|
|
|
|
|
|
string json_data; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
json_data += line; |
|
|
|
|
|
|
|
} while (std::getline(in_file, line) && line != "}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
json_data += "}"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = json::parse(json_data); |
|
|
|
|
|
|
|
std::cout << "JSON: " << config << '\n'; |
|
|
|
|
|
|
|
} else if(line == "===") { |
|
|
|
|
|
|
|
fmt::println("START"); |
|
|
|
|
|
|
|
started = true; |
|
|
|
|
|
|
|
} else if(line == "---") { |
|
|
|
|
|
|
|
fmt::println("START SLIDE"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if(started) { |
|
|
|
|
|
|
|
string title = line; |
|
|
|
|
|
|
|
string content; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(std::getline(in_file, line) && line != "---") { |
|
|
|
|
|
|
|
content += line + "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
(void)md_file; |
|
|
|
slides->emplace_back(title, content, config); |
|
|
|
|
|
|
|
config = json::parse("{}"); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt::println("JUNK: {}", line); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return slides; |
|
|
|
return slides; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() { |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dbc::check(argc == 2, "USAGE: besos my_fucking_slides.md"); |
|
|
|
|
|
|
|
|
|
|
|
sfml::Backend backend; |
|
|
|
sfml::Backend backend; |
|
|
|
guecs::init(&backend); |
|
|
|
guecs::init(&backend); |
|
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow window(sf::VideoMode({WINDOW_WIDTH, WINDOW_HEIGHT}), "Besos Loves Slides"); |
|
|
|
auto& modes = sf::VideoMode::getFullscreenModes(); |
|
|
|
|
|
|
|
WINDOW_WIDTH = modes[1].size.x; |
|
|
|
|
|
|
|
WINDOW_HEIGHT = modes[1].size.y; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sf::RenderWindow window(modes[1], "Besos Loves Slides", sf::Style::None); |
|
|
|
window.setFramerateLimit(FRAME_LIMIT); |
|
|
|
window.setFramerateLimit(FRAME_LIMIT); |
|
|
|
window.setVerticalSyncEnabled(VSYNC); |
|
|
|
window.setVerticalSyncEnabled(VSYNC); |
|
|
|
|
|
|
|
|
|
|
|
auto data = parse_slides("some_bullshit.md"); |
|
|
|
auto data = parse_slides(argv[1]); |
|
|
|
SlidesUI slides(data); |
|
|
|
SlidesUI slides(data); |
|
|
|
slides.init(); |
|
|
|
slides.init(); |
|
|
|
|
|
|
|
|
|
|
|