generated from sigonasr2/CPlusPlusProjectTemplate
Update wrap function! Much cleaner.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
ebbfafbebc
commit
4d7118f065
Binary file not shown.
41
main.cpp
41
main.cpp
@ -16,7 +16,7 @@
|
|||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "SeasonI.h"
|
#include "SeasonI.h"
|
||||||
|
|
||||||
#include "test/test.h"
|
//#include "test/test.h"
|
||||||
|
|
||||||
#ifndef TEST_SUITE
|
#ifndef TEST_SUITE
|
||||||
#define OLC_PGE_APPLICATION
|
#define OLC_PGE_APPLICATION
|
||||||
@ -4275,33 +4275,24 @@ void SeasonI::CalculateEquipmentStats(int partyMemberSlot,int&atk,int&def) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string SeasonI::Wrap(std::string str,int width,bool proportional,vd2d scale) {
|
std::string SeasonI::Wrap(std::string str,int width,bool proportional,vd2d scale) {
|
||||||
int marker=0;
|
std::string newStr;
|
||||||
std::string newStr="";
|
while (true) {
|
||||||
bool firstChar=false;
|
std::string word;
|
||||||
while (marker<str.length()) {
|
if (str.find(" ")==std::string::npos) {
|
||||||
if (firstChar||!firstChar&&str[marker]!=' ') {
|
word=str;
|
||||||
newStr+=str[marker];
|
|
||||||
}
|
|
||||||
vd2d siz;
|
|
||||||
if (proportional) {
|
|
||||||
siz={GetTextSizeProp(newStr).x*scale.x,GetTextSizeProp(newStr).y*scale.y};
|
|
||||||
} else {
|
} else {
|
||||||
siz={GetTextSize(newStr).x*scale.x,GetTextSize(newStr).y*scale.y};
|
word = str.substr(0,str.find(" "));
|
||||||
}
|
}
|
||||||
if (siz.x>width) {
|
vi2d newSize = (proportional?GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
|
||||||
do {
|
if (newSize.x>width) {
|
||||||
if (newStr[newStr.length()-1]!=' ') {
|
newStr+="\n"+word;
|
||||||
marker--;
|
|
||||||
//printf("%s\n",newStr.c_str());
|
|
||||||
}
|
|
||||||
newStr.erase(newStr.end()-1);
|
|
||||||
} while (newStr[newStr.length()-1]!=' ');
|
|
||||||
//newStr.erase(newStr.end()-1);
|
|
||||||
newStr+='\n';
|
|
||||||
firstChar=false;
|
|
||||||
} else {
|
} else {
|
||||||
firstChar=true;
|
newStr+=(newStr.size()>0?" ":"")+word;
|
||||||
marker++;
|
}
|
||||||
|
if (str.find(" ")==std::string::npos) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
str.erase(0,str.find(" ")+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newStr;
|
return newStr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user