Size.cpp 885 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/String.h>
  7. #include <LibGfx/Size.h>
  8. #include <LibIPC/Decoder.h>
  9. #include <LibIPC/Encoder.h>
  10. namespace Gfx {
  11. template<>
  12. String IntSize::to_string() const
  13. {
  14. return String::formatted("[{}x{}]", m_width, m_height);
  15. }
  16. template<>
  17. String FloatSize::to_string() const
  18. {
  19. return String::formatted("[{}x{}]", m_width, m_height);
  20. }
  21. }
  22. namespace IPC {
  23. bool encode(Encoder& encoder, Gfx::IntSize const& size)
  24. {
  25. encoder << size.width() << size.height();
  26. return true;
  27. }
  28. ErrorOr<void> decode(Decoder& decoder, Gfx::IntSize& size)
  29. {
  30. int width = 0;
  31. int height = 0;
  32. TRY(decoder.decode(width));
  33. TRY(decoder.decode(height));
  34. size = { width, height };
  35. return {};
  36. }
  37. }
  38. template class Gfx::Size<int>;
  39. template class Gfx::Size<float>;