1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 23:27:35 +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 { namespace IPC {
template<> template<OneOf<Gfx::IntPoint, Gfx::FloatPoint> Point>
ErrorOr<void> encode(Encoder& encoder, Gfx::IntPoint const& point) ErrorOr<void> encode(Encoder& encoder, Point const& point)
{ {
TRY(encoder.encode(point.x())); TRY(encoder.encode(point.x()));
TRY(encoder.encode(point.y())); TRY(encoder.encode(point.y()));
return {}; return {};
} }
template ErrorOr<void> encode(Encoder&, Gfx::IntPoint const& point);
template ErrorOr<void> encode(Encoder&, Gfx::FloatPoint const& point);
template<> template<>
ErrorOr<Gfx::IntPoint> decode(Decoder& decoder) ErrorOr<Gfx::IntPoint> decode(Decoder& decoder)
{ {
@ -67,6 +70,14 @@ ErrorOr<Gfx::IntPoint> decode(Decoder& decoder)
return Gfx::IntPoint { x, y }; 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>; template class Gfx::Point<int>;

View file

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