From 59e75e9403668871cdffc089c7ed3ea5fea44802 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Wed, 11 Mar 2026 08:01:54 -0400 Subject: [PATCH] I can load images now. --- meson.build | 9 ++++++++- sample/01-a-good-first-program.md | 5 +++-- src/backend.cpp | 33 +++++++++++++++++++++++++++++++ src/backend.hpp | 14 +++++++++++++ src/main.cpp | 4 ++-- src/slides_ui.cpp | 7 +++---- 6 files changed, 63 insertions(+), 9 deletions(-) create mode 100644 src/backend.cpp create mode 100644 src/backend.hpp diff --git a/meson.build b/meson.build index 2d23244..e297b7f 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,13 @@ project('bezos-loves-slides', 'cpp', ]) # use this for common options only for our executables -cpp_args=[] +cpp_args=[ + '-Wno-unused-parameter', + '-Wno-unused-function', + '-Wno-unused-variable', + '-Wno-unused-but-set-variable', + '-Wno-deprecated-declarations', +] link_args=[] # these are passed as override_defaults exe_defaults = [ 'warning_level=2' ] @@ -85,6 +91,7 @@ sources = [ 'src/control_ui.cpp', 'src/slides_ui.cpp', 'src/parser.cpp', + 'src/backend.cpp', ] tests = [ diff --git a/sample/01-a-good-first-program.md b/sample/01-a-good-first-program.md index 16f77d6..bdbd588 100644 --- a/sample/01-a-good-first-program.md +++ b/sample/01-a-good-first-program.md @@ -1,6 +1,7 @@ { "title": "Test", - "description": "Test" + "description": "Test", + "bg_image": "assets/sample_bg.jpg" } === # 1: A Good First Program @@ -17,7 +18,7 @@ --- # Study Drills -!(image/thing.png) +!(assets/sample_bg.jpg) --- # Common Student Questions diff --git a/src/backend.cpp b/src/backend.cpp new file mode 100644 index 0000000..19ae66f --- /dev/null +++ b/src/backend.cpp @@ -0,0 +1,33 @@ +#include "backend.hpp" +#include "dbc.hpp" + +namespace gui { + guecs::SpriteTexture Backend::get_sprite(const std::string& file_path) { + auto texture = std::make_shared(); + bool good = texture->loadFromFile(file_path); + dbc::check(good, fmt::format("failed to load image {}", file_path)); + + texture->setSmooth(false); + + auto sprite = std::make_shared(*texture); + auto size = texture->getSize(); + return {sprite, texture, {int(size.x), int(size.y)}}; + } + + guecs::Theme Backend::theme() { + guecs::Theme theme; + + theme.PADDING = 3; + theme.BORDER_PX = 1; + theme.TEXT_SIZE = 30; + theme.LABEL_SIZE = 20; + theme.FILL_COLOR = theme.DARK_MID; + theme.TEXT_COLOR = theme.LIGHT_LIGHT; + theme.BG_COLOR = theme.DARK_DARK; + theme.BORDER_COLOR = theme.DARK_LIGHT; + theme.BG_COLOR_DARK = theme.BLACK; + theme.FONT_FILE_NAME = "assets/text.otf"; + + return theme; + } +} diff --git a/src/backend.hpp b/src/backend.hpp new file mode 100644 index 0000000..a47bd4e --- /dev/null +++ b/src/backend.hpp @@ -0,0 +1,14 @@ +#pragma once +#include "guecs/ui.hpp" +#include "guecs/sfml/backend.hpp" +#include + +namespace gui { + class Backend : public sfml::Backend { + int $shaders_version = 0; + + public: + guecs::SpriteTexture get_sprite(const std::string& name) override; + guecs::Theme theme() override; + }; +} diff --git a/src/main.cpp b/src/main.cpp index 7a39f14..ff4a718 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,4 @@ -#include "guecs/sfml/backend.hpp" +#include "backend.hpp" #include "guecs/ui.hpp" #include #include "dbc.hpp" @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) { dbc::check(argc >= 2, "USAGE: bezos my_fucking_slides.md"); - sfml::Backend backend; + gui::Backend backend; guecs::init(&backend); auto& modes = sf::VideoMode::getFullscreenModes(); diff --git a/src/slides_ui.cpp b/src/slides_ui.cpp index f4a9f57..bb125e4 100644 --- a/src/slides_ui.cpp +++ b/src/slides_ui.cpp @@ -41,8 +41,7 @@ void Slide::init(lel::Cell& cell) { guecs::THEME.TEXT_COLOR, 20}); if($config.contains("image")) { - // STOPPED HERE, need to fix how images are loaded - // $gui.set(content, {$config["image"]}); + $gui.set(content, {$config["image"]}); } $gui.init(); @@ -107,8 +106,8 @@ void SlidesUI::show_slide() { auto& bg = $gui.get($gui.MAIN); sf::Color color = guecs::THEME.FILL_COLOR; - if(slide.$config.contains("bg_image")) { - bg.set_sprite(slide.$config["bg_image"], true); + if($deck->config.contains("bg_image")) { + bg.set_sprite($deck->config["bg_image"], true); } else 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]};