1
1
/*
2
2
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
3
+ * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
3
4
*
4
5
* SPDX-License-Identifier: BSD-2-Clause
5
6
*/
@@ -84,6 +85,8 @@ PreviewWidget::PreviewWidget(const Gfx::Palette& preview_palette)
84
85
m_maximize_bitmap = Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/upward-triangle.png" );
85
86
m_minimize_bitmap = Gfx::Bitmap::try_load_from_file (" /res/icons/16x16/downward-triangle.png" );
86
87
88
+ load_theme_bitmaps ();
89
+
87
90
m_gallery = add<MiniWidgetGallery>();
88
91
set_greedy_for_hits (true );
89
92
}
@@ -92,10 +95,33 @@ PreviewWidget::~PreviewWidget()
92
95
{
93
96
}
94
97
98
+ void PreviewWidget::load_theme_bitmaps ()
99
+ {
100
+ auto load_bitmap = [](String const & path, String& last_path, RefPtr<Gfx::Bitmap>& bitmap) {
101
+ if (path.is_empty ()) {
102
+ last_path = String::empty ();
103
+ bitmap = nullptr ;
104
+ } else if (last_path != path) {
105
+ bitmap = Gfx::Bitmap::try_load_from_file (path);
106
+ if (bitmap)
107
+ last_path = path;
108
+ else
109
+ last_path = String::empty ();
110
+ }
111
+ };
112
+
113
+ load_bitmap (m_preview_palette.active_window_shadow_path (), m_last_active_window_shadow_path, m_active_window_shadow);
114
+ load_bitmap (m_preview_palette.inactive_window_shadow_path (), m_last_inactive_window_shadow_path, m_inactive_window_shadow);
115
+ load_bitmap (m_preview_palette.menu_shadow_path (), m_last_menu_shadow_path, m_menu_shadow);
116
+ load_bitmap (m_preview_palette.taskbar_shadow_path (), m_last_taskbar_shadow_path, m_taskbar_shadow);
117
+ load_bitmap (m_preview_palette.tooltip_shadow_path (), m_last_tooltip_shadow_path, m_tooltip_shadow);
118
+ }
119
+
95
120
void PreviewWidget::set_preview_palette (const Gfx::Palette& palette)
96
121
{
97
122
m_preview_palette = palette;
98
123
m_gallery->set_preview_palette (palette);
124
+ load_theme_bitmaps ();
99
125
update ();
100
126
}
101
127
@@ -139,14 +165,27 @@ void PreviewWidget::paint_event(GUI::PaintEvent& event)
139
165
140
166
for (auto & button : buttons) {
141
167
pos -= window_button_width;
142
- Gfx::IntRect rect { pos, 0 , window_button_width, window_button_height };
143
- rect .center_vertically_within (titlebar_text_rect);
144
- button.rect = rect ;
168
+ Gfx::IntRect button_rect { pos, 0 , window_button_width, window_button_height };
169
+ button_rect .center_vertically_within (titlebar_text_rect);
170
+ button.rect = button_rect ;
145
171
}
146
172
147
173
painter.fill_rect (rect, m_preview_palette.window ());
148
174
149
175
auto frame_rect = Gfx::WindowTheme::current ().frame_rect_for_window (Gfx::WindowTheme::WindowType::Normal, rect, m_preview_palette, 0 );
176
+
177
+ auto paint_shadow = [](Gfx::Painter& painter, Gfx::IntRect& frame_rect, Gfx::Bitmap const & shadow_bitmap) {
178
+ auto total_shadow_size = shadow_bitmap.height ();
179
+ auto shadow_rect = frame_rect.inflated (total_shadow_size, total_shadow_size);
180
+ Gfx::StylePainter::paint_simple_rect_shadow (painter, shadow_rect, shadow_bitmap);
181
+ };
182
+
183
+ if (state == Gfx::WindowTheme::WindowState::Active && m_active_window_shadow) {
184
+ paint_shadow (painter, frame_rect, *m_active_window_shadow);
185
+ } else if (state == Gfx::WindowTheme::WindowState::Inactive && m_inactive_window_shadow) {
186
+ paint_shadow (painter, frame_rect, *m_inactive_window_shadow);
187
+ }
188
+
150
189
Gfx::PainterStateSaver saver (painter);
151
190
painter.translate (frame_rect.location ());
152
191
Gfx::WindowTheme::current ().paint_normal_frame (painter, state, rect, title, icon, m_preview_palette, buttons.last ().rect , 0 , false );
0 commit comments