mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 12:19:54 +00:00
LibGfx: Add ImageCursor type and Cursor variant
Besides standard cursors, we also need to support custom images. For now, everything still uses StandardCursor.
This commit is contained in:
parent
6a4a60cbd5
commit
1990b2fc52
Notes:
github-actions[bot]
2025-02-28 12:52:16 +00:00
Author: https://github.com/AtkinsSJ
Commit: 1990b2fc52
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3644
8 changed files with 104 additions and 39 deletions
|
@ -8,6 +8,7 @@ set(SOURCES
|
|||
CMYKBitmap.cpp
|
||||
Color.cpp
|
||||
ColorSpace.cpp
|
||||
Cursor.cpp
|
||||
FontCascadeList.cpp
|
||||
Font/Font.cpp
|
||||
Font/FontData.cpp
|
||||
|
|
40
Libraries/LibGfx/Cursor.cpp
Normal file
40
Libraries/LibGfx/Cursor.cpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibGfx/Cursor.h>
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
bool ImageCursor::operator==(ImageCursor const& other) const
|
||||
{
|
||||
return hotspot == other.hotspot
|
||||
&& bitmap.bitmap() == other.bitmap.bitmap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Gfx::ImageCursor const& image_cursor)
|
||||
{
|
||||
TRY(encoder.encode(image_cursor.bitmap));
|
||||
TRY(encoder.encode(image_cursor.hotspot));
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Gfx::ImageCursor> decode(Decoder& decoder)
|
||||
{
|
||||
Gfx::ImageCursor result;
|
||||
result.bitmap = TRY(decoder.decode<Gfx::ShareableBitmap>());
|
||||
result.hotspot = TRY(decoder.decode<Gfx::IntPoint>());
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
60
Libraries/LibGfx/Cursor.h
Normal file
60
Libraries/LibGfx/Cursor.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Variant.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
|
||||
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<StandardCursor, ImageCursor>;
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder&, Gfx::ImageCursor const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<Gfx::ImageCursor> decode(Decoder&);
|
||||
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* 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,
|
||||
};
|
||||
|
||||
}
|
|
@ -16,13 +16,13 @@
|
|||
#include <AK/Weakable.h>
|
||||
#include <LibGC/Heap.h>
|
||||
#include <LibGC/Root.h>
|
||||
#include <LibGfx/Cursor.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Palette.h>
|
||||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/ShareableBitmap.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <LibGfx/StandardCursor.h>
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/CSS/PreferredColorScheme.h>
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include <AK/String.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibCore/Promise.h>
|
||||
#include <LibGfx/Cursor.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/StandardCursor.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/ActivateTab.h>
|
||||
#include <LibWeb/HTML/AudioPlayState.h>
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <LibGfx/Point.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/Size.h>
|
||||
#include <LibGfx/StandardCursor.h>
|
||||
#include <LibWeb/CSS/PreferredColorScheme.h>
|
||||
#include <LibWeb/CSS/PreferredContrast.h>
|
||||
#include <LibWeb/CSS/PreferredMotion.h>
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#include <AK/ByteString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <LibGfx/Cursor.h>
|
||||
#include <LibGfx/Forward.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibGfx/StandardCursor.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/CSS/PreferredColorScheme.h>
|
||||
#include <LibWeb/CSS/PreferredContrast.h>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue