Rect.cpp 1022 B

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