Update wrap function! Much cleaner.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent ebbfafbebc
commit 4d7118f065
  1. BIN
      C++ProjectTemplate
  2. 39
      main.cpp

Binary file not shown.

@ -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]; } else {
word = str.substr(0,str.find(" "));
} }
vd2d siz; vi2d newSize = (proportional?GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
if (proportional) { if (newSize.x>width) {
siz={GetTextSizeProp(newStr).x*scale.x,GetTextSizeProp(newStr).y*scale.y}; newStr+="\n"+word;
} else { } else {
siz={GetTextSize(newStr).x*scale.x,GetTextSize(newStr).y*scale.y}; newStr+=(newStr.size()>0?" ":"")+word;
} }
if (siz.x>width) { if (str.find(" ")==std::string::npos) {
do { break;
if (newStr[newStr.length()-1]!=' ') {
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; str.erase(0,str.find(" ")+1);
marker++;
} }
} }
return newStr; return newStr;

Loading…
Cancel
Save