1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

Refactor text box contents to not use a separate length-tracker

This removes the variable numlines from each text box object, in favor
of using line.size().
This commit is contained in:
Misa 2020-04-03 17:41:01 -07:00 committed by Ethan Lee
parent 2ec1080b3d
commit 09c9a6b862
3 changed files with 14 additions and 27 deletions

View file

@ -591,14 +591,14 @@ void Graphics::drawgui()
{
if(flipmode)
{
for (j = 0; j < textbox[i].numlines; j++)
for (j = 0; j < (int) textbox[i].line.size(); j++)
{
Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].numlines*8) - (j * 8), textbox[i].line[j], 196, 196, 255 - help.glow);
Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].line.size()*8) - (j * 8), textbox[i].line[j], 196, 196, 255 - help.glow);
}
}
else
{
for (j = 0; j < textbox[i].numlines; j++)
for (j = 0; j < (int) textbox[i].line.size(); j++)
{
Print(textbox[i].xp + 8, textbox[i].yp + 8 + (j * 8), textbox[i].line[j], 196, 196, 255 - help.glow);
}
@ -618,7 +618,7 @@ void Graphics::drawgui()
drawcoloredtile(textbox[i].xp + 8 + (k * 8), textbox[i].yp, 41, textbox[i].r, textbox[i].g, textbox[i].b);
drawcoloredtile(textbox[i].xp + 8 + (k * 8), textbox[i].yp+textbox[i].h-8, 46, textbox[i].r, textbox[i].g, textbox[i].b);
}
for (int k = 0; k < textbox[i].numlines; k++)
for (size_t k = 0; k < textbox[i].line.size(); k++)
{
drawcoloredtile(textbox[i].xp, textbox[i].yp + 8 + (k * 8), 43, textbox[i].r, textbox[i].g, textbox[i].b);
drawcoloredtile(textbox[i].xp + textbox[i].w-8, textbox[i].yp + 8 + (k * 8), 44, textbox[i].r, textbox[i].g, textbox[i].b);
@ -626,14 +626,14 @@ void Graphics::drawgui()
if(flipmode)
{
for (j = 0; j < textbox[i].numlines; j++)
for (j = 0; j < (int) textbox[i].line.size(); j++)
{
Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].numlines*8) - (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b);
Print(textbox[i].xp + 8, textbox[i].yp + (textbox[i].line.size()*8) - (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b);
}
}
else
{
for (j = 0; j < textbox[i].numlines; j++)
for (j = 0; j < (int) textbox[i].line.size(); j++)
{
Print(textbox[i].xp + 8, textbox[i].yp +8 + (j * 8), textbox[i].line[j], textbox[i].r, textbox[i].g, textbox[i].b);
}
@ -1008,8 +1008,7 @@ void Graphics::createtextbox( std::string t, int xp, int yp, int r/*= 255*/, int
if(m<20)
{
textboxclass text;
text.clear();
text.line[0] = t;
text.line.push_back(t);
text.xp = xp;
int length = utf8::unchecked::distance(t.begin(), t.end());
if (xp == -1) text.xp = 160 - (((length / 2) + 1) * 8);

View file

@ -9,17 +9,10 @@ textboxclass::textboxclass()
void textboxclass::firstcreate()
{
//Like clear, only it creates the actual arrays, etc
for (int iter = 0; iter < 10; iter++)
{
std::string t;
t = "";
line.push_back(t);
}
x = 0;
y = 0;
w = 0;
h = 0;
numlines = 0;
lw = 0;
tl = 0;
tm = 0;
@ -29,15 +22,11 @@ void textboxclass::firstcreate()
void textboxclass::clear()
{
//Set all values to a default, required for creating a new entity
for (size_t iter = 0; iter < line.size(); iter++)
{
line[iter]="";
}
line.resize(1);
xp = 0;
yp = 0;
w = 0;
h = 0;
numlines = 1;
lw = 0;
tl = 0;
tm = 0;
@ -130,7 +119,7 @@ void textboxclass::resize()
{
//Set the width and height to the correct sizes
max = 0;
for (int iter = 0; iter < numlines; iter++)
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;
@ -138,7 +127,7 @@ void textboxclass::resize()
lw = max;
w = (max +2) * 8;
h = (numlines + 2) * 8;
h = (line.size() + 2) * 8;
textrect.x = xp;
textrect.y = yp;
textrect.w = w;
@ -147,8 +136,7 @@ void textboxclass::resize()
void textboxclass::addline(std::string t)
{
line[numlines] = t;
numlines++;
line.push_back(t);
resize();
if (numlines >= 12) numlines = 0;
if ((int) line.size() >= 12) line.clear();
}

View file

@ -36,7 +36,7 @@ public:
public:
//Fundamentals
std::vector<std::string> line;
int xp, yp, lw, w, h, numlines;
int xp, yp, lw, w, h;
int x,y;
int r,g,b;
int tr,tg,tb;