diff options
-rw-r--r-- | Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp | 19 | ||||
-rw-r--r-- | Userland/Applications/MouseSettings/HighlightPreviewWidget.h | 5 |
2 files changed, 22 insertions, 2 deletions
diff --git a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp index 2ee4f852a4..1b467000ae 100644 --- a/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp +++ b/Userland/Applications/MouseSettings/HighlightPreviewWidget.cpp @@ -34,6 +34,17 @@ ErrorOr<void> HighlightPreviewWidget::reload_cursor() auto cursor_path = String::formatted("/res/cursor-themes/{}/{}", cursor_theme, cursor_theme_config->read_entry("Cursor", "Arrow")); m_cursor_bitmap = TRY(load_bitmap(cursor_path, default_cursor_path)); + m_cursor_params = Gfx::CursorParams::parse_from_filename(cursor_path, m_cursor_bitmap->rect().center()).constrained(*m_cursor_bitmap); + // Setup cursor animation: + if (m_cursor_params.frames() > 1 && m_cursor_params.frame_ms() > 0) { + m_frame_timer = Core::Timer::create_repeating(m_cursor_params.frame_ms(), [&] { + m_cursor_frame = (m_cursor_frame + 1) % m_cursor_params.frames(); + update(); + }); + m_frame_timer->start(); + } else { + m_frame_timer = nullptr; + } return {}; } @@ -46,8 +57,12 @@ void HighlightPreviewWidget::paint_preview(GUI::PaintEvent&) highlight_rect.center_within(frame_inner_rect()); aa_painter.fill_ellipse(highlight_rect, m_color); } - if (m_cursor_bitmap) - painter.blit(m_cursor_bitmap->rect().centered_within(frame_inner_rect()).location(), *m_cursor_bitmap, m_cursor_bitmap->rect()); + if (m_cursor_bitmap) { + auto cursor_rect = m_cursor_bitmap->rect(); + if (m_cursor_params.frames() > 1) + cursor_rect.set_width(cursor_rect.width() / m_cursor_params.frames()); + painter.blit(cursor_rect.centered_within(frame_inner_rect()).location(), *m_cursor_bitmap, cursor_rect.translated(m_cursor_frame * cursor_rect.width(), 0)); + } } } diff --git a/Userland/Applications/MouseSettings/HighlightPreviewWidget.h b/Userland/Applications/MouseSettings/HighlightPreviewWidget.h index 01d4b3d5ba..06714f13c8 100644 --- a/Userland/Applications/MouseSettings/HighlightPreviewWidget.h +++ b/Userland/Applications/MouseSettings/HighlightPreviewWidget.h @@ -6,8 +6,10 @@ #pragma once +#include <LibCore/Timer.h> #include <LibGUI/AbstractThemePreview.h> #include <LibGfx/Color.h> +#include <LibGfx/CursorParams.h> namespace MouseSettings { @@ -36,7 +38,10 @@ private: ErrorOr<void> reload_cursor(); RefPtr<Gfx::Bitmap> m_cursor_bitmap; + Gfx::CursorParams m_cursor_params; + RefPtr<Core::Timer> m_frame_timer; + int m_cursor_frame { 0 }; int m_radius { 0 }; Gfx::Color m_color; }; |