mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 12:37:44 +00:00
LibWeb: Add GradientPainting for painting linear-gradients
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.
This commit is contained in:
parent
4246d04e5a
commit
469491906f
3 changed files with 234 additions and 1 deletions
34
Userland/Libraries/LibWeb/Painting/GradientPainting.h
Normal file
34
Userland/Libraries/LibWeb/Painting/GradientPainting.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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&);
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue