diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp index f922db8278e..461bf76b79a 100644 --- a/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp +++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.cpp @@ -17,10 +17,10 @@ namespace Gfx { -void AntiAliasingPainter::draw_anti_aliased_line(FloatPoint actual_from, FloatPoint actual_to, Color color, float thickness, Painter::LineStyle style, Color, LineLengthMode line_length_mode) +void AntiAliasingPainter::draw_anti_aliased_line(FloatPoint actual_from, FloatPoint actual_to, Color color, float thickness, LineStyle style, Color, LineLengthMode line_length_mode) { // FIXME: Implement this :P - VERIFY(style == Painter::LineStyle::Solid); + VERIFY(style == LineStyle::Solid); if (color.alpha() == 0) return; @@ -142,7 +142,7 @@ void AntiAliasingPainter::draw_dotted_line(IntPoint point1, IntPoint point2, Col { // AA circles don't really work below a radius of 2px. if (thickness < 4) - return m_underlying_painter.draw_line(point1, point2, color, thickness, Painter::LineStyle::Dotted); + return m_underlying_painter.draw_line(point1, point2, color, thickness, LineStyle::Dotted); auto draw_spaced_dots = [&](int start, int end, auto to_point) { int step = thickness * 2; @@ -180,14 +180,14 @@ void AntiAliasingPainter::draw_dotted_line(IntPoint point1, IntPoint point2, Col } } -void AntiAliasingPainter::draw_line(IntPoint actual_from, IntPoint actual_to, Color color, float thickness, Painter::LineStyle style, Color alternate_color, LineLengthMode line_length_mode) +void AntiAliasingPainter::draw_line(IntPoint actual_from, IntPoint actual_to, Color color, float thickness, LineStyle style, Color alternate_color, LineLengthMode line_length_mode) { draw_line(actual_from.to_type(), actual_to.to_type(), color, thickness, style, alternate_color, line_length_mode); } -void AntiAliasingPainter::draw_line(FloatPoint actual_from, FloatPoint actual_to, Color color, float thickness, Painter::LineStyle style, Color alternate_color, LineLengthMode line_length_mode) +void AntiAliasingPainter::draw_line(FloatPoint actual_from, FloatPoint actual_to, Color color, float thickness, LineStyle style, Color alternate_color, LineLengthMode line_length_mode) { - if (style == Painter::LineStyle::Dotted) + if (style == LineStyle::Dotted) return draw_dotted_line(actual_from.to_rounded(), actual_to.to_rounded(), color, static_cast(round(thickness))); draw_anti_aliased_line(actual_from, actual_to, color, thickness, style, alternate_color, line_length_mode); } diff --git a/Userland/Libraries/LibGfx/AntiAliasingPainter.h b/Userland/Libraries/LibGfx/AntiAliasingPainter.h index 9ce3ec86114..d0687fb76ec 100644 --- a/Userland/Libraries/LibGfx/AntiAliasingPainter.h +++ b/Userland/Libraries/LibGfx/AntiAliasingPainter.h @@ -27,9 +27,9 @@ public: Distance }; - void draw_line(IntPoint, IntPoint, Color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint); - void draw_line(FloatPoint, FloatPoint, Color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint); - void draw_line(FloatLine line, Color color, float thickness = 1, Painter::LineStyle style = Painter::LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint) + void draw_line(IntPoint, IntPoint, Color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint); + void draw_line(FloatPoint, FloatPoint, Color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint); + void draw_line(FloatLine line, Color color, float thickness = 1, LineStyle style = LineStyle::Solid, Color alternate_color = Color::Transparent, LineLengthMode line_length_mode = LineLengthMode::PointToPoint) { draw_line(line.a(), line.b(), color, thickness, style, alternate_color, line_length_mode); } @@ -90,7 +90,7 @@ private: Range draw_ellipse_part(IntPoint a_rect, int radius_a, int radius_b, Color alternate_color, bool flip_x_and_y, Optional x_clip, BlendMode blend_mode); - void draw_anti_aliased_line(FloatPoint, FloatPoint, Color, float thickness, Painter::LineStyle, Color, LineLengthMode); + void draw_anti_aliased_line(FloatPoint, FloatPoint, Color, float thickness, LineStyle, Color, LineLengthMode); void draw_dotted_line(IntPoint, IntPoint, Gfx::Color, int thickness); Painter& m_underlying_painter; diff --git a/Userland/Libraries/LibGfx/LineStyle.h b/Userland/Libraries/LibGfx/LineStyle.h new file mode 100644 index 00000000000..b30921bdc59 --- /dev/null +++ b/Userland/Libraries/LibGfx/LineStyle.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Gfx { + +enum class LineStyle { + Solid, + Dotted, + Dashed, +}; + +} diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index 22ebffab9a6..b9a7638f827 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,6 @@ public: explicit Painter(Gfx::Bitmap&); ~Painter() = default; - enum class LineStyle { - Solid, - Dotted, - Dashed, - }; - void clear_rect(IntRect const&, Color); void fill_rect(IntRect const&, Color); void fill_rect(IntRect const&, PaintStyle const&); diff --git a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp index 7f43b072e82..ba5978f2945 100644 --- a/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/BorderPainting.cpp @@ -100,19 +100,19 @@ void paint_border(RecordingPainter& painter, BorderEdge edge, DevicePixelRect co } }; - auto gfx_line_style = Gfx::Painter::LineStyle::Solid; + auto gfx_line_style = Gfx::LineStyle::Solid; switch (border_style) { case CSS::LineStyle::None: case CSS::LineStyle::Hidden: return; case CSS::LineStyle::Dotted: - gfx_line_style = Gfx::Painter::LineStyle::Dotted; + gfx_line_style = Gfx::LineStyle::Dotted; break; case CSS::LineStyle::Dashed: - gfx_line_style = Gfx::Painter::LineStyle::Dashed; + gfx_line_style = Gfx::LineStyle::Dashed; break; case CSS::LineStyle::Solid: - gfx_line_style = Gfx::Painter::LineStyle::Solid; + gfx_line_style = Gfx::LineStyle::Solid; break; case CSS::LineStyle::Double: case CSS::LineStyle::Groove: @@ -123,7 +123,7 @@ void paint_border(RecordingPainter& painter, BorderEdge edge, DevicePixelRect co break; } - if (gfx_line_style != Gfx::Painter::LineStyle::Solid) { + if (gfx_line_style != Gfx::LineStyle::Solid) { auto [p1, p2] = points_for_edge(edge, rect); switch (edge) { case BorderEdge::Top: diff --git a/Userland/Libraries/LibWeb/Painting/Command.h b/Userland/Libraries/LibWeb/Painting/Command.h index d4fb2243e8f..865498e6873 100644 --- a/Userland/Libraries/LibWeb/Painting/Command.h +++ b/Userland/Libraries/LibWeb/Painting/Command.h @@ -275,7 +275,7 @@ struct DrawLine { Gfx::IntPoint from; Gfx::IntPoint to; int thickness; - Gfx::Painter::LineStyle style; + Gfx::LineStyle style; Color alternate_color; void translate_by(Gfx::IntPoint const& offset) diff --git a/Userland/Libraries/LibWeb/Painting/CommandExecutorCPU.cpp b/Userland/Libraries/LibWeb/Painting/CommandExecutorCPU.cpp index 04acc99dd17..37618af50df 100644 --- a/Userland/Libraries/LibWeb/Painting/CommandExecutorCPU.cpp +++ b/Userland/Libraries/LibWeb/Painting/CommandExecutorCPU.cpp @@ -370,7 +370,7 @@ CommandResult CommandExecutorCPU::fill_ellipse(FillEllipse const& command) CommandResult CommandExecutorCPU::draw_line(DrawLine const& command) { - if (command.style == Gfx::Painter::LineStyle::Dotted) { + if (command.style == Gfx::LineStyle::Dotted) { Gfx::AntiAliasingPainter aa_painter(painter()); aa_painter.draw_line(command.from, command.to, command.color, command.thickness, command.style, command.alternate_color); } else { diff --git a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp index 6e9aec4003c..156309035c1 100644 --- a/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp +++ b/Userland/Libraries/LibWeb/Painting/PaintableBox.cpp @@ -615,7 +615,7 @@ void paint_text_decoration(PaintContext& context, TextPaintable const& paintable switch (paintable.computed_values().text_decoration_style()) { case CSS::TextDecorationStyle::Solid: - painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Solid); + painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::LineStyle::Solid); break; case CSS::TextDecorationStyle::Double: switch (line) { @@ -637,10 +637,10 @@ void paint_text_decoration(PaintContext& context, TextPaintable const& paintable painter.draw_line(line_start_point.translated(0, device_line_thickness + 1).to_type(), line_end_point.translated(0, device_line_thickness + 1).to_type(), line_color, device_line_thickness.value()); break; case CSS::TextDecorationStyle::Dashed: - painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Dashed); + painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::LineStyle::Dashed); break; case CSS::TextDecorationStyle::Dotted: - painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Dotted); + painter.draw_line(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value(), Gfx::LineStyle::Dotted); break; case CSS::TextDecorationStyle::Wavy: painter.draw_triangle_wave(line_start_point.to_type(), line_end_point.to_type(), line_color, device_line_thickness.value() + 1, device_line_thickness.value()); diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp index dbb296b33f1..702aaa76ad8 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.cpp @@ -210,7 +210,7 @@ void RecordingPainter::draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect }); } -void RecordingPainter::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness, Gfx::Painter::LineStyle style, Color alternate_color) +void RecordingPainter::draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness, Gfx::LineStyle style, Color alternate_color) { append(DrawLine { .color = color, diff --git a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h index cf783899207..c067f5456e4 100644 --- a/Userland/Libraries/LibWeb/Painting/RecordingPainter.h +++ b/Userland/Libraries/LibWeb/Painting/RecordingPainter.h @@ -93,7 +93,7 @@ public: void draw_scaled_bitmap(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode = Gfx::ScalingMode::NearestNeighbor); void draw_scaled_immutable_bitmap(Gfx::IntRect const& dst_rect, Gfx::ImmutableBitmap const& bitmap, Gfx::IntRect const& src_rect, Gfx::ScalingMode scaling_mode = Gfx::ScalingMode::NearestNeighbor, Vector const& clip_paths = {}); - void draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness = 1, Gfx::Painter::LineStyle style = Gfx::Painter::LineStyle::Solid, Color alternate_color = Color::Transparent); + void draw_line(Gfx::IntPoint from, Gfx::IntPoint to, Color color, int thickness = 1, Gfx::LineStyle style = Gfx::LineStyle::Solid, Color alternate_color = Color::Transparent); void draw_text(Gfx::IntRect const&, String, Gfx::Font const&, Gfx::TextAlignment = Gfx::TextAlignment::TopLeft, Color = Color::Black, Gfx::TextElision = Gfx::TextElision::None, Gfx::TextWrapping = Gfx::TextWrapping::DontWrap); diff --git a/Userland/Libraries/LibWeb/Painting/TableBordersPainting.cpp b/Userland/Libraries/LibWeb/Painting/TableBordersPainting.cpp index f4bdda158f8..0ab45c66759 100644 --- a/Userland/Libraries/LibWeb/Painting/TableBordersPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/TableBordersPainting.cpp @@ -284,9 +284,9 @@ static void paint_collected_edges(PaintContext& context, Vector(), p2.to_type(), color, width.value(), Gfx::Painter::LineStyle::Dotted); + context.recording_painter().draw_line(p1.to_type(), p2.to_type(), color, width.value(), Gfx::LineStyle::Dotted); } else if (border_style == CSS::LineStyle::Dashed) { - context.recording_painter().draw_line(p1.to_type(), p2.to_type(), color, width.value(), Gfx::Painter::LineStyle::Dashed); + context.recording_painter().draw_line(p1.to_type(), p2.to_type(), color, width.value(), Gfx::LineStyle::Dashed); } else { // FIXME: Support the remaining line styles instead of rendering them as solid. context.recording_painter().fill_rect(Gfx::IntRect(border_edge_painting_info.rect.location(), border_edge_painting_info.rect.size()), color);