1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-05 02:39:41 +01:00
VVVVVV/desktop_version/src/Textbox.cpp
Misa b3f7c174ea Fix special text box images sometimes flashing
These special images are the crewmates, Level Complete, and Game
Complete images. They flashed depending on if you were lucky and
happened to got your delta-timesteps just right when text boxes were
fading in and out.

Honestly, I'm surprised text box fading in/out hasn't ran into this
issue before. It's insane luck that this issue hasn't occurred before or
anything.

Well, anyways, to fix this, there's now an attribute `allowspecial` on
text boxes, and an optional parameter of the same name for
Graphics::createtextbox(). This attribute is the only thing that will
let these special text box images render. And any createtextbox()es that
utilize these special images have been updated accordingly.
2020-06-19 09:05:48 -04:00

123 lines
1.9 KiB
C++

#include "Textbox.h"
#include <utf8/unchecked.h>
textboxclass::textboxclass()
{
x = 0;
y = 0;
w = 0;
h = 0;
lw = 0;
tl = 0;
prev_tl = 0;
tm = 0;
timer = 0;
allowspecial = false;
}
void textboxclass::centerx()
{
resize();
xp = 160 - (w / 2);
resize();
}
void textboxclass::centery()
{
resize();
yp = 120 - (h / 2);
resize();
}
void textboxclass::adjust()
{
resize();
if (xp < 10) xp = 10;
if (yp < 10) yp = 10;
if (xp + w > 310) xp = 310 - w;
if (yp + h > 230) yp = 230 - h;
resize();
}
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;
}
void textboxclass::update()
{
prev_tl = tl;
if (tm == 0)
{
tl += .1f;
if (tl >= 1)
{
tl = 1;
tm = 1;
}
}
else if (tm == 2)
{
tl -= .1f;
if (tl <= 0.5)
{
tl = 0.5;
//this textbox will be removed by updatetextboxes() later
}
}
if (timer > 0)
{
timer--;
if (timer == 0) tm = 2;
}
}
void textboxclass::remove()
{
tm = 2;
tl = 1.0f; //Remove mode
}
void textboxclass::removefast()
{
tm = 2;
tl = 0.4f; //Remove mode
}
void textboxclass::resize()
{
//Set the width and height to the correct sizes
max = 0;
for (size_t iter = 0; iter < line.size(); iter++)
{
unsigned int len = utf8::unchecked::distance(line[iter].begin(), line[iter].end());
if (len > (unsigned int)max) max = len;
}
lw = max;
w = (max +2) * 8;
h = (line.size() + 2) * 8;
textrect.x = xp;
textrect.y = yp;
textrect.w = w;
textrect.h = h;
}
void textboxclass::addline(std::string t)
{
line.push_back(t);
resize();
if ((int) line.size() >= 12) line.clear();
}