I can load images now.

master
Zed A. Shaw 1 week ago
parent c47526499a
commit 59e75e9403
  1. 9
      meson.build
  2. 5
      sample/01-a-good-first-program.md
  3. 33
      src/backend.cpp
  4. 14
      src/backend.hpp
  5. 4
      src/main.cpp
  6. 7
      src/slides_ui.cpp

@ -8,7 +8,13 @@ project('bezos-loves-slides', 'cpp',
]) ])
# use this for common options only for our executables # 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=[] link_args=[]
# these are passed as override_defaults # these are passed as override_defaults
exe_defaults = [ 'warning_level=2' ] exe_defaults = [ 'warning_level=2' ]
@ -85,6 +91,7 @@ sources = [
'src/control_ui.cpp', 'src/control_ui.cpp',
'src/slides_ui.cpp', 'src/slides_ui.cpp',
'src/parser.cpp', 'src/parser.cpp',
'src/backend.cpp',
] ]
tests = [ tests = [

@ -1,6 +1,7 @@
{ {
"title": "Test", "title": "Test",
"description": "Test" "description": "Test",
"bg_image": "assets/sample_bg.jpg"
} }
=== ===
# 1: A Good First Program # 1: A Good First Program
@ -17,7 +18,7 @@
--- ---
# Study Drills # Study Drills
!(image/thing.png) !(assets/sample_bg.jpg)
--- ---
# Common Student Questions # Common Student Questions

@ -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<sf::Texture>();
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<sf::Sprite>(*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;
}
}

@ -0,0 +1,14 @@
#pragma once
#include "guecs/ui.hpp"
#include "guecs/sfml/backend.hpp"
#include <string>
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;
};
}

@ -1,4 +1,4 @@
#include "guecs/sfml/backend.hpp" #include "backend.hpp"
#include "guecs/ui.hpp" #include "guecs/ui.hpp"
#include <fmt/xchar.h> #include <fmt/xchar.h>
#include "dbc.hpp" #include "dbc.hpp"
@ -10,7 +10,7 @@
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
dbc::check(argc >= 2, "USAGE: bezos my_fucking_slides.md"); dbc::check(argc >= 2, "USAGE: bezos my_fucking_slides.md");
sfml::Backend backend; gui::Backend backend;
guecs::init(&backend); guecs::init(&backend);
auto& modes = sf::VideoMode::getFullscreenModes(); auto& modes = sf::VideoMode::getFullscreenModes();

@ -41,8 +41,7 @@ void Slide::init(lel::Cell& cell) {
guecs::THEME.TEXT_COLOR, 20}); guecs::THEME.TEXT_COLOR, 20});
if($config.contains("image")) { if($config.contains("image")) {
// STOPPED HERE, need to fix how images are loaded $gui.set<guecs::Sprite>(content, {$config["image"]});
// $gui.set<guecs::Sprite>(content, {$config["image"]});
} }
$gui.init(); $gui.init();
@ -107,8 +106,8 @@ void SlidesUI::show_slide() {
auto& bg = $gui.get<guecs::Background>($gui.MAIN); auto& bg = $gui.get<guecs::Background>($gui.MAIN);
sf::Color color = guecs::THEME.FILL_COLOR; sf::Color color = guecs::THEME.FILL_COLOR;
if(slide.$config.contains("bg_image")) { if($deck->config.contains("bg_image")) {
bg.set_sprite(slide.$config["bg_image"], true); bg.set_sprite($deck->config["bg_image"], true);
} else if(slide.$config.contains("bg_color")) { } else if(slide.$config.contains("bg_color")) {
auto color_conf = slide.$config["bg_color"]; auto color_conf = slide.$config["bg_color"];
color = {color_conf[0], color_conf[1], color_conf[2], color_conf[3]}; color = {color_conf[0], color_conf[1], color_conf[2], color_conf[3]};

Loading…
Cancel
Save