Prepare framework with Draw and DrawDecal split.

This commit is contained in:
2023-10-11 19:50:12 -05:00
parent dd2ff24d85
commit e3d0283fcb
16 changed files with 479 additions and 46 deletions
+25
View File
@@ -1,4 +1,5 @@
#include "utils.h"
#include "olcPixelGameEngine.h"
float util::random(float range){
return float(rand())/RAND_MAX*range;
@@ -42,4 +43,28 @@ std::string util::timerStr(float time){
timeStr+=std::to_string(seconds%60);
return timeStr;
}
std::string util::WrapText(PixelGameEngine*pge,std::string str,int width,bool proportional,vd2d scale){
std::string newStr;
while (true) {
std::string word;
if (str.find(" ")==std::string::npos) {
word=str;
} else {
word = str.substr(0,str.find(" "));
}
vi2d newSize = vd2d(proportional?pge->GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):pge->GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
if (newSize.x>width) {
newStr+="\n"+word;
} else {
newStr+=(newStr.size()>0?" ":"")+word;
}
if (str.find(" ")==std::string::npos) {
break;
} else {
str.erase(0,str.find(" ")+1);
}
}
return newStr;
}