2020-02-14 23:58:14 +00:00
|
|
|
/*
|
2021-06-16 17:21:42 +00:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-02-14 23:58:14 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-02-14 23:58:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <AK/String.h>
|
|
|
|
#include <LibGfx/Size.h>
|
2020-03-29 17:03:13 +00:00
|
|
|
#include <LibIPC/Decoder.h>
|
2020-05-12 16:05:43 +00:00
|
|
|
#include <LibIPC/Encoder.h>
|
2020-02-14 23:58:14 +00:00
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
2020-07-26 04:31:47 +00:00
|
|
|
template<>
|
2020-06-10 08:57:59 +00:00
|
|
|
String IntSize::to_string() const
|
2020-02-14 23:58:14 +00:00
|
|
|
{
|
2021-01-03 14:26:47 +00:00
|
|
|
return String::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 23:58:14 +00:00
|
|
|
}
|
|
|
|
|
2020-07-26 04:31:47 +00:00
|
|
|
template<>
|
|
|
|
String FloatSize::to_string() const
|
2020-02-14 23:58:14 +00:00
|
|
|
{
|
2021-01-03 14:26:47 +00:00
|
|
|
return String::formatted("[{}x{}]", m_width, m_height);
|
2020-02-14 23:58:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-02-15 11:04:35 +00:00
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
|
2021-06-16 17:20:35 +00:00
|
|
|
bool encode(Encoder& encoder, Gfx::IntSize const& size)
|
2020-05-12 16:05:43 +00:00
|
|
|
{
|
|
|
|
encoder << size.width() << size.height();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-11-28 10:56:31 +00:00
|
|
|
ErrorOr<void> decode(Decoder& decoder, Gfx::IntSize& size)
|
2020-02-15 11:04:35 +00:00
|
|
|
{
|
2020-02-23 00:32:00 +00:00
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2021-11-28 10:56:31 +00:00
|
|
|
TRY(decoder.decode(width));
|
|
|
|
TRY(decoder.decode(height));
|
2020-02-15 11:04:35 +00:00
|
|
|
size = { width, height };
|
2021-11-28 10:56:31 +00:00
|
|
|
return {};
|
2020-02-15 11:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-07-26 04:31:47 +00:00
|
|
|
|
|
|
|
template class Gfx::Size<int>;
|
|
|
|
template class Gfx::Size<float>;
|