Browse Source

LibGfx: Move Gfx::Painter::LineStyle => Gfx::LineStyle

Andreas Kling 1 year ago
parent
commit
0e47e5e265

+ 6 - 6
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<float>(), actual_to.to_type<float>(), 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<int>(), actual_to.to_rounded<int>(), color, static_cast<int>(round(thickness)));
     draw_anti_aliased_line(actual_from, actual_to, color, thickness, style, alternate_color, line_length_mode);
 }

+ 4 - 4
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<Range> 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;

+ 17 - 0
Userland/Libraries/LibGfx/LineStyle.h

@@ -0,0 +1,17 @@
+/*
+ * Copyright (c) 2024, Andreas Kling <andreas@ladybird.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace Gfx {
+
+enum class LineStyle {
+    Solid,
+    Dotted,
+    Dashed,
+};
+
+}

+ 1 - 6
Userland/Libraries/LibGfx/Painter.h

@@ -16,6 +16,7 @@
 #include <LibGfx/Forward.h>
 #include <LibGfx/Gradients.h>
 #include <LibGfx/GrayscaleBitmap.h>
+#include <LibGfx/LineStyle.h>
 #include <LibGfx/PaintStyle.h>
 #include <LibGfx/Point.h>
 #include <LibGfx/Rect.h>
@@ -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&);

+ 5 - 5
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:

+ 1 - 1
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)

+ 1 - 1
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 {

+ 3 - 3
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<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Solid);
+            painter.draw_line(line_start_point.to_type<int>(), line_end_point.to_type<int>(), 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<int>(), line_end_point.translated(0, device_line_thickness + 1).to_type<int>(), line_color, device_line_thickness.value());
             break;
         case CSS::TextDecorationStyle::Dashed:
-            painter.draw_line(line_start_point.to_type<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Dashed);
+            painter.draw_line(line_start_point.to_type<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value(), Gfx::LineStyle::Dashed);
             break;
         case CSS::TextDecorationStyle::Dotted:
-            painter.draw_line(line_start_point.to_type<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value(), Gfx::Painter::LineStyle::Dotted);
+            painter.draw_line(line_start_point.to_type<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value(), Gfx::LineStyle::Dotted);
             break;
         case CSS::TextDecorationStyle::Wavy:
             painter.draw_triangle_wave(line_start_point.to_type<int>(), line_end_point.to_type<int>(), line_color, device_line_thickness.value() + 1, device_line_thickness.value());

+ 1 - 1
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,

+ 1 - 1
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<Gfx::Path> 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);
 

+ 2 - 2
Userland/Libraries/LibWeb/Painting/TableBordersPainting.cpp

@@ -284,9 +284,9 @@ static void paint_collected_edges(PaintContext& context, Vector<BorderEdgePainti
             : border_edge_painting_info.rect.bottom_left();
 
         if (border_style == CSS::LineStyle::Dotted) {
-            context.recording_painter().draw_line(p1.to_type<int>(), p2.to_type<int>(), color, width.value(), Gfx::Painter::LineStyle::Dotted);
+            context.recording_painter().draw_line(p1.to_type<int>(), p2.to_type<int>(), color, width.value(), Gfx::LineStyle::Dotted);
         } else if (border_style == CSS::LineStyle::Dashed) {
-            context.recording_painter().draw_line(p1.to_type<int>(), p2.to_type<int>(), color, width.value(), Gfx::Painter::LineStyle::Dashed);
+            context.recording_painter().draw_line(p1.to_type<int>(), p2.to_type<int>(), 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);