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

pull/28/head
sigonasr2 1 year ago
parent 2af830d400
commit f9b00a8931
  1. 3
      Crawler/Crawler.cpp
  2. 2
      Crawler/Version.h
  3. 32
      Crawler/VisualNovel.cpp
  4. 10
      Crawler/VisualNovel.h
  5. BIN
      Crawler/assets/LessRoundBox.ttf
  6. 3
      Crawler/assets/config/configuration.txt
  7. 118
      Crawler/olcPGEX_TTF.h
  8. 38
      Crawler/olcPixelGameEngine.h
  9. BIN
      Crawler/pge.data
  10. 2
      Crawler/pge.js
  11. BIN
      Crawler/pge.wasm
  12. 2
      Crawler/pixelGameEngine.cpp
  13. 45
      Crawler/util.cpp
  14. 7
      Crawler/util.h

@ -64,6 +64,7 @@ All rights reserved.
#include "ItemDrop.h"
#include "VisualNovel.h"
#include "util.h"
#include "olcPGEX_TTF.h"
INCLUDE_EMITTER_LIST
@ -137,6 +138,8 @@ Crawler::Crawler()
}
bool Crawler::OnUserCreate(){
Font::init();
InitializeDefaultKeybinds();
VisualNovel::Initialize();

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3260
#define VERSION_BUILD 3283
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -50,8 +50,10 @@ INCLUDE_GFX
VisualNovel VisualNovel::novel;
safemap<std::string,std::vector<std::unique_ptr<Command>>>VisualNovel::storyLevelData;
std::set<std::string>VisualNovel::graphicsToLoad;
Font VisualNovel::font;
void VisualNovel::Initialize(){
font=Font("GFX_Prefix"_S+"dialog_font_size"_s[0]+".ttf","dialog_font_size"_i[1]);
for(int chapter=1;chapter<=6;chapter++){
std::string chapterFilename="assets/"+"story_directory"_S+"Chapter "+std::to_string(chapter)+".txt";
std::ifstream file(chapterFilename);
@ -167,7 +169,7 @@ void VisualNovel::Initialize(){
};
void VisualNovel::LoadVisualNovel(std::string storyLevelName){
novel.storyLevel=storyLevelName;
novel.activeText="";
novel.activeText=U"";
novel.leftCharacters.clear();
novel.rightCharacters.clear();
novel.backgroundFilename="";
@ -182,7 +184,7 @@ void VisualNovel::LoadVisualNovel(std::string storyLevelName){
}
void VisualNovel::Update(){
if(transitionTime==0&&game->KEY_CONFIRM.Pressed()){
activeText="";
activeText=U"";
novel.ExecuteNextCommand();
}
locationDisplayTime=std::max(0.f,locationDisplayTime-game->GetElapsedTime());
@ -192,7 +194,7 @@ void VisualNovel::Update(){
void VisualNovel::ExecuteNextCommand(){
if(commandIndex<commands.size()){
commandIndex++;
commands[commandIndex-1]->Execute(novel);
commands[size_t(commandIndex-1)]->Execute(novel);
}else{
Unlock::UnlockCurrentMap();
Menu::themeSelection=novel.prevTheme;
@ -214,14 +216,14 @@ void VisualNovel::Draw(){
}
for(int i=leftCharacters.size()-1;i>=0;i--){
//Start 72 from the bottom.
std::string character=leftCharacters[i];
std::u32string character(leftCharacters[i].begin(),leftCharacters[i].end());
Pixel fadeColor=WHITE;
if(character!=actualSpeakerName)fadeColor={128,128,128,255};
game->DrawDecal(vi2d{0,game->GetScreenSize().y}-vi2d{-i*64,72+168},GFX[GetCharacterImage(character)].Decal(),{1,1},fadeColor);
}
for(int i=rightCharacters.size()-1;i>=0;i--){
//Start 72 from the bottom.
std::string character=rightCharacters[i];
std::u32string character(rightCharacters[i].begin(),rightCharacters[i].end());
Pixel fadeColor=WHITE;
if(character!=actualSpeakerName)fadeColor={128,128,128,255};
float spriteWidth=GFX[GetCharacterImage(character)].Sprite()->width;
@ -242,9 +244,9 @@ void VisualNovel::Draw(){
vf2d dialogDisplayPos={24.f,game->GetScreenSize().y-48.f};
vf2d dialogDisplaySize={game->GetScreenSize().x-48.f,20.f};
Menu::DrawThemedWindow(dialogDisplayPos,dialogDisplaySize);
vf2d speakerTextSize=game->GetTextSizeProp(speakerDisplayName);
game->DrawShadowStringPropDecal(nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize/2,speakerDisplayName);
game->DrawShadowStringPropDecal(dialogDisplayPos-vf2d{10,10},activeText);
FontRect speakerTextSize=font.GetStringBounds(speakerDisplayName);
game->DrawShadowStringDecal(font,nameDisplayPos-vf2d{10,8}+(nameDisplayWindowSize+vf2d{24,0})/2-speakerTextSize.size/2,speakerDisplayName);
game->DrawShadowStringDecal(font,dialogDisplayPos-vf2d{10,10},activeText);
float yOffset=util::lerp(dialogDisplaySize.y+12,-8,textScrollTime/maxTextScrollTime);
game->DrawPolygonDecal(
Menu::GetPatchPart(1,1).Decal(),
@ -253,11 +255,11 @@ void VisualNovel::Draw(){
{{255,255,255,240},{255,255,255,255},{255,255,255,255},{255,255,255,240}});
}
}
std::string VisualNovel::GetCharacterImage(std::string name){
if(name=="You"){ //Assume we are using female player avatar for now!
std::string VisualNovel::GetCharacterImage(std::u32string name){
if(name==U"You"){ //Assume we are using female player avatar for now!
return "character_image_location"_S+"Player_F.png";
}
return "character_image_location"_S+name+".png";
return "character_image_location"_S+std::string(name.begin(),name.end())+".png";
}
VisualNovel::VisualNovel(){}
@ -300,8 +302,8 @@ RightCommand::RightCommand(std::vector<std::string>characters)
CommandType::CommandType RightCommand::GetType(){return CommandType::RIGHT;}
void SpeakerCommand::Execute(VisualNovel&vn){
vn.speakerDisplayName=displayedName;
vn.actualSpeakerName=actualSpeakerName;
vn.speakerDisplayName.assign(displayedName.begin(),displayedName.end());
vn.actualSpeakerName.assign(actualSpeakerName.begin(),actualSpeakerName.end());
vn.ExecuteNextCommand();
}
SpeakerCommand::SpeakerCommand(std::string speaker)
@ -313,8 +315,8 @@ CommandType::CommandType SpeakerCommand::GetType(){return CommandType::SPEAKER;}
void DialogCommand::Execute(VisualNovel&vn){
vn.textScrollTime=VisualNovel::maxTextScrollTime;
bool mustDisplay=vn.activeText.length()==0;
std::string newText=util::WrapText(game,vn.activeText+(vn.activeText.length()>0?" ":"")+dialog,game->GetScreenSize().x-48,true,{1,1});
if(game->GetTextSizeProp(newText).y>40){//Hit the maximum of 3 lines.
std::u32string newText=util::WrapText(game,vn.activeText+(vn.activeText.length()>0?U" ":U"")+std::u32string(dialog.begin(),dialog.end()),game->GetScreenSize().x-48,VisualNovel::font,{1,1});
if(VisualNovel::font.GetStringBounds(newText).size.y>40){//Hit the maximum of 3 lines.
if(!mustDisplay){
vn.commandIndex--;
}

@ -40,6 +40,7 @@ All rights reserved.
#include <memory>
#include "safemap.h"
#include <set>
#include "olcPGEX_TTF.h"
class VisualNovel;
@ -133,9 +134,9 @@ class VisualNovel{
friend class DialogCommand;
friend class PauseCommand;
std::string storyLevel;
std::string speakerDisplayName="";
std::string actualSpeakerName="";
std::string activeText;
std::u32string speakerDisplayName=U"";
std::u32string actualSpeakerName=U"";
std::u32string activeText;
std::vector<std::string>leftCharacters;
std::vector<std::string>rightCharacters;
std::string backgroundFilename;
@ -149,6 +150,7 @@ class VisualNovel{
std::string prevTheme="";
float textScrollTime=0;
static constexpr float maxTextScrollTime=1.0f;
static Font font;
static std::set<std::string>graphicsToLoad;
static safemap<std::string,std::vector<std::unique_ptr<Command>>>storyLevelData;
@ -163,5 +165,5 @@ public:
void ExecuteNextCommand();
void Update();
void Draw();
std::string GetCharacterImage(std::string name);
std::string GetCharacterImage(std::u32string name);
};

Binary file not shown.

@ -60,6 +60,9 @@ story_background_image_location = backgrounds/
# The name substituted for the player in dialogs
story_player_name = You
# Dialog font and size.
dialog_font_size = LessRoundBox,24
# Whether or not to show individual data accesses from config data structure.
debug_access_options = 0

@ -72,28 +72,8 @@ namespace olc {
Font(std::string path, int fontSize) : fontSize(fontSize) {
FT_Error error = FT_New_Face(library, path.c_str(), 0, &fontFace);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while loading the font! Error code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
}
error = FT_Set_Pixel_Sizes(fontFace, 0, fontSize);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while loading the font!Error Code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
}
}
Font(const Font &other) = delete;
@ -134,6 +114,8 @@ namespace olc {
for (size_t i = 0; i < string.size(); i++) {
char32_t chr = string[i];
Font *toUse = this;
FT_UInt chrIndex = GetCharIndex(chr);
@ -159,26 +141,23 @@ namespace olc {
FT_Set_Transform(toUse->fontFace, &rotMat, &pen);
FT_Error error = FT_Load_Char(toUse->fontFace, chr,
FT_LOAD_RENDER | FT_LOAD_COLOR);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while rendering a glyph! Error code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
return;
}
FT_Bitmap bmp = toUse->fontFace->glyph->bitmap;
FT_GlyphSlot slot = toUse->fontFace->glyph;
DrawBitmap(slot->bitmap_left,
pge->ScreenHeight() - slot->bitmap_top, bmp, color);
pen.x += toUse->fontFace->glyph->advance.x;
pen.y += toUse->fontFace->glyph->advance.y;
if(chr=='\n'){
int scaled_line_spacing = fontFace->size->metrics.height;
pen.y -=scaled_line_spacing;
pen.x=x*64;
} else {
DrawBitmap(slot->bitmap_left,
pge->ScreenHeight() - slot->bitmap_top, bmp, color);
}
prevToUse = toUse;
}
@ -189,8 +168,8 @@ namespace olc {
olc::Pixel color = olc::BLACK, float angle = 0.0f) {
DrawString(string, pos.x, pos.y, color, angle);
}
FontRect GetStringBounds(std::u32string string, float angle = 0.0f) {
private:
FontRect _GetStringBounds(std::u32string string, float angle = 0.0f) {
FT_Matrix rotMat;
rotMat.xx = (FT_Fixed)(std::cos(angle) * 0x10000L);
rotMat.xy = (FT_Fixed)(-std::sin(angle) * 0x10000L);
@ -214,6 +193,7 @@ namespace olc {
for (size_t i = 0; i < string.size(); i++) {
char32_t chr = string[i];
if(chr=='\r')continue;
Font *toUse = this;
FT_UInt chrIndex = GetCharIndex(chr);
@ -238,19 +218,7 @@ namespace olc {
}
FT_Set_Transform(toUse->fontFace, &rotMat, &pen);
FT_Error error = FT_Load_Char(toUse->fontFace, chr,
FT_LOAD_BITMAP_METRICS_ONLY);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while loading a glyph! Error code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
return olc::FontRect{{0, 0}, {0, 0}};
}
FT_Error error = FT_Load_Char(toUse->fontFace, chr, FT_LOAD_RENDER);
FT_GlyphSlot slot = toUse->fontFace->glyph;
FT_Glyph glyph;
@ -275,6 +243,11 @@ namespace olc {
pen.x += slot->advance.x;
pen.y += slot->advance.y;
if(chr=='\n'){
int scaled_line_spacing = fontFace->size->metrics.height;
pen.y -=scaled_line_spacing;
pen.x=minX;
}
FT_Done_Glyph(glyph);
}
@ -285,9 +258,15 @@ namespace olc {
return olc::FontRect{{minX, -maxY}, {maxX - minX, maxY - minY}};
}
public:
FontRect GetStringBounds(std::u32string string, float angle = 0.0f) {
FontRect temp=_GetStringBounds(string,angle);
return {temp.offset/2,{temp.size/2}};
}
olc::Sprite *RenderStringToSprite(std::u32string string,
olc::Pixel color) {
olc::FontRect rect = GetStringBounds(string);
olc::FontRect rect = _GetStringBounds(string);
olc::Sprite *sprite = new olc::Sprite{rect.size.x, rect.size.y};
for (int x = 0; x < rect.size.x; x++) {
@ -307,7 +286,7 @@ namespace olc {
for (size_t i = 0; i < string.size(); i++) {
char32_t chr = string[i];
if(chr=='\r')continue;
Font *toUse = this;
FT_UInt chrIndex = GetCharIndex(chr);
@ -333,26 +312,22 @@ namespace olc {
FT_Set_Transform(toUse->fontFace, nullptr, &pen);
FT_Error error = FT_Load_Char(toUse->fontFace, chr,
FT_LOAD_RENDER | FT_LOAD_COLOR);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while rendering a glyph! Error code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
return nullptr;
}
FT_Bitmap bmp = toUse->fontFace->glyph->bitmap;
FT_GlyphSlot slot = toUse->fontFace->glyph;
DrawBitmapTo(slot->bitmap_left,
pge->ScreenHeight() - slot->bitmap_top, bmp, color,
sprite);
pen.x += toUse->fontFace->glyph->advance.x;
pen.y += toUse->fontFace->glyph->advance.y;
if(chr=='\n'){
int scaled_line_spacing = fontFace->size->metrics.height;
pen.y -=scaled_line_spacing;
pen.x=rect.offset.x;
} else {
DrawBitmapTo(slot->bitmap_left,
pge->ScreenHeight() - slot->bitmap_top, bmp, color,
sprite);
}
}
pge->SetPixelMode(prevMode);
@ -393,19 +368,6 @@ namespace olc {
static bool init() {
FT_Error error = FT_Init_FreeType(&library);
if (error) {
const char *errorString = FT_Error_String(error);
if (errorString == nullptr) {
std::cerr
<< "An unknown error occured while loading the font library! "
"Error code: "
<< error << "\n";
} else {
std::cerr << errorString << "\n";
}
return false;
}
return true;
}
@ -431,7 +393,7 @@ namespace olc {
if (byte == 0) {
continue;
}
color.a = byte;
color.a = 255;
pge->Draw(x + bx, y + by, color);
}
}

@ -571,6 +571,7 @@ namespace olc
{
class PixelGameEngine;
class Sprite;
class Font;
// Pixel Game Engine Advanced Configuration
constexpr inline uint8_t nMouseButtons = 5;
@ -1140,9 +1141,11 @@ namespace olc
void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE);
// Draws a multiline string as a decal, with tiniting and scaling
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
// Draws a single shaded filled rectangle as a decal
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
@ -1465,7 +1468,7 @@ namespace olc
// O------------------------------------------------------------------------------O
#ifdef OLC_PGE_APPLICATION
#undef OLC_PGE_APPLICATION
#include "olcPGEX_TTF.h"
// O------------------------------------------------------------------------------O
// | olcPixelGameEngine INTERFACE IMPLEMENTATION (CORE) |
// | Note: The core implementation is platform independent |
@ -3281,6 +3284,7 @@ namespace olc
olc::vf2d spos = { 0.0f, 0.0f };
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n')
{
spos.x = 0; spos.y += 8.0f * scale.y;
@ -3304,6 +3308,7 @@ namespace olc
olc::vf2d spos = { 0.0f, 0.0f };
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n')
{
spos.x = 0; spos.y += 8.0f * scale.y;
@ -3333,6 +3338,33 @@ namespace olc
DrawStringDecal(pos, sText, col,scale);
}
void PixelGameEngine::DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const olc::vf2d& scale){
if(sText.length()==0)return;
static Decal*temp=nullptr;
if(temp!=nullptr){
delete temp;
}
temp=font.RenderStringToDecal(sText,col);
DrawDecal(pos,temp,scale/2,col);
}
void PixelGameEngine::DrawShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
if(sText.length()==0)return;
static Decal*temp=nullptr;
if(temp!=nullptr){
delete temp;
}
temp=font.RenderStringToDecal(sText,col);
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
if(x!=0||y!=0){
DrawDecal(pos+vf2d{x,y},temp,scale/2,shadowCol);
}
}
}
DrawDecal(pos,temp,scale/2,col);
}
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
@ -3440,6 +3472,7 @@ namespace olc
olc::vi2d pos = { 0,1 };
for (auto c : s)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n') { pos.y++; pos.x = 0; }
else if (c == '\t') { pos.x += nTabSizeInSpaces; }
else pos.x++;
@ -3465,6 +3498,7 @@ namespace olc
}
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n')
{
sx = 0; sy += 8 * scale;
@ -3506,6 +3540,7 @@ namespace olc
olc::vi2d pos = { 0,1 };
for (auto c : s)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n') { pos.y += 1; pos.x = 0; }
else if (c == '\t') { pos.x += nTabSizeInSpaces * 8; }
else pos.x += vFontSpacing[c - 32].y;
@ -3533,6 +3568,7 @@ namespace olc
}
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
if (c == '\n')
{
sx = 0; sy += 8 * scale;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 MiB

After

Width:  |  Height:  |  Size: 9.2 MiB

File diff suppressed because one or more lines are too long

Binary file not shown.

@ -37,6 +37,8 @@ All rights reserved.
#pragma endregion
#define _CRTDBG_MAP_ALLOC
//#define OLC_PGE_HEADLESS
#define OLC_PGEX_TTF
#include "olcPGEX_TTF.h"
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#define OLC_PGEX_TRANSFORMEDVIEW

@ -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;
}

@ -38,6 +38,12 @@ All rights reserved.
#pragma once
#include <stdlib.h>
#include "olcUTIL_Geometry2D.h"
#if defined(__EMSCRIPTEN__)
#include "olcPGEX_TTF.h"
#else
class olc::Font;
#endif
namespace util{
//Returns 0-range (as a float).
float random(float range);
@ -50,4 +56,5 @@ namespace util{
float lerp(float n1,float n2,double t);
std::string timerStr(float time);
std::string WrapText(PixelGameEngine*pge,std::string str,int width,bool proportional,vd2d scale);
std::u32string WrapText(PixelGameEngine*pge,std::u32string str,int width,Font&font,vd2d scale);
}
Loading…
Cancel
Save