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