From 730c935218f54033313a285054491e5bed4fda25 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 6 Sep 2021 00:48:42 -0700 Subject: [PATCH] Textboxes: Don't use separate RGB variables Text boxes have `r`, `g`, and `b`, and `tr`, `tg`, and `tb`. `tr`, `tg`, and `tb` are the real colors of the text box, and `r`, `g`, and `b` are merely the colors of the text box as the text box's alpha value is applied to them. Compare this with, say, activity zones (which are drawn like text boxes but aren't text boxes): There is `activity_r`, `activity_g`, and `activity_b`, and when they're drawn they're all multiplied by `act_alpha`. So just do the same thing here. Ditch the `tr`, `tg`, and `tb` variables, and make `r`, `g`, and `b` the new `tr`, `tg`, and `tb` variables. That way, there's simply less state to have to update separately. So we can get rid of `textboxclass::setcol()` as well. --- desktop_version/src/Graphics.cpp | 38 ++++++++++++++++---------------- desktop_version/src/Textbox.cpp | 15 +------------ desktop_version/src/Textbox.h | 3 --- 3 files changed, 20 insertions(+), 36 deletions(-) diff --git a/desktop_version/src/Graphics.cpp b/desktop_version/src/Graphics.cpp index c877c83e..be000ad8 100644 --- a/desktop_version/src/Graphics.cpp +++ b/desktop_version/src/Graphics.cpp @@ -1002,11 +1002,7 @@ void Graphics::drawgui(void) yp += 2 * (120 - yp) - 8 * (textbox[i].line.size() + 2); } - //This routine also updates textbox colors - float tl_lerp = lerp(textbox[i].prev_tl, textbox[i].tl); - textbox[i].setcol(textbox[i].tr * tl_lerp, textbox[i].tg * tl_lerp, textbox[i].tb * tl_lerp); - - if (textbox[i].tr == 0 && textbox[i].tg == 0 && textbox[i].tb == 0) + if (textbox[i].r == 0 && textbox[i].g == 0 && textbox[i].b == 0) { size_t j; for (j = 0; j < textbox[i].line.size(); j++) @@ -1016,13 +1012,17 @@ void Graphics::drawgui(void) } else { + const float tl_lerp = lerp(textbox[i].prev_tl, textbox[i].tl); + const int r = textbox[i].r * tl_lerp; + const int g = textbox[i].g * tl_lerp; + const int b = textbox[i].b * tl_lerp; size_t j; - drawtextbox(textbox[i].xp, yp, textbox[i].w/8, textbox[i].h/8, textbox[i].r, textbox[i].g, textbox[i].b); + drawtextbox(textbox[i].xp, yp, textbox[i].w/8, textbox[i].h/8, r, g, b); for (j = 0; j < textbox[i].line.size(); j++) { - Print(textbox[i].xp + 8, yp + text_yoff + text_sign * (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b); + Print(textbox[i].xp + 8, yp + text_yoff + text_sign * (j * 8), textbox[i].line[j], r, g, b); } } @@ -1033,7 +1033,7 @@ void Graphics::drawgui(void) continue; } - if (textbox[i].yp == 12 && textbox[i].tr == 165) + if (textbox[i].yp == 12 && textbox[i].r == 165) { if (flipmode) { @@ -1044,7 +1044,7 @@ void Graphics::drawgui(void) drawimage(0, 0, 12, true); } } - else if (textbox[i].yp == 12 && textbox[i].tg == 165) + else if (textbox[i].yp == 12 && textbox[i].g == 165) { if (flipmode) { @@ -1055,27 +1055,27 @@ void Graphics::drawgui(void) drawimage(4, 0, 12, true); } } - if (textbox[i].tr == 175 && textbox[i].tg == 175) + if (textbox[i].r == 175 && textbox[i].g == 175) { //purple guy drawsprite(80 - 6, crew_yp, crew_sprite, 220- help.glow/4 - textbox[i].rand, 120- help.glow/4, 210 - help.glow/4); } - else if (textbox[i].tr == 175 && textbox[i].tb == 175) + else if (textbox[i].r == 175 && textbox[i].b == 175) { //red guy drawsprite(80 - 6, crew_yp, crew_sprite, 255 - help.glow/8, 70 - help.glow/4, 70 - help.glow / 4); } - else if (textbox[i].tr == 175) + else if (textbox[i].r == 175) { //green guy drawsprite(80 - 6, crew_yp, crew_sprite, 120 - help.glow / 4 - textbox[i].rand, 220 - help.glow / 4, 120 - help.glow / 4); } - else if (textbox[i].tg == 175) + else if (textbox[i].g == 175) { //yellow guy drawsprite(80 - 6, crew_yp, crew_sprite, 220- help.glow/4 - textbox[i].rand, 210 - help.glow/4, 120- help.glow/4); } - else if (textbox[i].tb == 175) + else if (textbox[i].b == 175) { //blue guy drawsprite(80 - 6, crew_yp, crew_sprite, 75, 75, 255- help.glow/4 - textbox[i].rand); @@ -1097,11 +1097,11 @@ void Graphics::updatetextboxes(void) } if (textbox[i].tl >= 1.0f - && ((textbox[i].tr == 175 && textbox[i].tg == 175) - || textbox[i].tr == 175 - || textbox[i].tg == 175 - || textbox[i].tb == 175) - && (textbox[i].tr != 175 || textbox[i].tb != 175)) + && ((textbox[i].r == 175 && textbox[i].g == 175) + || textbox[i].r == 175 + || textbox[i].g == 175 + || textbox[i].b == 175) + && (textbox[i].r != 175 || textbox[i].b != 175)) { textbox[i].rand = fRandom() * 20; } diff --git a/desktop_version/src/Textbox.cpp b/desktop_version/src/Textbox.cpp index 092aa997..797a7b3c 100644 --- a/desktop_version/src/Textbox.cpp +++ b/desktop_version/src/Textbox.cpp @@ -16,9 +16,6 @@ textboxclass::textboxclass(void) r = 0; g = 0; b = 0; - tr = 0; - tg = 0; - tb = 0; flipme = false; @@ -49,21 +46,11 @@ void textboxclass::adjust(void) } void textboxclass::initcol(int rr, int gg, int bb) -{ - tr = rr; - tg = gg; - tb = bb; - r = 0; - g = 0; - b = 0; - tl = 0.5; -} - -void textboxclass::setcol(int rr, int gg, int bb) { r = rr; g = gg; b = bb; + tl = 0.5; } void textboxclass::update(void) diff --git a/desktop_version/src/Textbox.h b/desktop_version/src/Textbox.h index b9d1ebf8..f319927e 100644 --- a/desktop_version/src/Textbox.h +++ b/desktop_version/src/Textbox.h @@ -17,8 +17,6 @@ public: void initcol(int rr, int gg, int bb); - void setcol(int rr, int gg, int bb); - void update(void); void remove(void); @@ -33,7 +31,6 @@ public: std::vector line; int xp, yp, w, h; int r,g,b; - int tr,tg,tb; int timer; float tl;