mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-30 03:09:53 +02:00
Use C++ allocation/freeing for text masking and multiline processing
This commit is contained in:
@@ -28,8 +28,8 @@ void Textblock::SetText(std::string text)
|
|||||||
|
|
||||||
void Textblock::updateMultiline()
|
void Textblock::updateMultiline()
|
||||||
{
|
{
|
||||||
char * rawText = (char*)malloc(text.length()+1);
|
char * rawText = new char[text.length()+1];
|
||||||
memcpy(rawText, text.c_str(), text.length());
|
std::copy(text.begin(), text.end(), rawText);
|
||||||
rawText[text.length()] = 0;
|
rawText[text.length()] = 0;
|
||||||
|
|
||||||
int lines = 1;
|
int lines = 1;
|
||||||
@@ -60,7 +60,8 @@ void Textblock::updateMultiline()
|
|||||||
{
|
{
|
||||||
Size.Y = lines*12;
|
Size.Y = lines*12;
|
||||||
}
|
}
|
||||||
textLines = rawText;
|
textLines = std::string(rawText);
|
||||||
|
delete[] rawText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textblock::Draw(const Point &screenPos)
|
void Textblock::Draw(const Point &screenPos)
|
||||||
|
@@ -129,10 +129,10 @@ void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
|
|||||||
{
|
{
|
||||||
if(masked)
|
if(masked)
|
||||||
{
|
{
|
||||||
char * tempText = new char[text.length()];
|
char * tempText = new char[text.length()+1];
|
||||||
std::fill(tempText, tempText+text.length(), 0x8d);
|
std::fill(tempText, tempText+text.length(), 0x8d);
|
||||||
tempText[text.length()] = 0;
|
tempText[text.length()] = 0;
|
||||||
displayText = tempText;
|
displayText = std::string(tempText);
|
||||||
delete tempText;
|
delete tempText;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Reference in New Issue
Block a user