mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-03 08:08:43 +00:00
LibWeb: Simplify filling rects with rounded corners
We can use BorderRadiiData::as_corners() to avoid converting the corners one by one. Instead of passing all four corners one by one, use a reference to CornerRadii. No functional changes.
This commit is contained in:
parent
e421b34e14
commit
64acef30ec
Notes:
github-actions[bot]
2025-08-19 19:55:15 +00:00
Author: https://github.com/gmta
Commit: 64acef30ec
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5911
4 changed files with 11 additions and 23 deletions
|
@ -116,10 +116,7 @@ void paint_background(DisplayListRecordingContext& context, PaintableBox const&
|
||||||
display_list_recorder.fill_rect_with_rounded_corners(
|
display_list_recorder.fill_rect_with_rounded_corners(
|
||||||
context.rounded_device_rect(color_box.rect).to_type<int>(),
|
context.rounded_device_rect(color_box.rect).to_type<int>(),
|
||||||
resolved_background.color,
|
resolved_background.color,
|
||||||
color_box.radii.top_left.as_corner(context.device_pixel_converter()),
|
color_box.radii.as_corners(context.device_pixel_converter()));
|
||||||
color_box.radii.top_right.as_corner(context.device_pixel_converter()),
|
|
||||||
color_box.radii.bottom_right.as_corner(context.device_pixel_converter()),
|
|
||||||
color_box.radii.bottom_left.as_corner(context.device_pixel_converter()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
@ -113,7 +113,7 @@ void CheckBoxPaintable::paint(DisplayListRecordingContext& context, PaintPhase p
|
||||||
int radius = 0.05 * checkbox_rect.width();
|
int radius = 0.05 * checkbox_rect.width();
|
||||||
auto dash_color = increase_contrast(input_colors.dark_gray, background_color);
|
auto dash_color = increase_contrast(input_colors.dark_gray, background_color);
|
||||||
auto dash_rect = checkbox_rect.inflated(-0.4 * checkbox_rect.width(), -0.8 * checkbox_rect.height());
|
auto dash_rect = checkbox_rect.inflated(-0.4 * checkbox_rect.width(), -0.8 * checkbox_rect.height());
|
||||||
context.display_list_recorder().fill_rect_with_rounded_corners(dash_rect, dash_color, radius, radius, radius, radius);
|
context.display_list_recorder().fill_rect_with_rounded_corners(dash_rect, dash_color, radius);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,12 +347,12 @@ void DisplayListRecorder::paint_text_shadow(int blur_radius, Gfx::IntRect boundi
|
||||||
.color = color });
|
.color = color });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadius top_left_radius, CornerRadius top_right_radius, CornerRadius bottom_right_radius, CornerRadius bottom_left_radius)
|
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadii const& corner_radii)
|
||||||
{
|
{
|
||||||
if (rect.is_empty())
|
if (rect.is_empty() || color.alpha() == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!top_left_radius && !top_right_radius && !bottom_right_radius && !bottom_left_radius) {
|
if (!corner_radii.has_any_radius()) {
|
||||||
fill_rect(rect, color);
|
fill_rect(rect, color);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -360,31 +360,22 @@ void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& rec
|
||||||
APPEND(FillRectWithRoundedCorners {
|
APPEND(FillRectWithRoundedCorners {
|
||||||
.rect = rect,
|
.rect = rect,
|
||||||
.color = color,
|
.color = color,
|
||||||
.corner_radii = {
|
.corner_radii = corner_radii,
|
||||||
.top_left = top_left_radius,
|
|
||||||
.top_right = top_right_radius,
|
|
||||||
.bottom_right = bottom_right_radius,
|
|
||||||
.bottom_left = bottom_left_radius,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius)
|
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius)
|
||||||
{
|
{
|
||||||
if (a_rect.is_empty() || color.alpha() == 0)
|
|
||||||
return;
|
|
||||||
fill_rect_with_rounded_corners(a_rect, color, radius, radius, radius, radius);
|
fill_rect_with_rounded_corners(a_rect, color, radius, radius, radius, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius)
|
void DisplayListRecorder::fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius)
|
||||||
{
|
{
|
||||||
if (a_rect.is_empty() || color.alpha() == 0)
|
|
||||||
return;
|
|
||||||
fill_rect_with_rounded_corners(a_rect, color,
|
fill_rect_with_rounded_corners(a_rect, color,
|
||||||
{ top_left_radius, top_left_radius },
|
{ { top_left_radius, top_left_radius },
|
||||||
{ top_right_radius, top_right_radius },
|
{ top_right_radius, top_right_radius },
|
||||||
{ bottom_right_radius, bottom_right_radius },
|
{ bottom_right_radius, bottom_right_radius },
|
||||||
{ bottom_left_radius, bottom_left_radius });
|
{ bottom_left_radius, bottom_left_radius } });
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayListRecorder::paint_scrollbar(int scroll_frame_id, Gfx::IntRect gutter_rect, Gfx::IntRect thumb_rect, CSSPixelFraction scroll_size, Color thumb_color, Color track_color, bool vertical)
|
void DisplayListRecorder::paint_scrollbar(int scroll_frame_id, Gfx::IntRect gutter_rect, Gfx::IntRect thumb_rect, CSSPixelFraction scroll_size, Color thumb_color, Color track_color, bool vertical)
|
||||||
|
|
|
@ -121,7 +121,7 @@ public:
|
||||||
void paint_inner_box_shadow(PaintBoxShadowParams params);
|
void paint_inner_box_shadow(PaintBoxShadowParams params);
|
||||||
void paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Gfx::GlyphRun const&, double glyph_run_scale, Color color, Gfx::FloatPoint draw_location);
|
void paint_text_shadow(int blur_radius, Gfx::IntRect bounding_rect, Gfx::IntRect text_rect, Gfx::GlyphRun const&, double glyph_run_scale, Color color, Gfx::FloatPoint draw_location);
|
||||||
|
|
||||||
void fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadius top_left_radius, CornerRadius top_right_radius, CornerRadius bottom_right_radius, CornerRadius bottom_left_radius);
|
void fill_rect_with_rounded_corners(Gfx::IntRect const& rect, Color color, CornerRadii const&);
|
||||||
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius);
|
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int radius);
|
||||||
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
|
void fill_rect_with_rounded_corners(Gfx::IntRect const& a_rect, Color color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue