diff --git a/LibGUI/GButton.cpp b/LibGUI/GButton.cpp index 006c6a79c2..b94a863f75 100644 --- a/LibGUI/GButton.cpp +++ b/LibGUI/GButton.cpp @@ -28,15 +28,11 @@ void GButton::paint_event(GPaintEvent&) Color shadow_color = Color(96, 96, 96); Painter painter(*this); - - painter.draw_line({ 1, 0 }, { width() - 2, 0 }, Color::Black); - painter.draw_line({ 1, height() - 1 }, { width() - 2, height() - 1}, Color::Black); - painter.draw_line({ 0, 1 }, { 0, height() - 2 }, Color::Black); - painter.draw_line({ width() - 1, 1 }, { width() - 1, height() - 2 }, Color::Black); + painter.draw_rect(rect(), Color::Black, true); if (m_being_pressed) { // Base - painter.fill_rect({ 1, 1, width() - 2, height() - 2 }, button_color); + painter.fill_rect(rect().shrunken(2, 2), button_color); // Sunken shadow painter.draw_line({ 1, 1 }, { width() - 2, 1 }, shadow_color); diff --git a/LibGUI/GCheckBox.cpp b/LibGUI/GCheckBox.cpp index c935e7c2b8..57158a90f1 100644 --- a/LibGUI/GCheckBox.cpp +++ b/LibGUI/GCheckBox.cpp @@ -68,17 +68,11 @@ void GCheckBox::paint_event(GPaintEvent&) painter.fill_rect(box_rect, Color::White); painter.draw_rect(box_rect, Color::Black); - if (m_being_modified) { - auto modification_rect = box_rect; - modification_rect.shrink(2, 2); - painter.draw_rect(modification_rect, Color::MidGray); - } + if (m_being_modified) + painter.draw_rect(box_rect.shrunken(2, 2), Color::MidGray); - if (m_checked) { - auto bitmap_rect = box_rect; - bitmap_rect.shrink(2, 2); - painter.draw_bitmap(bitmap_rect.location(), *s_checked_bitmap, foreground_color()); - } + if (m_checked) + painter.draw_bitmap(box_rect.shrunken(2, 2).location(), *s_checked_bitmap, foreground_color()); if (!caption().is_empty()) painter.draw_text(text_rect, caption(), Painter::TextAlignment::TopLeft, foreground_color()); diff --git a/SharedGraphics/Painter.cpp b/SharedGraphics/Painter.cpp index a9965c713b..31e2728194 100644 --- a/SharedGraphics/Painter.cpp +++ b/SharedGraphics/Painter.cpp @@ -137,7 +137,7 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start, } } -void Painter::draw_rect(const Rect& a_rect, Color color) +void Painter::draw_rect(const Rect& a_rect, Color color, bool rough) { Rect rect = a_rect; rect.move_by(m_translation); @@ -150,11 +150,15 @@ void Painter::draw_rect(const Rect& a_rect, Color color) int max_y = clipped_rect.bottom(); if (rect.top() >= clipped_rect.top() && rect.top() <= clipped_rect.bottom()) { - fast_dword_fill(m_target->scanline(rect.top()) + clipped_rect.left(), color.value(), clipped_rect.width()); + int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x(); + int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width(); + fast_dword_fill(m_target->scanline(rect.top()) + start_x, color.value(), width); ++min_y; } if (rect.bottom() >= clipped_rect.top() && rect.bottom() <= clipped_rect.bottom()) { - fast_dword_fill(m_target->scanline(rect.bottom()) + clipped_rect.left(), color.value(), clipped_rect.width()); + int start_x = rough ? max(rect.x() + 1, clipped_rect.x()) : clipped_rect.x(); + int width = rough ? min(rect.width() - 2, clipped_rect.width()) : clipped_rect.width(); + fast_dword_fill(m_target->scanline(rect.bottom()) + start_x, color.value(), width); --max_y; } diff --git a/SharedGraphics/Painter.h b/SharedGraphics/Painter.h index ef0fed89da..dd9b807f2b 100644 --- a/SharedGraphics/Painter.h +++ b/SharedGraphics/Painter.h @@ -25,7 +25,7 @@ public: ~Painter(); void fill_rect(const Rect&, Color); void fill_rect_with_gradient(const Rect&, Color gradient_start, Color gradient_end); - void draw_rect(const Rect&, Color); + void draw_rect(const Rect&, Color, bool rough = false); void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color()); void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color()); void set_pixel(const Point&, Color); diff --git a/SharedGraphics/Rect.h b/SharedGraphics/Rect.h index 6273559d1b..eab74724fd 100644 --- a/SharedGraphics/Rect.h +++ b/SharedGraphics/Rect.h @@ -67,6 +67,27 @@ public: set_height(height() - h); } + Rect shrunken(int w, int h) + { + Rect rect = *this; + rect.shrink(w, h); + return rect; + } + + Rect inflated(int w, int h) + { + Rect rect = *this; + rect.inflate(w, h); + return rect; + } + + Rect translated(int dx, int dy) + { + Rect rect = *this; + rect.move_by(dx, dy); + return rect; + } + bool contains(int x, int y) const { return x >= m_location.x() && x <= right() && y >= m_location.y() && y <= bottom(); diff --git a/WindowServer/WSWindowManager.cpp b/WindowServer/WSWindowManager.cpp index eb64e487b4..93f8c59a89 100644 --- a/WindowServer/WSWindowManager.cpp +++ b/WindowServer/WSWindowManager.cpp @@ -236,8 +236,9 @@ void WSWindowManager::paint_window_frame(WSWindow& window) if (!s_close_button_bitmap) s_close_button_bitmap = CharacterBitmap::create_from_ascii(s_close_button_bitmap_data, s_close_button_bitmap_width, s_close_button_bitmap_height).leak_ref(); - m_back_painter->fill_rect_with_gradient(close_button_rect, Color::LightGray, Color::White); - m_back_painter->draw_rect(close_button_rect, Color::Black); + m_back_painter->fill_rect_with_gradient(close_button_rect.shrunken(2, 2), Color::LightGray, Color::White); + + m_back_painter->draw_rect(close_button_rect, Color::Black, true); auto x_location = close_button_rect.center(); x_location.move_by(-(s_close_button_bitmap_width / 2), -(s_close_button_bitmap_height / 2)); m_back_painter->draw_bitmap(x_location, *s_close_button_bitmap, Color::Black);