Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Vertical Gradient for fonts #8262

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,47 @@ namespace fheroes2
}
}

void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor )
{
assert( !image.singleLayer() );

const int32_t height = image.height();
const int32_t width = image.width();

uint8_t * inData = image.image();
uint8_t * inTransform = image.transform();

const uint8_t centerY = static_cast<uint8_t>( std::max( 1, ( height / 2 ) - height % 2 ) );
const uint8_t dColor = outsideColor - insideColor;

for ( uint8_t row = 0; row < height; row++ ) {
const uint8_t heightScale = ( dColor * static_cast<uint8_t>( std::abs( centerY - row ) ) ) / centerY;

const uint8_t val = static_cast<uint8_t>( std::abs( insideColor + heightScale ) );
uint8_t * inRowStart = inData + static_cast<ptrdiff_t>( row ) * width;

const uint8_t * inRowEnd = inData + static_cast<ptrdiff_t>( row + 1 ) * width;
uint8_t * inTrans = inTransform + static_cast<ptrdiff_t>( row ) * width;

for ( ; inRowStart != inRowEnd; ++inRowStart, ++inTrans ) {
if ( *inTrans == 0 ) {
// 21 is the pixel limit of shadows in Base white Font
if ( *inRowStart < 21 ) {
*inRowStart = val;
}
else {
*inTrans = 1;
}
}
}
}

for ( uint8_t i = 0; i < borderWidth; i++ ) {
fheroes2::Sprite cnt = CreateContour( image, borderColor );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
Blit( cnt, image );
}
}

void Blit( const Image & in, Image & out, const bool flip /* = false */ )
{
Blit( in, 0, 0, out, 0, 0, in.width(), in.height(), flip );
Expand Down
3 changes: 3 additions & 0 deletions src/engine/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ namespace fheroes2

void ApplyTransform( Image & image, int32_t x, int32_t y, int32_t width, int32_t height, const uint8_t transformId );

void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth,
const uint8_t borderColor );

// draw one image onto another
void Blit( const Image & in, Image & out, const bool flip = false );
void Blit( const Image & in, Image & out, int32_t outX, int32_t outY, const bool flip = false );
Expand Down
22 changes: 22 additions & 0 deletions src/engine/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ namespace PAL
CUSTOM
};

enum ColorRanges : uint8_t
{
GRAY_START = 10,
GRAY_END = 36,
BROWN_START = 37,
BROWN_END = 62,
BLUE_START = 63,
BLUE_END = 84,
GREEN_START = 85,
GREEN_END = 107,
YELLOW_START = 108,
YELLOW_END = 130,
PURPLE_START = 131,
PURPLE_END = 152,
CYAN_START = 153,
CYAN_END = 174,
RED_START = 175,
RED_END = 197,
ORANGE_START = 198,
ORANGE_END = 213
};

std::vector<uint8_t> GetCyclingPalette( const uint32_t stepId );
const std::vector<uint8_t> & GetPalette( const PaletteType type );
std::vector<uint8_t> CombinePalettes( const std::vector<uint8_t> & first, const std::vector<uint8_t> & second );
Expand Down
90 changes: 90 additions & 0 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,88 @@ namespace
case ICN::GRAY_SMALL_FONT:
CopyICNWithPalette( id, ICN::SMALFONT, PAL::PaletteType::GRAY_FONT );
return true;
case ICN::GOLDEN_GRADIENT_FONT: {
fheroes2::AGG::GetICN( ICN::FONT, 0 );
const std::vector<fheroes2::Sprite> & original = _icnVsSprite[ICN::FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const fheroes2::Sprite & in = original[i];
fheroes2::Sprite & out = _icnVsSprite[id][i];
out.resize( in.width() + 6, in.height() + 6 );
out.reset();
Copy( in, 0, 0, out, 3, 3, in.width(), in.height() );
out.setPosition( in.x() - 2, in.y() - 2 );

applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 );

const fheroes2::Sprite contourBlack = CreateContour( out, 0 );
Blit( contourBlack, out );
const fheroes2::Sprite contourGray = CreateContour( out, 62 );
Blit( contourGray, out );
}
return true;
}
case ICN::GOLDEN_GRADIENT_LARGE_FONT: {
fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 );
const std::vector<fheroes2::Sprite> & original = _icnVsSprite[ICN::WHITE_LARGE_FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const fheroes2::Sprite & in = original[i];
fheroes2::Sprite & out = _icnVsSprite[id][i];
out.resize( in.width() + 6, in.height() + 6 );
out.reset();
Copy( in, 0, 0, out, 3, 3, in.width(), in.height() );
out.setPosition( in.x() - 2, in.y() - 2 );
applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 );

