diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-03-29 02:20:22 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-03-29 02:20:22 +0100 |
commit | d48f48663426d77da875dc0ae35bff649bc430bb (patch) | |
tree | 271de6f917cab706105c9b81b023dd507e52e363 | |
parent | 9d7a5136810f359dd5e889e5854e71c7497211da (diff) | |
download | serenity-d48f48663426d77da875dc0ae35bff649bc430bb.zip |
LibGUI: Don't draw left and right side of surfaces that span entire window.
In other words, if a surface stretches from the left side of the window
all the way to the right side, skip shading and highlighting the sides.
This makes widgets blend together just slightly with the window. :^)
-rw-r--r-- | LibGUI/GFrame.cpp | 7 | ||||
-rw-r--r-- | LibGUI/GStatusBar.cpp | 4 | ||||
-rw-r--r-- | LibGUI/GToolBar.cpp | 2 | ||||
-rw-r--r-- | LibGUI/GWidget.cpp | 15 | ||||
-rw-r--r-- | LibGUI/GWidget.h | 2 | ||||
-rw-r--r-- | SharedGraphics/StylePainter.cpp | 8 | ||||
-rw-r--r-- | SharedGraphics/StylePainter.h | 2 |
7 files changed, 31 insertions, 9 deletions
diff --git a/LibGUI/GFrame.cpp b/LibGUI/GFrame.cpp index 528666012c..ac82e11936 100644 --- a/LibGUI/GFrame.cpp +++ b/LibGUI/GFrame.cpp @@ -38,8 +38,11 @@ void GFrame::paint_event(GPaintEvent& event) if (m_thickness >= 1) { painter.draw_line(rect().top_left(), rect().top_right(), top_left_color); painter.draw_line(rect().bottom_left(), rect().bottom_right(), bottom_right_color); - painter.draw_line(rect().top_left().translated(0, 1), rect().bottom_left().translated(0, -1), top_left_color); - painter.draw_line(rect().top_right(), rect().bottom_right().translated(0, -1), bottom_right_color); + + if (m_shape != Shape::Panel || !spans_entire_window_horizontally()) { + painter.draw_line(rect().top_left().translated(0, 1), rect().bottom_left().translated(0, -1), top_left_color); + painter.draw_line(rect().top_right(), rect().bottom_right().translated(0, -1), bottom_right_color); + } } if (m_shape == Shape::Container && m_thickness >= 2) { diff --git a/LibGUI/GStatusBar.cpp b/LibGUI/GStatusBar.cpp index e0e92be646..6a72ec32f8 100644 --- a/LibGUI/GStatusBar.cpp +++ b/LibGUI/GStatusBar.cpp @@ -10,7 +10,7 @@ GStatusBar::GStatusBar(GWidget* parent) set_size_policy(SizePolicy::Fill, SizePolicy::Fixed); set_preferred_size({ 0, 20 }); set_layout(make<GBoxLayout>(Orientation::Horizontal)); - layout()->set_margins({ 4, 2, 4, 2 }); + layout()->set_margins({ 2, 2, 2, 2 }); m_label = new GLabel(this); m_label->set_frame_shadow(GFrame::Shadow::Sunken); m_label->set_frame_shape(GFrame::Shape::Panel); @@ -36,5 +36,5 @@ void GStatusBar::paint_event(GPaintEvent& event) { GPainter painter(*this); painter.set_clip_rect(event.rect()); - StylePainter::the().paint_surface(painter, rect()); + StylePainter::the().paint_surface(painter, rect(), !spans_entire_window_horizontally()); } diff --git a/LibGUI/GToolBar.cpp b/LibGUI/GToolBar.cpp index 3acc17108d..53e50ec093 100644 --- a/LibGUI/GToolBar.cpp +++ b/LibGUI/GToolBar.cpp @@ -79,5 +79,5 @@ void GToolBar::paint_event(GPaintEvent& event) { GPainter painter(*this); painter.set_clip_rect(event.rect()); - StylePainter::the().paint_surface(painter, rect()); + StylePainter::the().paint_surface(painter, rect(), !spans_entire_window_horizontally()); } diff --git a/LibGUI/GWidget.cpp b/LibGUI/GWidget.cpp index e22dd03b59..8a13b8ecae 100644 --- a/LibGUI/GWidget.cpp +++ b/LibGUI/GWidget.cpp @@ -353,3 +353,18 @@ void GWidget::set_visible(bool visible) if (m_visible) update(); } + +bool GWidget::spans_entire_window_horizontally() const +{ + auto* w = window(); + if (!w) + return false; + auto* main_widget = w->main_widget(); + if (!main_widget) + return false; + if (main_widget == this) + return true; + auto wrr = window_relative_rect(); + dbgprintf("Checking %s{%p} wrr=%s, mwr=%s\n", class_name(), this, wrr.to_string().characters(), main_widget->rect().to_string().characters()); + return wrr.left() == main_widget->rect().left() && wrr.right() == main_widget->rect().right(); +} diff --git a/LibGUI/GWidget.h b/LibGUI/GWidget.h index 6dfb00fde6..b05bcfa024 100644 --- a/LibGUI/GWidget.h +++ b/LibGUI/GWidget.h @@ -139,6 +139,8 @@ public: bool is_visible() const { return m_visible; } void set_visible(bool); + bool spans_entire_window_horizontally() const; + private: virtual bool is_widget() const final { return true; } diff --git a/SharedGraphics/StylePainter.cpp b/SharedGraphics/StylePainter.cpp index 2c12bf8caa..5d1cf6e1cc 100644 --- a/SharedGraphics/StylePainter.cpp +++ b/SharedGraphics/StylePainter.cpp @@ -98,11 +98,13 @@ void StylePainter::paint_button(Painter& painter, const Rect& rect, ButtonStyle } } -void StylePainter::paint_surface(Painter& painter, const Rect& rect) +void StylePainter::paint_surface(Painter& painter, const Rect& rect, bool paint_vertical_lines) { painter.fill_rect({ rect.x(), rect.y() + 1, rect.width(), rect.height() - 2 }, Color::LightGray); painter.draw_line(rect.top_left(), rect.top_right(), Color::White); painter.draw_line(rect.bottom_left(), rect.bottom_right(), Color::MidGray); - painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White); - painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::MidGray); + if (paint_vertical_lines) { + painter.draw_line(rect.top_left().translated(0, 1), rect.bottom_left().translated(0, -1), Color::White); + painter.draw_line(rect.top_right(), rect.bottom_right().translated(0, -1), Color::MidGray); + } } diff --git a/SharedGraphics/StylePainter.h b/SharedGraphics/StylePainter.h index 7e6ad5f955..d11affb344 100644 --- a/SharedGraphics/StylePainter.h +++ b/SharedGraphics/StylePainter.h @@ -10,7 +10,7 @@ public: static StylePainter& the(); void paint_button(Painter&, const Rect&, ButtonStyle, bool pressed, bool hovered = false); - void paint_surface(Painter&, const Rect&); + void paint_surface(Painter&, const Rect&, bool paint_vertical_lines = true); private: StylePainter(); |