diff options
author | Linus Groh <mail@linusgroh.de> | 2020-05-10 11:58:33 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-10 13:34:59 +0200 |
commit | 59d00e5df6c3ebbde3c24461af7a3628f3531966 (patch) | |
tree | 6c1b48a833528c5adb20576c4e66cdcf2a9c4b7c /Libraries | |
parent | da42279171c8a10864de7f1962986a782f379408 (diff) | |
download | serenity-59d00e5df6c3ebbde3c24461af7a3628f3531966.zip |
LibGfx: Replace 'bool dotted' with a LineStyle::{Solid,Dotted} enum
Just a bool is insufficient as we'll have to support dashed lines as well.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGfx/Painter.cpp | 14 | ||||
-rw-r--r-- | Libraries/LibGfx/Painter.h | 10 | ||||
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutBox.cpp | 8 |
3 files changed, 21 insertions, 11 deletions
diff --git a/Libraries/LibGfx/Painter.cpp b/Libraries/LibGfx/Painter.cpp index 5387b3c707..992e7a4cb8 100644 --- a/Libraries/LibGfx/Painter.cpp +++ b/Libraries/LibGfx/Painter.cpp @@ -966,7 +966,7 @@ void Painter::draw_pixel(const Point& position, Color color, int thickness) fill_rect(rect.translated(-state().translation), color); } -void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thickness, bool dotted) +void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thickness, LineStyle style) { auto clip_rect = this->clip_rect(); @@ -989,7 +989,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick return; int min_y = max(point1.y(), clip_rect.top()); int max_y = min(point2.y(), clip_rect.bottom()); - if (dotted) { + if (style == LineStyle::Dotted) { for (int y = min_y; y <= max_y; y += thickness * 2) draw_pixel({ x, y }, color, thickness); } else { @@ -1012,7 +1012,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick return; int min_x = max(point1.x(), clip_rect.left()); int max_x = min(point2.x(), clip_rect.right()); - if (dotted) { + if (style == LineStyle::Dotted) { for (int x = min_x; x <= max_x; x += thickness * 2) draw_pixel({ x, y }, color, thickness); } else { @@ -1023,7 +1023,7 @@ void Painter::draw_line(const Point& p1, const Point& p2, Color color, int thick } // FIXME: Implement dotted diagonal lines. - ASSERT(!dotted); + ASSERT(style == LineStyle::Solid); const double adx = abs(point2.x() - point1.x()); const double ady = abs(point2.y() - point1.y()); @@ -1116,10 +1116,10 @@ void Painter::for_each_line_segment_on_bezier_curve(const FloatPoint& control_po for_each_line_segment_on_bezier_curve(control_point, p1, p2, callback); } -void Painter::draw_quadratic_bezier_curve(const Point& control_point, const Point& p1, const Point& p2, Color color, int thickness, bool dotted) +void Painter::draw_quadratic_bezier_curve(const Point& control_point, const Point& p1, const Point& p2, Color color, int thickness, LineStyle style) { for_each_line_segment_on_bezier_curve(FloatPoint(control_point.x(), control_point.y()), FloatPoint(p1.x(), p1.y()), FloatPoint(p2.x(), p2.y()), [&](const FloatPoint& p1, const FloatPoint& p2) { - draw_line(Point(p1.x(), p1.y()), Point(p2.x(), p2.y()), color, thickness, dotted); + draw_line(Point(p1.x(), p1.y()), Point(p2.x(), p2.y()), color, thickness, style); }); } @@ -1263,7 +1263,7 @@ void Painter::fill_path(Path& path, Color color, WindingRule winding_rule) #ifdef FILL_PATH_DEBUG dbg() << "y=" << scanline << ": " << winding_number << " at " << i << ": " << from << " -- " << to; #endif - draw_line(from, to, color, 1, false); + draw_line(from, to, color, 1); } skip_drawing:; diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index d02535e608..9176bef88c 100644 --- a/Libraries/LibGfx/Painter.h +++ b/Libraries/LibGfx/Painter.h @@ -43,6 +43,12 @@ class Painter { public: explicit Painter(Gfx::Bitmap&); ~Painter(); + + enum class LineStyle { + Solid, + Dotted, + }; + void clear_rect(const Rect&, Color); void fill_rect(const Rect&, Color); void fill_rect_with_dither_pattern(const Rect&, Color, Color); @@ -55,8 +61,8 @@ public: void draw_triangle(const Point&, const Point&, const Point&, Color); void draw_ellipse_intersecting(const Rect&, Color, int thickness = 1); void set_pixel(const Point&, Color); - void draw_line(const Point&, const Point&, Color, int thickness = 1, bool dotted = false); - void draw_quadratic_bezier_curve(const Point& control_point, const Point&, const Point&, Color, int thickness = 1, bool dotted = false); + void draw_line(const Point&, const Point&, Color, int thickness = 1, LineStyle style = LineStyle::Solid); + void draw_quadratic_bezier_curve(const Point& control_point, const Point&, const Point&, Color, int thickness = 1, LineStyle style = LineStyle::Solid); void draw_scaled_bitmap(const Rect& dst_rect, const Gfx::Bitmap&, const Rect& src_rect); void blit(const Point&, const Gfx::Bitmap&, const Rect& src_rect, float opacity = 1.0f); void blit_dimmed(const Point&, const Gfx::Bitmap&, const Rect& src_rect); diff --git a/Libraries/LibWeb/Layout/LayoutBox.cpp b/Libraries/LibWeb/Layout/LayoutBox.cpp index 415592f659..7fe66dd9b0 100644 --- a/Libraries/LibWeb/Layout/LayoutBox.cpp +++ b/Libraries/LibWeb/Layout/LayoutBox.cpp @@ -102,10 +102,14 @@ void LayoutBox::paint_border(RenderingContext& context, Edge edge, const Gfx::Fl color = (edge == Edge::Left || edge == Edge::Top) ? top_left_color : bottom_right_color; } - bool dotted = border_style.has_value() && border_style.value()->to_string() == "dotted"; + auto line_style = Gfx::Painter::LineStyle::Solid; + if (border_style.has_value()) { + if (border_style.value()->to_string() == "dotted") + line_style = Gfx::Painter::LineStyle::Dotted; + } auto draw_line = [&](auto& p1, auto& p2) { - context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, 1, dotted); + context.painter().draw_line({ (int)p1.x(), (int)p1.y() }, { (int)p2.x(), (int)p2.y() }, color, 1, line_style); }; auto width_for = [&](CSS::PropertyID property_id) -> float { |