commit 0b8fb137
No longer requires a c_str for setting the text
Changed files
diff --git a/source/code/BlockGameSdl.inc b/source/code/BlockGameSdl.inc
index 437f0cf..8f83081 100644
--- a/source/code/BlockGameSdl.inc
+++ b/source/code/BlockGameSdl.inc
@@ -327,7 +327,7 @@ public:
strHolder = _("Moves left: ") + std::to_string(MovesLeft);
static sago::SagoTextField movesPuzzleLabel;
sagoTextSetHelpFont(movesPuzzleLabel);
- movesPuzzleLabel.SetText(strHolder.c_str());
+ movesPuzzleLabel.SetText(strHolder);
movesPuzzleLabel.Draw(globalData.screen, topx+5, topy+5);
}
@@ -372,7 +372,7 @@ public:
}
}
if (!bGameOver && stop > 20) {
- stopIntField.SetText(std::to_string(stop/10).c_str());
+ stopIntField.SetText(std::to_string(stop/10));
stopIntField.Draw(globalData.screen, 240+topx, -40+topy);
}
@@ -380,7 +380,7 @@ public:
if (AI_Enabled&&(!bGameOver)) {
sagoTextSetBlueFont(aiStatusField);
strHolder = "AI_status: " + std::to_string(AIstatus)+ ", "+ std::to_string(AIlineToClear);
- aiStatusField.SetText(strHolder.c_str());
+ aiStatusField.SetText(strHolder);
aiStatusField.Draw(globalData.screen, topx+5, topy+5);
}
#endif
diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp
index 94ed269..cd85480 100644
--- a/source/code/DialogBox.cpp
+++ b/source/code/DialogBox.cpp
@@ -114,7 +114,7 @@ void DialogBox::Draw(SDL_Renderer* target) {
enterLabel.Draw(target, x+150, y+140, sago::SagoTextField::Alignment::center);
cancelLabel.Draw(target, x+450, y+140, sago::SagoTextField::Alignment::center);
DrawRectWhite(target, x+26, y+64, 54, 600-2*26);
- textField.SetText(rk->GetString().c_str());
+ textField.SetText(rk->GetString());
textField.Draw(target, x+40, y+76);
std::string strHolder = rk->GetString();
strHolder.erase((int)rk->CharsBeforeCursor());
diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp
index 4327460..7cc5dfc 100644
--- a/source/code/MenuSystem.cpp
+++ b/source/code/MenuSystem.cpp
@@ -59,7 +59,7 @@ sago::SagoTextField* ButtonGfx::getLabel(const std::string& text) {
newField->SetFont("freeserif");
newField->SetFontSize(30);
newField->SetOutline(1, {0,0,0,255});
- newField->SetText(text.c_str());
+ newField->SetText(text);
labels[text] = newField;
return labels[text].get();
}
diff --git a/source/code/ScoresDisplay.cpp b/source/code/ScoresDisplay.cpp
index b1e562e..8e49742 100644
--- a/source/code/ScoresDisplay.cpp
+++ b/source/code/ScoresDisplay.cpp
@@ -45,7 +45,7 @@ sago::SagoTextField* ScoresDisplay::getCachedText(const std::string& text) {
if (!ptr) {
std::shared_ptr<sago::SagoTextField> newText = std::make_shared<sago::SagoTextField>();
sagoTextSetBlueFont(*newText.get());
- newText->SetText(text.c_str());
+ newText->SetText(text);
fieldCache[text] = newText;
}
return fieldCache[text].get();
diff --git a/source/code/levelselect.cpp b/source/code/levelselect.cpp
index 89200db..7275c65 100644
--- a/source/code/levelselect.cpp
+++ b/source/code/levelselect.cpp
@@ -45,7 +45,7 @@ static sago::SagoTextField* getCachedText(const std::string& text) {
if (!ptr) {
std::shared_ptr<sago::SagoTextField> newText = std::make_shared<sago::SagoTextField>();
sagoTextSetBlueFont(*newText.get());
- newText->SetText(text.c_str());
+ newText->SetText(text);
fieldCache[text] = newText;
}
return fieldCache[text].get();
diff --git a/source/code/main.cpp b/source/code/main.cpp
index a90cb1b..c7688b7 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -389,7 +389,7 @@ static sago::SagoTextField* getSmallInt(size_t number) {
newNumber->SetFont("freeserif");
newNumber->SetFontSize(16);
newNumber->SetColor({255,0,0,255});
- newNumber->SetText(std::to_string(number).c_str());
+ newNumber->SetText(std::to_string(number));
smallFontCache[number] = newNumber;
}
return smallFontCache[number].get();
@@ -446,7 +446,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
theGame2->DoPaintJob();
string strHolder;
strHolder = std::to_string(theGame->GetScore()+theGame->GetHandicap());
- player1score.SetText(strHolder.c_str());
+ player1score.SetText(strHolder);
player1score.Draw(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+100);
if (theGame->GetAIenabled()) {
player1name.SetText(_("AI"));
@@ -455,7 +455,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
player1name.SetText(_("Playing field"));
}
else {
- player1name.SetText(globalData.player1name.c_str());
+ player1name.SetText(globalData.player1name);
}
player1name.Draw(globalData.screen, theGame->GetTopX()+10,theGame->GetTopY()-34);
if (theGame->isTimeTrial()) {
@@ -482,7 +482,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
else {
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
- player1time.SetText(strHolder.c_str());
+ player1time.SetText(strHolder);
}
else {
int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000;
@@ -499,15 +499,15 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
else {
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
- player1time.SetText(strHolder.c_str());
+ player1time.SetText(strHolder);
}
player1time.Draw(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+150);
strHolder = std::to_string(theGame->GetChains());
- player1chain.SetText(strHolder.c_str());
+ player1chain.SetText(strHolder);
player1chain.Draw(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+200);
//drawspeedLevel:
strHolder = std::to_string(theGame->GetSpeedLevel());
- player1speed.SetText(strHolder.c_str());
+ player1speed.SetText(strHolder);
player1speed.Draw(globalData.screen, theGame->GetTopX()+310,theGame->GetTopY()+250);
if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY())) {
oldBubleX = theGame->GetTopX()+280;
@@ -548,11 +548,11 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
static sago::SagoTextField gametypeNameField;
sagoTextSetHelpFont(infoBox);
infoBox.SetMaxWidth(290);
- infoBox.SetText(infostring.c_str());
+ infoBox.SetText(infostring);
sagoTextSetHelpFont(objectiveField);
objectiveField.SetText(_("Objective:"));
sagoTextSetHelpFont(gametypeNameField);
- gametypeNameField.SetText(gametypeName.c_str());
+ gametypeNameField.SetText(gametypeName);
gametypeNameField.Draw(globalData.screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10);
objectiveField.Draw(globalData.screen, theGame2->GetTopX()+7, theGame2->GetTopY()+160);
infoBox.Draw(globalData.screen, theGame2->GetTopX()+7, theGame2->GetTopY()+160+32);
@@ -575,17 +575,17 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
controldBox.SetFontSize(30);
controldBox.SetMaxWidth(290);
controldBox.SetOutline(1, {0,0,0,255});
- controldBox.SetText(controldBoxText.c_str());
+ controldBox.SetText(controldBoxText);
controldBox.Draw(globalData.screen, theGame2->GetTopX()+7,y);
}
strHolder = std::to_string(theGame2->GetScore()+theGame2->GetHandicap());
- player2score.SetText(strHolder.c_str());
+ player2score.SetText(strHolder);
player2score.Draw(globalData.screen, theGame2->GetTopX()+310, theGame2->GetTopY()+100);
if (theGame2->GetAIenabled()) {
player2name.SetText(_("AI"));
}
else {
- player2name.SetText(theGame2->name.c_str());
+ player2name.SetText(theGame2->name);
}
player2name.Draw(globalData.screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34);
if (theGame2->isTimeTrial()) {
@@ -629,13 +629,13 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th
strHolder = std::to_string(minutes)+":0"+std::to_string(seconds);
}
}
- player2time.SetText(strHolder.c_str());
+ player2time.SetText(strHolder);
player2time.Draw(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150);
strHolder = std::to_string(theGame2->GetChains());
- player2chain.SetText(strHolder.c_str());
+ player2chain.SetText(strHolder);
player2chain.Draw(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200);
strHolder = std::to_string(theGame2->GetSpeedLevel());
- player2speed.SetText(strHolder.c_str());
+ player2speed.SetText(strHolder);
player2speed.Draw(globalData.screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250);
}
//player2 finnish
diff --git a/source/code/sago/SagoTextBox.cpp b/source/code/sago/SagoTextBox.cpp
index 01694ac..730612b 100644
--- a/source/code/sago/SagoTextBox.cpp
+++ b/source/code/sago/SagoTextBox.cpp
@@ -60,6 +60,10 @@ void SagoTextBox::SetText(const char* text) {
data->text = text;
}
+void SagoTextBox::SetText(const std::string& text) {
+ data->text = text;
+}
+
void SagoTextBox::SetColor(const SDL_Color& color) {
data->color = color;
}
@@ -93,7 +97,7 @@ void SagoTextBox::AppendLineToCache(const std::string& text) {
tf.SetFontSize(data->fontSize);
tf.SetColor(data->color);
tf.SetOutline(data->outline, data->outlineColor);
- tf.SetText(text.c_str());
+ tf.SetText(text);
}
diff --git a/source/code/sago/SagoTextBox.hpp b/source/code/sago/SagoTextBox.hpp
index 6fe19d9..025010d 100644
--- a/source/code/sago/SagoTextBox.hpp
+++ b/source/code/sago/SagoTextBox.hpp
@@ -36,6 +36,7 @@ public:
virtual ~SagoTextBox();
void SetHolder(const SagoDataHolder* holder);
void SetText(const char* text);
+ void SetText(const std::string& text);
void SetColor(const SDL_Color& color);
void SetFont(const char* fontName);
void SetFontSize(int fontSize);
diff --git a/source/code/sago/SagoTextField.cpp b/source/code/sago/SagoTextField.cpp
index 830cdfe..62df1d4 100644
--- a/source/code/sago/SagoTextField.cpp
+++ b/source/code/sago/SagoTextField.cpp
@@ -115,6 +115,10 @@ void SagoTextField::SetText(const char* text) {
data->text = text;
}
+void SagoTextField::SetText(const std::string& text) {
+ data->text = text;
+}
+
void SagoTextField::SetColor(const SDL_Color& color) {
data->color = color;
}
diff --git a/source/code/sago/SagoTextField.hpp b/source/code/sago/SagoTextField.hpp
index 188cf2e..962a924 100644
--- a/source/code/sago/SagoTextField.hpp
+++ b/source/code/sago/SagoTextField.hpp
@@ -55,6 +55,7 @@ public:
* @param text The actual UTF-8 encoded text
*/
void SetText(const char* text);
+ void SetText(const std::string& text);
void SetColor(const SDL_Color& color);
/**
* Set the name of the font. Must be known to the data holder.