mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
LibWeb: Fix passing size/position to paint_radial_gradient()
This was wrong twice making it right... But let's fix that. The center was being passed as a DevicePixelPoint, but was in fact in CSS pixels, the size was passed as a Gfx::FloatSize but was in CSS pixels again. Then we were scaling from device pixels to CSS pixels when painting which does not need to be done if everything is passed which the correct scale factors already applied.
This commit is contained in:
parent
6c27f2c071
commit
a9ea0ee9af
3 changed files with 9 additions and 7 deletions
|
@ -2178,7 +2178,9 @@ bool RadialGradientStyleValue::equals(StyleValue const& other) const
|
|||
void RadialGradientStyleValue::paint(PaintContext& context, Gfx::IntRect const& dest_rect, CSS::ImageRendering) const
|
||||
{
|
||||
VERIFY(m_resolved.has_value());
|
||||
Painting::paint_radial_gradient(context, dest_rect.to_type<DevicePixels>(), m_resolved->data, m_resolved->center.to_rounded<DevicePixels>(), m_resolved->gradient_size);
|
||||
Painting::paint_radial_gradient(context, dest_rect.to_type<DevicePixels>(), m_resolved->data,
|
||||
context.rounded_device_point(m_resolved->center.to_type<CSSPixels>()),
|
||||
context.rounded_device_size(m_resolved->gradient_size.to_type<CSSPixels>()));
|
||||
}
|
||||
|
||||
DeprecatedString ConicGradientStyleValue::to_deprecated_string() const
|
||||
|
|
|
@ -304,18 +304,18 @@ void paint_conic_gradient(PaintContext& context, DevicePixelRect const& gradient
|
|||
});
|
||||
}
|
||||
|
||||
void paint_radial_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, RadialGradientData const& data, DevicePixelPoint center, Gfx::FloatSize size)
|
||||
void paint_radial_gradient(PaintContext& context, DevicePixelRect const& gradient_rect, RadialGradientData const& data, DevicePixelPoint center, DevicePixelSize size)
|
||||
{
|
||||
// A conservative guesstimate on how many colors we need to generate:
|
||||
auto max_dimension = max(gradient_rect.width(), gradient_rect.height());
|
||||
int max_visible_gradient = max(max_dimension.value() / 2, min(size.width(), max_dimension.value()));
|
||||
auto max_visible_gradient = max(max_dimension / 2, min(size.width(), max_dimension.value())).value();
|
||||
GradientLine gradient_line(max_visible_gradient, data.color_stops);
|
||||
auto center_point = Gfx::FloatPoint { center.to_type<int>() }.translated(0.5, 0.5);
|
||||
gradient_line.paint_into_rect(context.painter(), gradient_rect, [&](DevicePixels x, DevicePixels y) {
|
||||
// FIXME: See if there's a more efficient calculation we do there :^)
|
||||
auto point = context.scale_to_css_point({ x, y }).to_type<float>() - center_point;
|
||||
auto gradient_x = point.x() / size.width();
|
||||
auto gradient_y = point.y() / size.height();
|
||||
auto point = Gfx::FloatPoint(x.value(), y.value()) - center_point;
|
||||
auto gradient_x = point.x() / size.width().value();
|
||||
auto gradient_y = point.y() / size.height().value();
|
||||
return AK::sqrt(gradient_x * gradient_x + gradient_y * gradient_y) * max_visible_gradient;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -47,6 +47,6 @@ RadialGradientData resolve_radial_gradient_data(Layout::Node const&, CSSPixelSiz
|
|||
|
||||
void paint_linear_gradient(PaintContext&, DevicePixelRect const&, LinearGradientData const&);
|
||||
void paint_conic_gradient(PaintContext&, DevicePixelRect const&, ConicGradientData const&, DevicePixelPoint position);
|
||||
void paint_radial_gradient(PaintContext&, DevicePixelRect const&, RadialGradientData const&, DevicePixelPoint position, Gfx::FloatSize size);
|
||||
void paint_radial_gradient(PaintContext&, DevicePixelRect const&, RadialGradientData const&, DevicePixelPoint position, DevicePixelSize size);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue