From 9ed32582e26e59f4a0ae36ba9871811e3b262721 Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Fri, 3 Sep 2021 08:24:38 -0400 Subject: [PATCH] LibGfx/Painter: Add `draw_rect_with_thickness` method Previously there was no way to draw rectangles with any specific thickness, like we can do with ellises, for instance. This method is just a simple wrapper around `draw_line()` several times. At least for now, we don't need to do anything sophisticated since this will only be used by PixelPaint.` --- Userland/Libraries/LibGfx/Painter.cpp | 16 ++++++++++++++++ Userland/Libraries/LibGfx/Painter.h | 1 + 2 files changed, 17 insertions(+) diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index b5f06dd68a2..1a634487644 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2021, Idan Horowitz + * Copyright (c) 2021, Mustafa Quraish * * SPDX-License-Identifier: BSD-2-Clause */ @@ -585,6 +586,21 @@ void Painter::draw_rect(const IntRect& a_rect, Color color, bool rough) } } +void Painter::draw_rect_with_thickness(const IntRect& rect, Color color, int thickness) +{ + VERIFY(scale() == 1); // FIXME: Add scaling support. + + IntPoint p1 = rect.location(); + IntPoint p2 = { rect.location().x() + rect.width(), rect.location().y() }; + IntPoint p3 = { rect.location().x() + rect.width(), rect.location().y() + rect.height() }; + IntPoint p4 = { rect.location().x(), rect.location().y() + rect.height() }; + + draw_line(p1, p2, color, thickness); + draw_line(p2, p3, color, thickness); + draw_line(p3, p4, color, thickness); + draw_line(p4, p1, color, thickness); +} + void Painter::draw_bitmap(const IntPoint& p, const CharacterBitmap& bitmap, Color color) { VERIFY(scale() == 1); // FIXME: Add scaling support. diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index 48946e9c7cf..96b9c2be6a4 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -42,6 +42,7 @@ public: void fill_rect_with_rounded_corners(const IntRect&, Color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius); void fill_ellipse(const IntRect&, Color); void draw_rect(const IntRect&, Color, bool rough = false); + void draw_rect_with_thickness(const IntRect&, Color, int thickness); void draw_focus_rect(const IntRect&, Color); void draw_bitmap(const IntPoint&, const CharacterBitmap&, Color = Color()); void draw_bitmap(const IntPoint&, const GlyphBitmap&, Color = Color());