From 8a24d18b6f5c0d86a135fc622587c11700a49f61 Mon Sep 17 00:00:00 2001 From: "Zed A. Shaw" Date: Sun, 17 Aug 2025 00:44:18 -0400 Subject: [PATCH] First stab at an images format but needs work. Also, wasn't really using the backend class but also don't know why it didn't destroy things. --- backend.cpp | 68 -------- backend.hpp | 19 --- md_parser.cpp | 255 +++++++++++++++++++++++------- md_parser.rl | 8 +- meson.build | 1 - sample/01-a-good-first-program.md | 2 +- slides_ui.cpp | 2 +- 7 files changed, 208 insertions(+), 147 deletions(-) delete mode 100644 backend.cpp delete mode 100644 backend.hpp diff --git a/backend.cpp b/backend.cpp deleted file mode 100644 index 7fa60d1..0000000 --- a/backend.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "backend.hpp" -#include -#include -#include -#include - -namespace sfml { - guecs::SpriteTexture Backend::texture_get(const string& name) { - auto sp = textures::get(name); - return {sp.sprite, sp.texture, sp.frame_size}; - } - - Backend::Backend() { - sound::init(); - shaders::init(); - textures::init(); - } - - void Backend::sound_play(const string& name) { - sound::play(name); - } - - void Backend::sound_stop(const string& name) { - sound::stop(name); - } - - std::shared_ptr Backend::shader_get(const std::string& name) { - return shaders::get(name); - } - - bool Backend::shader_updated() { - if(shaders::updated($shaders_version)) { - $shaders_version = shaders::version(); - return true; - } else { - return false; - } - } - - guecs::Theme Backend::theme() { - guecs::Theme theme; - // { - // .BLACK={1, 4, 2}, - // .DARK_DARK={9, 29, 16}, - // .DARK_MID={14, 50, 26}, - // .DARK_LIGHT={0, 109, 44}, - // .MID={63, 171, 92}, - // .LIGHT_DARK={161, 217, 155}, - // .LIGHT_MID={199, 233, 192}, - // .LIGHT_LIGHT={229, 245, 224}, - // .WHITE={255, 255, 255}, - // .TRANSPARENT = sf::Color::Transparent - // }; - - theme.PADDING = 3; - theme.BORDER_PX = 1; - theme.TEXT_SIZE = 40; - theme.LABEL_SIZE = 40; - theme.FILL_COLOR = theme.DARK_DARK; - theme.TEXT_COLOR = theme.LIGHT_LIGHT; - theme.BG_COLOR = theme.MID; - theme.BORDER_COLOR = theme.LIGHT_DARK; - theme.BG_COLOR_DARK = theme.BLACK; - theme.FONT_FILE_NAME = Config::path_to("assets/text.otf").string(); - - return theme; - } -} diff --git a/backend.hpp b/backend.hpp deleted file mode 100644 index fed18f8..0000000 --- a/backend.hpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "guecs/ui.hpp" - -namespace sfml { - using std::string; - - class Backend : public guecs::Backend { - int $shaders_version = 0; - - public: - - Backend(); - guecs::SpriteTexture texture_get(const string& name); - void sound_play(const string& name); - void sound_stop(const string& name); - std::shared_ptr shader_get(const std::string& name); - bool shader_updated(); - guecs::Theme theme(); - }; -} diff --git a/md_parser.cpp b/md_parser.cpp index 6e3d353..321750c 100644 --- a/md_parser.cpp +++ b/md_parser.cpp @@ -10,7 +10,7 @@ enum { }; -#line 66 "md_parser.rl" +#line 72 "md_parser.rl" @@ -18,92 +18,229 @@ enum { static const char _Parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, - 7, 2, 1, 3, 2, 2, 3, 2, - 3, 2, 2, 6, 0 + 7, 1, 8, 2, 0, 5, 2, 1, + 3, 2, 2, 3, 2, 3, 0, 2, + 3, 2, 2, 5, 0, 2, 7, 0, + 3, 5, 7, 0 }; -static const char _Parser_key_offsets[] = { +static const short _Parser_key_offsets[] = { 0, 0, 1, 1, 2, 3, 4, 5, - 6, 7, 11, 13, 17, 22, 27, 34, - 39, 44, 51, 56, 58, 60, 65, 67, - 68, 73, 78 + 6, 7, 12, 14, 19, 22, 24, 27, + 33, 37, 40, 43, 48, 53, 58, 66, + 69, 71, 74, 79, 84, 89, 97, 102, + 104, 106, 111, 113, 114, 117, 119, 122, + 128, 132, 135, 138, 139, 145, 151, 154, + 157, 160, 169, 173, 176, 179, 182, 188, + 194, 200, 209, 215, 221, 227, 230, 232, + 236, 239, 245, 251, 254, 259, 264, 267, + 273, 279, 288, 292, 295, 301, 307, 313, + 322, 328, 332, 335, 341, 347, 350, 356, + 359, 364 }; static const char _Parser_trans_keys[] = { 123, 125, 10, 61, 61, 61, 10, 10, - 35, 42, 45, 10, 45, 10, 35, 42, - 45, 10, 32, 45, 9, 13, 10, 32, - 45, 9, 13, 10, 32, 35, 42, 45, - 9, 13, 10, 32, 45, 9, 13, 10, - 32, 45, 9, 13, 10, 32, 35, 42, + 33, 35, 42, 45, 10, 45, 10, 33, + 35, 42, 45, 10, 40, 45, 10, 45, + 10, 41, 45, 10, 33, 35, 41, 42, + 45, 10, 40, 41, 45, 10, 41, 45, + 10, 41, 45, 10, 33, 35, 42, 45, + 10, 32, 45, 9, 13, 10, 32, 45, + 9, 13, 10, 32, 33, 35, 42, 45, + 9, 13, 10, 40, 45, 10, 45, 10, + 41, 45, 10, 33, 35, 42, 45, 10, + 32, 45, 9, 13, 10, 32, 45, 9, + 13, 10, 32, 33, 35, 42, 45, 9, + 13, 10, 32, 45, 9, 13, 10, 45, + 10, 45, 10, 32, 45, 9, 13, 10, + 45, 10, 10, 40, 45, 10, 45, 10, + 41, 45, 10, 33, 35, 41, 42, 45, + 10, 40, 41, 45, 10, 41, 45, 10, + 41, 45, 41, 10, 32, 41, 45, 9, + 13, 10, 32, 41, 45, 9, 13, 10, + 41, 45, 10, 41, 45, 10, 41, 45, + 10, 32, 33, 35, 41, 42, 45, 9, + 13, 10, 40, 41, 45, 10, 41, 45, + 10, 41, 45, 10, 41, 45, 10, 32, + 41, 45, 9, 13, 10, 32, 41, 45, + 9, 13, 10, 32, 41, 45, 9, 13, + 10, 32, 33, 35, 41, 42, 45, 9, + 13, 10, 32, 41, 45, 9, 13, 10, + 32, 41, 45, 9, 13, 10, 32, 41, + 45, 9, 13, 10, 41, 45, 10, 41, + 10, 40, 41, 45, 10, 41, 45, 10, + 32, 41, 45, 9, 13, 10, 32, 41, + 45, 9, 13, 10, 41, 45, 10, 32, 45, 9, 13, 10, 32, 45, 9, 13, - 10, 45, 10, 45, 10, 32, 45, 9, - 13, 10, 45, 10, 10, 32, 45, 9, - 13, 10, 32, 45, 9, 13, 10, 35, + 10, 41, 45, 10, 32, 41, 45, 9, + 13, 10, 32, 41, 45, 9, 13, 10, + 32, 33, 35, 41, 42, 45, 9, 13, + 10, 40, 41, 45, 10, 41, 45, 10, + 32, 41, 45, 9, 13, 10, 32, 41, + 45, 9, 13, 10, 32, 41, 45, 9, + 13, 10, 32, 33, 35, 41, 42, 45, + 9, 13, 10, 32, 41, 45, 9, 13, + 10, 40, 41, 45, 10, 41, 45, 10, + 32, 41, 45, 9, 13, 10, 32, 41, + 45, 9, 13, 10, 41, 45, 10, 32, + 41, 45, 9, 13, 10, 41, 45, 10, + 33, 35, 42, 45, 10, 33, 35, 41, 42, 45, 0 }; static const char _Parser_single_lengths[] = { 0, 1, 0, 1, 1, 1, 1, 1, - 1, 4, 2, 4, 3, 3, 5, 3, - 3, 5, 3, 2, 2, 3, 2, 1, - 3, 3, 4 + 1, 5, 2, 5, 3, 2, 3, 6, + 4, 3, 3, 5, 3, 3, 6, 3, + 2, 3, 5, 3, 3, 6, 3, 2, + 2, 3, 2, 1, 3, 2, 3, 6, + 4, 3, 3, 1, 4, 4, 3, 3, + 3, 7, 4, 3, 3, 3, 4, 4, + 4, 7, 4, 4, 4, 3, 2, 4, + 3, 4, 4, 3, 3, 3, 3, 4, + 4, 7, 4, 3, 4, 4, 4, 7, + 4, 4, 3, 4, 4, 3, 4, 3, + 5, 6 }; static const char _Parser_range_lengths[] = { 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 1, 1, 1, - 1, 1, 1, 0, 0, 1, 0, 0, - 1, 1, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 0, + 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 0, + 0, 1, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 0, 0, 0, + 0, 1, 1, 0, 1, 1, 0, 1, + 1, 1, 0, 0, 1, 1, 1, 1, + 1, 0, 0, 1, 1, 0, 1, 0, + 0, 0 }; -static const char _Parser_index_offsets[] = { +static const short _Parser_index_offsets[] = { 0, 0, 2, 3, 5, 7, 9, 11, - 13, 15, 20, 23, 28, 33, 38, 45, - 50, 55, 62, 67, 70, 73, 78, 81, - 83, 88, 93 + 13, 15, 21, 24, 30, 34, 37, 41, + 48, 53, 57, 61, 67, 72, 77, 85, + 89, 92, 96, 102, 107, 112, 120, 125, + 128, 131, 136, 139, 141, 145, 148, 152, + 159, 164, 168, 172, 174, 180, 186, 190, + 194, 198, 207, 212, 216, 220, 224, 230, + 236, 242, 251, 257, 263, 269, 273, 276, + 281, 285, 291, 297, 301, 306, 311, 315, + 321, 327, 336, 341, 345, 351, 357, 363, + 372, 378, 383, 387, 393, 399, 403, 409, + 413, 419 }; -static const char _Parser_indicies[] = { +static const unsigned char _Parser_indicies[] = { 0, 1, 2, 3, 2, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 10, - 11, 12, 13, 9, 15, 16, 14, 18, - 19, 20, 21, 17, 23, 22, 16, 22, - 14, 25, 24, 26, 24, 17, 27, 24, - 19, 28, 29, 24, 17, 31, 30, 16, - 30, 14, 33, 32, 26, 32, 17, 34, - 32, 19, 20, 21, 32, 17, 35, 30, - 16, 30, 14, 15, 36, 14, 15, 1, - 14, 35, 30, 37, 30, 14, 15, 38, - 14, 39, 1, 35, 30, 36, 30, 14, - 31, 30, 37, 30, 14, 10, 11, 12, - 13, 9, 0 + 11, 12, 13, 14, 9, 16, 17, 15, + 19, 20, 21, 22, 23, 18, 16, 24, + 17, 15, 26, 27, 25, 29, 30, 31, + 28, 32, 33, 34, 35, 36, 37, 25, + 29, 38, 30, 31, 28, 26, 39, 27, + 25, 29, 30, 40, 28, 16, 20, 21, + 22, 23, 18, 42, 41, 17, 41, 15, + 44, 43, 45, 43, 18, 46, 43, 47, + 21, 48, 49, 43, 18, 16, 50, 17, + 15, 26, 52, 51, 29, 54, 55, 53, + 16, 47, 21, 48, 49, 18, 57, 56, + 17, 56, 15, 59, 58, 45, 58, 18, + 60, 58, 20, 21, 22, 23, 58, 18, + 61, 56, 17, 56, 15, 16, 62, 15, + 16, 1, 15, 61, 56, 63, 56, 15, + 16, 64, 15, 65, 1, 16, 66, 17, + 15, 68, 69, 67, 71, 30, 72, 70, + 73, 74, 75, 35, 76, 77, 67, 71, + 38, 30, 72, 70, 71, 30, 78, 70, + 71, 30, 79, 70, 39, 79, 81, 80, + 30, 72, 80, 70, 84, 83, 85, 86, + 83, 82, 71, 54, 88, 87, 71, 54, + 89, 87, 71, 54, 79, 87, 90, 83, + 91, 92, 85, 93, 94, 83, 82, 71, + 95, 54, 88, 87, 26, 39, 52, 51, + 29, 54, 96, 53, 29, 54, 79, 53, + 81, 80, 54, 88, 80, 87, 98, 97, + 54, 88, 97, 87, 100, 99, 85, 86, + 99, 82, 102, 101, 74, 75, 103, 76, + 77, 101, 67, 100, 101, 103, 69, 101, + 67, 105, 104, 30, 72, 104, 70, 105, + 104, 30, 106, 104, 70, 71, 30, 107, + 70, 108, 39, 79, 71, 109, 30, 72, + 70, 68, 39, 69, 67, 105, 104, 30, + 78, 104, 70, 98, 97, 54, 110, 97, + 87, 71, 54, 107, 87, 61, 56, 62, + 56, 15, 57, 56, 63, 56, 15, 29, + 30, 79, 28, 112, 111, 30, 31, 111, + 28, 114, 113, 85, 52, 113, 51, 115, + 113, 116, 117, 85, 118, 119, 113, 51, + 29, 120, 54, 55, 53, 26, 54, 52, + 51, 112, 111, 54, 55, 111, 53, 122, + 121, 54, 55, 121, 53, 124, 123, 85, + 52, 123, 51, 126, 125, 127, 34, 103, + 36, 37, 125, 25, 124, 125, 103, 27, + 125, 25, 29, 128, 30, 31, 28, 26, + 30, 27, 25, 130, 129, 30, 31, 129, + 28, 130, 129, 30, 131, 129, 28, 29, + 30, 107, 28, 122, 121, 54, 132, 121, + 53, 29, 54, 107, 53, 10, 11, 12, + 13, 14, 9, 134, 135, 136, 137, 138, + 139, 133, 0 }; static const char _Parser_trans_targs[] = { 2, 0, 3, 4, 5, 6, 7, 8, - 9, 10, 11, 12, 18, 24, 10, 11, - 19, 10, 11, 12, 18, 21, 13, 14, - 13, 14, 19, 14, 15, 25, 16, 17, - 16, 17, 17, 17, 20, 22, 23, 26 + 9, 10, 11, 36, 20, 30, 68, 10, + 11, 31, 10, 11, 12, 20, 30, 33, + 13, 14, 15, 18, 14, 15, 19, 18, + 15, 16, 71, 19, 83, 84, 17, 11, + 70, 21, 22, 21, 22, 31, 22, 23, + 27, 69, 24, 25, 52, 25, 26, 52, + 28, 29, 28, 29, 29, 29, 32, 34, + 35, 88, 37, 38, 39, 41, 38, 39, + 41, 39, 40, 44, 59, 60, 42, 43, + 45, 49, 46, 45, 49, 26, 47, 46, + 47, 48, 49, 50, 54, 55, 66, 51, + 53, 56, 57, 56, 57, 58, 57, 19, + 58, 57, 61, 62, 89, 64, 67, 72, + 73, 72, 73, 73, 74, 76, 77, 86, + 75, 78, 79, 78, 79, 80, 79, 81, + 82, 80, 79, 85, 87, 38, 39, 63, + 44, 19, 59, 65 }; static const char _Parser_trans_actions[] = { 1, 0, 0, 0, 9, 0, 0, 0, - 11, 26, 13, 26, 26, 26, 0, 7, - 0, 1, 0, 1, 1, 1, 3, 17, - 1, 7, 1, 0, 1, 1, 5, 23, - 1, 7, 0, 20, 0, 0, 0, 15 + 13, 37, 15, 37, 37, 37, 37, 0, + 7, 0, 1, 0, 1, 1, 1, 1, + 0, 1, 28, 1, 0, 7, 11, 0, + 0, 1, 1, 34, 1, 1, 0, 11, + 0, 3, 22, 1, 7, 1, 0, 1, + 1, 1, 0, 1, 1, 0, 11, 0, + 5, 31, 1, 7, 0, 25, 0, 0, + 0, 17, 0, 1, 28, 1, 0, 7, + 0, 0, 1, 1, 1, 1, 0, 0, + 3, 22, 1, 1, 7, 19, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 0, + 0, 5, 31, 1, 7, 1, 0, 19, + 5, 25, 0, 0, 17, 0, 0, 3, + 22, 1, 7, 0, 1, 1, 1, 1, + 0, 5, 31, 1, 7, 1, 0, 1, + 0, 5, 25, 0, 0, 37, 15, 37, + 37, 40, 37, 37 }; static const int Parser_start = 1; -static const int Parser_first_final = 26; +static const int Parser_first_final = 88; static const int Parser_error = 0; static const int Parser_en_main = 1; -#line 69 "md_parser.rl" +#line 75 "md_parser.rl" bool Parser::parse(const std::string& input) { @@ -116,14 +253,14 @@ bool Parser::parse(const std::string& input) { std::string tk; -#line 111 "md_parser.cpp" +#line 248 "md_parser.cpp" { cs = Parser_start; } -#line 81 "md_parser.rl" +#line 87 "md_parser.rl" -#line 114 "md_parser.cpp" +#line 251 "md_parser.cpp" { int _klen; unsigned int _trans; @@ -235,22 +372,28 @@ _match: break; case 5: #line 38 "md_parser.rl" - { fmt::println("----- START"); } + { + config["image"] = input.substr(start - begin, p - start); + } break; case 6: -#line 40 "md_parser.rl" +#line 42 "md_parser.rl" + { fmt::println("----- START"); } + break; + case 7: +#line 44 "md_parser.rl" { title.clear(); content.clear(); } break; - case 7: -#line 45 "md_parser.rl" + case 8: +#line 49 "md_parser.rl" { deck->slides.emplace_back(title, content, config); } break; -#line 232 "md_parser.cpp" +#line 374 "md_parser.cpp" } } @@ -263,7 +406,7 @@ _again: _out: {} } -#line 82 "md_parser.rl" +#line 88 "md_parser.rl" bool good = pe - p == 0; diff --git a/md_parser.rl b/md_parser.rl index 882898d..0b4fa31 100644 --- a/md_parser.rl +++ b/md_parser.rl @@ -35,6 +35,10 @@ enum { std::cout << "META:" << deck->config << '\n'; } + action image { + config["image"] = input.substr(start - begin, fpc - start); + } + action start { fmt::println("----- START"); } action start_slide { @@ -52,7 +56,9 @@ enum { pound = '#' %title; asterisk = '*' %enum; dash = '-' %enum; + bang = '!'; + image = bang '(' (any+) >mark %image :>> ')'; meta = ('{' ( any+) :>> '}') >mark %meta; content = (any+ -- (eol|end)) >mark %content; title = pound space+ content eol; @@ -60,7 +66,7 @@ enum { line = content :>> eol; blank = space* eol; - slide = (title | enum | line | blank)+ >start_slide end eol; + slide = (title | enum | line | blank | image)+ >start_slide end eol; main := meta eol start eol (slide)+; }%% diff --git a/meson.build b/meson.build index 0b15ba1..afedb20 100644 --- a/meson.build +++ b/meson.build @@ -81,7 +81,6 @@ dependencies += [ sources = [ 'dbc.cpp', - 'backend.cpp', 'control_ui.cpp', 'slides_ui.cpp', 'parser.cpp', diff --git a/sample/01-a-good-first-program.md b/sample/01-a-good-first-program.md index 45807cf..9647b60 100644 --- a/sample/01-a-good-first-program.md +++ b/sample/01-a-good-first-program.md @@ -14,7 +14,7 @@ Yes, but with more feeling. --- # Study Drills -Besos would be proud. +!(image/thing.png) --- # Common Student Questions diff --git a/slides_ui.cpp b/slides_ui.cpp index 19eebd2..6726500 100644 --- a/slides_ui.cpp +++ b/slides_ui.cpp @@ -68,7 +68,7 @@ SlidesUI::SlidesUI(shared_ptr deck) { } void SlidesUI::init() { - guecs::Background bg{$gui.$parser, }; + guecs::Background bg{$gui.$parser}; bg.set_color(guecs::THEME.BG_COLOR_DARK); $gui.set($gui.MAIN, bg);