Size.cpp 922 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. bool decode(Decoder& decoder, Gfx::IntSize& size)
  29. {
  30. int width = 0;
  31. int height = 0;
  32. if (!decoder.decode(width))
  33. return false;
  34. if (!decoder.decode(height))
  35. return false;
  36. size = { width, height };
  37. return true;
  38. }
  39. }
  40. template class Gfx::Size<int>;
  41. template class Gfx::Size<float>;