1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-11-16 16:09:42 +01:00
VVVVVV/desktop_version/src/Textbox.cpp

116 lines
1.8 KiB
C++
Raw Normal View History

2020-01-01 21:29:24 +01:00
#include "Textbox.h"
#include <utf8/unchecked.h>
2020-01-01 21:29:24 +01:00
textboxclass::textboxclass(void)
2020-01-01 21:29:24 +01:00
{
w = 0;
h = 0;
tl = 0;
prev_tl = 0;
2020-01-01 21:29:24 +01:00
tm = 0;
timer = 0;
xp = 0;
yp = 0;
r = 0;
g = 0;
b = 0;
flipme = false;
rand = 0;
2020-01-01 21:29:24 +01:00
}
void textboxclass::centerx(void)
2020-01-01 21:29:24 +01:00
{
resize();
xp = 160 - (w / 2);
resize();
}
void textboxclass::centery(void)
2020-01-01 21:29:24 +01:00
{
resize();
yp = 120 - (h / 2);
resize();
}
void textboxclass::adjust(void)
2020-01-01 21:29:24 +01:00
{
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)
{
r = rr;
g = gg;
b = bb;
tl = 0.5;
2020-01-01 21:29:24 +01:00
}
void textboxclass::update(void)
2020-01-01 21:29:24 +01:00
{
prev_tl = tl;
2020-01-01 21:29:24 +01:00
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
2020-01-01 21:29:24 +01:00
}
}
if (timer > 0)
{
timer--;
if (timer == 0) tm = 2;
}
}
void textboxclass::remove(void)
2020-01-01 21:29:24 +01:00
{
tm = 2;
tl = 1.0f; //Remove mode
}
void textboxclass::removefast(void)
2020-01-01 21:29:24 +01:00
{
tm = 2;
tl = 0.4f; //Remove mode
}
void textboxclass::resize(void)
2020-01-01 21:29:24 +01:00
{
//Set the width and height to the correct sizes
int max = 0;
for (size_t iter = 0; iter < lines.size(); iter++)
2020-01-01 21:29:24 +01:00
{
unsigned int len = utf8::unchecked::distance(lines[iter].begin(), lines[iter].end());
if (len > (unsigned int)max) max = len;
2020-01-01 21:29:24 +01:00
}
w = (max +2) * 8;
h = (lines.size() + 2) * 8;
2020-01-01 21:29:24 +01:00
}
void textboxclass::addline(const std::string& t)
2020-01-01 21:29:24 +01:00
{
lines.push_back(t);
2020-01-01 21:29:24 +01:00
resize();
if ((int) lines.size() >= 12) lines.clear();
2020-01-01 21:29:24 +01:00
}