Rect.cpp 1.0 KB

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