Size.cpp 950 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/ByteString.h>
  7. #include <LibGfx/Size.h>
  8. #include <LibIPC/Decoder.h>
  9. #include <LibIPC/Encoder.h>
  10. namespace Gfx {
  11. template<>
  12. ByteString IntSize::to_byte_string() const
  13. {
  14. return ByteString::formatted("[{}x{}]", m_width, m_height);
  15. }
  16. template<>
  17. ByteString FloatSize::to_byte_string() const
  18. {
  19. return ByteString::formatted("[{}x{}]", m_width, m_height);
  20. }
  21. }
  22. namespace IPC {
  23. template<>
  24. ErrorOr<void> encode(Encoder& encoder, Gfx::IntSize const& size)
  25. {
  26. TRY(encoder.encode(size.width()));
  27. TRY(encoder.encode(size.height()));
  28. return {};
  29. }
  30. template<>
  31. ErrorOr<Gfx::IntSize> decode(Decoder& decoder)
  32. {
  33. auto width = TRY(decoder.decode<int>());
  34. auto height = TRY(decoder.decode<int>());
  35. return Gfx::IntSize { width, height };
  36. }
  37. }
  38. template class Gfx::Size<int>;
  39. template class Gfx::Size<float>;