From dfc9d94cf525322e92b17b33fa86b9d8aecc0f46 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Fri, 15 Aug 2025 13:23:04 -0400 Subject: [PATCH] Can now go full screen and change backgrounds. --- Makefile | 8 +-- main.cpp | 89 ++++++++++++++++++++++++++----- sample/01-a-good-first-program.md | 15 ++++++ 3 files changed, 96 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index e632d6e..46352a5 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +SAMPLE=./sample/01-a-good-first-program.md + all: build reset: @@ -25,16 +27,16 @@ tracy_build: run: build ifeq '$(OS)' 'Windows_NT' powershell "cp ./builddir/besos.exe ." - ./besos + ./besos ${SAMPLE} else - ./builddir/game + ./builddir/besos ${SAMPLE} endif debug: build gdb --nx -x .gdbinit --ex run --args builddir/besos debug_run: build - gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/besos + gdb --nx -x .gdbinit --batch --ex run --ex bt --ex q --args builddir/besos ${SAMPLE} clean: meson compile --clean -C builddir diff --git a/main.cpp b/main.cpp index c2c0078..dc0a3a8 100644 --- a/main.cpp +++ b/main.cpp @@ -7,24 +7,32 @@ #include #include "dbc.hpp" #include +#include +#include +#include -constexpr const int WINDOW_WIDTH=1280; -constexpr const int WINDOW_HEIGHT=720; +int WINDOW_WIDTH=1280; +int WINDOW_HEIGHT=720; constexpr const int FRAME_LIMIT=60; 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 nlohmann::json; +namespace fs = std::filesystem; struct Slide { guecs::UI $gui; wstring $title; wstring $content; + json $config; bool $initialized = false; - Slide(const string& title, const string& content) : + Slide(const string& title, const string& content, json& config) : $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"); $gui.set(title, { - $title, 124}); + $title, TITLE_SIZE}); auto content = $gui.entity("content"); $gui.set(content, { $content, - 56, guecs::THEME.TEXT_COLOR, 20}); + CONTENT_SIZE, guecs::THEME.TEXT_COLOR, 20}); $gui.init(); } @@ -115,6 +123,17 @@ struct SlidesUI { void show_slide() { auto& slide = current(); + auto& bg = $gui.get($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"); slide.init(cell); } @@ -143,24 +162,68 @@ struct SlidesUI { shared_ptr parse_slides(const string& md_file) { shared_ptr slides = make_shared(); - for(int i = 0; i < 10; i++) { - slides->emplace_back(fmt::format("Title {}", i),"content"); + dbc::check(fs::exists(md_file), "md file missing"); + + 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"; + } + + slides->emplace_back(title, content, config); + config = json::parse("{}"); + } else { + fmt::println("JUNK: {}", line); + } + } + } } - (void)md_file; - return slides; } -int main() { +int main(int argc, char *argv[]) { + + dbc::check(argc == 2, "USAGE: besos my_fucking_slides.md"); + sfml::Backend 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.setVerticalSyncEnabled(VSYNC); - auto data = parse_slides("some_bullshit.md"); + auto data = parse_slides(argv[1]); SlidesUI slides(data); slides.init(); diff --git a/sample/01-a-good-first-program.md b/sample/01-a-good-first-program.md index 2ea36d3..887b0db 100644 --- a/sample/01-a-good-first-program.md +++ b/sample/01-a-good-first-program.md @@ -4,14 +4,29 @@ } === 1: A Good First Program + +* The key is this +* That's what we want --- What You Should See + +Yes, but with more feeling. --- +{ +"bg_color": [255, 0, 0, 255] +} Study Drills + +Besos would be proud. --- Common Student Questions + +- This again. +- That too. --- The Blue Plus + +_You must find it_. --- The End