1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:27:46 +00:00

WindowServer+LibGUI: Yank out window-global opacity

From what I can tell, this facility was added to WSWindow/GWindow in
2019 in 9b71307. I only found a single place in the codebase still using
this facility: `WindowServer::Menu::start_activation_animation()`. A
subtle fade-out animation that happens when a menu item is selected, and
the menu disappears.
I think our compositing facilities have improved enough to make this
facility redundant. The remaining use mentioned above was ported to just
directly blit the fade-out animation instead of requesting it from
WindowServer.
This commit is contained in:
Valtteri Koskivuori 2023-06-21 23:16:26 +03:00 committed by Jelle Raaijmakers
parent 4fd71e3c3a
commit 6931a5a0a8
9 changed files with 18 additions and 70 deletions

View file

@ -501,7 +501,7 @@ void Menu::start_activation_animation(MenuItem& item)
auto window = Window::construct(*this, WindowType::Menu);
window->set_frameless(true);
window->set_hit_testing_enabled(false);
window->set_opacity(0.8f); // start out transparent so we don't have to recompute occlusions
window->set_has_alpha_channel(true);
window->set_rect(item.rect().translated(m_menu_window->rect().location()));
window->set_event_filter([](Core::Event&) {
// ignore all events
@ -509,8 +509,11 @@ void Menu::start_activation_animation(MenuItem& item)
});
VERIFY(window->backing_store());
NonnullRefPtr<Gfx::Bitmap> original_bitmap = *menu_window()->backing_store();
Gfx::IntRect item_rect = item.rect();
Gfx::Painter painter(*window->backing_store());
painter.blit({}, *menu_window()->backing_store(), item.rect(), 1.0f, false);
painter.blit({}, original_bitmap, item_rect, 0.8f, true); // start out transparent so we don't have to recompute occlusions
window->invalidate();
struct AnimationInfo {
@ -525,7 +528,7 @@ void Menu::start_activation_animation(MenuItem& item)
};
auto animation = adopt_own(*new AnimationInfo(move(window)));
auto& timer = animation->timer;
timer = Core::Timer::create_repeating(50, [animation = animation.ptr(), animation_ref = move(animation)] {
timer = Core::Timer::create_repeating(50, [animation = animation.ptr(), animation_ref = move(animation), original_bitmap, item_rect] {
VERIFY(animation->step % 2 == 0);
animation->step -= 2;
if (animation->step == 0) {
@ -536,7 +539,10 @@ void Menu::start_activation_animation(MenuItem& item)
}
float opacity = (float)animation->step / 10.0f;
animation->window->set_opacity(opacity);
Gfx::Painter painter(*animation->window->backing_store());
painter.clear_rect({ {}, animation->window->rect().size() }, Color::Transparent);
painter.blit({}, original_bitmap, item_rect, opacity, true);
animation->window->invalidate();
}).release_value_but_fixme_should_propagate_errors();
timer->start();
}