mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +00:00
WindowServer: Fix animated cursor regression
This commit is contained in:
parent
e79ef6461a
commit
08e2dc22be
2 changed files with 12 additions and 6 deletions
|
@ -106,6 +106,11 @@ Cursor::Cursor(NonnullRefPtr<Gfx::Bitmap>&& bitmap, int scale_factor, const Curs
|
||||||
, m_rect(bitmap->rect())
|
, m_rect(bitmap->rect())
|
||||||
{
|
{
|
||||||
m_bitmaps.set(scale_factor, move(bitmap));
|
m_bitmaps.set(scale_factor, move(bitmap));
|
||||||
|
update_rect_if_animated();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Cursor::update_rect_if_animated()
|
||||||
|
{
|
||||||
if (m_params.frames() > 1) {
|
if (m_params.frames() > 1) {
|
||||||
VERIFY(m_rect.width() % m_params.frames() == 0);
|
VERIFY(m_rect.width() % m_params.frames() == 0);
|
||||||
m_rect.set_width(m_rect.width() / m_params.frames());
|
m_rect.set_width(m_rect.width() / m_params.frames());
|
||||||
|
@ -129,17 +134,11 @@ RefPtr<Cursor> Cursor::create(const StringView& filename, const StringView& defa
|
||||||
bool Cursor::load(const StringView& filename, const StringView& default_filename)
|
bool Cursor::load(const StringView& filename, const StringView& default_filename)
|
||||||
{
|
{
|
||||||
bool did_load_any = false;
|
bool did_load_any = false;
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
auto load_bitmap = [&](const StringView& path, int scale_factor) {
|
auto load_bitmap = [&](const StringView& path, int scale_factor) {
|
||||||
auto bitmap = Gfx::Bitmap::load_from_file(path, scale_factor);
|
auto bitmap = Gfx::Bitmap::load_from_file(path, scale_factor);
|
||||||
if (bitmap) {
|
if (bitmap) {
|
||||||
did_load_any = true;
|
did_load_any = true;
|
||||||
if (first) {
|
|
||||||
m_params = CursorParams::parse_from_filename(filename, bitmap->rect().center());
|
|
||||||
m_rect = bitmap->rect();
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
m_bitmaps.set(scale_factor, bitmap.release_nonnull());
|
m_bitmaps.set(scale_factor, bitmap.release_nonnull());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -154,6 +153,12 @@ bool Cursor::load(const StringView& filename, const StringView& default_filename
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (did_load_any) {
|
||||||
|
auto& bitmap = this->bitmap(1);
|
||||||
|
m_rect = bitmap.rect();
|
||||||
|
m_params = CursorParams::parse_from_filename(filename, m_rect.center()).constrained(bitmap);
|
||||||
|
update_rect_if_animated();
|
||||||
|
}
|
||||||
return did_load_any;
|
return did_load_any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
Cursor(NonnullRefPtr<Gfx::Bitmap>&&, int, const CursorParams&);
|
Cursor(NonnullRefPtr<Gfx::Bitmap>&&, int, const CursorParams&);
|
||||||
|
|
||||||
bool load(const StringView&, const StringView&);
|
bool load(const StringView&, const StringView&);
|
||||||
|
void update_rect_if_animated();
|
||||||
|
|
||||||
HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps;
|
HashMap<int, NonnullRefPtr<Gfx::Bitmap>> m_bitmaps;
|
||||||
CursorParams m_params;
|
CursorParams m_params;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue