Implemented hex color font coloring.
This commit is contained in:
@@ -3340,8 +3340,17 @@ namespace olc
|
||||
{
|
||||
olc::vf2d spos = { 0.0f, 0.0f };
|
||||
Pixel textCol=col;
|
||||
for (auto c : sText)
|
||||
const auto hexToNumber=[](char c){
|
||||
if(c<='9')return c-'0';
|
||||
return (c-'A')+10;
|
||||
};
|
||||
for (int skip=0,index=-1;auto c : sText)
|
||||
{
|
||||
index++;
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
|
||||
if (c == '\n')
|
||||
{
|
||||
@@ -3355,9 +3364,23 @@ namespace olc
|
||||
{
|
||||
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
|
||||
}
|
||||
else if (c==Reset[0])
|
||||
else if (c=='#')
|
||||
{
|
||||
textCol=col;
|
||||
skip=6;
|
||||
textCol=BLACK;
|
||||
for(int i=1;i<7;i++){
|
||||
if(i<3){
|
||||
textCol.r*=16;
|
||||
textCol.r+=hexToNumber(sText[index+i]);
|
||||
}else
|
||||
if(i<5){
|
||||
textCol.g*=16;
|
||||
textCol.g+=hexToNumber(sText[index+i]);
|
||||
}else{
|
||||
textCol.b*=16;
|
||||
textCol.b+=hexToNumber(sText[index+i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -3373,8 +3396,17 @@ namespace olc
|
||||
{
|
||||
olc::vf2d spos = { 0.0f, 0.0f };
|
||||
Pixel textCol=col;
|
||||
for (auto c : sText)
|
||||
const auto hexToNumber=[](char c){
|
||||
if(c<='9')return c-'0';
|
||||
return (c-'A')+10;
|
||||
};
|
||||
for (int skip=0,index=-1;auto c : sText)
|
||||
{
|
||||
index++;
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
|
||||
if (c == '\n')
|
||||
{
|
||||
@@ -3392,6 +3424,24 @@ namespace olc
|
||||
{
|
||||
textCol=col;
|
||||
}
|
||||
else if (c=='#')
|
||||
{
|
||||
skip=6;
|
||||
textCol=BLACK;
|
||||
for(int i=1;i<7;i++){
|
||||
if(i<3){
|
||||
textCol.r*=16;
|
||||
textCol.r+=hexToNumber(sText[index+i]);
|
||||
}else
|
||||
if(i<5){
|
||||
textCol.g*=16;
|
||||
textCol.g+=hexToNumber(sText[index+i]);
|
||||
}else{
|
||||
textCol.b*=16;
|
||||
textCol.b+=hexToNumber(sText[index+i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t ox = (c - 32) % 16;
|
||||
@@ -3405,6 +3455,8 @@ namespace olc
|
||||
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
std::string strippedText=sText;
|
||||
std::erase_if(strippedText,[](char chr){return chr<0;});
|
||||
int skip=0;
|
||||
std::erase_if(strippedText,[&](char chr){if(skip>0){skip--;return true;}if(chr=='#'){skip=6;return true;}return false;});
|
||||
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){
|
||||
@@ -3494,6 +3546,8 @@ namespace olc
|
||||
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
|
||||
std::string strippedText=sText;
|
||||
std::erase_if(strippedText,[](char chr){return chr<0;});
|
||||
int skip=0;
|
||||
std::erase_if(strippedText,[&](char chr){if(skip>0){skip--;return true;}if(chr=='#'){skip=6;return true;}return false;});
|
||||
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){
|
||||
@@ -3602,12 +3656,21 @@ namespace olc
|
||||
{
|
||||
olc::vi2d size = { 0,1 };
|
||||
olc::vi2d pos = { 0,1 };
|
||||
for (auto c : s)
|
||||
for (int skip=0;auto c : s)
|
||||
{
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
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 if(c<0)continue;
|
||||
else if (c=='#')
|
||||
{
|
||||
skip=6;
|
||||
continue;
|
||||
}
|
||||
else pos.x++;
|
||||
size.x = std::max(size.x, pos.x);
|
||||
size.y = std::max(size.y, pos.y);
|
||||
@@ -3630,8 +3693,17 @@ namespace olc
|
||||
if (col.a != 255) SetPixelMode(Pixel::ALPHA);
|
||||
else SetPixelMode(Pixel::MASK);
|
||||
}
|
||||
for (auto c : sText)
|
||||
const auto hexToNumber=[](char c){
|
||||
if(c<='9')return c-'0';
|
||||
return (c-'A')+10;
|
||||
};
|
||||
for (int skip=0,index=-1;auto c : sText)
|
||||
{
|
||||
index++;
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
|
||||
if (c == '\n')
|
||||
{
|
||||
@@ -3645,6 +3717,24 @@ namespace olc
|
||||
{
|
||||
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
|
||||
}
|
||||
else if (c=='#')
|
||||
{
|
||||
skip=6;
|
||||
textCol=BLACK;
|
||||
for(int i=1;i<7;i++){
|
||||
if(i<3){
|
||||
textCol.r*=16;
|
||||
textCol.r+=hexToNumber(sText[index+i]);
|
||||
}else
|
||||
if(i<5){
|
||||
textCol.g*=16;
|
||||
textCol.g+=hexToNumber(sText[index+i]);
|
||||
}else{
|
||||
textCol.b*=16;
|
||||
textCol.b+=hexToNumber(sText[index+i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (c==Reset[0])
|
||||
{
|
||||
textCol=col;
|
||||
@@ -3680,12 +3770,21 @@ namespace olc
|
||||
{
|
||||
olc::vi2d size = { 0,1 };
|
||||
olc::vi2d pos = { 0,1 };
|
||||
for (auto c : s)
|
||||
for (int skip=0;auto c : s)
|
||||
{
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
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 if(c<0)continue;
|
||||
else if (c=='#')
|
||||
{
|
||||
skip=6;
|
||||
continue;
|
||||
}
|
||||
else pos.x += vFontSpacing[c - 32].y;
|
||||
size.x = std::max(size.x, pos.x);
|
||||
size.y = std::max(size.y, pos.y);
|
||||
@@ -3704,13 +3803,22 @@ namespace olc
|
||||
int32_t sy = 0;
|
||||
Pixel::Mode m = nPixelMode;
|
||||
Pixel textCol=col;
|
||||
const auto hexToNumber=[](char c){
|
||||
if(c<='9')return c-'0';
|
||||
return (c-'A')+10;
|
||||
};
|
||||
if (m != Pixel::CUSTOM)
|
||||
{
|
||||
if (col.a != 255) SetPixelMode(Pixel::ALPHA);
|
||||
else SetPixelMode(Pixel::MASK);
|
||||
}
|
||||
for (auto c : sText)
|
||||
for (int skip=0,index=-1;auto c : sText)
|
||||
{
|
||||
index++;
|
||||
if(skip){
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
|
||||
if (c == '\n')
|
||||
{
|
||||
@@ -3728,6 +3836,24 @@ namespace olc
|
||||
{
|
||||
textCol=col;
|
||||
}
|
||||
else if (c=='#')
|
||||
{
|
||||
skip=6;
|
||||
textCol=BLACK;
|
||||
for(int i=1;i<7;i++){
|
||||
if(i<3){
|
||||
textCol.r*=16;
|
||||
textCol.r+=hexToNumber(sText[index+i]);
|
||||
}else
|
||||
if(i<5){
|
||||
textCol.g*=16;
|
||||
textCol.g+=hexToNumber(sText[index+i]);
|
||||
}else{
|
||||
textCol.b*=16;
|
||||
textCol.b+=hexToNumber(sText[index+i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t ox = (c - 32) % 16;
|
||||
|
||||
Reference in New Issue
Block a user