From 913c52660ac2dc2fe588b54777b4d59363490a69 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 12 Jan 2024 03:17:11 +0330 Subject: [PATCH 01/35] Adding Color Ranges for all colors To PAL Namespace Adding GOLDEN_GRADIENT ICN for Normal And Large Fonts --- src/engine/pal.h | 22 ++++++++++++++++++++++ src/fheroes2/agg/icn.h | 3 +++ 2 files changed, 25 insertions(+) diff --git a/src/engine/pal.h b/src/engine/pal.h index f69cfb4c71e..b58dafceeb1 100644 --- a/src/engine/pal.h +++ b/src/engine/pal.h @@ -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 GetCyclingPalette( const uint32_t stepId ); const std::vector & GetPalette( const PaletteType type ); std::vector CombinePalettes( const std::vector & first, const std::vector & second ); diff --git a/src/fheroes2/agg/icn.h b/src/fheroes2/agg/icn.h index 953db60ff3b..ff2f89135b1 100644 --- a/src/fheroes2/agg/icn.h +++ b/src/fheroes2/agg/icn.h @@ -937,8 +937,11 @@ namespace ICN UNIFORM_EVIL_CANCEL_BUTTON, UNIFORM_GOOD_EXIT_BUTTON, UNIFORM_EVIL_EXIT_BUTTON, + + GOLDEN_GRADIENT_FONT, WHITE_LARGE_FONT, + GOLDEN_GRADIENT_LARGE_FONT, SWAP_ARROW_LEFT_TO_RIGHT, SWAP_ARROW_RIGHT_TO_LEFT, From 770795ce726658b1d993acd3e443d59dead934c2 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 12 Jan 2024 03:18:55 +0330 Subject: [PATCH 02/35] - Definition for ApplyVerticalGradient --- src/engine/image.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++ src/engine/image.h | 3 +++ 2 files changed, 55 insertions(+) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 1fc4634e3bc..b080469a3de 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3106,4 +3106,56 @@ namespace fheroes2 } } } + void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t offset, uint8_t borderWidth ) + { + const int32_t height = image.height(); + const int32_t width = image.width(); + uint8_t * inData = image.image(); + uint8_t * inTransform = image.transform(); + + uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); + // offsetting provides better visibility + float scale = ( outsideColor - insideColor - offset ) / static_cast( center_y ); + // bottom Half + for ( uint8_t pos_y = center_y; pos_y <= height; pos_y++ ) { + uint8_t val = static_cast( insideColor + abs( center_y - pos_y ) * scale ); + + uint8_t * rowStart = inData + static_cast( pos_y * width ); + uint8_t * rowEnd = inData + static_cast( ( pos_y + 1 ) * width ); + uint8_t * inTrans = inTransform + static_cast( pos_y * width ); + + for ( ; rowStart != rowEnd; ++rowStart, ++inTrans ) { + if ( *inTrans == 0 ) { + *rowStart = val; + } + } + } + + // top Half + for ( uint8_t neg_y = 0; neg_y <= center_y; neg_y++ ) { + uint8_t neg_Val = static_cast( insideColor + abs( center_y - neg_y ) * scale ); + uint8_t * neg_rowStart = inData + static_cast( neg_y * width ); + uint8_t * neg_rowEnd = inData + static_cast( ( neg_y + 1 ) * width ); + uint8_t * neg_inTrans = inTransform + static_cast( neg_y * width ); + for ( ; neg_rowStart != neg_rowEnd; ++neg_rowStart, ++neg_inTrans ) { + if ( *neg_inTrans == 0 || neg_y == 0 ) { + *neg_rowStart = neg_Val; + } + } + } + + // first line is broken for unknown reason + uint8_t * data = inData; + uint8_t * transform = inTransform; + const uint8_t * dataEnd = data + width; + for ( ; data != dataEnd; ++data, ++transform ) { + *transform = 1; + } + + for ( uint8_t i = 0; i < borderWidth; i++ ) { + fheroes2::Image cnt = CreateContour( image, 0 ); + Blit( cnt, image ); + } + + } } diff --git a/src/engine/image.h b/src/engine/image.h index cf65ee08fbe..8d8f9fcaf73 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -318,4 +318,7 @@ 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, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth ); + } From 9bcbb57369927110e1f5f94240831726d124607a Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 12 Jan 2024 03:24:27 +0330 Subject: [PATCH 03/35] - Adding GOLDEN_GRADIENT to font colors with it's respectable logic for LARGE and NORMAL font type - Adding ICN generation for both font types - style Fix --- src/engine/image.cpp | 1 - src/engine/image.h | 2 +- src/fheroes2/agg/agg_image.cpp | 30 ++++++++++++++++++++++++++++++ src/fheroes2/gui/ui_text.h | 3 ++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index b080469a3de..210ff3cf167 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3156,6 +3156,5 @@ namespace fheroes2 fheroes2::Image cnt = CreateContour( image, 0 ); Blit( cnt, image ); } - } } diff --git a/src/engine/image.h b/src/engine/image.h index 8d8f9fcaf73..560ddebb9f2 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -319,6 +319,6 @@ namespace fheroes2 void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners ); - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth ); + void ApplyVerticalGradient( fheroes2::Image & image, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth ); } diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 4f487a105d9..598e8c8edd1 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2493,6 +2493,32 @@ 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 & 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]; + Copy( in, out ); + out.setPosition( in.x(), in.y() ); + ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 1 ); + } + return true; + } + case ICN::GOLDEN_GRADIENT_LARGE_FONT: { + GetICN( ICN::WHITE_LARGE_FONT, 0 ); + const std::vector & 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]; + Copy( in, out ); + out.setPosition( in.x(), in.y() ); + ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 3 ); + } + return true; + } case ICN::SPELLS: LoadOriginalICN( id ); if ( _icnVsSprite[id].size() != 60 ) { @@ -4998,6 +5024,8 @@ namespace fheroes2 return GetICN( ICN::GRAY_FONT, character - 0x20 ); case FontColor::YELLOW: return GetICN( ICN::YELLOW_FONT, character - 0x20 ); + case FontColor::GOLDEN_GRADINT: + return GetICN( ICN::GOLDEN_GRADIENT_FONT, character - 0x20 ); default: // Did you add a new font color? Add the corresponding logic for it! assert( 0 ); @@ -5008,6 +5036,8 @@ namespace fheroes2 switch ( fontType.color ) { case FontColor::WHITE: return GetICN( ICN::WHITE_LARGE_FONT, character - 0x20 ); + case FontColor::GOLDEN_GRADINT: + return GetICN( ICN::GOLDEN_GRADIENT_LARGE_FONT, character - 0x20 ); default: // Did you add a new font color? Add the corresponding logic for it! assert( 0 ); diff --git a/src/fheroes2/gui/ui_text.h b/src/fheroes2/gui/ui_text.h index 6fb184ec388..03c931abdc3 100644 --- a/src/fheroes2/gui/ui_text.h +++ b/src/fheroes2/gui/ui_text.h @@ -43,7 +43,8 @@ namespace fheroes2 { WHITE, GRAY, - YELLOW + YELLOW, + GOLDEN_GRADINT, }; struct FontType From 07a1eeb2478aba39e8a6d2ea1aa89e3ed31b4672 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 12 Jan 2024 03:49:32 +0330 Subject: [PATCH 04/35] style fix --- src/engine/image.h | 1 - src/fheroes2/agg/icn.h | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/engine/image.h b/src/engine/image.h index 560ddebb9f2..4e48f4f4201 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -320,5 +320,4 @@ namespace fheroes2 void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners ); void ApplyVerticalGradient( fheroes2::Image & image, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth ); - } diff --git a/src/fheroes2/agg/icn.h b/src/fheroes2/agg/icn.h index ff2f89135b1..dd21556ee58 100644 --- a/src/fheroes2/agg/icn.h +++ b/src/fheroes2/agg/icn.h @@ -937,7 +937,7 @@ namespace ICN UNIFORM_EVIL_CANCEL_BUTTON, UNIFORM_GOOD_EXIT_BUTTON, UNIFORM_EVIL_EXIT_BUTTON, - + GOLDEN_GRADIENT_FONT, WHITE_LARGE_FONT, From b1f5c3e8248ff7cd6cb84dd90b31beeed3a4ec25 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 12 Jan 2024 03:55:27 +0330 Subject: [PATCH 05/35] Fix Date on Copyright header --- src/engine/image.h | 2 +- src/engine/pal.cpp | 2 +- src/engine/pal.h | 2 +- src/fheroes2/gui/ui_text.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/engine/image.h b/src/engine/image.h index 4e48f4f4201..d93fe20c313 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -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 * diff --git a/src/engine/pal.cpp b/src/engine/pal.cpp index 5ff0b84e6a4..d527cec6667 100644 --- a/src/engine/pal.cpp +++ b/src/engine/pal.cpp @@ -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 * diff --git a/src/engine/pal.h b/src/engine/pal.h index b58dafceeb1..742dbb226f4 100644 --- a/src/engine/pal.h +++ b/src/engine/pal.h @@ -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 * diff --git a/src/fheroes2/gui/ui_text.h b/src/fheroes2/gui/ui_text.h index 03c931abdc3..c477ee8074b 100644 --- a/src/fheroes2/gui/ui_text.h +++ b/src/fheroes2/gui/ui_text.h @@ -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 * From 9ceac686d0b207a8acc1452e05c62d3deb9ec7c5 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 19:04:17 +0330 Subject: [PATCH 06/35] Addressing Reviews --- src/engine/pal.cpp | 2 +- src/fheroes2/agg/agg_image.cpp | 20 +++++++++++++------- src/fheroes2/gui/ui_text.h | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/engine/pal.cpp b/src/engine/pal.cpp index d527cec6667..5ff0b84e6a4 100644 --- a/src/engine/pal.cpp +++ b/src/engine/pal.cpp @@ -1,6 +1,6 @@ /*************************************************************************** * fheroes2: https://github.com/ihhub/fheroes2 * - * Copyright (C) 2020 - 2024 * + * Copyright (C) 2020 - 2023 * * * * 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 * diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 598e8c8edd1..7fae234df3f 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2500,9 +2500,12 @@ namespace fheroes2 for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { const Sprite & in = original[i]; Sprite & out = _icnVsSprite[id][i]; - Copy( in, out ); - out.setPosition( in.x(), in.y() ); + out.resize( in.width() + 3, in.height() + 2 ); + out.reset(); + Copy( in, 0, 0, out, 1, 1, in.width(), in.height() ); + out.setPosition( in.x() - 1, in.y() - 1 ); ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 1 ); + fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } return true; } @@ -2513,9 +2516,12 @@ namespace fheroes2 for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { const Sprite & in = original[i]; Sprite & out = _icnVsSprite[id][i]; - Copy( in, out ); - out.setPosition( in.x(), in.y() ); - ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 3 ); + out.resize( in.width() + 3, in.height() + 2 ); + out.reset(); + Copy( in, 0, 0, out, 1, 1, in.width(), in.height() ); + out.setPosition( in.x() - 1, in.y() - 1 ); + ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 2 ); + fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } return true; } @@ -5024,7 +5030,7 @@ namespace fheroes2 return GetICN( ICN::GRAY_FONT, character - 0x20 ); case FontColor::YELLOW: return GetICN( ICN::YELLOW_FONT, character - 0x20 ); - case FontColor::GOLDEN_GRADINT: + case FontColor::GOLDEN_GRADIENT: return GetICN( ICN::GOLDEN_GRADIENT_FONT, character - 0x20 ); default: // Did you add a new font color? Add the corresponding logic for it! @@ -5036,7 +5042,7 @@ namespace fheroes2 switch ( fontType.color ) { case FontColor::WHITE: return GetICN( ICN::WHITE_LARGE_FONT, character - 0x20 ); - case FontColor::GOLDEN_GRADINT: + case FontColor::GOLDEN_GRADIENT: return GetICN( ICN::GOLDEN_GRADIENT_LARGE_FONT, character - 0x20 ); default: // Did you add a new font color? Add the corresponding logic for it! diff --git a/src/fheroes2/gui/ui_text.h b/src/fheroes2/gui/ui_text.h index c477ee8074b..5ea6af75d04 100644 --- a/src/fheroes2/gui/ui_text.h +++ b/src/fheroes2/gui/ui_text.h @@ -44,7 +44,7 @@ namespace fheroes2 WHITE, GRAY, YELLOW, - GOLDEN_GRADINT, + GOLDEN_GRADIENT, }; struct FontType From 3a2081f5920b58da4907d48776b6f20b55b7a212 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 20:58:48 +0330 Subject: [PATCH 07/35] Reformat function and fix to prevent overwritting of font details --- src/engine/image.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 210ff3cf167..eed94ca6310 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3116,20 +3116,6 @@ namespace fheroes2 uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); // offsetting provides better visibility float scale = ( outsideColor - insideColor - offset ) / static_cast( center_y ); - // bottom Half - for ( uint8_t pos_y = center_y; pos_y <= height; pos_y++ ) { - uint8_t val = static_cast( insideColor + abs( center_y - pos_y ) * scale ); - - uint8_t * rowStart = inData + static_cast( pos_y * width ); - uint8_t * rowEnd = inData + static_cast( ( pos_y + 1 ) * width ); - uint8_t * inTrans = inTransform + static_cast( pos_y * width ); - - for ( ; rowStart != rowEnd; ++rowStart, ++inTrans ) { - if ( *inTrans == 0 ) { - *rowStart = val; - } - } - } // top Half for ( uint8_t neg_y = 0; neg_y <= center_y; neg_y++ ) { @@ -3138,9 +3124,32 @@ namespace fheroes2 uint8_t * neg_rowEnd = inData + static_cast( ( neg_y + 1 ) * width ); uint8_t * neg_inTrans = inTransform + static_cast( neg_y * width ); for ( ; neg_rowStart != neg_rowEnd; ++neg_rowStart, ++neg_inTrans ) { - if ( *neg_inTrans == 0 || neg_y == 0 ) { + if ( *neg_inTrans == 0 && *neg_rowStart < 20 ) { *neg_rowStart = neg_Val; } + else if ( *neg_rowStart < std::min(insideColor,outsideColor) ) { + *neg_inTrans = 1; + } + } + } + + // bottom Half + for ( uint8_t pos_y = center_y; pos_y <= height; pos_y++ ) { + uint8_t val = static_cast( insideColor + abs( center_y - pos_y ) * scale ); + + uint8_t * rowStart = inData + static_cast( pos_y * width ); + uint8_t * rowEnd = inData + static_cast( ( pos_y + 1 ) * width ); + uint8_t * inTrans = inTransform + static_cast( pos_y * width ); + + for ( ; rowStart != rowEnd; rowStart++, inTrans++ ) { + if ( *inTrans == 0 ) { + if ( *rowStart < 21 ) { + *rowStart = val; + } + else if ( *rowStart < std::min( insideColor, outsideColor ) ) { + *inTrans = 1; + } + } } } From 78f0dc3b70c306eb8bbf893ce5669af380ed2575 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 13 Jan 2024 21:00:26 +0330 Subject: [PATCH 08/35] fix style --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index eed94ca6310..882124827c6 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3127,7 +3127,7 @@ namespace fheroes2 if ( *neg_inTrans == 0 && *neg_rowStart < 20 ) { *neg_rowStart = neg_Val; } - else if ( *neg_rowStart < std::min(insideColor,outsideColor) ) { + else if ( *neg_rowStart < std::min( insideColor, outsideColor ) ) { *neg_inTrans = 1; } } From 8e8d10ca46c43cb0ece6461946850e6e906139cd Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 04:11:29 +0330 Subject: [PATCH 09/35] - Fixing Names ApplyVerticalGradient declaration - Fixing Data type from Sprite to Image --- src/engine/image.cpp | 2 +- src/engine/image.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 882124827c6..846f40e41e2 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3162,7 +3162,7 @@ namespace fheroes2 } for ( uint8_t i = 0; i < borderWidth; i++ ) { - fheroes2::Image cnt = CreateContour( image, 0 ); + fheroes2::Sprite cnt = CreateContour( image, 0 ); Blit( cnt, image ); } } diff --git a/src/engine/image.h b/src/engine/image.h index d93fe20c313..7ccabb81522 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -319,5 +319,5 @@ namespace fheroes2 void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners ); - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth ); + void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t offset, uint8_t borderWidth ); } From 2fd124c5b14535d0c54b5692fe8b1b82c8498e01 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 05:38:26 +0330 Subject: [PATCH 10/35] Adding Color param for border Adding Black contour Wrap at the end --- src/engine/image.cpp | 9 ++++++--- src/engine/image.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 846f40e41e2..34c6a8e5021 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3106,7 +3106,7 @@ namespace fheroes2 } } } - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t offset, uint8_t borderWidth ) + void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t borderWidth, uint8_t borderColor ) { const int32_t height = image.height(); const int32_t width = image.width(); @@ -3115,7 +3115,7 @@ namespace fheroes2 uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); // offsetting provides better visibility - float scale = ( outsideColor - insideColor - offset ) / static_cast( center_y ); + float scale = ( outsideColor - insideColor ) / static_cast( center_y ); // top Half for ( uint8_t neg_y = 0; neg_y <= center_y; neg_y++ ) { @@ -3162,8 +3162,11 @@ namespace fheroes2 } for ( uint8_t i = 0; i < borderWidth; i++ ) { - fheroes2::Sprite cnt = CreateContour( image, 0 ); + fheroes2::Sprite cnt = CreateContour( image, borderColor ); Blit( cnt, image ); } + + fheroes2::Sprite cnt = CreateContour( image, 0 ); + Blit( cnt, image ); } } diff --git a/src/engine/image.h b/src/engine/image.h index 7ccabb81522..114737b2c96 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -319,5 +319,5 @@ namespace fheroes2 void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners ); - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t offset, uint8_t borderWidth ); + void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t borderWidth, uint8_t borderColor ); } From fc6bfc506e5e376b588adfce7fdf4797f24c0dd2 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Mon, 15 Jan 2024 05:39:09 +0330 Subject: [PATCH 11/35] fixing positioning and Colors to match Reqired Colors --- src/fheroes2/agg/agg_image.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 7fae234df3f..62e12f748e4 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2502,9 +2502,9 @@ namespace fheroes2 Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 3, in.height() + 2 ); out.reset(); - Copy( in, 0, 0, out, 1, 1, in.width(), in.height() ); + Copy( in, 0, 0, out, 1, 2, in.width(), in.height() ); out.setPosition( in.x() - 1, in.y() - 1 ); - ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 1 ); + ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 4, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 ); fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } return true; @@ -2518,9 +2518,9 @@ namespace fheroes2 Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 3, in.height() + 2 ); out.reset(); - Copy( in, 0, 0, out, 1, 1, in.width(), in.height() ); + Copy( in, 0, 0, out, 1, 2, in.width(), in.height() ); out.setPosition( in.x() - 1, in.y() - 1 ); - ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END, PAL::ColorRanges::YELLOW_START, 4, 2 ); + ApplyVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 4, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 ); fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } return true; From f9838ed581da313973f58118ef6409c266dab31c Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Tue, 16 Jan 2024 00:44:41 +0330 Subject: [PATCH 12/35] Addressing Reviews --- src/engine/image.cpp | 11 ++++++----- src/engine/image.h | 2 +- src/fheroes2/agg/agg_image.cpp | 12 ++++++------ src/fheroes2/gui/ui_font.cpp | 2 ++ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 34c6a8e5021..0bbeb06bb79 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3106,16 +3106,17 @@ namespace fheroes2 } } } - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t borderWidth, uint8_t borderColor ) + + 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(); - uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); + const uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); // offsetting provides better visibility - float scale = ( outsideColor - insideColor ) / static_cast( center_y ); + const float scale = ( outsideColor - insideColor ) / static_cast( center_y ); // top Half for ( uint8_t neg_y = 0; neg_y <= center_y; neg_y++ ) { @@ -3166,7 +3167,7 @@ namespace fheroes2 Blit( cnt, image ); } - fheroes2::Sprite cnt = CreateContour( image, 0 ); - Blit( cnt, image ); + const fheroes2::Sprite contourBlack = CreateContour( image, 0 ); + Blit( contourBlack, image ); } } diff --git a/src/engine/image.h b/src/engine/image.h index 114737b2c96..50337116999 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -319,5 +319,5 @@ namespace fheroes2 void updateShadow( Image & image, const Point & shadowOffset, const uint8_t transformId, const bool connectCorners ); - void ApplyVerticalGradient( fheroes2::Image & image, uint8_t outsideColor, uint8_t insideColor, uint8_t borderWidth, uint8_t borderColor ); + void ApplyVerticalGradient( fheroes2::Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor ); } diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 62e12f748e4..74c0f10305d 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2500,10 +2500,10 @@ namespace fheroes2 for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { const Sprite & in = original[i]; Sprite & out = _icnVsSprite[id][i]; - out.resize( in.width() + 3, in.height() + 2 ); + out.resize( in.width() + 6, in.height() + 6 ); out.reset(); - Copy( in, 0, 0, out, 1, 2, in.width(), in.height() ); - out.setPosition( in.x() - 1, in.y() - 1 ); + 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 ); fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } @@ -2516,10 +2516,10 @@ namespace fheroes2 for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { const Sprite & in = original[i]; Sprite & out = _icnVsSprite[id][i]; - out.resize( in.width() + 3, in.height() + 2 ); + out.resize( in.width() + 6, in.height() + 6 ); out.reset(); - Copy( in, 0, 0, out, 1, 2, in.width(), in.height() ); - out.setPosition( in.x() - 1, in.y() - 1 ); + 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 ); fheroes2::updateShadow( out, { -1, 2 }, 2, false ); } diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index ec07d28c9da..5e9d07ee15c 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -5791,6 +5791,8 @@ 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(); } bool isAlphabetSupported( const SupportedLanguage language ) From d99b8071aa18f4e7f2f4d9c4c32dd91289bd383f Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Tue, 16 Jan 2024 01:41:11 +0330 Subject: [PATCH 13/35] removing static Contour from gradient Method Fix Header --- src/engine/image.cpp | 3 --- src/fheroes2/agg/agg_image.cpp | 12 ++++++++++-- src/fheroes2/gui/ui_font.cpp | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 0bbeb06bb79..56e9a0bca34 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3166,8 +3166,5 @@ namespace fheroes2 fheroes2::Sprite cnt = CreateContour( image, borderColor ); Blit( cnt, image ); } - - const fheroes2::Sprite contourBlack = CreateContour( image, 0 ); - Blit( contourBlack, image ); } } diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 74c0f10305d..58219e799ad 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2505,7 +2505,11 @@ namespace fheroes2 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 ); - fheroes2::updateShadow( out, { -1, 2 }, 2, false ); + + const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); + Blit( contourBlack, out ); + const fheroes2::Sprite contourGray = CreateContour( out, 62 ); + Blit( contourGray, out ); } return true; } @@ -2521,7 +2525,11 @@ namespace fheroes2 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 ); - fheroes2::updateShadow( out, { -1, 2 }, 2, false ); + + const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); + Blit( contourBlack, out ); + const fheroes2::Sprite contourGray = CreateContour( out, 62 ); + Blit( contourGray, out ); } return true; } diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index 5e9d07ee15c..a560f68f7fc 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -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 * From 1e9d3c249f7ca3ba5ed6c02bd8774d0b215eb516 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Thu, 18 Jan 2024 01:12:51 +0330 Subject: [PATCH 14/35] Adding Silver Gradient Font (Laget And Normal) --- src/engine/image.cpp | 52 +++++++++++++++++++--------------- src/fheroes2/agg/agg_image.cpp | 45 +++++++++++++++++++++++++++++ src/fheroes2/agg/icn.h | 2 ++ src/fheroes2/gui/ui_font.cpp | 2 ++ src/fheroes2/gui/ui_text.h | 1 + 5 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 56e9a0bca34..a534b85ce23 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3111,51 +3111,57 @@ namespace fheroes2 { const int32_t height = image.height(); const int32_t width = image.width(); + uint8_t * inData = image.image(); uint8_t * inTransform = image.transform(); + uint8_t * outData = image.image(); + const uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); - // offsetting provides better visibility const float scale = ( outsideColor - insideColor ) / static_cast( center_y ); // top Half - for ( uint8_t neg_y = 0; neg_y <= center_y; neg_y++ ) { - uint8_t neg_Val = static_cast( insideColor + abs( center_y - neg_y ) * scale ); - uint8_t * neg_rowStart = inData + static_cast( neg_y * width ); - uint8_t * neg_rowEnd = inData + static_cast( ( neg_y + 1 ) * width ); - uint8_t * neg_inTrans = inTransform + static_cast( neg_y * width ); - for ( ; neg_rowStart != neg_rowEnd; ++neg_rowStart, ++neg_inTrans ) { - if ( *neg_inTrans == 0 && *neg_rowStart < 20 ) { - *neg_rowStart = neg_Val; + for ( uint8_t top_half_y = 0; top_half_y <= center_y; top_half_y++ ) { + uint8_t val = static_cast( insideColor + abs( center_y - top_half_y ) * scale ); + uint8_t * th_inRowStart = inData + static_cast( top_half_y * width ); + uint8_t * th_outRowStart = outData + static_cast( top_half_y * width ); + + uint8_t * th_inRowEnd = inData + static_cast( ( top_half_y + 1 ) * width ); + uint8_t * th_inTrans = inTransform + static_cast( top_half_y * width ); + + for ( ; th_inRowStart != th_inRowEnd; ++th_inRowStart, ++th_inTrans, ++th_outRowStart ) { + if ( *th_inTrans == 0 && *th_inRowStart < 21 ) { + *th_outRowStart = val; } - else if ( *neg_rowStart < std::min( insideColor, outsideColor ) ) { - *neg_inTrans = 1; + else if ( *th_inRowStart < std::min( insideColor, outsideColor ) ) { + *th_inTrans = 1; } } } // bottom Half - for ( uint8_t pos_y = center_y; pos_y <= height; pos_y++ ) { - uint8_t val = static_cast( insideColor + abs( center_y - pos_y ) * scale ); + for ( uint8_t btm_half_y = center_y; btm_half_y <= height; btm_half_y++ ) { + uint8_t val = static_cast( insideColor + abs( center_y - btm_half_y ) * scale ); + uint8_t * bh_inRowStart = inData + static_cast( btm_half_y * width ); + uint8_t * bh_outRowStart = outData + static_cast( btm_half_y * width ); - uint8_t * rowStart = inData + static_cast( pos_y * width ); - uint8_t * rowEnd = inData + static_cast( ( pos_y + 1 ) * width ); - uint8_t * inTrans = inTransform + static_cast( pos_y * width ); + uint8_t * bh_inRowEnd = inData + static_cast( ( btm_half_y + 1 ) * width ); + uint8_t * bh_inTrans = inTransform + static_cast( btm_half_y * width ); - for ( ; rowStart != rowEnd; rowStart++, inTrans++ ) { - if ( *inTrans == 0 ) { - if ( *rowStart < 21 ) { - *rowStart = val; + for ( ; bh_inRowStart != bh_inRowEnd; bh_inRowStart++, bh_inTrans++ ) { + if ( *bh_inTrans == 0 ) { + if ( *bh_inRowStart < 21 ) { + *bh_outRowStart = val; } - else if ( *rowStart < std::min( insideColor, outsideColor ) ) { - *inTrans = 1; + else if ( *bh_inRowStart < std::min( insideColor, outsideColor ) ) { + *bh_inTrans = 1; } } } } // first line is broken for unknown reason - uint8_t * data = inData; + uint8_t * data = outData; uint8_t * transform = inTransform; const uint8_t * dataEnd = data + width; for ( ; data != dataEnd; ++data, ++transform ) { diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 58219e799ad..bd1b5daf3d6 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2533,6 +2533,47 @@ namespace fheroes2 } return true; } + case ICN::SILVER_GRADIENT_FONT: { + GetICN( ICN::FONT, 0 ); + const std::vector & 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 & 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 + 13, PAL::ColorRanges::GRAY_START, 1, PAL::ColorRanges::GRAY_END - 8 ); + + 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 ) { @@ -5040,6 +5081,8 @@ namespace fheroes2 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 ); @@ -5052,6 +5095,8 @@ namespace fheroes2 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 ); diff --git a/src/fheroes2/agg/icn.h b/src/fheroes2/agg/icn.h index dd21556ee58..96a495b8530 100644 --- a/src/fheroes2/agg/icn.h +++ b/src/fheroes2/agg/icn.h @@ -939,9 +939,11 @@ namespace ICN 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, diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index a560f68f7fc..0156d60bc27 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -5793,6 +5793,8 @@ namespace fheroes2 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 ) diff --git a/src/fheroes2/gui/ui_text.h b/src/fheroes2/gui/ui_text.h index 5ea6af75d04..0f7cf85a464 100644 --- a/src/fheroes2/gui/ui_text.h +++ b/src/fheroes2/gui/ui_text.h @@ -45,6 +45,7 @@ namespace fheroes2 GRAY, YELLOW, GOLDEN_GRADIENT, + SILVER_GRADIENT, }; struct FontType From be3fcb0a328f26d52b5e602afba2185abcfdfd9c Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sun, 14 Apr 2024 21:59:27 +0330 Subject: [PATCH 15/35] Changed Gradient Calculation function --- src/engine/image.cpp | 66 +++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 43 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index a534b85ce23..19510368e24 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3115,62 +3115,42 @@ namespace fheroes2 uint8_t * inData = image.image(); uint8_t * inTransform = image.transform(); - uint8_t * outData = image.image(); + fheroes2::Image outImage; + fheroes2::Copy( image, outImage ); + uint8_t * outData = outImage.image(); + uint8_t * outTransform = outImage.transform(); const uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); - const float scale = ( outsideColor - insideColor ) / static_cast( center_y ); + const float dColor = (float)( outsideColor - insideColor ); - // top Half - for ( uint8_t top_half_y = 0; top_half_y <= center_y; top_half_y++ ) { - uint8_t val = static_cast( insideColor + abs( center_y - top_half_y ) * scale ); - uint8_t * th_inRowStart = inData + static_cast( top_half_y * width ); - uint8_t * th_outRowStart = outData + static_cast( top_half_y * width ); + for ( uint8_t row = 0; row < height; row++ ) { + float heightScale = static_cast( abs( center_y - row ) ) / center_y; - uint8_t * th_inRowEnd = inData + static_cast( ( top_half_y + 1 ) * width ); - uint8_t * th_inTrans = inTransform + static_cast( top_half_y * width ); + uint8_t val = static_cast( abs( insideColor + ( heightScale * dColor ) ) ); + uint8_t * inRowStart = inData + static_cast( row * width ); + uint8_t * outRowStart = outData + static_cast( row * width ); - for ( ; th_inRowStart != th_inRowEnd; ++th_inRowStart, ++th_inTrans, ++th_outRowStart ) { - if ( *th_inTrans == 0 && *th_inRowStart < 21 ) { - *th_outRowStart = val; - } - else if ( *th_inRowStart < std::min( insideColor, outsideColor ) ) { - *th_inTrans = 1; - } - } - } + uint8_t * inRowEnd = inData + static_cast( ( row + 1 ) * width ); + uint8_t * inTrans = inTransform + static_cast( row * width ); + uint8_t * outTrans = outTransform + static_cast( row * width ); - // bottom Half - for ( uint8_t btm_half_y = center_y; btm_half_y <= height; btm_half_y++ ) { - uint8_t val = static_cast( insideColor + abs( center_y - btm_half_y ) * scale ); - uint8_t * bh_inRowStart = inData + static_cast( btm_half_y * width ); - uint8_t * bh_outRowStart = outData + static_cast( btm_half_y * width ); - - uint8_t * bh_inRowEnd = inData + static_cast( ( btm_half_y + 1 ) * width ); - uint8_t * bh_inTrans = inTransform + static_cast( btm_half_y * width ); - - for ( ; bh_inRowStart != bh_inRowEnd; bh_inRowStart++, bh_inTrans++ ) { - if ( *bh_inTrans == 0 ) { - if ( *bh_inRowStart < 21 ) { - *bh_outRowStart = val; + 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 if ( *bh_inRowStart < std::min( insideColor, outsideColor ) ) { - *bh_inTrans = 1; + else { + *outTrans = 1; } } } } - // first line is broken for unknown reason - uint8_t * data = outData; - uint8_t * transform = inTransform; - const uint8_t * dataEnd = data + width; - for ( ; data != dataEnd; ++data, ++transform ) { - *transform = 1; - } - for ( uint8_t i = 0; i < borderWidth; i++ ) { - fheroes2::Sprite cnt = CreateContour( image, borderColor ); - Blit( cnt, image ); + fheroes2::Sprite cnt = CreateContour( outImage, borderColor ); + Blit( cnt, outImage ); } + fheroes2::Copy( outImage, image ); } } From d75b0adeadb69f3cf25261f0c0f142bf285a662e Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sun, 14 Apr 2024 22:00:55 +0330 Subject: [PATCH 16/35] Fix Color Ranges --- src/fheroes2/agg/agg_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index bd1b5daf3d6..49c2d131dee 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2564,7 +2564,7 @@ namespace fheroes2 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 + 13, PAL::ColorRanges::GRAY_START, 1, PAL::ColorRanges::GRAY_END - 8 ); + 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 ); From 2dc02afefdd27340e36abcb856dd064b5160e82f Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sun, 14 Apr 2024 22:25:13 +0330 Subject: [PATCH 17/35] fix Style --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 19510368e24..322d62f02f1 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3140,7 +3140,7 @@ namespace fheroes2 if ( *inRowStart < 21 ) { *outRowStart = val; } - else { + else { *outTrans = 1; } } From 0f1934f1bbd6275d9cc9114e4f6883242a82b343 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sun, 14 Apr 2024 22:54:16 +0330 Subject: [PATCH 18/35] fix Warning --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 322d62f02f1..056e8933d54 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -3126,7 +3126,7 @@ namespace fheroes2 for ( uint8_t row = 0; row < height; row++ ) { float heightScale = static_cast( abs( center_y - row ) ) / center_y; - uint8_t val = static_cast( abs( insideColor + ( heightScale * dColor ) ) ); + uint8_t val = static_cast( abs( insideColor + (int)( heightScale * dColor ) ) ); uint8_t * inRowStart = inData + static_cast( row * width ); uint8_t * outRowStart = outData + static_cast( row * width ); From 2c74ed444d8973315f27477cd3fad8a4a425944c Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Fri, 19 Apr 2024 19:27:36 +0330 Subject: [PATCH 19/35] Fix Golden Gradient Color Rnages --- src/fheroes2/agg/agg_image.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 49c2d131dee..c573a2b72b2 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2504,7 +2504,8 @@ namespace fheroes2 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 ); + + ApplyVerticalGradient( 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 ); @@ -2524,7 +2525,7 @@ namespace fheroes2 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 ); + ApplyVerticalGradient( 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 ); From d63ee6f86eacbd36951a5192f5b890ccce596b9c Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 20 Apr 2024 15:53:31 +0330 Subject: [PATCH 20/35] Addressing Changes --- src/engine/image.cpp | 96 ++++++++++++++++++++++---------------------- src/engine/image.h | 4 +- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 056e8933d54..3f4041f0099 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1120,6 +1120,55 @@ namespace fheroes2 } } + void ApplyVerticalGradient( fheroes2::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(); + + fheroes2::Image outImage( image ); + + uint8_t * outData = outImage.image(); + uint8_t * outTransform = outImage.transform(); + + const uint8_t centerY = static_cast( 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( std::abs( centerY - row ) ) ) / centerY; + + const uint8_t val = static_cast( std::abs( insideColor + heightScale ) ); + const uint8_t * inRowStart = inData + static_cast( row ) * width; + uint8_t * outRowStart = outData + static_cast( row ) * width; + + const uint8_t * inRowEnd = inData + static_cast( row + 1 ) * width; + const uint8_t * inTrans = inTransform + static_cast( row ) * width; + uint8_t * outTrans = outTransform + static_cast( 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 ); + } + void Blit( const Image & in, Image & out, const bool flip /* = false */ ) { Blit( in, 0, 0, out, 0, 0, in.width(), in.height(), flip ); @@ -3106,51 +3155,4 @@ 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(); - - fheroes2::Image outImage; - fheroes2::Copy( image, outImage ); - uint8_t * outData = outImage.image(); - uint8_t * outTransform = outImage.transform(); - - const uint8_t center_y = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); - const float dColor = (float)( outsideColor - insideColor ); - - for ( uint8_t row = 0; row < height; row++ ) { - float heightScale = static_cast( abs( center_y - row ) ) / center_y; - - uint8_t val = static_cast( abs( insideColor + (int)( heightScale * dColor ) ) ); - uint8_t * inRowStart = inData + static_cast( row * width ); - uint8_t * outRowStart = outData + static_cast( row * width ); - - uint8_t * inRowEnd = inData + static_cast( ( row + 1 ) * width ); - uint8_t * inTrans = inTransform + static_cast( row * width ); - uint8_t * outTrans = outTransform + static_cast( 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 ); - } } diff --git a/src/engine/image.h b/src/engine/image.h index 50337116999..30709e74beb 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -227,6 +227,8 @@ namespace fheroes2 void ApplyTransform( Image & image, int32_t x, int32_t y, int32_t width, int32_t height, const uint8_t transformId ); + void ApplyVerticalGradient( 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 ); @@ -318,6 +320,4 @@ 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 ); } From a9304ba516f161a7ac3431b2bea561b6763fcb53 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 20 Apr 2024 18:30:02 +0330 Subject: [PATCH 21/35] Addressing Reviews --- src/engine/image.cpp | 26 +++++++++----------------- src/engine/image.h | 3 ++- src/fheroes2/agg/agg_image.cpp | 8 ++++---- 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 3f4041f0099..ebfc597b494 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1120,9 +1120,9 @@ namespace fheroes2 } } - void ApplyVerticalGradient( fheroes2::Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor ) + void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor ) { - assert( !image.singleLayer() ); + assert( !image.singleLayer() ); const int32_t height = image.height(); const int32_t width = image.width(); @@ -1130,11 +1130,6 @@ namespace fheroes2 uint8_t * inData = image.image(); uint8_t * inTransform = image.transform(); - fheroes2::Image outImage( image ); - - uint8_t * outData = outImage.image(); - uint8_t * outTransform = outImage.transform(); - const uint8_t centerY = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); const uint8_t dColor = outsideColor - insideColor; @@ -1142,31 +1137,28 @@ namespace fheroes2 const uint8_t heightScale = ( dColor * static_cast( std::abs( centerY - row ) ) ) / centerY; const uint8_t val = static_cast( std::abs( insideColor + heightScale ) ); - const uint8_t * inRowStart = inData + static_cast( row ) * width; - uint8_t * outRowStart = outData + static_cast( row ) * width; + uint8_t * inRowStart = inData + static_cast( row ) * width; const uint8_t * inRowEnd = inData + static_cast( row + 1 ) * width; - const uint8_t * inTrans = inTransform + static_cast( row ) * width; - uint8_t * outTrans = outTransform + static_cast( row ) * width; + uint8_t * inTrans = inTransform + static_cast( row ) * width; - for ( ; inRowStart != inRowEnd; ++inRowStart, ++inTrans, ++outRowStart, ++outTrans ) { + for ( ; inRowStart != inRowEnd; ++inRowStart, ++inTrans ) { if ( *inTrans == 0 ) { // 21 is the pixel limit of shadows in Base white Font if ( *inRowStart < 21 ) { - *outRowStart = val; + *inRowStart = val; } else { - *outTrans = 1; + *inTrans = 1; } } } } for ( uint8_t i = 0; i < borderWidth; i++ ) { - fheroes2::Sprite cnt = CreateContour( outImage, borderColor ); - Blit( cnt, outImage ); + fheroes2::Sprite cnt = CreateContour( image, borderColor ); + Blit( cnt, image ); } - fheroes2::Copy( outImage, image ); } void Blit( const Image & in, Image & out, const bool flip /* = false */ ) diff --git a/src/engine/image.h b/src/engine/image.h index 30709e74beb..4be524b5dd3 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -227,7 +227,8 @@ namespace fheroes2 void ApplyTransform( Image & image, int32_t x, int32_t y, int32_t width, int32_t height, const uint8_t transformId ); - void ApplyVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor ); + 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 ); diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index c573a2b72b2..0b6d79a449c 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2505,7 +2505,7 @@ namespace fheroes2 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 + 3, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 ); + 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 ); @@ -2525,7 +2525,7 @@ namespace fheroes2 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 - 3, PAL::ColorRanges::YELLOW_START, 1, PAL::ColorRanges::BROWN_START + 18 ); + 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 ); @@ -2545,7 +2545,7 @@ namespace fheroes2 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 ); + 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 ); @@ -2565,7 +2565,7 @@ namespace fheroes2 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 ); + 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 ); From b8e23c3e406f4750b7a0a9306d0718c3a7908722 Mon Sep 17 00:00:00 2001 From: Mohammad Ali Gholami Date: Sat, 20 Apr 2024 18:33:38 +0330 Subject: [PATCH 22/35] fix style --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index ebfc597b494..1bb3311a197 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1122,7 +1122,7 @@ 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() ); + assert( !image.singleLayer() ); const int32_t height = image.height(); const int32_t width = image.width(); From 98ed4a345ea42918c8e0188ead9ec47ed6e11375 Mon Sep 17 00:00:00 2001 From: Oleg Derevenetz Date: Sun, 15 Sep 2024 21:31:18 +0300 Subject: [PATCH 23/35] Add const --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index d67617eb45c..fd65a03a4a3 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1175,7 +1175,7 @@ namespace fheroes2 } for ( uint8_t i = 0; i < borderWidth; i++ ) { - fheroes2::Sprite cnt = CreateContour( image, borderColor ); + const fheroes2::Sprite cnt = CreateContour( image, borderColor ); Blit( cnt, image ); } } From 1c4a07638cf81a0cbeb7dbb9697767edb0488a52 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 22:46:21 +0800 Subject: [PATCH 24/35] Keep the same increment style --- src/engine/image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index fd65a03a4a3..5e38c0e369b 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1152,7 +1152,7 @@ namespace fheroes2 const uint8_t centerY = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); const uint8_t dColor = outsideColor - insideColor; - for ( uint8_t row = 0; row < height; row++ ) { + for ( uint8_t row = 0; row < height; ++row ) { const uint8_t heightScale = ( dColor * static_cast( std::abs( centerY - row ) ) ) / centerY; const uint8_t val = static_cast( std::abs( insideColor + heightScale ) ); From 9ae01cd29460651abb14944ce1c66712479cb464 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 23:14:09 +0800 Subject: [PATCH 25/35] Add proper checks --- src/engine/image.cpp | 11 ++++++----- src/engine/image.h | 3 +-- src/fheroes2/agg/agg_image.cpp | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 5e38c0e369b..1a195245de1 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1139,10 +1139,14 @@ namespace fheroes2 } } - void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderWidth, const uint8_t borderColor ) + void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderColor ) { assert( !image.singleLayer() ); + if ( image.width() < 3 || image.height() < 3 ) { + return; + } + const int32_t height = image.height(); const int32_t width = image.width(); @@ -1174,10 +1178,7 @@ namespace fheroes2 } } - for ( uint8_t i = 0; i < borderWidth; i++ ) { - const fheroes2::Sprite cnt = CreateContour( image, borderColor ); - Blit( cnt, image ); - } + Blit( CreateContour( image, borderColor ), image ); } void Blit( const Image & in, Image & out, const bool flip /* = false */ ) diff --git a/src/engine/image.h b/src/engine/image.h index 4e97fccf73b..632a939ff2c 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -228,8 +228,7 @@ 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 ); + void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderColor ); // draw one image onto another void Blit( const Image & in, Image & out, const bool flip = false ); diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 84df4ad6005..9c544c79288 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2564,7 +2564,7 @@ namespace 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 ); + applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::BROWN_START + 18 ); const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); Blit( contourBlack, out ); @@ -2584,7 +2584,7 @@ namespace 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 ); + applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::BROWN_START + 18 ); const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); Blit( contourBlack, out ); @@ -2604,7 +2604,7 @@ namespace 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 ); + applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_END - 7 ); const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); Blit( contourBlack, out ); @@ -2624,7 +2624,7 @@ namespace 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 ); + applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_END - 7 ); const fheroes2::Sprite contourBlack = CreateContour( out, 0 ); Blit( contourBlack, out ); From cb77d7d765b0af3ff36dbffd282e73babe4f053e Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 23:16:20 +0800 Subject: [PATCH 26/35] Remove redundant code --- src/fheroes2/agg/agg_image.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 9c544c79288..36e5e6b867a 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2566,10 +2566,8 @@ namespace applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::YELLOW_START, 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 ); + Blit( CreateContour( out, 0 ), out ); + Blit( CreateContour( out, 62 ), out ); } return true; } @@ -2586,10 +2584,8 @@ namespace out.setPosition( in.x() - 2, in.y() - 2 ); applyFontVerticalGradientAndContour( out, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::YELLOW_START, 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 ); + Blit( CreateContour( out, 0 ), out ); + Blit( CreateContour( out, 62 ), out ); } return true; } @@ -2606,10 +2602,8 @@ namespace out.setPosition( in.x() - 2, in.y() - 2 ); applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_START, 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 ); + Blit( CreateContour( out, 0 ), out ); + Blit( CreateContour( out, 0 ), out ); } return true; } @@ -2626,10 +2620,8 @@ namespace out.setPosition( in.x() - 2, in.y() - 2 ); applyFontVerticalGradientAndContour( out, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_START, 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 ); + Blit( CreateContour( out, 0 ), out ); + Blit( CreateContour( out, 0 ), out ); } return true; } From 92765e1ec5cfb03b3dd55e2a8a52b38b1a0f1ef6 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 23:20:42 +0800 Subject: [PATCH 27/35] Code style cleanup --- src/fheroes2/agg/agg_image.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 36e5e6b867a..06d3d72426d 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2555,8 +2555,10 @@ namespace case ICN::GOLDEN_GRADIENT_FONT: { fheroes2::AGG::GetICN( ICN::FONT, 0 ); const std::vector & original = _icnVsSprite[ICN::FONT]; + _icnVsSprite[id].resize( original.size() ); - for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { + + for ( size_t i = 0; i < original.size(); ++i ) { const fheroes2::Sprite & in = original[i]; fheroes2::Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 6, in.height() + 6 ); @@ -2574,8 +2576,10 @@ namespace case ICN::GOLDEN_GRADIENT_LARGE_FONT: { fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 ); const std::vector & original = _icnVsSprite[ICN::WHITE_LARGE_FONT]; + _icnVsSprite[id].resize( original.size() ); - for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { + + for ( size_t i = 0; i < original.size(); ++i ) { const fheroes2::Sprite & in = original[i]; fheroes2::Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 6, in.height() + 6 ); @@ -2592,8 +2596,10 @@ namespace case ICN::SILVER_GRADIENT_FONT: { fheroes2::AGG::GetICN( ICN::FONT, 0 ); const std::vector & original = _icnVsSprite[ICN::FONT]; + _icnVsSprite[id].resize( original.size() ); - for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { + + for ( size_t i = 0; i < original.size(); ++i ) { const fheroes2::Sprite & in = original[i]; fheroes2::Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 6, in.height() + 6 ); @@ -2610,8 +2616,10 @@ namespace case ICN::SILVER_GRADIENT_LARGE_FONT: { fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 ); const std::vector & original = _icnVsSprite[ICN::WHITE_LARGE_FONT]; + _icnVsSprite[id].resize( original.size() ); - for ( size_t i = 0; i < _icnVsSprite[id].size(); ++i ) { + + for ( size_t i = 0; i < original.size(); ++i ) { const fheroes2::Sprite & in = original[i]; fheroes2::Sprite & out = _icnVsSprite[id][i]; out.resize( in.width() + 6, in.height() + 6 ); @@ -2625,7 +2633,6 @@ namespace } return true; } - case ICN::SPELLS: LoadOriginalICN( id ); if ( _icnVsSprite[id].size() != 60 ) { From f99e3a874c9c2748dcd6c954b6647a376a4fe63a Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 23:28:18 +0800 Subject: [PATCH 28/35] Simplify the code --- src/engine/image.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 1a195245de1..f40318f4b93 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1143,7 +1143,7 @@ namespace fheroes2 { assert( !image.singleLayer() ); - if ( image.width() < 3 || image.height() < 3 ) { + if ( image.width() < 2 || image.height() < 2 ) { return; } @@ -1153,23 +1153,22 @@ namespace fheroes2 uint8_t * inData = image.image(); uint8_t * inTransform = image.transform(); - const uint8_t centerY = static_cast( std::max( 1, ( height / 2 ) - height % 2 ) ); + const int32_t centerY = 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( std::abs( centerY - row ) ) ) / centerY; + for ( int32_t row = 0; row < height; ++row ) { + const int32_t heightScale = ( dColor * std::abs( centerY - row ) ) / centerY; + const uint8_t color = static_cast( std::abs( insideColor + heightScale ) ); - const uint8_t val = static_cast( std::abs( insideColor + heightScale ) ); - uint8_t * inRowStart = inData + static_cast( row ) * width; - - const uint8_t * inRowEnd = inData + static_cast( row + 1 ) * width; - uint8_t * inTrans = inTransform + static_cast( row ) * width; + uint8_t * inRowStart = inData + row * width; + const uint8_t * inRowEnd = inRowStart + width; + uint8_t * inTrans = inTransform + 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; + *inRowStart = color; } else { *inTrans = 1; From b20acff465ada00285f36a6f2458297476931c26 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Wed, 18 Sep 2024 23:33:50 +0800 Subject: [PATCH 29/35] Simplify the logic more to avoid static_cast usage --- src/engine/image.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index f40318f4b93..96b032457dd 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1150,28 +1150,28 @@ namespace fheroes2 const int32_t height = image.height(); const int32_t width = image.width(); - uint8_t * inData = image.image(); - uint8_t * inTransform = image.transform(); + uint8_t * imageY = image.image(); + uint8_t * transformY = image.transform(); const int32_t centerY = std::max( 1, ( height / 2 ) - height % 2 ); const uint8_t dColor = outsideColor - insideColor; - for ( int32_t row = 0; row < height; ++row ) { + for ( int32_t row = 0; row < height; ++row, imageY += width, transformY += width ) { const int32_t heightScale = ( dColor * std::abs( centerY - row ) ) / centerY; const uint8_t color = static_cast( std::abs( insideColor + heightScale ) ); - uint8_t * inRowStart = inData + row * width; - const uint8_t * inRowEnd = inRowStart + width; - uint8_t * inTrans = inTransform + row * width; + uint8_t * imageX = imageY; + const uint8_t * imageXEnd = imageX + width; + uint8_t * transformX = transformY; - for ( ; inRowStart != inRowEnd; ++inRowStart, ++inTrans ) { - if ( *inTrans == 0 ) { + for ( ; imageX != imageXEnd; ++imageX, ++transformX ) { + if ( *transformX == 0 ) { // 21 is the pixel limit of shadows in Base white Font - if ( *inRowStart < 21 ) { - *inRowStart = color; + if ( *imageX < 21 ) { + *imageX = color; } else { - *inTrans = 1; + *transformX = 1; } } } From 2bc1171bea7f4bf09742ccefb73f42f6382309d7 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Thu, 19 Sep 2024 21:28:26 +0800 Subject: [PATCH 30/35] Separate logic --- src/engine/image.cpp | 4 +--- src/engine/image.h | 2 +- src/fheroes2/agg/agg_image.cpp | 15 +++++++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 96b032457dd..7a81302a06a 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1139,7 +1139,7 @@ namespace fheroes2 } } - void applyFontVerticalGradientAndContour( Image & image, const uint8_t outsideColor, const uint8_t insideColor, const uint8_t borderColor ) + void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ) { assert( !image.singleLayer() ); @@ -1176,8 +1176,6 @@ namespace fheroes2 } } } - - Blit( CreateContour( image, borderColor ), image ); } void Blit( const Image & in, Image & out, const bool flip /* = false */ ) diff --git a/src/engine/image.h b/src/engine/image.h index 632a939ff2c..8167cedc799 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -228,7 +228,7 @@ 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 borderColor ); + void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ); // draw one image onto another void Blit( const Image & in, Image & out, const bool flip = false ); diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 06d3d72426d..fa688f331e6 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2566,8 +2566,9 @@ namespace 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, PAL::ColorRanges::BROWN_START + 18 ); + applyFontVerticalGradient( out, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::YELLOW_START ); + Blit( CreateContour( out, PAL::ColorRanges::BROWN_START + 18 ), out ); Blit( CreateContour( out, 0 ), out ); Blit( CreateContour( out, 62 ), out ); } @@ -2586,8 +2587,10 @@ namespace 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, PAL::ColorRanges::BROWN_START + 18 ); + applyFontVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::YELLOW_START ); + + Blit( CreateContour( out, PAL::ColorRanges::BROWN_START + 18 ), out ); Blit( CreateContour( out, 0 ), out ); Blit( CreateContour( out, 62 ), out ); } @@ -2606,8 +2609,10 @@ namespace 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, PAL::ColorRanges::GRAY_END - 7 ); + applyFontVerticalGradient( out, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_START ); + + Blit( CreateContour( out, PAL::ColorRanges::GRAY_END - 7 ), out ); Blit( CreateContour( out, 0 ), out ); Blit( CreateContour( out, 0 ), out ); } @@ -2626,8 +2631,10 @@ namespace 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, PAL::ColorRanges::GRAY_END - 7 ); + applyFontVerticalGradient( out, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_START ); + + Blit( CreateContour( out, PAL::ColorRanges::GRAY_END - 7 ), out ); Blit( CreateContour( out, 0 ), out ); Blit( CreateContour( out, 0 ), out ); } From 7975ca2c19a054acc8fc6fcddb5b0d580a2ddf7a Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 21 Sep 2024 10:09:41 +0800 Subject: [PATCH 31/35] Move the function to the corresponding place --- src/engine/image.cpp | 39 ------------------------------------ src/engine/image.h | 2 -- src/fheroes2/gui/ui_font.cpp | 39 ++++++++++++++++++++++++++++++++++++ src/fheroes2/gui/ui_font.h | 3 +++ 4 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/engine/image.cpp b/src/engine/image.cpp index 7a81302a06a..8ff20ff42d8 100644 --- a/src/engine/image.cpp +++ b/src/engine/image.cpp @@ -1139,45 +1139,6 @@ namespace fheroes2 } } - void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ) - { - assert( !image.singleLayer() ); - - if ( image.width() < 2 || image.height() < 2 ) { - return; - } - - const int32_t height = image.height(); - const int32_t width = image.width(); - - uint8_t * imageY = image.image(); - uint8_t * transformY = image.transform(); - - const int32_t centerY = std::max( 1, ( height / 2 ) - height % 2 ); - const uint8_t dColor = outsideColor - insideColor; - - for ( int32_t row = 0; row < height; ++row, imageY += width, transformY += width ) { - const int32_t heightScale = ( dColor * std::abs( centerY - row ) ) / centerY; - const uint8_t color = static_cast( std::abs( insideColor + heightScale ) ); - - uint8_t * imageX = imageY; - const uint8_t * imageXEnd = imageX + width; - uint8_t * transformX = transformY; - - for ( ; imageX != imageXEnd; ++imageX, ++transformX ) { - if ( *transformX == 0 ) { - // 21 is the pixel limit of shadows in Base white Font - if ( *imageX < 21 ) { - *imageX = color; - } - else { - *transformX = 1; - } - } - } - } - } - void Blit( const Image & in, Image & out, const bool flip /* = false */ ) { Blit( in, 0, 0, out, 0, 0, in.width(), in.height(), flip ); diff --git a/src/engine/image.h b/src/engine/image.h index 8167cedc799..d626cdd7789 100644 --- a/src/engine/image.h +++ b/src/engine/image.h @@ -228,8 +228,6 @@ namespace fheroes2 void ApplyTransform( Image & image, int32_t x, int32_t y, int32_t width, int32_t height, const uint8_t transformId ); - void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ); - // 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 ); diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index 07494b84089..669a2cb044e 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -6007,4 +6007,43 @@ namespace fheroes2 icnVsSprite[75].setPosition( icnVsSprite[75].x(), icnVsSprite[75].y() ); updateSmallFontLetterShadow( icnVsSprite[75] ); } + + void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ) + { + assert( !image.singleLayer() ); + + if ( image.width() < 2 || image.height() < 2 ) { + return; + } + + const int32_t height = image.height(); + const int32_t width = image.width(); + + uint8_t * imageY = image.image(); + uint8_t * transformY = image.transform(); + + const int32_t centerY = std::max( 1, ( height / 2 ) - height % 2 ); + const uint8_t dColor = outsideColor - insideColor; + + for ( int32_t row = 0; row < height; ++row, imageY += width, transformY += width ) { + const int32_t heightScale = ( dColor * std::abs( centerY - row ) ) / centerY; + const uint8_t color = static_cast( std::abs( insideColor + heightScale ) ); + + uint8_t * imageX = imageY; + const uint8_t * imageXEnd = imageX + width; + uint8_t * transformX = transformY; + + for ( ; imageX != imageXEnd; ++imageX, ++transformX ) { + if ( *transformX == 0 ) { + // 21 is the pixel limit of shadows in Base white Font + if ( *imageX < 21 ) { + *imageX = color; + } + else { + *transformX = 1; + } + } + } + } + } } diff --git a/src/fheroes2/gui/ui_font.h b/src/fheroes2/gui/ui_font.h index 34581a583e1..dfedbdfda5d 100644 --- a/src/fheroes2/gui/ui_font.h +++ b/src/fheroes2/gui/ui_font.h @@ -25,6 +25,7 @@ namespace fheroes2 { + class Image; class Sprite; enum class SupportedLanguage : uint8_t; @@ -41,4 +42,6 @@ namespace fheroes2 void modifyBaseNormalFont( std::vector & icnVsSprite ); void modifyBaseSmallFont( std::vector & icnVsSprite ); + + void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ); } From deadc2455f540be376d0eb46fcc99a8cbca87ac5 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 21 Sep 2024 10:43:17 +0800 Subject: [PATCH 32/35] Reduce code duplication --- src/fheroes2/agg/agg_image.cpp | 118 ++++++++++----------------------- 1 file changed, 34 insertions(+), 84 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index fa688f331e6..4cca0ec472c 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2419,6 +2419,32 @@ namespace generateDefaultImages( id ); } + void generateGradientFont( const int fontId, const int originalFontId, const uint8_t gradientInnerColor, const uint8_t gradientOuterColor, + const uint8_t contourInnerColor, const uint8_t contourOuterColor ) + { + assert( fontId != originalFontId ); + + fheroes2::AGG::GetICN( originalFontId, 0 ); + const std::vector & original = _icnVsSprite[originalFontId]; + + _icnVsSprite[fontId].resize( original.size() ); + + for ( size_t i = 0; i < original.size(); ++i ) { + const fheroes2::Sprite & in = original[i]; + fheroes2::Sprite & out = _icnVsSprite[fontId][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 ); + + applyFontVerticalGradient( out, gradientOuterColor, gradientInnerColor ); + + Blit( CreateContour( out, contourInnerColor ), out ); + Blit( CreateContour( out, 0 ), out ); + Blit( CreateContour( out, contourOuterColor ), out ); + } + } + // This function must return true is resources have been modified, false otherwise. bool LoadModifiedICN( const int id ) { @@ -2552,94 +2578,18 @@ 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 & original = _icnVsSprite[ICN::FONT]; - - _icnVsSprite[id].resize( original.size() ); - - for ( size_t i = 0; i < original.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 ); - - applyFontVerticalGradient( out, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::YELLOW_START ); - - Blit( CreateContour( out, PAL::ColorRanges::BROWN_START + 18 ), out ); - Blit( CreateContour( out, 0 ), out ); - Blit( CreateContour( out, 62 ), out ); - } + case ICN::GOLDEN_GRADIENT_FONT: + generateGradientFont( id, ICN::FONT, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::BROWN_START + 18, 62 ); return true; - } - case ICN::GOLDEN_GRADIENT_LARGE_FONT: { - fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 ); - const std::vector & original = _icnVsSprite[ICN::WHITE_LARGE_FONT]; - - _icnVsSprite[id].resize( original.size() ); - - for ( size_t i = 0; i < original.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 ); - - applyFontVerticalGradient( out, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::YELLOW_START ); - - Blit( CreateContour( out, PAL::ColorRanges::BROWN_START + 18 ), out ); - Blit( CreateContour( out, 0 ), out ); - Blit( CreateContour( out, 62 ), out ); - } + case ICN::GOLDEN_GRADIENT_LARGE_FONT: + generateGradientFont( id, ICN::WHITE_LARGE_FONT, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::BROWN_START + 18, 62 ); return true; - } - case ICN::SILVER_GRADIENT_FONT: { - fheroes2::AGG::GetICN( ICN::FONT, 0 ); - const std::vector & original = _icnVsSprite[ICN::FONT]; - - _icnVsSprite[id].resize( original.size() ); - - for ( size_t i = 0; i < original.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 ); - - applyFontVerticalGradient( out, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_START ); - - Blit( CreateContour( out, PAL::ColorRanges::GRAY_END - 7 ), out ); - Blit( CreateContour( out, 0 ), out ); - Blit( CreateContour( out, 0 ), out ); - } + case ICN::SILVER_GRADIENT_FONT: + generateGradientFont( id, ICN::FONT, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_END - 7, 0 ); return true; - } - case ICN::SILVER_GRADIENT_LARGE_FONT: { - fheroes2::AGG::GetICN( ICN::WHITE_LARGE_FONT, 0 ); - const std::vector & original = _icnVsSprite[ICN::WHITE_LARGE_FONT]; - - _icnVsSprite[id].resize( original.size() ); - - for ( size_t i = 0; i < original.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 ); - - applyFontVerticalGradient( out, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_START ); - - Blit( CreateContour( out, PAL::ColorRanges::GRAY_END - 7 ), out ); - Blit( CreateContour( out, 0 ), out ); - Blit( CreateContour( out, 0 ), out ); - } + case ICN::SILVER_GRADIENT_LARGE_FONT: + generateGradientFont( id, ICN::WHITE_LARGE_FONT, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_END - 7, 0 ); return true; - } case ICN::SPELLS: LoadOriginalICN( id ); if ( _icnVsSprite[id].size() != 60 ) { From 77aef9f714e4e62223519958c3f5ecad47c67cad Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 21 Sep 2024 10:44:37 +0800 Subject: [PATCH 33/35] Swap input arguments to have logical order --- src/fheroes2/agg/agg_image.cpp | 2 +- src/fheroes2/gui/ui_font.cpp | 2 +- src/fheroes2/gui/ui_font.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index 4cca0ec472c..f069a7c6871 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2437,7 +2437,7 @@ namespace Copy( in, 0, 0, out, 3, 3, in.width(), in.height() ); out.setPosition( in.x() - 2, in.y() - 2 ); - applyFontVerticalGradient( out, gradientOuterColor, gradientInnerColor ); + applyFontVerticalGradient( out, gradientInnerColor, gradientOuterColor ); Blit( CreateContour( out, contourInnerColor ), out ); Blit( CreateContour( out, 0 ), out ); diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index 669a2cb044e..3035db56e99 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -6008,7 +6008,7 @@ namespace fheroes2 updateSmallFontLetterShadow( icnVsSprite[75] ); } - void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ) + void applyFontVerticalGradient( Image & image, const uint8_t insideColor, const uint8_t outsideColor ) { assert( !image.singleLayer() ); diff --git a/src/fheroes2/gui/ui_font.h b/src/fheroes2/gui/ui_font.h index dfedbdfda5d..5461b79e299 100644 --- a/src/fheroes2/gui/ui_font.h +++ b/src/fheroes2/gui/ui_font.h @@ -43,5 +43,5 @@ namespace fheroes2 void modifyBaseSmallFont( std::vector & icnVsSprite ); - void applyFontVerticalGradient( Image & image, const uint8_t outsideColor, const uint8_t insideColor ); + void applyFontVerticalGradient( Image & image, const uint8_t insideColor, const uint8_t outsideColor ); } From c5e833b6cc90aca5cb69bd0fcbfc32c4107567c2 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 21 Sep 2024 10:53:01 +0800 Subject: [PATCH 34/35] No use to have ranges if we still apply offsets to values --- src/engine/pal.h | 22 ---------------------- src/fheroes2/agg/agg_image.cpp | 8 ++++---- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/engine/pal.h b/src/engine/pal.h index 2eb4869eb0d..8187b650393 100644 --- a/src/engine/pal.h +++ b/src/engine/pal.h @@ -43,28 +43,6 @@ 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 GetCyclingPalette( const uint32_t stepId ); const std::vector & GetPalette( const PaletteType type ); std::vector CombinePalettes( const std::vector & first, const std::vector & second ); diff --git a/src/fheroes2/agg/agg_image.cpp b/src/fheroes2/agg/agg_image.cpp index f069a7c6871..93ce41d0ea0 100644 --- a/src/fheroes2/agg/agg_image.cpp +++ b/src/fheroes2/agg/agg_image.cpp @@ -2579,16 +2579,16 @@ namespace CopyICNWithPalette( id, ICN::SMALFONT, PAL::PaletteType::GRAY_FONT ); return true; case ICN::GOLDEN_GRADIENT_FONT: - generateGradientFont( id, ICN::FONT, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::YELLOW_END + 3, PAL::ColorRanges::BROWN_START + 18, 62 ); + generateGradientFont( id, ICN::FONT, 108, 133, 55, 62 ); return true; case ICN::GOLDEN_GRADIENT_LARGE_FONT: - generateGradientFont( id, ICN::WHITE_LARGE_FONT, PAL::ColorRanges::YELLOW_START, PAL::ColorRanges::YELLOW_END - 3, PAL::ColorRanges::BROWN_START + 18, 62 ); + generateGradientFont( id, ICN::WHITE_LARGE_FONT, 108, 127, 55, 62 ); return true; case ICN::SILVER_GRADIENT_FONT: - generateGradientFont( id, ICN::FONT, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_END - 5, PAL::ColorRanges::GRAY_END - 7, 0 ); + generateGradientFont( id, ICN::FONT, 10, 31, 29, 0 ); return true; case ICN::SILVER_GRADIENT_LARGE_FONT: - generateGradientFont( id, ICN::WHITE_LARGE_FONT, PAL::ColorRanges::GRAY_START, PAL::ColorRanges::GRAY_START + 16, PAL::ColorRanges::GRAY_END - 7, 0 ); + generateGradientFont( id, ICN::WHITE_LARGE_FONT, 10, 26, 29, 0 ); return true; case ICN::SPELLS: LoadOriginalICN( id ); From b6a1427b0c289c33f75d9031f9bacf92da16e757 Mon Sep 17 00:00:00 2001 From: Ihar Hubchyk Date: Sat, 21 Sep 2024 11:45:03 +0800 Subject: [PATCH 35/35] Make IWYU happy --- src/fheroes2/gui/ui_font.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fheroes2/gui/ui_font.cpp b/src/fheroes2/gui/ui_font.cpp index 3035db56e99..4854756181b 100644 --- a/src/fheroes2/gui/ui_font.cpp +++ b/src/fheroes2/gui/ui_font.cpp @@ -20,9 +20,11 @@ #include "ui_font.h" +#include #include #include #include +#include #include #include "game_language.h"