Corrected word wrapping issues with PGEX_TTF. Added another line, fixed word wrapping width. Fixed up which fonts were used for measuring sizes.

This commit is contained in:
2023-11-29 23:09:03 -06:00
parent d9b1908985
commit 25b6dc0299
10 changed files with 61 additions and 14 deletions
+26
View File
@@ -1147,6 +1147,7 @@ namespace olc
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);
void DrawDropShadowStringDecal(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 });
// 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);
@@ -3394,6 +3395,31 @@ namespace olc
DrawDecal(pos,garbageCollector[key].decal,scale/4,col);
}
void PixelGameEngine::DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale){
struct DecalData{
Decal*decal;
float expireTime=0.0f;
};
if(sText.length()==0)return;
static std::map<std::u32string,DecalData>garbageCollector;
std::u32string key=font.GetFontName()+U"_"+sText;
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
garbageCollector[key].decal=font.RenderStringToDecal(sText,WHITE);
}
garbageCollector[key].expireTime=GetRuntime()+120.0f;
std::erase_if(garbageCollector,[&](auto&key){
if(key.second.expireTime<GetRuntime()){
delete key.second.decal;
return true;
}
return false;
});
DrawDecal(pos+vf2d{0,0.5f},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos+vf2d{0.5f,0},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos+vf2d{0.5f,0.5f},garbageCollector[key].decal,scale/4,shadowCol);
DrawDecal(pos,garbageCollector[key].decal,scale/4,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){