2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2024-10-04 08:19:50 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <andreas@ladybird.org>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2023-12-16 11:19:34 -03:00
|
|
|
#include <AK/ByteString.h>
|
2020-02-14 17:41:10 -03:00
|
|
|
#include <LibGfx/Rect.h>
|
2020-03-29 14:03:13 -03:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-05-12 13:05:43 -03:00
|
|
|
#include <LibIPC/Encoder.h>
|
2019-01-08 23:06:04 -02:00
|
|
|
|
2020-02-06 09:02:38 -03:00
|
|
|
namespace Gfx {
|
|
|
|
|
|
2020-07-26 01:31:47 -03:00
|
|
|
template<>
|
2023-12-16 11:19:34 -03:00
|
|
|
ByteString IntRect::to_byte_string() const
|
2020-02-14 20:58:14 -03:00
|
|
|
{
|
2023-12-16 11:19:34 -03:00
|
|
|
return ByteString::formatted("[{},{} {}x{}]", x(), y(), width(), height());
|
2020-02-14 20:58:14 -03:00
|
|
|
}
|
|
|
|
|
|
2020-07-26 01:31:47 -03:00
|
|
|
template<>
|
2023-12-16 11:19:34 -03:00
|
|
|
ByteString FloatRect::to_byte_string() const
|
2020-02-14 20:58:14 -03:00
|
|
|
{
|
2023-12-16 11:19:34 -03:00
|
|
|
return ByteString::formatted("[{},{} {}x{}]", x(), y(), width(), height());
|
2020-02-14 20:58:14 -03:00
|
|
|
}
|
|
|
|
|
|
2020-02-06 09:02:38 -03:00
|
|
|
}
|
2020-02-15 08:04:35 -03:00
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
|
2022-11-15 13:24:59 -03:00
|
|
|
template<>
|
2023-01-02 01:37:35 -03:00
|
|
|
ErrorOr<void> encode(Encoder& encoder, Gfx::IntRect const& rect)
|
2020-05-12 13:05:43 -03:00
|
|
|
{
|
2023-01-02 01:37:35 -03:00
|
|
|
TRY(encoder.encode(rect.location()));
|
|
|
|
|
TRY(encoder.encode(rect.size()));
|
|
|
|
|
return {};
|
2020-05-12 13:05:43 -03:00
|
|
|
}
|
|
|
|
|
|
2022-11-15 13:24:59 -03:00
|
|
|
template<>
|
2022-12-22 22:40:33 -03:00
|
|
|
ErrorOr<Gfx::IntRect> decode(Decoder& decoder)
|
2020-02-15 08:04:35 -03:00
|
|
|
{
|
2022-12-22 22:40:33 -03:00
|
|
|
auto point = TRY(decoder.decode<Gfx::IntPoint>());
|
|
|
|
|
auto size = TRY(decoder.decode<Gfx::IntSize>());
|
|
|
|
|
return Gfx::IntRect { point, size };
|
2020-02-15 08:04:35 -03:00
|
|
|
}
|
|
|
|
|
|
2026-06-11 18:31:15 -03:00
|
|
|
template<>
|
|
|
|
|
ErrorOr<void> encode(Encoder& encoder, Gfx::FloatRect const& rect)
|
|
|
|
|
{
|
|
|
|
|
TRY(encoder.encode(rect.x()));
|
|
|
|
|
TRY(encoder.encode(rect.y()));
|
|
|
|
|
TRY(encoder.encode(rect.width()));
|
|
|
|
|
TRY(encoder.encode(rect.height()));
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
|
|
|
|
ErrorOr<Gfx::FloatRect> decode(Decoder& decoder)
|
|
|
|
|
{
|
|
|
|
|
auto x = TRY(decoder.decode<float>());
|
|
|
|
|
auto y = TRY(decoder.decode<float>());
|
|
|
|
|
auto width = TRY(decoder.decode<float>());
|
|
|
|
|
auto height = TRY(decoder.decode<float>());
|
|
|
|
|
return Gfx::FloatRect { x, y, width, height };
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 08:04:35 -03:00
|
|
|
}
|
2020-07-26 01:31:47 -03:00
|
|
|
|
|
|
|
|
template class Gfx::Rect<int>;
|
|
|
|
|
template class Gfx::Rect<float>;
|