Prepare framework with Draw and DrawDecal split.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user