From 58abb91c64446523662709542cdc8055461e2b4f Mon Sep 17 00:00:00 2001 From: nedko Date: Thu, 4 Dec 2025 15:32:42 +0200 Subject: [PATCH] Updated README. Added example config. Added default font for ease of use. --- README.md | 7 ++++--- config_example.json | 14 ++++++++++++++ main.cpp | 1 + sdl_helpers.cpp | 2 +- sdl_helpers.h | 4 +++- 5 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 config_example.json diff --git a/README.md b/README.md index 3579363..3968d69 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,10 @@ A utility which can be used to create custom images for TRMNL devices via code # How to write new visual stuff 1. Inherit from `Widget` and then do your magic inside your own class. -2. Instantiate your widget in `main.cpp` and add it to the vector of widgets. -3. ??? -4. Profit +2. Add your widget builder in `main.cpp` inside `init builders`. +3. Write your config file. +4. ??? +5. Profit # ImageMagick commands ### Convert image without dithering diff --git a/config_example.json b/config_example.json new file mode 100644 index 0000000..5a27adf --- /dev/null +++ b/config_example.json @@ -0,0 +1,14 @@ +{ + "width": 800, + "height": 600, + "output": "trmnl.png", + "font": "font.ttf", + "widgets": + [ + { + "name": "widget_name", + "parameter1": "example", + "parameter2": 10 + } + ] +} diff --git a/main.cpp b/main.cpp index 7a45aa8..66fee5d 100644 --- a/main.cpp +++ b/main.cpp @@ -63,6 +63,7 @@ int main(int argc, char **argv) // Change screen size from JSON json_extract(cfg, "width", screen_width); json_extract(cfg, "height", screen_height); + json_extract(cfg, "font", default_font_name); // Create surface main_surface = SDL_CreateRGBSurfaceWithFormat(0, screen_width, screen_height, 32, SDL_PIXELFORMAT_RGBA8888); diff --git a/sdl_helpers.cpp b/sdl_helpers.cpp index bfe4399..a739fc1 100644 --- a/sdl_helpers.cpp +++ b/sdl_helpers.cpp @@ -53,7 +53,7 @@ void clean_sdl() SDL_Quit(); } -TTF_Font* get_font(const string& filename, int size) +TTF_Font* get_font(int size, const string& filename) { pair key(filename, size); if (0 != font_map.count(key)) diff --git a/sdl_helpers.h b/sdl_helpers.h index a028e63..ac00c63 100644 --- a/sdl_helpers.h +++ b/sdl_helpers.h @@ -8,6 +8,8 @@ #include "json.hpp" +std::string default_font_name = "font.ttf"; + // Call this before everything // Prints its messages bool init_sdl(); @@ -17,7 +19,7 @@ void clean_sdl(); // A simple way to get a font pointer to use // Can return NULL -TTF_Font* get_font(const std::string& filename, int size); +TTF_Font* get_font(int size, const std::string& filename = default_font_name); // Reads the file and tries to parse a JSON file with comments // cfg - output json struct