From 878c94a334e2b830e57f90def10d3654b6996ed5 Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 5 Sep 2020 15:06:12 +0100 Subject: [PATCH 1/4] Changed rencache to store font tab_width with font command Fixes bug where text would be drawn/cached wrongly if more than one tab_width was used in a given frame --- src/rencache.c | 3 +++ src/renderer.c | 6 ++++++ src/renderer.h | 1 + 3 files changed, 10 insertions(+) diff --git a/src/rencache.c b/src/rencache.c index b0b06cf9..5c6de328 100644 --- a/src/rencache.c +++ b/src/rencache.c @@ -18,6 +18,7 @@ typedef struct { RenRect rect; RenColor color; RenFont *font; + int tab_width; char text[0]; } Command; @@ -143,6 +144,7 @@ int rencache_draw_text(RenFont *font, const char *text, int x, int y, RenColor c cmd->color = color; cmd->font = font; cmd->rect = rect; + cmd->tab_width = ren_get_font_tab_width(font); } } @@ -254,6 +256,7 @@ void rencache_end_frame(void) { ren_draw_rect(cmd->rect, cmd->color); break; case DRAW_TEXT: + ren_set_font_tab_width(cmd->font, cmd->tab_width); ren_draw_text(cmd->font, cmd->text, cmd->rect.x, cmd->rect.y, cmd->color); break; } diff --git a/src/renderer.c b/src/renderer.c index 695634f2..0751d0be 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -222,6 +222,12 @@ void ren_set_font_tab_width(RenFont *font, int n) { } +int ren_get_font_tab_width(RenFont *font) { + GlyphSet *set = get_glyphset(font, '\t'); + return set->glyphs['\t'].xadvance; +} + + int ren_get_font_width(RenFont *font, const char *text) { int x = 0; const char *p = text; diff --git a/src/renderer.h b/src/renderer.h index 3cefa5c9..69cc1f0f 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -22,6 +22,7 @@ void ren_free_image(RenImage *image); RenFont* ren_load_font(const char *filename, float size); void ren_free_font(RenFont *font); void ren_set_font_tab_width(RenFont *font, int n); +int ren_get_font_tab_width(RenFont *font); int ren_get_font_width(RenFont *font, const char *text); int ren_get_font_height(RenFont *font); From de5cb4fa52f50e915ff90ccfec2eafc0923dde7f Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 27 Sep 2020 15:03:01 +0100 Subject: [PATCH 2/4] Improved behaviour of `doc:join-lines` when joining to empty line --- data/core/commands/doc.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/core/commands/doc.lua b/data/core/commands/doc.lua index 1afd546c..0a4ee42c 100644 --- a/data/core/commands/doc.lua +++ b/data/core/commands/doc.lua @@ -160,7 +160,9 @@ local commands = { local line1, _, line2 = doc():get_selection(true) if line1 == line2 then line2 = line2 + 1 end local text = doc():get_text(line1, 1, line2, math.huge) - text = text:gsub("\n[\t ]*", " ") + text = text:gsub("(.-)\n[\t ]*", function(x) + return x:find("^%s*$") and x or x .. " " + end) doc():insert(line1, 1, text) doc():remove(line1, #text + 1, line2, math.huge) if doc():has_selection() then From b2ddc140d63f8df433fe7b52082b95ee50836d1d Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 3 Oct 2020 13:38:04 +0100 Subject: [PATCH 3/4] Added build.bat --- build.bat | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 build.bat diff --git a/build.bat b/build.bat new file mode 100644 index 00000000..7bfe7815 --- /dev/null +++ b/build.bat @@ -0,0 +1,16 @@ +@echo off + +rem download this: +rem https://nuwen.net/mingw.html + +echo compiling (windows)... + +windres res.rc -O coff -o res.res +gcc src/*.c src/api/*.c src/lib/lua52/*.c src/lib/stb/*.c^ + -O3 -s -std=gnu11 -fno-strict-aliasing -Isrc -DLUA_USE_POPEN^ + -Iwinlib/SDL2-2.0.10/x86_64-w64-mingw32/include^ + -lmingw32 -lm -lSDL2main -lSDL2 -Lwinlib/SDL2-2.0.10/x86_64-w64-mingw32/lib^ + -mwindows res.res^ + -o lite.exe + +echo done From 79c4f9fcae94a801de7b8c44bb7eae0b1aaaec8f Mon Sep 17 00:00:00 2001 From: rxi Date: Sat, 3 Oct 2020 13:49:14 +0100 Subject: [PATCH 4/4] Updated README.md for build.bat addition --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index cade9553..6081e8b1 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,10 @@ The editor can be customized by making changes to the [user module](data/user/init.lua). ## Building -You can build the project yourself on Linux using the provided `build.sh` -script. Note that the project does not need to be rebuilt if you are only making -changes to the Lua portion of the code. +You can build the project yourself on Linux using the `build.sh` script +or on Windows using the `build.bat` script *([MinGW](https://nuwen.net/mingw.html) is required)*. +Note that the project does not need to be rebuilt if you are only making changes +to the Lua portion of the code. ## Contributing Any additional functionality that can be added through a plugin should be done