1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 06:34:57 +00:00

LibGfx: Make FloatPoint compatible with IPC

This commit is contained in:
Lucas CHOLLET 2024-02-14 01:07:55 -05:00 committed by Sam Atkins
parent 41c76e6ba6
commit 8dd887b3c8
2 changed files with 17 additions and 2 deletions

View file

@ -51,14 +51,17 @@ ByteString FloatPoint::to_byte_string() const
namespace IPC {
template<>
ErrorOr<void> encode(Encoder& encoder, Gfx::IntPoint const& point)
template<OneOf<Gfx::IntPoint, Gfx::FloatPoint> Point>
ErrorOr<void> encode(Encoder& encoder, Point const& point)
{
TRY(encoder.encode(point.x()));
TRY(encoder.encode(point.y()));
return {};
}
template ErrorOr<void> encode(Encoder&, Gfx::IntPoint const& point);
template ErrorOr<void> encode(Encoder&, Gfx::FloatPoint const& point);
template<>
ErrorOr<Gfx::IntPoint> decode(Decoder& decoder)
{
@ -67,6 +70,14 @@ ErrorOr<Gfx::IntPoint> decode(Decoder& decoder)
return Gfx::IntPoint { x, y };
}
template<>
ErrorOr<Gfx::FloatPoint> decode(Decoder& decoder)
{
auto x = TRY(decoder.decode<float>());
auto y = TRY(decoder.decode<float>());
return Gfx::FloatPoint { x, y };
}
}
template class Gfx::Point<int>;

View file

@ -306,9 +306,13 @@ namespace IPC {
template<>
ErrorOr<void> encode(Encoder&, Gfx::IntPoint const&);
template<>
ErrorOr<void> encode(Encoder&, Gfx::FloatPoint const&);
template<>
ErrorOr<Gfx::IntPoint> decode(Decoder&);
template<>
ErrorOr<Gfx::FloatPoint> decode(Decoder&);
}