1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-10-31 18:02:44 +00:00
serenity/Userland/Libraries/LibWeb/Painting/BorderPainting.h
MacDue c9b363de56 LibWeb: Fix regression in painting the 'caret' icon on GitHub
This commit reimplements the (normally) 45 degree (depends on
the widths) connection between to adjacent borders. Which is
needed to paint the 'caret' icon seen in a few buttons on GitHub.

The issue of overlapping pixels while painting this has also
been solved for the 45 degree case (the the most likely case,
the other cases only occur of mixed-with borders).
2022-06-14 14:13:18 +01:00

62 lines
1.7 KiB
C++

/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/AntiAliasingPainter.h>
#include <LibGfx/Forward.h>
#include <LibWeb/CSS/ComputedValues.h>
namespace Web::Painting {
struct BorderRadiusData {
float horizontal_radius { 0 };
float vertical_radius { 0 };
Gfx::AntiAliasingPainter::CornerRadius as_corner() const
{
return Gfx::AntiAliasingPainter::CornerRadius {
static_cast<int>(horizontal_radius),
static_cast<int>(vertical_radius)
};
};
inline operator bool() const
{
return static_cast<int>(horizontal_radius) > 0 && static_cast<int>(vertical_radius) > 0;
}
};
struct BorderRadiiData {
BorderRadiusData top_left;
BorderRadiusData top_right;
BorderRadiusData bottom_right;
BorderRadiusData bottom_left;
inline bool has_any_radius() const
{
return top_left || top_right || bottom_right || bottom_left;
}
};
BorderRadiiData normalized_border_radii_data(Layout::Node const&, Gfx::FloatRect const&, CSS::BorderRadiusData top_left_radius, CSS::BorderRadiusData top_right_radius, CSS::BorderRadiusData bottom_right_radius, CSS::BorderRadiusData bottom_left_radius);
enum class BorderEdge {
Top,
Right,
Bottom,
Left,
};
struct BordersData {
CSS::BorderData top;
CSS::BorderData right;
CSS::BorderData bottom;
CSS::BorderData left;
};
void paint_border(PaintContext& context, BorderEdge edge, Gfx::IntRect const& rect, BorderRadiiData const& border_radii_data, BordersData const& borders_data);
void paint_all_borders(PaintContext& context, Gfx::FloatRect const& bordered_rect, BorderRadiiData const& border_radii_data, BordersData const&);
}