mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 08:00:20 +00:00
MouseSettings: Support animated cursors in the highlighting preview
This commit is contained in:
parent
ceab9903cd
commit
3c2c6790df
Notes:
sideshowbarker
2024-07-17 10:19:17 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/3c2c6790df Pull-request: https://github.com/SerenityOS/serenity/pull/14219
2 changed files with 22 additions and 2 deletions
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue