summaryrefslogtreecommitdiff
path: root/Userland/Demos/WidgetGallery/GalleryModels.h
diff options
context:
space:
mode:
authorKarol Kosek <krkk@serenityos.org>2021-09-19 23:51:41 +0200
committerAndreas Kling <kling@serenityos.org>2021-09-20 15:59:34 +0200
commitbcfb07bc303e3f3a25318f6f76ab1f70db005dad (patch)
tree85797f4c6f2f017a4d2f7a4c8f2b9b5f538d9ec4 /Userland/Demos/WidgetGallery/GalleryModels.h
parentd1846867cd1c8c477afc723b3a6e6705e0915aa3 (diff)
downloadserenity-bcfb07bc303e3f3a25318f6f76ab1f70db005dad.zip
WidgetGallery: Crop animated cursors
Selecting the wait cursor displayed the full sprite image. This has been borrowed from the MouseSettings.
Diffstat (limited to 'Userland/Demos/WidgetGallery/GalleryModels.h')
-rw-r--r--Userland/Demos/WidgetGallery/GalleryModels.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/Userland/Demos/WidgetGallery/GalleryModels.h b/Userland/Demos/WidgetGallery/GalleryModels.h
index b810093d86..ad457d625a 100644
--- a/Userland/Demos/WidgetGallery/GalleryModels.h
+++ b/Userland/Demos/WidgetGallery/GalleryModels.h
@@ -12,6 +12,7 @@
#include <LibCore/DirIterator.h>
#include <LibGUI/Model.h>
#include <LibGUI/WindowServerConnection.h>
+#include <LibGfx/CursorParams.h>
class MouseCursorModel final : public GUI::Model {
public:
@@ -69,8 +70,15 @@ public:
continue;
Cursor cursor;
cursor.path = move(path);
- cursor.bitmap = Gfx::Bitmap::try_load_from_file(cursor.path);
cursor.name = LexicalPath::basename(cursor.path);
+
+ // FIXME: Animated cursor bitmaps
+ auto cursor_bitmap = Gfx::Bitmap::try_load_from_file(cursor.path);
+ auto cursor_bitmap_rect = cursor_bitmap->rect();
+
+ cursor.params = Gfx::CursorParams::parse_from_filename(cursor.name, cursor_bitmap_rect.center()).constrained(*cursor_bitmap);
+ cursor.bitmap = cursor_bitmap->cropped(Gfx::IntRect(Gfx::FloatRect(cursor_bitmap_rect).scaled(1.0 / cursor.params.frames(), 1.0)));
+
m_cursors.append(move(cursor));
}
@@ -84,6 +92,7 @@ private:
RefPtr<Gfx::Bitmap> bitmap;
String path;
String name;
+ Gfx::CursorParams params;
};
Vector<Cursor> m_cursors;