More improvements in config and using a more fancy bullet char.

master
Zed A. Shaw 1 week ago
parent 6ebdf6e26c
commit de225cf25c
  1. 4
      src/main.cpp
  2. 42
      src/md_parser.cpp
  3. 4
      src/md_parser.rl
  4. 36
      src/slides_ui.cpp
  5. 9
      src/slides_ui.hpp

@ -18,10 +18,10 @@ int main(int argc, char *argv[]) {
return a.size.x == WINDOW_WIDTH && a.size.y == WINDOW_HEIGHT; return a.size.x == WINDOW_WIDTH && a.size.y == WINDOW_HEIGHT;
}); });
sf::RenderWindow controller(sf::VideoMode({CONTROL_WIDTH, CONTROL_HEIGHT}), "Besos Loves Control"); sf::RenderWindow controller(sf::VideoMode({CONTROL_WIDTH, CONTROL_HEIGHT}), "Bezos Loves Control");
sf::RenderWindow presenter(*screen_mode, sf::RenderWindow presenter(*screen_mode,
"Besos Loves Slides", sf::Style::None, sf::State::Windowed); "Bezos Loves Slides", sf::Style::None, sf::State::Windowed);
presenter.setFramerateLimit(FRAME_LIMIT); presenter.setFramerateLimit(FRAME_LIMIT);
presenter.setVerticalSyncEnabled(VSYNC); presenter.setVerticalSyncEnabled(VSYNC);

