From 92c073a9d1e24ca055949c4940c889fdfd025929 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 28 Dec 2020 12:40:48 +0100 Subject: [PATCH] LIbGUI+LibGfx: Paint focused push buttons with a heavier look Draw a heavy shadow frame around focused push buttons for emphasis. For now I've used the ThreedShadow2 color role as it feels dark enough. --- Libraries/LibGUI/Button.cpp | 2 +- Libraries/LibGUI/ColorPicker.cpp | 2 +- Libraries/LibGUI/ControlBoxButton.cpp | 2 +- Libraries/LibGfx/ClassicStylePainter.cpp | 14 +++++++++++--- Libraries/LibGfx/ClassicStylePainter.h | 2 +- Libraries/LibGfx/StylePainter.cpp | 4 ++-- Libraries/LibGfx/StylePainter.h | 4 ++-- 7 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Libraries/LibGUI/Button.cpp b/Libraries/LibGUI/Button.cpp index 3cd6667817..721abed9cd 100644 --- a/Libraries/LibGUI/Button.cpp +++ b/Libraries/LibGUI/Button.cpp @@ -52,7 +52,7 @@ void Button::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); - Gfx::StylePainter::paint_button(painter, rect(), palette(), m_button_style, is_being_pressed(), is_hovered(), is_checked(), is_enabled()); + Gfx::StylePainter::paint_button(painter, rect(), palette(), m_button_style, is_being_pressed(), is_hovered(), is_checked(), is_enabled(), is_focused()); if (text().is_empty() && !m_icon) return; diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index 2f44060729..3986a064f5 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -441,7 +441,7 @@ void ColorButton::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); - Gfx::StylePainter::paint_button(painter, rect(), palette(), Gfx::ButtonStyle::Normal, is_being_pressed(), is_hovered(), is_checked(), is_enabled()); + Gfx::StylePainter::paint_button(painter, rect(), palette(), Gfx::ButtonStyle::Normal, is_being_pressed(), is_hovered(), is_checked(), is_enabled(), is_focused()); painter.fill_rect(rect().shrunken(2, 2), m_color); diff --git a/Libraries/LibGUI/ControlBoxButton.cpp b/Libraries/LibGUI/ControlBoxButton.cpp index b6f0ebcb75..ae94129679 100644 --- a/Libraries/LibGUI/ControlBoxButton.cpp +++ b/Libraries/LibGUI/ControlBoxButton.cpp @@ -68,7 +68,7 @@ void ControlBoxButton::paint_event(PaintEvent& event) Painter painter(*this); painter.add_clip_rect(event.rect()); - Gfx::StylePainter::paint_button(painter, rect(), palette(), Gfx::ButtonStyle::Normal, is_being_pressed(), is_hovered(), is_checked(), is_enabled()); + Gfx::StylePainter::paint_button(painter, rect(), palette(), Gfx::ButtonStyle::Normal, is_being_pressed(), is_hovered(), is_checked(), is_enabled(), is_focused()); auto button_location = rect().location().translated((width() - s_bitmap_width) / 2, (height() - s_bitmap_height) / 2); diff --git a/Libraries/LibGfx/ClassicStylePainter.cpp b/Libraries/LibGfx/ClassicStylePainter.cpp index 4422152374..5759bba87c 100644 --- a/Libraries/LibGfx/ClassicStylePainter.cpp +++ b/Libraries/LibGfx/ClassicStylePainter.cpp @@ -93,7 +93,7 @@ void ClassicStylePainter::paint_tab_button(Painter& painter, const IntRect& rect } } -static void paint_button_new(Painter& painter, const IntRect& rect, const Palette& palette, bool pressed, bool checked, bool hovered, bool enabled) +static void paint_button_new(Painter& painter, const IntRect& a_rect, const Palette& palette, bool pressed, bool checked, bool hovered, bool enabled, bool focused) { Color button_color = palette.button(); Color highlight_color = palette.threed_highlight(); @@ -109,11 +109,19 @@ static void paint_button_new(Painter& painter, const IntRect& rect, const Palett button_color = palette.hover_highlight(); PainterStateSaver saver(painter); + + auto rect = a_rect; + if (focused) { + painter.draw_rect(a_rect, palette.threed_shadow2()); + rect.shrink(2, 2); + } + painter.translate(rect.location()); if (pressed || checked) { // Base Gfx::IntRect base_rect { 1, 1, rect.width() - 2, rect.height() - 2 }; + if (checked && !pressed) painter.fill_rect_with_dither_pattern(base_rect, palette.button().lightened(1.3f), palette.button()); else @@ -152,10 +160,10 @@ static void paint_button_new(Painter& painter, const IntRect& rect, const Palett } } -void ClassicStylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled) +void ClassicStylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused) { if (button_style == ButtonStyle::Normal) - return paint_button_new(painter, rect, palette, pressed, checked, hovered, enabled); + return paint_button_new(painter, rect, palette, pressed, checked, hovered, enabled, focused); if (button_style == ButtonStyle::CoolBar && !enabled) return; diff --git a/Libraries/LibGfx/ClassicStylePainter.h b/Libraries/LibGfx/ClassicStylePainter.h index cd80698557..de5302ecb5 100644 --- a/Libraries/LibGfx/ClassicStylePainter.h +++ b/Libraries/LibGfx/ClassicStylePainter.h @@ -35,7 +35,7 @@ namespace Gfx { class ClassicStylePainter : public BaseStylePainter { public: - void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true) override; + void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false) override; void paint_tab_button(Painter&, const IntRect&, const Palette&, bool active, bool hovered, bool enabled, bool top) override; void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true) override; void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) override; diff --git a/Libraries/LibGfx/StylePainter.cpp b/Libraries/LibGfx/StylePainter.cpp index 2fadbd2029..ad830958d8 100644 --- a/Libraries/LibGfx/StylePainter.cpp +++ b/Libraries/LibGfx/StylePainter.cpp @@ -43,9 +43,9 @@ void StylePainter::paint_tab_button(Painter& painter, const IntRect& rect, const current().paint_tab_button(painter, rect, palette, active, hovered, enabled, top); } -void StylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled) +void StylePainter::paint_button(Painter& painter, const IntRect& rect, const Palette& palette, ButtonStyle button_style, bool pressed, bool hovered, bool checked, bool enabled, bool focused) { - current().paint_button(painter, rect, palette, button_style, pressed, hovered, checked, enabled); + current().paint_button(painter, rect, palette, button_style, pressed, hovered, checked, enabled, focused); } void StylePainter::paint_surface(Painter& painter, const IntRect& rect, const Palette& palette, bool paint_vertical_lines, bool paint_top_line) diff --git a/Libraries/LibGfx/StylePainter.h b/Libraries/LibGfx/StylePainter.h index 6a42f4590c..779241c252 100644 --- a/Libraries/LibGfx/StylePainter.h +++ b/Libraries/LibGfx/StylePainter.h @@ -54,7 +54,7 @@ class BaseStylePainter { public: virtual ~BaseStylePainter() { } - virtual void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true) = 0; + virtual void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false) = 0; virtual void paint_tab_button(Painter&, const IntRect&, const Palette&, bool active, bool hovered, bool enabled, bool top) = 0; virtual void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true) = 0; virtual void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false) = 0; @@ -73,7 +73,7 @@ public: static BaseStylePainter& current(); // FIXME: These are here for API compatibility, we should probably remove them and move BaseStylePainter into here - static void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true); + static void paint_button(Painter&, const IntRect&, const Palette&, ButtonStyle, bool pressed, bool hovered = false, bool checked = false, bool enabled = true, bool focused = false); static void paint_tab_button(Painter&, const IntRect&, const Palette&, bool active, bool hovered, bool enabled, bool top); static void paint_surface(Painter&, const IntRect&, const Palette&, bool paint_vertical_lines = true, bool paint_top_line = true); static void paint_frame(Painter&, const IntRect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false);