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

WindowServer: Add a more generic mechanism for animations

This patch adds the WindowServer::Animation class, which represents
a simple animation driven by the compositor.

An animation has a length (in milliseconds) and two hooks:

- on_update: called whenever the animation should render something.
- on_stop: called when the animation is finished and/or stopped.

This patch also ports the window minimization animation to this new
mechanism. :^)
This commit is contained in:
Andreas Kling 2021-06-27 16:47:52 +02:00
parent 1f33c517df
commit 75f870a93f
7 changed files with 171 additions and 70 deletions

View file

@ -0,0 +1,48 @@
/*
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Forward.h>
#include <AK/Function.h>
#include <AK/NonnullRefPtr.h>
#include <AK/RefCounted.h>
#include <LibCore/ElapsedTimer.h>
#include <LibGfx/Forward.h>
namespace WindowServer {
class Compositor;
class Screen;
class Animation : public RefCounted<Animation> {
public:
static NonnullRefPtr<Animation> create() { return adopt_ref(*new Animation); }
~Animation();
bool is_running() const { return m_running; }
void start();
void stop();
void set_length(int length_in_ms);
int length() const { return m_length; }
void update(Badge<Compositor>, Gfx::Painter&, Screen&, Gfx::DisjointRectSet& flush_rects);
Function<void(float progress, Gfx::Painter&, Screen&, Gfx::DisjointRectSet& flush_rects)> on_update;
Function<void()> on_stop;
private:
Animation();
Core::ElapsedTimer m_timer;
int m_length { 0 };
bool m_running { false };
};
}