2020-01-01 15:29:24 -05:00
|
|
|
#include "Textbox.h"
|
2020-07-19 12:43:29 -07:00
|
|
|
|
2020-01-31 13:25:37 -05:00
|
|
|
#include <utf8/unchecked.h>
|
2020-01-01 15:29:24 -05:00
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
textboxclass::textboxclass(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
w = 0;
|
|
|
|
h = 0;
|
|
|
|
lw = 0;
|
|
|
|
tl = 0;
|
2020-04-28 21:49:15 -07:00
|
|
|
prev_tl = 0;
|
2020-01-01 15:29:24 -05:00
|
|
|
tm = 0;
|
|
|
|
timer = 0;
|
2020-07-06 13:04:34 -07:00
|
|
|
|
|
|
|
xp = 0;
|
|
|
|
yp = 0;
|
|
|
|
r = 0;
|
|
|
|
g = 0;
|
|
|
|
b = 0;
|
|
|
|
tr = 0;
|
|
|
|
tg = 0;
|
|
|
|
tb = 0;
|
|
|
|
max = 0;
|
2021-03-19 19:51:36 -07:00
|
|
|
|
|
|
|
flipme = false;
|
2021-03-23 14:29:32 -07:00
|
|
|
|
|
|
|
rand = 0;
|
2020-01-01 15:29:24 -05:00
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::centerx(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
resize();
|
|
|
|
xp = 160 - (w / 2);
|
|
|
|
resize();
|
|
|
|
}
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::centery(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
resize();
|
|
|
|
yp = 120 - (h / 2);
|
|
|
|
resize();
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::adjust(void)
|
2020-01-01 15:29:24 -05: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)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::update(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
2020-04-28 21:49:15 -07:00
|
|
|
prev_tl = tl;
|
2020-01-01 15:29:24 -05: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;
|
2020-04-28 18:38:43 -07:00
|
|
|
//this textbox will be removed by updatetextboxes() later
|
2020-01-01 15:29:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (timer > 0)
|
|
|
|
{
|
|
|
|
timer--;
|
|
|
|
if (timer == 0) tm = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::remove(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
tm = 2;
|
|
|
|
tl = 1.0f; //Remove mode
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::removefast(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
tm = 2;
|
|
|
|
tl = 0.4f; //Remove mode
|
|
|
|
}
|
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 14:23:59 -08:00
|
|
|
void textboxclass::resize(void)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
|
|
|
//Set the width and height to the correct sizes
|
|
|
|
max = 0;
|
2020-04-03 17:41:01 -07:00
|
|
|
for (size_t iter = 0; iter < line.size(); iter++)
|
2020-01-01 15:29:24 -05:00
|
|
|
{
|
2020-01-31 13:25:37 -05:00
|
|
|
unsigned int len = utf8::unchecked::distance(line[iter].begin(), line[iter].end());
|
|
|
|
if (len > (unsigned int)max) max = len;
|
2020-01-01 15:29:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
lw = max;
|
|
|
|
w = (max +2) * 8;
|
2020-04-03 17:41:01 -07:00
|
|
|
h = (line.size() + 2) * 8;
|
2020-01-01 15:29:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void textboxclass::addline(std::string t)
|
|
|
|
{
|
2020-04-03 17:41:01 -07:00
|
|
|
line.push_back(t);
|
2020-01-01 15:29:24 -05:00
|
|
|
resize();
|
2020-04-03 17:41:01 -07:00
|
|
|
if ((int) line.size() >= 12) line.clear();
|
2020-01-01 15:29:24 -05:00
|
|
|
}
|