diff options
author | Andreas Kling <kling@serenityos.org> | 2020-03-30 19:57:44 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-03-30 19:57:44 +0200 |
commit | b4fde7201328fb73e7789ebf8bf6ee8c47b4cb64 (patch) | |
tree | 50213d4a244b81a5a7d2327d4155d64a84fbb4a6 /Libraries | |
parent | add93bf593c5cb079c02f176f78d4966c0d54b0e (diff) | |
download | serenity-b4fde7201328fb73e7789ebf8bf6ee8c47b4cb64.zip |
LibGUI: Brighten icons when hovering items in item views
View classes now track their hovered item and paint them in a slightly
brighter shade to liven up the user interface. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/AbstractView.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibGUI/AbstractView.h | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/ColumnsView.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibGUI/ItemView.cpp | 9 | ||||
-rw-r--r-- | Libraries/LibGUI/TableView.cpp | 10 | ||||
-rw-r--r-- | Libraries/LibGUI/TreeView.cpp | 8 |
6 files changed, 40 insertions, 11 deletions
diff --git a/Libraries/LibGUI/AbstractView.cpp b/Libraries/LibGUI/AbstractView.cpp index 3842ae117f..bc06ba4b2c 100644 --- a/Libraries/LibGUI/AbstractView.cpp +++ b/Libraries/LibGUI/AbstractView.cpp @@ -193,7 +193,16 @@ void AbstractView::mousedown_event(MouseEvent& event) void AbstractView::mousemove_event(MouseEvent& event) { - if (!model() || !m_might_drag) + if (!model()) + return ScrollableWidget::mousemove_event(event); + + auto hovered_index = index_at_event_position(event.position()); + if (m_hovered_index != hovered_index) { + m_hovered_index = hovered_index; + update(); + } + + if (!m_might_drag) return ScrollableWidget::mousemove_event(event); if (!(event.buttons() & MouseButton::Left) || m_selection.is_empty()) { diff --git a/Libraries/LibGUI/AbstractView.h b/Libraries/LibGUI/AbstractView.h index 5e041a1d64..dfedbd7614 100644 --- a/Libraries/LibGUI/AbstractView.h +++ b/Libraries/LibGUI/AbstractView.h @@ -96,6 +96,8 @@ protected: Gfx::Point m_left_mousedown_position; bool m_might_drag { false }; + ModelIndex m_hovered_index; + private: RefPtr<Model> m_model; OwnPtr<ModelEditingDelegate> m_editing_delegate; diff --git a/Libraries/LibGUI/ColumnsView.cpp b/Libraries/LibGUI/ColumnsView.cpp index 3e8da13ff3..b4feee1c38 100644 --- a/Libraries/LibGUI/ColumnsView.cpp +++ b/Libraries/LibGUI/ColumnsView.cpp @@ -128,9 +128,14 @@ void ColumnsView::paint_event(PaintEvent& event) auto icon = model()->data(index, Model::Role::Icon); Gfx::Rect icon_rect = { column_x + icon_spacing(), 0, icon_size(), icon_size() }; icon_rect.center_vertically_within(row_rect); - if (icon.is_icon()) - if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) - painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); + if (icon.is_icon()) { + if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { + if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) + painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect()); + else + painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); + } + } Gfx::Rect text_rect = { icon_rect.right() + 1 + icon_spacing(), row * item_height(), diff --git a/Libraries/LibGUI/ItemView.cpp b/Libraries/LibGUI/ItemView.cpp index 42b4effe72..f3b33fd561 100644 --- a/Libraries/LibGUI/ItemView.cpp +++ b/Libraries/LibGUI/ItemView.cpp @@ -299,8 +299,13 @@ void ItemView::paint_event(PaintEvent& event) get_item_rects(item_index, font, item_text, item_rect, icon_rect, text_rect); if (icon.is_icon()) { - if (auto bitmap = icon.as_icon().bitmap_for_size(icon_rect.width())) - painter.draw_scaled_bitmap(icon_rect, *bitmap, bitmap->rect()); + if (auto bitmap = icon.as_icon().bitmap_for_size(icon_rect.width())) { + if (m_hovered_index.is_valid() && m_hovered_index == model_index) { + painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect()); + } else { + painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); + } + } } Color text_color; diff --git a/Libraries/LibGUI/TableView.cpp b/Libraries/LibGUI/TableView.cpp index 3522f08464..30204b6087 100644 --- a/Libraries/LibGUI/TableView.cpp +++ b/Libraries/LibGUI/TableView.cpp @@ -26,7 +26,6 @@ #include <AK/StringBuilder.h> #include <Kernel/KeyCode.h> -#include <LibGfx/Palette.h> #include <LibGUI/Action.h> #include <LibGUI/Menu.h> #include <LibGUI/Model.h> @@ -35,6 +34,7 @@ #include <LibGUI/TableView.h> #include <LibGUI/TextBox.h> #include <LibGUI/Window.h> +#include <LibGfx/Palette.h> namespace GUI { @@ -119,8 +119,12 @@ void TableView::paint_event(PaintEvent& event) if (data.is_bitmap()) { painter.blit(cell_rect.location(), data.as_bitmap(), data.as_bitmap().rect()); } else if (data.is_icon()) { - if (auto bitmap = data.as_icon().bitmap_for_size(16)) - painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); + if (auto bitmap = data.as_icon().bitmap_for_size(16)) { + if (m_hovered_index.is_valid() && cell_index.row() == m_hovered_index.row()) + painter.blit_brightened(cell_rect.location(), *bitmap, bitmap->rect()); + else + painter.blit(cell_rect.location(), *bitmap, bitmap->rect()); + } } else { Color text_color; if (is_selected_row) diff --git a/Libraries/LibGUI/TreeView.cpp b/Libraries/LibGUI/TreeView.cpp index bbc6ef97e5..93604b0ba6 100644 --- a/Libraries/LibGUI/TreeView.cpp +++ b/Libraries/LibGUI/TreeView.cpp @@ -260,8 +260,12 @@ void TreeView::paint_event(PaintEvent& event) Gfx::Rect icon_rect = { rect.x(), rect.y(), icon_size(), icon_size() }; auto icon = model.data(index, Model::Role::Icon); if (icon.is_icon()) { - if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) - painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); + if (auto* bitmap = icon.as_icon().bitmap_for_size(icon_size())) { + if (m_hovered_index.is_valid() && m_hovered_index.parent() == index.parent() && m_hovered_index.row() == index.row()) + painter.blit_brightened(icon_rect.location(), *bitmap, bitmap->rect()); + else + painter.blit(icon_rect.location(), *bitmap, bitmap->rect()); + } } Gfx::Rect text_rect = { icon_rect.right() + 1 + icon_spacing(), rect.y(), |