浏览代码

LibGfx: Add int overloads for (AntiAliasing)Painter float methods

Without this change, the upcoming LibWeb pixel types will require a
silly doubled conversion in some places.

eg: `some_rect.to_type<int>().to_type<float>()`

With these overloads, we can get away with `some_rect.to_type<int>()`.
Sam Atkins 2 年之前
父节点
当前提交
83f31cb4a7

+ 5 - 0
Userland/Libraries/LibGfx/AntiAliasingPainter.cpp

@@ -201,6 +201,11 @@ 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)
+{
+    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)
 {
     if (style == Painter::LineStyle::Dotted)

+ 1 - 0
Userland/Libraries/LibGfx/AntiAliasingPainter.h

@@ -26,6 +26,7 @@ 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_for_path(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_for_fill_path(FloatPoint from, FloatPoint to, Color color, float thickness = 1)

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

@@ -2446,6 +2446,11 @@ void Gfx::Painter::draw_ui_text(Gfx::IntRect const& rect, StringView text, Gfx::
     }
 }
 
+void Painter::draw_text_run(IntPoint baseline_start, Utf8View const& string, Font const& font, Color color)
+{
+    draw_text_run(baseline_start.to_type<float>(), string, font, color);
+}
+
 void Painter::draw_text_run(FloatPoint baseline_start, Utf8View const& string, Font const& font, Color color)
 {
     auto pixel_metrics = font.pixel_metrics();
@@ -2471,7 +2476,7 @@ void Painter::draw_text_run(FloatPoint baseline_start, Utf8View const& string, F
     }
 }
 
-void Painter::draw_scaled_bitmap_with_transform(Gfx::IntRect const& dst_rect, Gfx::Bitmap const& bitmap, Gfx::FloatRect const& src_rect, Gfx::AffineTransform const& transform, float opacity, Gfx::Painter::ScalingMode scaling_mode)
+void Painter::draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Bitmap const& bitmap, FloatRect const& src_rect, AffineTransform const& transform, float opacity, Painter::ScalingMode scaling_mode)
 {
     if (transform.is_identity_or_translation()) {
         translate(transform.e(), transform.f());

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

@@ -96,6 +96,7 @@ public:
     void draw_circle_arc_intersecting(IntRect const&, IntPoint, int radius, Color, int thickness);
 
     // Streamlined text drawing routine that does no wrapping/elision/alignment.
+    void draw_text_run(IntPoint baseline_start, Utf8View const&, Font const&, Color);
     void draw_text_run(FloatPoint baseline_start, Utf8View const&, Font const&, Color);
 
     enum class CornerOrientation {