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 16 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
47 changes: 47 additions & 0 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3106,4 +3106,51 @@ namespace fheroes2
}
}
}

void ApplyVerticalGradient( fheroes2::Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor )
{
const int32_t height = image.height();
const int32_t width = image.width();

uint8_t * inData = image.image();
uint8_t * inTransform = image.transform();
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved

fheroes2::Image outImage;
fheroes2::Copy( image, outImage );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * outData = outImage.image();
uint8_t * outTransform = outImage.transform();

const uint8_t center_y = static_cast<uint8_t>( std::max( 1, ( height / 2 ) - height % 2 ) );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
const float dColor = (float)( outsideColor - insideColor );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved

for ( uint8_t row = 0; row < height; row++ ) {
float heightScale = static_cast<float>( abs( center_y - row ) ) / center_y;
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved

uint8_t val = static_cast<uint8_t>( abs( insideColor + ( heightScale * dColor ) ) );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * inRowStart = inData + static_cast<ptrdiff_t>( row * width );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * outRowStart = outData + static_cast<ptrdiff_t>( row * width );

uint8_t * inRowEnd = inData + static_cast<ptrdiff_t>( ( row + 1 ) * width );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * inTrans = inTransform + static_cast<ptrdiff_t>( row * width );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * outTrans = outTransform + static_cast<ptrdiff_t>( row * width );

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

for ( uint8_t i = 0; i < borderWidth; i++ ) {
fheroes2::Sprite cnt = CreateContour( outImage, borderColor );
Blit( cnt, outImage );
}
fheroes2::Copy( outImage, image );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
}
}
4 changes: 3 additions & 1 deletion src/engine/image.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2020 - 2023 *
* Copyright (C) 2020 - 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -318,4 +318,6 @@ namespace fheroes2
void Transpose( const Image & in, Image & out );

void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners );

void ApplyVerticalGradient( fheroes2::Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
}
24 changes: 23 additions & 1 deletion src/engine/pal.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2020 - 2022 *
* Copyright (C) 2020 - 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -42,6 +42,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
89 changes: 89 additions & 0 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,87 @@ namespace fheroes2
case ICN::GRAY_SMALL_FONT:
CopyICNWithPalette( id, ICN::SMALFONT, PAL::PaletteType::GRAY_FONT );
return true;
case ICN::GOLDEN_GRADIENT_FONT: {
GetICN( ICN::FONT, 0 );
const std::vector<Sprite> & original = _icnVsSprite[ICN::FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const Sprite & in = original[i];
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 );
ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 4, 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: {
GetICN( ICN::WHITE_LARGE_FONT, 0 );
const std::vector<Sprite> & original = _icnVsSprite[ICN::WHITE_LARGE_FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const Sprite & in = original[i];
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 );
ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 4, 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: {
GetICN( ICN::FONT, 0 );
const std::vector<Sprite> & original = _icnVsSprite[ICN::FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const Sprite & in = original[i];
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 );
ApplyVerticalGradient( 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: {
GetICN( ICN::WHITE_LARGE_FONT, 0 );
const std::vector<Sprite> & original = _icnVsSprite[ICN::WHITE_LARGE_FONT];
_icnVsSprite[id].resize( original.size() );
for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) {
const Sprite & in = original[i];
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 );
ApplyVerticalGradient( 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 @@ -4998,6 +5079,10 @@ namespace fheroes2
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 @@ -5008,6 +5093,10 @@ namespace fheroes2
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 @@ -938,7 +938,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
6 changes: 5 additions & 1 deletion src/fheroes2/gui/ui_font.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2022 - 2023 *
* Copyright (C) 2022 - 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -5791,6 +5791,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
6 changes: 4 additions & 2 deletions src/fheroes2/gui/ui_text.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 - 2023 *
* Copyright (C) 2021 - 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -43,7 +43,9 @@ namespace fheroes2
{
WHITE,
GRAY,
YELLOW
YELLOW,
GOLDEN_GRADIENT,
SILVER_GRADIENT,
};

struct FontType
Expand Down
Loading