Просмотр исходного кода

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.
Andreas Kling 4 лет назад
Родитель
Сommit
92c073a9d1

+ 1 - 1
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;

+ 1 - 1
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);
 

+ 1 - 1
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);
 

+ 11 - 3
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;

+ 1 - 1
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;

+ 2 - 2
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)

+ 2 - 2
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);