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

Add vertical gradient fonts #8262

Merged
merged 38 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
913c526
Adding Color Ranges for all colors To PAL Namespace
MaMadDl Jan 11, 2024
770795c
- Definition for ApplyVerticalGradient
MaMadDl Jan 11, 2024
9bcbb57
- Adding GOLDEN_GRADIENT to font colors with it's respectable logic f…
MaMadDl Jan 11, 2024
07a1eeb
style fix
MaMadDl Jan 12, 2024
b1f5c3e
Fix Date on Copyright header
MaMadDl Jan 12, 2024
9ceac68
Addressing Reviews
MaMadDl Jan 13, 2024
3a2081f
Reformat function and fix to prevent overwritting of font details
MaMadDl Jan 13, 2024
78f0dc3
fix style
MaMadDl Jan 13, 2024
8e8d10c
- Fixing Names ApplyVerticalGradient declaration
MaMadDl Jan 15, 2024
2fd124c
Adding Color param for border
MaMadDl Jan 15, 2024
fc6bfc5
fixing positioning and Colors to match Reqired Colors
MaMadDl Jan 15, 2024
f9838ed
Addressing Reviews
MaMadDl Jan 15, 2024
d99b807
removing static Contour from gradient Method
MaMadDl Jan 15, 2024
1e9d3c2
Adding Silver Gradient Font (Laget And Normal)
MaMadDl Jan 17, 2024
be3fcb0
Changed Gradient Calculation function
MaMadDl Apr 14, 2024
d75b0ad
Fix Color Ranges
MaMadDl Apr 14, 2024
2dc02af
fix Style
MaMadDl Apr 14, 2024
0f1934f
fix Warning
MaMadDl Apr 14, 2024
2c74ed4
Fix Golden Gradient Color Rnages
MaMadDl Apr 19, 2024
d63ee6f
Addressing Changes
MaMadDl Apr 20, 2024
a9304ba
Addressing Reviews
MaMadDl Apr 20, 2024
b8e23c3
fix style
MaMadDl Apr 20, 2024
56f006e
Merge for PR #8262 into master.
MaMadDl Aug 26, 2024
bb0e60d
Merge branch master into gradientFont
oleg-derevenetz Sep 15, 2024
98ed4a3
Add const
oleg-derevenetz Sep 15, 2024
1c4a076
Keep the same increment style
ihhub Sep 18, 2024
92a20ec
Merge branch 'master' into pr/8262
ihhub Sep 18, 2024
9ae01cd
Add proper checks
ihhub Sep 18, 2024
cb77d7d
Remove redundant code
ihhub Sep 18, 2024
92765e1
Code style cleanup
ihhub Sep 18, 2024
f99e3a8
Simplify the code
ihhub Sep 18, 2024
b20acff
Simplify the logic more to avoid static_cast usage
ihhub Sep 18, 2024
2bc1171
Separate logic
ihhub Sep 19, 2024
7975ca2
Move the function to the corresponding place
ihhub Sep 21, 2024
deadc24
Reduce code duplication
ihhub Sep 21, 2024
77aef9f
Swap input arguments to have logical order
ihhub Sep 21, 2024
c5e833b
No use to have ranges if we still apply offsets to values
ihhub Sep 21, 2024
b6a1427
Make IWYU happy
ihhub Sep 21, 2024
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
51 changes: 51 additions & 0 deletions src/engine/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3106,4 +3106,55 @@ 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();
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved

uint8_t center_y = static_cast<uint8_t>( std::max( 1, ( height / 2 ) - height % 2 ) );
// offsetting provides better visibility
float scale = ( outsideColor - insideColor - offset ) / static_cast<float>( center_y );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
// bottom Half
for ( uint8_t pos_y = center_y; pos_y <= height; pos_y++ ) {
uint8_t val = static_cast<uint8_t>( insideColor + abs( center_y - pos_y ) * scale );
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 * rowStart = inData + static_cast<ptrdiff_t>( pos_y * width );
uint8_t * rowEnd = inData + static_cast<ptrdiff_t>( ( pos_y + 1 ) * width );
uint8_t * inTrans = inTransform + static_cast<ptrdiff_t>( 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<uint8_t>( insideColor + abs( center_y - neg_y ) * scale );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
uint8_t * neg_rowStart = inData + static_cast<ptrdiff_t>( neg_y * width );
uint8_t * neg_rowEnd = inData + static_cast<ptrdiff_t>( ( neg_y + 1 ) * width );
uint8_t * neg_inTrans = inTransform + static_cast<ptrdiff_t>( 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 );
MaMadDl marked this conversation as resolved.
Show resolved Hide resolved
Blit( cnt, image );
}
}
}
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, uint8_t darkColor, uint8_t brightColor, uint8_t offset, uint8_t borderWidth );
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
36 changes: 36 additions & 0 deletions src/fheroes2/agg/agg_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2493,6 +2493,38 @@ 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() + 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;
}
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() + 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;
}
case ICN::SPELLS:
LoadOriginalICN( id );
if ( _icnVsSprite[id].size() != 60 ) {
Expand Down Expand Up @@ -4998,6 +5030,8 @@ 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 );
default:
// Did you add a new font color? Add the corresponding logic for it!
assert( 0 );
Expand All @@ -5008,6 +5042,8 @@ 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 );
default:
// Did you add a new font color? Add the corresponding logic for it!
assert( 0 );
Expand Down
3 changes: 3 additions & 0 deletions src/fheroes2/agg/icn.h
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,10 @@ namespace ICN
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,

Expand Down
5 changes: 3 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,8 @@ namespace fheroes2
{
WHITE,
GRAY,
YELLOW
YELLOW,
GOLDEN_GRADIENT,
};

struct FontType
Expand Down