From cc1528aacc74be42f20654d86e5dd77cb660cba9 Mon Sep 17 00:00:00 2001 From: TerryCavanagh Date: Wed, 17 Jan 2024 20:26:52 +0100 Subject: [PATCH] add a one pixel gap between each line in textboxes (main game only) --- desktop_version/src/Graphics.cpp | 18 ++++++++++++------ desktop_version/src/Graphics.h | 1 + desktop_version/src/Script.cpp | 13 +++++++++---- desktop_version/src/Textbox.cpp | 5 +++-- desktop_version/src/Textbox.h | 3 ++- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index 0ada322b..4d734798 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -874,7 +874,7 @@ void Graphics::drawgui(void) int font_height = font::height(textboxes[i].print_flags); if (flipmode) { - text_yoff = 8 + (textboxes[i].lines.size() - 1) * font_height; + text_yoff = 8 + (textboxes[i].lines.size() - 1) * (font_height + textboxes[i].linegap); } else { @@ -884,7 +884,7 @@ void Graphics::drawgui(void) yp = textboxes[i].yp; if (flipmode && textboxes[i].flipme) { - yp = SCREEN_HEIGHT_PIXELS - yp - 16 - textboxes[i].lines.size() * font_height; + yp = SCREEN_HEIGHT_PIXELS - yp - 16 - textboxes[i].lines.size() * (font_height + textboxes[i].linegap); } char buffer[SCREEN_WIDTH_CHARS + 1]; @@ -931,7 +931,7 @@ void Graphics::drawgui(void) font::print( print_flags | PR_BOR, text_xp, - yp + text_yoff + text_sign * (j * font_height), + yp + text_yoff + text_sign * (j * (font_height + textboxes[i].linegap)), textbox_line(buffer, sizeof(buffer), i, j), 0, 0, 0 ); @@ -941,7 +941,7 @@ void Graphics::drawgui(void) font::print( print_flags, text_xp, - yp + text_yoff + text_sign * (j * font_height), + yp + text_yoff + text_sign * (j * (font_height + textboxes[i].linegap)), textbox_line(buffer, sizeof(buffer), i, j), 196, 196, 255 - help.glow ); @@ -961,7 +961,7 @@ void Graphics::drawgui(void) font::print( print_flags | PR_BRIGHTNESS(tl_lerp*255), text_xp, - yp + text_yoff + text_sign * (j * font_height), + yp + text_yoff + text_sign * (j * (font_height + textboxes[i].linegap)), textbox_line(buffer, sizeof(buffer), i, j), textboxes[i].r, textboxes[i].g, textboxes[i].b ); @@ -1506,6 +1506,12 @@ void Graphics::textboxadjust(void) textboxes[m].adjust(); } +int Graphics::getlinegap(void) +{ + // Don't use linegaps in custom levels, for now anyway + if (map.custommode) return 0; + return 1; +} void Graphics::createtextboxreal( const std::string& t, @@ -1517,7 +1523,7 @@ void Graphics::createtextboxreal( if (m < 20) { - textboxclass text; + textboxclass text(getlinegap()); text.lines.push_back(t); text.xp = xp; if (xp == -1) text.xp = 160 - ((font::len(PR_FONT_LEVEL, t.c_str()) / 2) + 8); diff --git a/desktop_version/src/Graphics.h b/desktop_version/src/Graphics.h index c34ad926..c47a9f63 100644 --- a/desktop_version/src/Graphics.h +++ b/desktop_version/src/Graphics.h @@ -65,6 +65,7 @@ public: void drawfade(void); + int getlinegap(void); void createtextboxreal( const std::string& t, int xp, int yp, diff --git a/desktop_version/src/Script.cpp b/desktop_version/src/Script.cpp index 3ae333ca..10b3ae17 100644 --- a/desktop_version/src/Script.cpp +++ b/desktop_version/src/Script.cpp @@ -569,18 +569,21 @@ void scriptclass::run(void) } } + int linegap = graphics.getlinegap(); + //next is whether to position above or below if (INBOUNDS_VEC(i, obj.entities) && words[2] == "above") { if (j == 1) //left { textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later - texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL)); + texty = obj.entities[i].yp - 16 - (txt.size() * (font::height(PR_FONT_LEVEL) + linegap) - linegap); + } else if (j == 0) //Right { textx = obj.entities[i].xp - 16; - texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL)); + texty = obj.entities[i].yp - 18 - (txt.size() * (font::height(PR_FONT_LEVEL) + linegap) - linegap); } } else if (INBOUNDS_VEC(i, obj.entities)) @@ -666,18 +669,20 @@ void scriptclass::run(void) texty = -500; } + int linegap = graphics.getlinegap(); + //next is whether to position above or below if (INBOUNDS_VEC(i, obj.entities) && words[2] == "above") { if (j == 1) //left { textx = obj.entities[i].xp -10000; //tells the box to be oriented correctly later - texty = obj.entities[i].yp - 16 - (txt.size() * font::height(PR_FONT_LEVEL)); + texty = obj.entities[i].yp - 16 - (txt.size() * (font::height(PR_FONT_LEVEL) + linegap) - linegap); } else if (j == 0) //Right { textx = obj.entities[i].xp - 16; - texty = obj.entities[i].yp - 18 - (txt.size() * font::height(PR_FONT_LEVEL)); + texty = obj.entities[i].yp - 18 - (txt.size() * (font::height(PR_FONT_LEVEL) + linegap) - linegap); } } else if (INBOUNDS_VEC(i, obj.entities)) diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index d717767e..d49f40aa 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -5,7 +5,7 @@ #include "Font.h" #include "UTF8.h" -textboxclass::textboxclass(void) +textboxclass::textboxclass(int gap) { w = 0; h = 0; @@ -19,6 +19,7 @@ textboxclass::textboxclass(void) r = 0; g = 0; b = 0; + linegap = gap; flipme = false; @@ -132,7 +133,7 @@ void textboxclass::resize(void) // 16 for the borders w = max + 16; - h = lines.size()*font::height(print_flags) + 16; + h = lines.size()*(font::height(print_flags) + linegap) + 16 - linegap; } void textboxclass::addline(const std::string& t) diff --git a/desktop_version/src/Textbox.h b/desktop_version/src/Textbox.h index 4f4a927e..176885b7 100644 --- a/desktop_version/src/Textbox.h +++ b/desktop_version/src/Textbox.h @@ -23,7 +23,7 @@ enum TextboxImage class textboxclass { public: - textboxclass(void); + textboxclass(int gap); void addsprite(int x, int y, int tile, int col); @@ -57,6 +57,7 @@ public: std::vector lines; int xp, yp, w, h; int r,g,b; + int linegap; int timer; float tl;