const fheroes2::Sprite contourBlack = CreateContour( out, 0 );
Blit( contourBlack, out );
const fheroes2::Sprite contourGray = CreateContour( out, 62 );
Blit( contourGray, out );
}
return true;
}
case ICN::SILVER_GRADIENT_FONT: {
fheroes2::AGG::GetICN( ICN::FONT, 0 );
const std::vector<fheroes2::Sprite> & original = _icnVsSprite[ICN::FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const fheroes2::Sprite & in = original[i];
fheroes2::Sprite & out = _icnVsSprite[id][i];
out.resize( in.width() + 6, in.height() + 6 );
out.reset();
Copy( in, 0, 0, out, 3, 3, in.width(), in.height() );
out.setPosition( in.x() - 2, in.y() - 2 );
applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_START, 1, PAL::ColorRanges::GRAY_END - 7 );

const fheroes2::Sprite contourBlack = CreateContour( out, 0 );
Blit( contourBlack, out );
const fheroes2::Sprite contourBlack2 = CreateContour( out, 0 );
Blit( contourBlack2, out );
}
return true;
}
case ICN::SILVER_GRADIENT_LARGE_FONT: {
fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 );
const std::vector<fheroes2::Sprite> & original = _icnVsSprite[ICN::WHITE_LARGE_FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const fheroes2::Sprite & in = original[i];
fheroes2::Sprite & out = _icnVsSprite[id][i];
out.resize( in.width() + 6, in.height() + 6 );
out.reset();
Copy( in, 0, 0, out, 3, 3, in.width(), in.height() );
out.setPosition( in.x() - 2, in.y() - 2 );
applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_START, 1, PAL::ColorRanges::GRAY_END - 7 );

const fheroes2::Sprite contourBlack = CreateContour( out, 0 );
Blit( contourBlack, out );
const fheroes2::Sprite contourBlack2 = CreateContour( out, 0 );
Blit( contourBlack2, out );
}
return true;
}

case ICN::SPELLS:
LoadOriginalICN( id );
if ( _icnVsSprite[id].size() != 60 ) {
Expand Down Expand Up @@ -5230,6 +5312,10 @@ namespace fheroes2::AGG
return GetICN( ICN::GRAY_FONT, character - 0x20 );
case FontColor::YELLOW:
return GetICN( ICN::YELLOW_FONT, character - 0x20 );
case FontColor::GOLDEN_GRADIENT:
return GetICN( ICN::GOLDEN_GRADIENT_FONT, character - 0x20 );
case FontColor::SILVER_GRADIENT:
return GetICN( ICN::SILVER_GRADIENT_FONT, character - 0x20 );
default:
// Did you add a new font color? Add the corresponding logic for it!
assert( 0 );
Expand All @@ -5240,6 +5326,10 @@ namespace fheroes2::AGG
switch ( fontType.color ) {
case FontColor::WHITE:
return GetICN( ICN::WHITE_LARGE_FONT, character - 0x20 );
case FontColor::GOLDEN_GRADIENT:
return GetICN( ICN::GOLDEN_GRADIENT_LARGE_FONT, character - 0x20 );
case FontColor::SILVER_GRADIENT:
return GetICN( ICN::SILVER_GRADIENT_LARGE_FONT, character - 0x20 );
default:
// Did you add a new font color? Add the corresponding logic for it!
assert( 0 );
Expand Down
5 changes: 5 additions & 0 deletions src/fheroes2/agg/icn.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,12 @@ namespace ICN
UNIFORM_GOOD_EXIT_BUTTON,
UNIFORM_EVIL_EXIT_BUTTON,

GOLDEN_GRADIENT_FONT,
SILVER_GRADIENT_FONT,

WHITE_LARGE_FONT,
GOLDEN_GRADIENT_LARGE_FONT,
SILVER_GRADIENT_LARGE_FONT,
SWAP_ARROW_LEFT_TO_RIGHT,
SWAP_ARROW_RIGHT_TO_LEFT,

Expand Down
4 changes: 4 additions & 0 deletions src/fheroes2/gui/ui_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5841,6 +5841,10 @@ namespace fheroes2
icnVsSprite[ICN::GRAY_FONT].clear();
icnVsSprite[ICN::GRAY_SMALL_FONT].clear();
icnVsSprite[ICN::WHITE_LARGE_FONT].clear();
icnVsSprite[ICN::GOLDEN_GRADIENT_FONT].clear();
icnVsSprite[ICN::GOLDEN_GRADIENT_LARGE_FONT].clear();
icnVsSprite[ICN::SILVER_GRADIENT_FONT].clear();
icnVsSprite[ICN::SILVER_GRADIENT_LARGE_FONT].clear();
}

bool isAlphabetSupported( const SupportedLanguage language )
Expand Down
4 changes: 3 additions & 1 deletion src/fheroes2/gui/ui_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ namespace fheroes2
{
WHITE,
GRAY,
YELLOW
YELLOW,
GOLDEN_GRADIENT,
SILVER_GRADIENT,
};

struct FontType
Expand Down
Loading