From b6eba388e33af245f9a456b17bdf64679989d4ec Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 24 Dec 2019 12:13:10 +0100 Subject: [PATCH] LibDraw: Add Selection and SelectionText system theme colors --- Applications/FontEditor/GlyphMapWidget.cpp | 2 +- Applications/HexEditor/HexEditor.cpp | 4 ++-- Base/res/themes/Dark.ini | 3 +++ Base/res/themes/Default.ini | 3 +++ Base/res/themes/Xmas.ini | 2 ++ DevTools/HackStudio/Editor.cpp | 2 +- Libraries/LibDraw/Color.cpp | 6 ++++++ Libraries/LibDraw/Color.h | 2 ++ Libraries/LibDraw/SystemTheme.cpp | 2 ++ Libraries/LibDraw/SystemTheme.h | 3 +++ Libraries/LibGUI/GItemView.cpp | 4 ++-- Libraries/LibGUI/GListView.cpp | 2 +- Libraries/LibGUI/GTableView.cpp | 6 +++--- Libraries/LibGUI/GTextEditor.cpp | 4 ++-- Libraries/LibGUI/GTreeView.cpp | 4 ++-- Servers/WindowServer/WSWindowSwitcher.cpp | 16 ++++++++-------- 16 files changed, 43 insertions(+), 22 deletions(-) diff --git a/Applications/FontEditor/GlyphMapWidget.cpp b/Applications/FontEditor/GlyphMapWidget.cpp index 1d86a83184..e8b88ae62d 100644 --- a/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Applications/FontEditor/GlyphMapWidget.cpp @@ -74,7 +74,7 @@ void GlyphMapWidget::paint_event(GPaintEvent& event) font().max_glyph_width(), font().glyph_height()); if (glyph == m_selected_glyph) { - painter.fill_rect(outer_rect, Color::from_rgb(0x84351a)); + painter.fill_rect(outer_rect, SystemColor::Selection); painter.draw_glyph(inner_rect.location(), glyph, Color::White); } else { painter.draw_glyph(inner_rect.location(), glyph, Color::Black); diff --git a/Applications/HexEditor/HexEditor.cpp b/Applications/HexEditor/HexEditor.cpp index 2e675cf23b..2c772f5bde 100644 --- a/Applications/HexEditor/HexEditor.cpp +++ b/Applications/HexEditor/HexEditor.cpp @@ -492,7 +492,7 @@ void HexEditor::paint_event(GPaintEvent& event) text_color = Color::Red; } - Color highlight_color = Color::from_rgb(0x84351a); + Color highlight_color = SystemColor::Selection; auto highlight_flag = false; if (m_selection_start > -1 && m_selection_end > -1) { if (byte_position >= m_selection_start && byte_position <= m_selection_end) { @@ -541,4 +541,4 @@ void HexEditor::leave_event(CEvent&) { ASSERT(window()); window()->set_override_cursor(GStandardCursor::None); -} \ No newline at end of file +} diff --git a/Base/res/themes/Dark.ini b/Base/res/themes/Dark.ini index 3e7cc3488c..8e9d934f12 100644 --- a/Base/res/themes/Dark.ini +++ b/Base/res/themes/Dark.ini @@ -32,3 +32,6 @@ ThreedShadow1=#3d3e40 ThreedShadow2=#2e2f30 HoverHighlight=#696969 + +Selection=#14141a +SelectionText=white diff --git a/Base/res/themes/Default.ini b/Base/res/themes/Default.ini index 7a99dc2027..2110c4c43f 100644 --- a/Base/res/themes/Default.ini +++ b/Base/res/themes/Default.ini @@ -33,3 +33,6 @@ ThreedShadow1=#808080 ThreedShadow2=#404040 HoverHighlight=#e3dfdb + +Selection=#84351a +SelectionText=white diff --git a/Base/res/themes/Xmas.ini b/Base/res/themes/Xmas.ini index 5725aeab67..83febd83d5 100644 --- a/Base/res/themes/Xmas.ini +++ b/Base/res/themes/Xmas.ini @@ -34,3 +34,5 @@ ThreedShadow2=#882d26 HoverHighlight=#e6e5e2 +Selection=#84351a +SelectionText=white diff --git a/DevTools/HackStudio/Editor.cpp b/DevTools/HackStudio/Editor.cpp index 27b5cd79d7..57167ef7af 100644 --- a/DevTools/HackStudio/Editor.cpp +++ b/DevTools/HackStudio/Editor.cpp @@ -68,7 +68,7 @@ void Editor::paint_event(GPaintEvent& event) rect.set_width(rect.width() - vertical_scrollbar().width()); if (horizontal_scrollbar().is_visible()) rect.set_height(rect.height() - horizontal_scrollbar().height()); - painter.draw_rect(rect, Color::from_rgb(0x955233)); + painter.draw_rect(rect, SystemColor::Selection); } } diff --git a/Libraries/LibDraw/Color.cpp b/Libraries/LibDraw/Color.cpp index 9027f7fd66..3644c4bf4b 100644 --- a/Libraries/LibDraw/Color.cpp +++ b/Libraries/LibDraw/Color.cpp @@ -35,6 +35,12 @@ Color::Color(SystemColor system_color) case SystemColor::HoverHighlight: m_value = theme.hover_highlight.value(); break; + case SystemColor::Selection: + m_value = theme.selection.value(); + break; + case SystemColor::SelectionText: + m_value = theme.selection_text.value(); + break; case SystemColor::DesktopBackground: m_value = theme.desktop_background.value(); break; diff --git a/Libraries/LibDraw/Color.h b/Libraries/LibDraw/Color.h index 976ab3a5c0..a887363018 100644 --- a/Libraries/LibDraw/Color.h +++ b/Libraries/LibDraw/Color.h @@ -37,6 +37,8 @@ enum class SystemColor { ThreedShadow1, ThreedShadow2, HoverHighlight, + Selection, + SelectionText, DisabledText = ThreedShadow1, }; diff --git a/Libraries/LibDraw/SystemTheme.cpp b/Libraries/LibDraw/SystemTheme.cpp index 226df7cb53..d05040105b 100644 --- a/Libraries/LibDraw/SystemTheme.cpp +++ b/Libraries/LibDraw/SystemTheme.cpp @@ -46,6 +46,8 @@ RefPtr load_system_theme(const String& path) data->threed_shadow1 = get("ThreedShadow1"); data->threed_shadow2 = get("ThreedShadow2"); data->hover_highlight = get("HoverHighlight"); + data->selection = get("Selection"); + data->selection_text = get("SelectionText"); data->window = get("Window"); data->window_text = get("WindowText"); data->base = get("Base"); diff --git a/Libraries/LibDraw/SystemTheme.h b/Libraries/LibDraw/SystemTheme.h index ab8d97f3a0..80c6c32089 100644 --- a/Libraries/LibDraw/SystemTheme.h +++ b/Libraries/LibDraw/SystemTheme.h @@ -38,6 +38,9 @@ struct SystemTheme { Color threed_shadow2; Color hover_highlight; + + Color selection; + Color selection_text; }; const SystemTheme& current_system_theme(); diff --git a/Libraries/LibGUI/GItemView.cpp b/Libraries/LibGUI/GItemView.cpp index 40912800b1..4d1fae3963 100644 --- a/Libraries/LibGUI/GItemView.cpp +++ b/Libraries/LibGUI/GItemView.cpp @@ -201,7 +201,7 @@ void GItemView::paint_event(GPaintEvent& event) bool is_selected_item = selection().contains(model()->index(item_index, m_model_column)); Color background_color; if (is_selected_item) { - background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); + background_color = is_focused() ? Color(SystemColor::Selection) : Color::from_rgb(0x606060); } else { background_color = SystemColor::Base; } @@ -228,7 +228,7 @@ void GItemView::paint_event(GPaintEvent& event) Color text_color; if (is_selected_item) - text_color = Color::White; + text_color = SystemColor::SelectionText; else text_color = model()->data(model_index, GModel::Role::ForegroundColor).to_color(SystemColor::WindowText); painter.fill_rect(text_rect, background_color); diff --git a/Libraries/LibGUI/GListView.cpp b/Libraries/LibGUI/GListView.cpp index 38224f1457..34467100dc 100644 --- a/Libraries/LibGUI/GListView.cpp +++ b/Libraries/LibGUI/GListView.cpp @@ -104,7 +104,7 @@ void GListView::paint_event(GPaintEvent& event) Color background_color; if (is_selected_row) { - background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); + background_color = is_focused() ? Color(SystemColor::SelectionText) : Color::from_rgb(0x606060); } else { if (alternating_row_colors() && (painted_item_index % 2)) background_color = Color(210, 210, 210); diff --git a/Libraries/LibGUI/GTableView.cpp b/Libraries/LibGUI/GTableView.cpp index f7062589f3..c0ebd6ff95 100644 --- a/Libraries/LibGUI/GTableView.cpp +++ b/Libraries/LibGUI/GTableView.cpp @@ -53,8 +53,8 @@ void GTableView::paint_event(GPaintEvent& event) Color background_color; Color key_column_background_color; if (is_selected_row) { - background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); - key_column_background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); + background_color = is_focused() ? Color(SystemColor::Selection) : Color::from_rgb(0x606060); + key_column_background_color = is_focused() ? Color(SystemColor::Selection) : Color::from_rgb(0x606060); } else { if (alternating_row_colors() && (painted_item_index % 2)) { background_color = Color(SystemColor::Base).darkened(0.8f); @@ -93,7 +93,7 @@ void GTableView::paint_event(GPaintEvent& event) } else { Color text_color; if (is_selected_row) - text_color = Color::White; + text_color = SystemColor::SelectionText; else text_color = model()->data(cell_index, GModel::Role::ForegroundColor).to_color(SystemColor::WindowText); painter.draw_text(cell_rect, data.to_string(), font, column_metadata.text_alignment, text_color, TextElision::Right); diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp index c4dd3ce9ce..cca6dcf675 100644 --- a/Libraries/LibGUI/GTextEditor.cpp +++ b/Libraries/LibGUI/GTextEditor.cpp @@ -424,7 +424,7 @@ void GTextEditor::paint_event(GPaintEvent& event) visual_line_rect.height() }; - painter.fill_rect(selection_rect, Color::from_rgb(0x955233)); + painter.fill_rect(selection_rect, SystemColor::Selection); size_t start_of_selection_within_visual_line = (size_t)max(0, (int)selection_start_column_within_line - (int)start_of_visual_line); size_t end_of_selection_within_visual_line = selection_end_column_within_line - start_of_visual_line; @@ -434,7 +434,7 @@ void GTextEditor::paint_event(GPaintEvent& event) end_of_selection_within_visual_line - start_of_selection_within_visual_line }; - painter.draw_text(selection_rect, visual_selected_text, TextAlignment::CenterLeft, Color::White); + painter.draw_text(selection_rect, visual_selected_text, TextAlignment::CenterLeft, SystemColor::SelectionText); } } ++visual_line_index; diff --git a/Libraries/LibGUI/GTreeView.cpp b/Libraries/LibGUI/GTreeView.cpp index f0e12b5386..4bd569e21d 100644 --- a/Libraries/LibGUI/GTreeView.cpp +++ b/Libraries/LibGUI/GTreeView.cpp @@ -185,8 +185,8 @@ void GTreeView::paint_event(GPaintEvent& event) Color background_color; Color key_column_background_color; if (is_selected_row) { - background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); - key_column_background_color = is_focused() ? Color::from_rgb(0x84351a) : Color::from_rgb(0x606060); + background_color = is_focused() ? Color(SystemColor::Selection) : Color::from_rgb(0x606060); + key_column_background_color = is_focused() ? Color(SystemColor::Selection) : Color::from_rgb(0x606060); } else { if (alternating_row_colors() && (painted_row_index % 2)) { background_color = Color(220, 220, 220); diff --git a/Servers/WindowServer/WSWindowSwitcher.cpp b/Servers/WindowServer/WSWindowSwitcher.cpp index d9cf40913a..c88074ea37 100644 --- a/Servers/WindowServer/WSWindowSwitcher.cpp +++ b/Servers/WindowServer/WSWindowSwitcher.cpp @@ -71,8 +71,8 @@ void WSWindowSwitcher::on_key_event(const WSKeyEvent& event) void WSWindowSwitcher::draw() { Painter painter(*m_switcher_window->backing_store()); - painter.fill_rect({ {}, m_rect.size() }, Color::WarmGray); - painter.draw_rect({ {}, m_rect.size() }, Color::DarkGray); + painter.fill_rect({ {}, m_rect.size() }, SystemColor::Window); + painter.draw_rect({ {}, m_rect.size() }, SystemColor::ThreedShadow2); for (int index = 0; index < m_windows.size(); ++index) { auto& window = *m_windows.at(index); Rect item_rect { @@ -84,12 +84,12 @@ void WSWindowSwitcher::draw() Color text_color; Color rect_text_color; if (index == m_selected_index) { - painter.fill_rect(item_rect, Color::from_rgb(0x84351a)); - text_color = Color::White; - rect_text_color = Color::WarmGray; + painter.fill_rect(item_rect, SystemColor::Selection); + text_color = SystemColor::SelectionText; + rect_text_color = SystemColor::ThreedShadow1; } else { - text_color = Color::Black; - rect_text_color = Color::MidGray; + text_color = SystemColor::WindowText; + rect_text_color = SystemColor::ThreedShadow2; } item_rect.shrink(item_padding(), 0); Rect thumbnail_rect = { item_rect.location().translated(0, 5), { thumbnail_width(), thumbnail_height() } }; @@ -98,7 +98,7 @@ void WSWindowSwitcher::draw() StylePainter::paint_frame(painter, thumbnail_rect.inflated(4, 4), FrameShape::Container, FrameShadow::Sunken, 2); } Rect icon_rect = { thumbnail_rect.bottom_right().translated(-window.icon().width(), -window.icon().height()), { window.icon().width(), window.icon().height() } }; - painter.fill_rect(icon_rect, Color::WarmGray); + painter.fill_rect(icon_rect, SystemColor::Window); painter.blit(icon_rect.location(), window.icon(), window.icon().rect()); painter.draw_text(item_rect.translated(thumbnail_width() + 12, 0), window.title(), WSWindowManager::the().window_title_font(), TextAlignment::CenterLeft, text_color); painter.draw_text(item_rect, window.rect().to_string(), TextAlignment::CenterRight, rect_text_color);