1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:38:11 +00:00

LibWeb: Calculate to <corner> angles for linear-gradients

This also renames LinearGradientStyleValue::angle() to
LinearGradientStyleValue::angle_degrees() to make the unit more
obvious.
This commit is contained in:
MacDue 2022-07-17 19:45:38 +01:00 committed by Linus Groh
parent 9e06fe4b3f
commit 4246d04e5a
3 changed files with 15 additions and 6 deletions

View file

@ -1502,9 +1502,11 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
return true;
}
float LinearGradientStyleValue::angle(Gfx::FloatRect const& background_box) const
float LinearGradientStyleValue::angle_degrees(Gfx::FloatRect const& gradient_rect) const
{
(void)background_box;
auto corner_angle_degrees = [&] {
return static_cast<float>(atan2(gradient_rect.height(), gradient_rect.width())) * 180 / AK::Pi<float>;
};
return m_direction.visit(
[&](SideOrCorner side_or_corner) {
switch (side_or_corner) {
@ -1516,9 +1518,16 @@ float LinearGradientStyleValue::angle(Gfx::FloatRect const& background_box) cons
return 270.0f;
case SideOrCorner::Right:
return 90.0f;
case SideOrCorner::TopRight:
return corner_angle_degrees();
case SideOrCorner::BottomLeft:
return corner_angle_degrees() + 180.0f;
case SideOrCorner::TopLeft:
return -corner_angle_degrees();
case SideOrCorner::BottomRight:
return -(corner_angle_degrees() + 180.0f);
default:
// FIXME: Angle gradients towards corners
return 0.0f;
VERIFY_NOT_REACHED();
}
},
[&](Angle const& angle) {