Pārlūkot izejas kodu

LibGUI: Raise toolbar button icons slightly when hovered :^)

This make buttons look extra clickable when hovered by lifting up their
icons (-1,-1) and painting a little icon-shaped shadow under them.

Partially inspired by the Office XP toolbars, although we don't go all
the way with the faux-hyperlink stuff that was all the rage back then.
Andreas Kling 4 gadi atpakaļ
vecāks
revīzija
8b12d200ba
1 mainītis faili ar 9 papildinājumiem un 0 dzēšanām
  1. 9 0
      Libraries/LibGUI/Button.cpp

+ 9 - 0
Libraries/LibGUI/Button.cpp

@@ -60,8 +60,17 @@ void Button::paint_event(PaintEvent& event)
     auto icon_location = m_icon ? content_rect.center().translated(-(m_icon->width() / 2), -(m_icon->height() / 2)) : Gfx::IntPoint();
     if (m_icon && !text().is_empty())
         icon_location.set_x(content_rect.x());
+
     if (is_being_pressed() || is_checked())
         painter.translate(1, 1);
+    else if (m_icon && is_enabled() && is_hovered() && button_style() == Gfx::ButtonStyle::CoolBar) {
+        auto shadow_color = palette().threed_shadow1();
+        painter.blit_filtered(icon_location, *m_icon, m_icon->rect(), [&shadow_color](auto) {
+            return shadow_color;
+        });
+        icon_location.move_by(-1, -1);
+    }
+
     if (m_icon) {
         if (is_enabled()) {
             if (is_hovered())