2021-06-27 17:47:52 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Animation.h"
|
|
|
|
#include "Compositor.h"
|
|
|
|
#include <AK/Badge.h>
|
|
|
|
|
|
|
|
namespace WindowServer {
|
|
|
|
|
|
|
|
Animation::Animation()
|
|
|
|
{
|
|
|
|
Compositor::the().register_animation({}, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
Animation::~Animation()
|
|
|
|
{
|
|
|
|
Compositor::the().unregister_animation({}, *this);
|
|
|
|
}
|
|
|
|
|
2021-06-28 21:38:44 +03:00
|
|
|
void Animation::set_duration(int duration_in_ms)
|
2021-06-27 17:47:52 +03:00
|
|
|
{
|
2021-06-28 21:38:44 +03:00
|
|
|
m_duration = duration_in_ms;
|
2021-06-27 17:47:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::start()
|
|
|
|
{
|
|
|
|
m_running = true;
|
|
|
|
m_timer.start();
|
2021-06-29 02:42:13 +03:00
|
|
|
Compositor::the().animation_started({});
|
2021-06-27 17:47:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::stop()
|
|
|
|
{
|
|
|
|
m_running = false;
|
|
|
|
if (on_stop)
|
|
|
|
on_stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Animation::update(Badge<Compositor>, Gfx::Painter& painter, Screen& screen, Gfx::DisjointRectSet& flush_rects)
|
|
|
|
{
|
|
|
|
int elapsed_ms = m_timer.elapsed();
|
2021-06-28 21:38:44 +03:00
|
|
|
float progress = min((float)elapsed_ms / (float)m_duration, 1.0f);
|
2021-06-27 17:47:52 +03:00
|
|
|
|
|
|
|
if (on_update)
|
|
|
|
on_update(progress, painter, screen, flush_rects);
|
|
|
|
|
|
|
|
if (progress >= 1.0f)
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|