mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +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:
parent
9e06fe4b3f
commit
4246d04e5a
3 changed files with 15 additions and 6 deletions
|
@ -1502,9 +1502,11 @@ bool LinearGradientStyleValue::equals(StyleValue const& other_) const
|
||||||
return true;
|
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(
|
return m_direction.visit(
|
||||||
[&](SideOrCorner side_or_corner) {
|
[&](SideOrCorner side_or_corner) {
|
||||||
switch (side_or_corner) {
|
switch (side_or_corner) {
|
||||||
|
@ -1516,9 +1518,16 @@ float LinearGradientStyleValue::angle(Gfx::FloatRect const& background_box) cons
|
||||||
return 270.0f;
|
return 270.0f;
|
||||||
case SideOrCorner::Right:
|
case SideOrCorner::Right:
|
||||||
return 90.0f;
|
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:
|
default:
|
||||||
// FIXME: Angle gradients towards corners
|
VERIFY_NOT_REACHED();
|
||||||
return 0.0f;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[&](Angle const& angle) {
|
[&](Angle const& angle) {
|
||||||
|
|
|
@ -936,7 +936,7 @@ public:
|
||||||
return m_color_stop_list;
|
return m_color_stop_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
float angle(Gfx::FloatRect const& background_box) const;
|
float angle_degrees(Gfx::FloatRect const& gradient_rect) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LinearGradientStyleValue(GradientDirection direction, Vector<ColorStopListElement> color_stop_list)
|
LinearGradientStyleValue(GradientDirection direction, Vector<ColorStopListElement> color_stop_list)
|
||||||
|
|
|
@ -27,7 +27,7 @@ static Optional<GfxGradient> linear_gradient_to_gfx_gradient(CSS::LinearGradient
|
||||||
if (linear_gradient.color_stop_list().size() != 2)
|
if (linear_gradient.color_stop_list().size() != 2)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto angle = round_to<int>(linear_gradient.angle(background_rect));
|
auto angle = round_to<int>(linear_gradient.angle_degrees(background_rect));
|
||||||
auto color_a = linear_gradient.color_stop_list()[0].color_stop.color;
|
auto color_a = linear_gradient.color_stop_list()[0].color_stop.color;
|
||||||
auto color_b = linear_gradient.color_stop_list()[1].color_stop.color;
|
auto color_b = linear_gradient.color_stop_list()[1].color_stop.color;
|
||||||
auto orientation = [&]() -> Optional<Gfx::Orientation> {
|
auto orientation = [&]() -> Optional<Gfx::Orientation> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue