mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 11:48:13 +00:00

This implements support for painting linear-gradients in a spec correct way :^). Right now it supports: - Multi-stop gradients - Color stop fixups - Using pre-multiplied alpha mixing when required - Painting gradients at arbitrary angles It still needs to support: - Transition hints - Double position color stops However what is implemented now seems to be accurate to other browsers, and covers the most common use cases.
34 lines
750 B
C++
34 lines
750 B
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/CSS/StyleValue.h>
|
|
#include <LibWeb/Forward.h>
|
|
#include <LibWeb/Painting/PaintContext.h>
|
|
|
|
namespace Web::Painting {
|
|
|
|
struct ColorStop {
|
|
Gfx::Color color;
|
|
float position = 0;
|
|
};
|
|
|
|
using ColorStopList = Vector<ColorStop, 4>;
|
|
|
|
struct LinearGradientData {
|
|
float gradient_angle;
|
|
ColorStopList color_stops;
|
|
};
|
|
|
|
LinearGradientData resolve_linear_gradient_data(Layout::Node const&, Gfx::FloatRect const&, CSS::LinearGradientStyleValue const&);
|
|
|
|
void paint_linear_gradient(PaintContext&, Gfx::IntRect const&, LinearGradientData const&);
|
|
|
|
}
|