From 1990b2fc52aea51e15b5e165680a53ee3d037004 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 17 Feb 2025 15:49:05 +0000 Subject: [PATCH] LibGfx: Add ImageCursor type and Cursor variant Besides standard cursors, we also need to support custom images. For now, everything still uses StandardCursor. --- Libraries/LibGfx/CMakeLists.txt | 1 + Libraries/LibGfx/Cursor.cpp | 40 ++++++++++++++ Libraries/LibGfx/Cursor.h | 60 +++++++++++++++++++++ Libraries/LibGfx/StandardCursor.h | 35 ------------ Libraries/LibWeb/Page/Page.h | 2 +- Libraries/LibWebView/ViewImplementation.h | 2 +- UI/AppKit/Interface/LadybirdWebViewBridge.h | 1 - UI/Qt/WebContentView.h | 2 +- 8 files changed, 104 insertions(+), 39 deletions(-) create mode 100644 Libraries/LibGfx/Cursor.cpp create mode 100644 Libraries/LibGfx/Cursor.h delete mode 100644 Libraries/LibGfx/StandardCursor.h diff --git a/Libraries/LibGfx/CMakeLists.txt b/Libraries/LibGfx/CMakeLists.txt index b8feb18e36f..5a2ff475dd4 100644 --- a/Libraries/LibGfx/CMakeLists.txt +++ b/Libraries/LibGfx/CMakeLists.txt @@ -8,6 +8,7 @@ set(SOURCES CMYKBitmap.cpp Color.cpp ColorSpace.cpp + Cursor.cpp FontCascadeList.cpp Font/Font.cpp Font/FontData.cpp diff --git a/Libraries/LibGfx/Cursor.cpp b/Libraries/LibGfx/Cursor.cpp new file mode 100644 index 00000000000..e7df96a8a38 --- /dev/null +++ b/Libraries/LibGfx/Cursor.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2025, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Gfx { + +bool ImageCursor::operator==(ImageCursor const& other) const +{ + return hotspot == other.hotspot + && bitmap.bitmap() == other.bitmap.bitmap(); +} + +} + +namespace IPC { + +template<> +ErrorOr encode(Encoder& encoder, Gfx::ImageCursor const& image_cursor) +{ + TRY(encoder.encode(image_cursor.bitmap)); + TRY(encoder.encode(image_cursor.hotspot)); + return {}; +} + +template<> +ErrorOr decode(Decoder& decoder) +{ + Gfx::ImageCursor result; + result.bitmap = TRY(decoder.decode()); + result.hotspot = TRY(decoder.decode()); + return result; +} + +} diff --git a/Libraries/LibGfx/Cursor.h b/Libraries/LibGfx/Cursor.h new file mode 100644 index 00000000000..834390961f3 --- /dev/null +++ b/Libraries/LibGfx/Cursor.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2025, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Gfx { + +enum class StandardCursor { + None = 0, + Hidden, + Arrow, + Crosshair, + IBeam, + ResizeHorizontal, + ResizeVertical, + ResizeDiagonalTLBR, + ResizeDiagonalBLTR, + ResizeColumn, + ResizeRow, + Hand, + Help, + Drag, + DragCopy, + Move, + Wait, + Disallowed, + Eyedropper, + Zoom, + __Count, +}; + +struct ImageCursor { + ShareableBitmap bitmap; + IntPoint hotspot; + + bool operator==(ImageCursor const& other) const; +}; + +using Cursor = Variant; + +} + +namespace IPC { + +template<> +ErrorOr encode(Encoder&, Gfx::ImageCursor const&); + +template<> +ErrorOr decode(Decoder&); + +} diff --git a/Libraries/LibGfx/StandardCursor.h b/Libraries/LibGfx/StandardCursor.h deleted file mode 100644 index 3635f079b5e..00000000000 --- a/Libraries/LibGfx/StandardCursor.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2018-2020, Andreas Kling - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -namespace Gfx { - -enum class StandardCursor { - None = 0, - Hidden, - Arrow, - Crosshair, - IBeam, - ResizeHorizontal, - ResizeVertical, - ResizeDiagonalTLBR, - ResizeDiagonalBLTR, - ResizeColumn, - ResizeRow, - Hand, - Help, - Drag, - DragCopy, - Move, - Wait, - Disallowed, - Eyedropper, - Zoom, - __Count, -}; - -} diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h index 55a34cdc05b..764aedc84cb 100644 --- a/Libraries/LibWeb/Page/Page.h +++ b/Libraries/LibWeb/Page/Page.h @@ -16,13 +16,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.h index 8fb77e9b3d4..9a85d2d0bfe 100644 --- a/Libraries/LibWebView/ViewImplementation.h +++ b/Libraries/LibWebView/ViewImplementation.h @@ -16,8 +16,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/UI/AppKit/Interface/LadybirdWebViewBridge.h b/UI/AppKit/Interface/LadybirdWebViewBridge.h index a6760034863..2d9f418192d 100644 --- a/UI/AppKit/Interface/LadybirdWebViewBridge.h +++ b/UI/AppKit/Interface/LadybirdWebViewBridge.h @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/UI/Qt/WebContentView.h b/UI/Qt/WebContentView.h index 377c32a0df3..292753e26ff 100644 --- a/UI/Qt/WebContentView.h +++ b/UI/Qt/WebContentView.h @@ -10,9 +10,9 @@ #include #include #include +#include #include #include -#include #include #include #include