Can now go full screen and change backgrounds.

master
Zed A. Shaw 1 week ago
parent 965e570182
commit dfc9d94cf5
  1. 8
      Makefile
  2. 87
      main.cpp
  3. 15
      sample/01-a-good-first-program.md

@ -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

@ -7,24 +7,32 @@
#include <nlohmann/json.hpp>
#include "dbc.hpp"
#include <memory>
#include <filesystem>
#include <fstream>
#include <iostream>
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<guecs::Text>(title, {
$title, 124});
$title, TITLE_SIZE});
auto content = $gui.entity("content");
$gui.set<guecs::Text>(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<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");
slide.init(cell);
}
@ -143,24 +162,68 @@ struct SlidesUI {
shared_ptr<SlideDeck> parse_slides(const string& md_file) {
shared_ptr<SlideDeck> slides = make_shared<SlideDeck>();
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";
}
(void)md_file;
slides->emplace_back(title, content, config);
config = json::parse("{}");
} else {
fmt::println("JUNK: {}", line);
}
}
}
}
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();

@ -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

Loading…
Cancel
Save