Implemented LessRoundBox custom font and FT2 extension font rendering. Enabled Emscripten compatible FT2 extension capabilities. Replaced original TTF PGEX with newline compatible version.

This commit is contained in:
2023-11-29 06:05:29 -06:00
parent 2af830d400
commit f9b00a8931
14 changed files with 152 additions and 110 deletions
+35 -10
View File
@@ -37,6 +37,7 @@ All rights reserved.
#pragma endregion
#include "util.h"
#include "olcPixelGameEngine.h"
#include "olcPGEX_TTF.h"
float util::random(float range){
return float(rand())/RAND_MAX*range;
@@ -83,25 +84,49 @@ std::string util::timerStr(float time){
}
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) {
std::string newStr="";
while(true){
std::string word="";
if(str.find(" ")==std::string::npos){
word=str;
} else {
word = str.substr(0,str.find(" "));
}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) {
if(newSize.x>width){
newStr+="\n"+word;
} else {
}else{
newStr+=(newStr.size()>0?" ":"")+word;
}
if (str.find(" ")==std::string::npos) {
if(str.find(" ")==std::string::npos){
break;
} else {
}else{
str.erase(0,str.find(" ")+1);
}
}
return newStr;
}
std::u32string util::WrapText(PixelGameEngine*pge,std::u32string str,int width,Font&font,vd2d scale){
std::u32string newStr=U"";
while(true){
std::u32string word=U"";
if(str.find(U" ")==std::u32string::npos){
word=str;
}else{
word=str.substr(0,str.find(U" "));
}
FontRect newSize = font.GetStringBounds(newStr+(newStr.size()>0?U" ":U"")+word);
if(newSize.size.x>width){
newStr+=U"\n"+word;
}else{
newStr+=(newStr.size()>0?U" ":U"")+word;
}
if(str.find(U" ")==std::u32string::npos){
break;
}else{
str.erase(0,str.find(U" ")+1);
}
}
return newStr;
}