Skip to content

Commit

Permalink
Themes: Support rubberband selection theming
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtechnobabble authored and awesomekling committed Jan 7, 2020
1 parent 56a2c21 commit 123dcad
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Base/res/themes/Dark.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ThreedShadow2=#2e2f30
HoverHighlight=#696969
Selection=#14141a
SelectionText=white
RubberBandFill=#8080803c
RubberBandBorder=black
2 changes: 2 additions & 0 deletions Base/res/themes/Default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ThreedShadow2=#404040
HoverHighlight=#e3dfdb
Selection=#84351a
SelectionText=white
RubberBandFill=#f4ca9e3c
RubberBandBorder=#6e2209
2 changes: 2 additions & 0 deletions Base/res/themes/Hotdog Stand.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ThreedShadow2=#909090
HoverHighlight=white
Selection=black
SelectionText=white
RubberBandFill=#fad7653c
RubberBandBorder=#f4ca9e
2 changes: 2 additions & 0 deletions Base/res/themes/Xmas.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ThreedShadow2=#882d26
HoverHighlight=#e6e5e2
Selection=#84351a
SelectionText=white
RubberBandFill=#0466033c
RubberBandBorder=#76943c
4 changes: 2 additions & 2 deletions DevTools/HackStudio/CursorTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ void CursorTool::on_second_paint(GPainter& painter, GPaintEvent&)
if (!m_rubber_banding)
return;
auto rect = rubber_band_rect();
painter.fill_rect(rect, Color(244, 202, 158, 60));
painter.draw_rect(rect, Color(110, 34, 9));
painter.fill_rect(rect, m_editor.palette().rubber_band_fill());
painter.draw_rect(rect, m_editor.palette().rubber_band_border());
}
3 changes: 3 additions & 0 deletions Libraries/LibDraw/Palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ class Palette {
Color threed_shadow1() const { return color(ColorRole::ThreedShadow1); }
Color threed_shadow2() const { return color(ColorRole::ThreedShadow2); }
Color hover_highlight() const { return color(ColorRole::ThreedHighlight); }
Color rubber_band_fill() const { return color(ColorRole::RubberBandFill); }
Color rubber_band_border() const { return color(ColorRole::RubberBandBorder); }

Color color(ColorRole role) const { return m_impl->color(role); }

void set_color(ColorRole, Color);

const SystemTheme& theme() const { return m_impl->theme(); }
Expand Down
8 changes: 5 additions & 3 deletions Libraries/LibDraw/SystemTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)

auto* data = (SystemTheme*)buffer->data();

auto get = [&](auto& name) {
auto get_color = [&](auto& name) {
auto color_string = file->read_entry("Colors", name);
auto color = Color::from_string(color_string);
if (!color.has_value())
return Color(Color::Black);
dbg() << "Parsed system color '" << name << "' = " << color.value();
dbg() << "Parsed system theme color '" << name << "' = " << color.value();
return color.value();
};

#define DO_COLOR(x) \
data->color[(int)ColorRole::x] = get(#x)
data->color[(int)ColorRole::x] = get_color(#x)

DO_COLOR(DesktopBackground);
DO_COLOR(ThreedHighlight);
Expand Down Expand Up @@ -75,6 +75,8 @@ RefPtr<SharedBuffer> load_system_theme(const String& path)
DO_COLOR(MenuBaseText);
DO_COLOR(MenuSelection);
DO_COLOR(MenuSelectionText);
DO_COLOR(RubberBandFill);
DO_COLOR(RubberBandBorder);

buffer->seal();
buffer->share_globally();
Expand Down
2 changes: 2 additions & 0 deletions Libraries/LibDraw/SystemTheme.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ enum class ColorRole {
HoverHighlight,
Selection,
SelectionText,
RubberBandFill,
RubberBandBorder,

__Count,

Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibGUI/GItemView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ void GItemView::second_paint_event(GPaintEvent& event)
painter.add_clip_rect(event.rect());

auto rubber_band_rect = Rect::from_two_points(m_rubber_band_origin, m_rubber_band_current);
painter.fill_rect(rubber_band_rect, Color(244, 202, 158, 60));
painter.draw_rect(rubber_band_rect, Color(110, 34, 9));
painter.fill_rect(rubber_band_rect, parent_widget()->palette().rubber_band_fill());
painter.draw_rect(rubber_band_rect, parent_widget()->palette().rubber_band_border());
}

void GItemView::paint_event(GPaintEvent& event)
Expand Down

0 comments on commit 123dcad

Please sign in to comment.