|
|
|
@ -1152,8 +1152,8 @@ namespace olc |
|
|
|
|
void DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false); |
|
|
|
|
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, std::string_view sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }, const float width=std::numeric_limits<float>::max(),const bool disableDynamicScaling=false); |
|
|
|
|
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1); |
|
|
|
|
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1); |
|
|
|
|
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false); |
|
|
|
|
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1,const bool disableDynamicScaling=false); |
|
|
|
|
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
|
|
|
|
@ -3420,15 +3420,52 @@ namespace olc |
|
|
|
|
DrawDecal(pos,garbageCollector[key].decal,scale,col); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,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){ |
|
|
|
|
if(x!=0||y!=0){ |
|
|
|
|
DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width); |
|
|
|
|
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){ |
|
|
|
|
struct DecalData{ |
|
|
|
|
Decal*decal; |
|
|
|
|
float expireTime=0.0f; |
|
|
|
|
}; |
|
|
|
|
if(sText.length()==0)return; |
|
|
|
|
static std::map<std::string,DecalData>garbageCollector; |
|
|
|
|
std::string key{sText}; |
|
|
|
|
key+=std::to_string(width); |
|
|
|
|
if(!disableDynamicScaling){ |
|
|
|
|
key+=scale.str(); |
|
|
|
|
} |
|
|
|
|
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
|
|
|
|
vi2d imageSize=GetWrappedTextSize(sText,width,scale); |
|
|
|
|
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x)); |
|
|
|
|
garbageCollector[key].decal=newDecal; |
|
|
|
|
SetDrawTarget(newDecal->sprite); |
|
|
|
|
Clear(BLANK); |
|
|
|
|
DrawString({0,0},sText,WHITE,1U,width/scale.x); |
|
|
|
|
newDecal->Update(); |
|
|
|
|
float adjustedShadowSizeFactor=shadowSizeFactor*4; |
|
|
|
|
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2)); |
|
|
|
|
garbageCollector[key+"_SHADOW"].decal=newShadowDecal; |
|
|
|
|
SetDrawTarget(newShadowDecal->sprite); |
|
|
|
|
Clear(BLANK); |
|
|
|
|
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){ |
|
|
|
|
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){ |
|
|
|
|
if(x!=0||y!=0){ |
|
|
|
|
DrawString(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
newShadowDecal->Update(); |
|
|
|
|
} |
|
|
|
|
DrawStringDecal(pos, sText, col,scale,width); |
|
|
|
|
garbageCollector[key].expireTime=GetRuntime()+120.0f; |
|
|
|
|
garbageCollector[key+"_SHADOW"].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{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol); |
|
|
|
|
DrawDecal(pos,garbageCollector[key].decal,scale,col); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PixelGameEngine::DrawStringDecal(Font&font, const olc::vf2d& pos, const std::u32string& sText, const Pixel col, const olc::vf2d& scale){ |
|
|
|
@ -3507,15 +3544,52 @@ namespace olc |
|
|
|
|
DrawDecal(pos,garbageCollector[key].decal,scale/4,col); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,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){ |
|
|
|
|
if(x!=0||y!=0){ |
|
|
|
|
DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale,width); |
|
|
|
|
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor,const bool disableDynamicScaling){ |
|
|
|
|
struct DecalData{ |
|
|
|
|
Decal*decal; |
|
|
|
|
float expireTime=0.0f; |
|
|
|
|
}; |
|
|
|
|
if(sText.length()==0)return; |
|
|
|
|
static std::map<std::string,DecalData>garbageCollector; |
|
|
|
|
std::string key{sText}; |
|
|
|
|
key+=std::to_string(width); |
|
|
|
|
if(!disableDynamicScaling){ |
|
|
|
|
key+=scale.str(); |
|
|
|
|
} |
|
|
|
|
if(!garbageCollector.count(key)){ //If the text key already exists, don't have to recreate the decal, just update the expire time.
|
|
|
|
|
vi2d imageSize=GetWrappedTextSizeProp(sText,width,scale); |
|
|
|
|
Decal*newDecal=new Decal(new Sprite(imageSize.x/scale.x,imageSize.y/scale.x)); |
|
|
|
|
garbageCollector[key].decal=newDecal; |
|
|
|
|
SetDrawTarget(newDecal->sprite); |
|
|
|
|
Clear(BLANK); |
|
|
|
|
DrawStringProp({0,0},sText,WHITE,1U,width/scale.x); |
|
|
|
|
newDecal->Update(); |
|
|
|
|
float adjustedShadowSizeFactor=shadowSizeFactor*4; |
|
|
|
|
Decal*newShadowDecal=new Decal(new Sprite((imageSize.x/scale.x*4)+adjustedShadowSizeFactor*2,(imageSize.y/scale.x*4)+adjustedShadowSizeFactor*2)); |
|
|
|
|
garbageCollector[key+"_SHADOW"].decal=newShadowDecal; |
|
|
|
|
SetDrawTarget(newShadowDecal->sprite); |
|
|
|
|
Clear(BLANK); |
|
|
|
|
for(float y=-adjustedShadowSizeFactor;y<=adjustedShadowSizeFactor+0.1;y+=adjustedShadowSizeFactor/2){ |
|
|
|
|
for(float x=-adjustedShadowSizeFactor;x<=adjustedShadowSizeFactor+0.1;x+=adjustedShadowSizeFactor/2){ |
|
|
|
|
if(x!=0||y!=0){ |
|
|
|
|
DrawStringProp(vf2d{x,y}+vf2d{adjustedShadowSizeFactor,adjustedShadowSizeFactor}, sText, WHITE,4U,width/scale.x*4); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
newShadowDecal->Update(); |
|
|
|
|
} |
|
|
|
|
DrawStringPropDecal(pos, sText, col,scale,width); |
|
|
|
|
garbageCollector[key].expireTime=GetRuntime()+120.0f; |
|
|
|
|
garbageCollector[key+"_SHADOW"].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{shadowSizeFactor,shadowSizeFactor}*scale,garbageCollector[key+"_SHADOW"].decal,scale/4,shadowCol); |
|
|
|
|
DrawDecal(pos,garbageCollector[key].decal,scale,col); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void PixelGameEngine::DrawShadowString(const olc::vi2d& pos, std::string_view sText, Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){ |
|
|
|
|