1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 00:08:11 +00:00
serenity/Userland/Libraries/LibWeb/Painting/GradientPainting.h
MacDue a9ea0ee9af 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.
2022-12-20 11:03:18 +01:00

52 lines
1.5 KiB
C++

/*
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Span.h>
#include <AK/Vector.h>
#include <LibGfx/Color.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Painting/PaintContext.h>
namespace Web::Painting {
struct ColorStop {
Gfx::Color color;
float position = AK::NaN<float>;
Optional<float> transition_hint = {};
};
using ColorStopList = Vector<ColorStop, 4>;
struct ColorStopData {
ColorStopList list;
Optional<float> repeat_length;
};
struct LinearGradientData {
float gradient_angle;
ColorStopData color_stops;
};
struct ConicGradientData {
float start_angle;
ColorStopData color_stops;
};
struct RadialGradientData {
ColorStopData color_stops;
};
LinearGradientData resolve_linear_gradient_data(Layout::Node const&, CSSPixelSize, CSS::LinearGradientStyleValue const&);
ConicGradientData resolve_conic_gradient_data(Layout::Node const&, CSS::ConicGradientStyleValue const&);
RadialGradientData resolve_radial_gradient_data(Layout::Node const&, CSSPixelSize, CSS::RadialGradientStyleValue const&);
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, DevicePixelSize size);
}