@ -1,5 +1,5 @@
#line 1 "..//src/md_parser.rl" #line 1 "src/md_parser.rl"
#include <fmt/core.h> #include <fmt/core.h>
#include <iostream> #include <iostream>
@ -11,11 +11,11 @@ enum {
}; };
#line 90 "..//src/md_parser.rl" #line 90 "src/md_parser.rl"
#line 14 "..//src/md_parser.cpp" #line 14 "src/md_parser.cpp"
static const char _Parser_actions[] = { static const char _Parser_actions[] = {
0, 1, 0, 1, 1, 1, 2, 1, 0, 1, 0, 1, 1, 1, 2, 1,
3, 1, 4, 1, 5, 1, 6, 1, 3, 1, 4, 1, 5, 1, 6, 1,
@ -122,7 +122,7 @@ static const int Parser_error = 0;
static const int Parser_en_main = 1; static const int Parser_en_main = 1;
#line 93 "..//src/md_parser.rl" #line 93 "src/md_parser.rl"
bool Parser::parse(const std::string& input) { bool Parser::parse(const std::string& input) {
@ -138,14 +138,14 @@ bool Parser::parse(const std::string& input) {
last = DECK; last = DECK;
#line 133 "..//src/md_parser.cpp" #line 133 "src/md_parser.cpp"
{ {
cs = Parser_start; cs = Parser_start;
} }
#line 108 "..//src/md_parser.rl" #line 108 "src/md_parser.rl"
#line 136 "..//src/md_parser.cpp" #line 136 "src/md_parser.cpp"
{ {
int _klen; int _klen;
unsigned int _trans; unsigned int _trans;
@ -220,30 +220,30 @@ _match:
switch ( *_acts++ ) switch ( *_acts++ )
{ {
case 0: case 0:
#line 15 "..//src/md_parser.rl" #line 15 "src/md_parser.rl"
{ start = p; } { start = p; }
break; break;
case 1: case 1:
#line 16 "..//src/md_parser.rl" #line 16 "src/md_parser.rl"
{ last = TITLE; } { last = TITLE; }
break; break;
case 2: case 2:
#line 17 "..//src/md_parser.rl" #line 17 "src/md_parser.rl"
{ last = PLAIN; } { last = PLAIN; }
break; break;
case 3: case 3:
#line 18 "..//src/md_parser.rl" #line 18 "src/md_parser.rl"
{ last = ENUM; } { last = ENUM; }
break; break;
case 4: case 4:
#line 20 "..//src/md_parser.rl" #line 20 "src/md_parser.rl"
{ {
tk = input.substr(start - begin, p - start); tk = input.substr(start - begin, p - start);
if(last == TITLE) { if(last == TITLE) {
title = tk; title = tk;
} else if(last == ENUM) { } else if(last == ENUM) {
content += "* " + tk; content += "° " + tk;
content += "\n"; content += "\n";
} else { } else {
content += input.substr(start - begin, p - start); content += input.substr(start - begin, p - start);
@ -254,7 +254,7 @@ _match:
} }
break; break;
case 5: case 5:
#line 36 "..//src/md_parser.rl" #line 36 "src/md_parser.rl"
{ {
tk = input.substr(start - begin, p - start); tk = input.substr(start - begin, p - start);
if(last == DECK) { if(last == DECK) {
@ -267,7 +267,7 @@ _match:
} }
break; break;
case 6: case 6:
#line 47 "..//src/md_parser.rl" #line 47 "src/md_parser.rl"
{ {
std::string image = input.substr(start - begin, p - start); std::string image = input.substr(start - begin, p - start);
fmt::println("IMAGE image={}, start={}, length={}", fmt::println("IMAGE image={}, start={}, length={}",
@ -276,27 +276,27 @@ _match:
} }
break; break;
case 7: case 7:
#line 54 "..//src/md_parser.rl" #line 54 "src/md_parser.rl"
{ {
last = PLAIN; last = PLAIN;
fmt::println("----- START"); fmt::println("----- START");
} }
break; break;
case 8: case 8:
#line 59 "..//src/md_parser.rl" #line 59 "src/md_parser.rl"
{ {
title.clear(); title.clear();
content.clear(); content.clear();
} }
break; break;
case 9: case 9:
#line 64 "..//src/md_parser.rl" #line 64 "src/md_parser.rl"
{ {
deck->slides.emplace_back(title, content, config); deck->slides.emplace_back(title, content, config, deck->config);
config.clear(); config.clear();
} }
break; break;
#line 276 "..//src/md_parser.cpp" #line 276 "src/md_parser.cpp"
} }
} }
@ -309,7 +309,7 @@ _again:
_out: {} _out: {}
} }
#line 109 "..//src/md_parser.rl" #line 109 "src/md_parser.rl"
bool good = pe - p == 0; bool good = pe - p == 0;

@ -23,7 +23,7 @@ enum {
if(last == TITLE) { if(last == TITLE) {
title = tk; title = tk;
} else if(last == ENUM) { } else if(last == ENUM) {
content += "* " + tk; content += "° " + tk;
content += "\n"; content += "\n";
} else { } else {
content += input.substr(start - begin, fpc - start); content += input.substr(start - begin, fpc - start);
@ -62,7 +62,7 @@ enum {
} }
action end_slide { action end_slide {
deck->slides.emplace_back(title, content, config); deck->slides.emplace_back(title, content, config, deck->config);
config.clear(); config.clear();
} }

@ -6,17 +6,23 @@
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include "dbc.hpp" #include "dbc.hpp"
#include <memory> #include <memory>
#include "constants.hpp"
#include "slides_ui.hpp" #include "slides_ui.hpp"
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;
Slide::Slide(const string& title, const string& content, json& config) : Slide::Slide(const string& title, const string& content, json& config, json& deck_config) :
$title(guecs::to_wstring(title)), $title(guecs::to_wstring(title)),
$content(guecs::to_wstring(content)), $content(guecs::to_wstring(content)),
$config(config) $config(config)
{ {
// first config the text with any font stuff from the deck
config_text($title_font, deck_config);
config_text($content_font, deck_config);
// then config it with the slide's config
config_text($title_font, $config);
config_text($content_font, $config);
} }
void Slide::init(lel::Cell& cell) { void Slide::init(lel::Cell& cell) {
@ -35,17 +41,10 @@ void Slide::init(lel::Cell& cell) {
"[_|_|_]"); "[_|_|_]");
auto title = $gui.entity("title"); auto title = $gui.entity("title");
guecs::Text title_text{$title, TITLE_SIZE}; $gui.set<guecs::Text>(title, $title_font);
config_text(title_text);
$gui.set<guecs::Text>(title, title_text);
auto content = $gui.entity("content"); auto content = $gui.entity("content");
guecs::Text content_text{ $gui.set<guecs::Text>(content, $content_font);
$content,
CONTENT_SIZE,
guecs::THEME.TEXT_COLOR, 20};
config_text(content_text);
$gui.set<guecs::Text>(content, content_text);
if($config.contains("image")) { if($config.contains("image")) {
$gui.set<guecs::Sprite>(content, {$config["image"]}); $gui.set<guecs::Sprite>(content, {$config["image"]});
@ -55,11 +54,11 @@ void Slide::init(lel::Cell& cell) {
} }
} }
void Slide::config_text(guecs::Text &result) { void Slide::config_text(guecs::Text &result, nlohmann::json& config) {
if($config.contains("font_size")) result.size = $config["font_size"]; if(config.contains("font_size")) result.size = config["font_size"];
if($config.contains("font_color")) { if(config.contains("font_color")) {
std::vector<uint8_t> color = $config["font_color"]; std::vector<uint8_t> color = config["font_color"];
dbc::check(color.size() == 4, "font_color on slide must have 4 values rgba"); dbc::check(color.size() == 4, "font_color on slide must have 4 values rgba");
@ -68,9 +67,9 @@ void Slide::config_text(guecs::Text &result) {
color[0], color[1], color[2], color[3]}; color[0], color[1], color[2], color[3]};
} }
if($config.contains("font_padding")) result.padding = $config["font_padding"]; if(config.contains("font_padding")) result.padding = config["font_padding"];
if($config.contains("font_centered")) result.centered = $config["font_centered"]; if(config.contains("font_centered")) result.centered = config["font_centered"];
} }
void Slide::render(sf::RenderWindow& window) { void Slide::render(sf::RenderWindow& window) {
@ -159,6 +158,9 @@ void SlidesUI::show_slide() {
if(slide.$config.contains("bg_color")) { 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]};
} else if($deck->config.contains("bg_color")) {
auto color_conf = $deck->config["bg_color"];
color = {color_conf[0], color_conf[1], color_conf[2], color_conf[3]};
} }
bg.set_color(color); bg.set_color(color);

@ -4,6 +4,7 @@
#include "guecs/ui.hpp" #include "guecs/ui.hpp"
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <memory> #include <memory>
#include "constants.hpp"
struct Slide { struct Slide {
guecs::UI $gui; guecs::UI $gui;
@ -11,14 +12,18 @@ struct Slide {
std::wstring $content; std::wstring $content;
nlohmann::json $config; nlohmann::json $config;
bool $initialized = false; bool $initialized = false;
guecs::Text $content_font{$content,
CONTENT_SIZE,
guecs::THEME.TEXT_COLOR, 20};
guecs::Text $title_font{$title, TITLE_SIZE};
Slide(const std::string& title, const std::string& content, nlohmann::json& config); Slide(const std::string& title, const std::string& content, nlohmann::json& config, nlohmann::json& deck_config);
Slide() {} Slide() {}
void init(lel::Cell& cell); void init(lel::Cell& cell);
void render(sf::RenderWindow& window); void render(sf::RenderWindow& window);
void config_text(guecs::Text &result); void config_text(guecs::Text &result, nlohmann::json& config);
}; };
using SlideSet = std::vector<Slide>; using SlideSet = std::vector<Slide>;

Loading…
Cancel
Save