summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-03 08:24:38 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-04 03:30:03 +0200
commit9ed32582e26e59f4a0ae36ba9871811e3b262721 (patch)
tree08fa232e54cfc5a6a4efd57a393857fc48e07b72 /Userland
parent6910cbc075c7768b84e2fc87c670bf7decd94dc8 (diff)
downloadserenity-9ed32582e26e59f4a0ae36ba9871811e3b262721.zip
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.`
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/Painter.cpp16
-rw-r--r--Userland/Libraries/LibGfx/Painter.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp
index b5f06dd68a..1a63448764 100644
--- a/Userland/Libraries/LibGfx/Painter.cpp
+++ b/Userland/Libraries/LibGfx/Painter.cpp
@@ -1,6 +1,7 @@
/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
+ * Copyright (c) 2021, Mustafa Quraish <mustafa@cs.toronto.edu>
*
* 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 48946e9c7c..96b9c2be6a 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());