ladybird/Userland/Libraries/LibGfx/Rect.cpp
Sam Atkins 732aa2c5c7 LibGfx: Make Rect<T> methods work when T is not int or float
Putting the implementations in the .cpp file meant that they only
existed for `IntRect` and `FloatRect`, since those were instantiated at
the bottom of the file. Now they work for other types. :^)

A couple of places in WindowServer had to be modified to disambiguate
between the two `Rect::intersected()` overloads.

Co-authored-by: davidot <davidot@serenityos.org>
2022-10-22 18:17:58 +02:00

52 lines
1,000 B
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/StdLibExtras.h>
#include <AK/String.h>
#include <AK/Vector.h>
#include <LibGfx/Line.h>
#include <LibGfx/Rect.h>
#include <LibIPC/Decoder.h>
#include <LibIPC/Encoder.h>
namespace Gfx {
template<>
String IntRect::to_string() const
{
return String::formatted("[{},{} {}x{}]", x(), y(), width(), height());
}
template<>
String FloatRect::to_string() const
{
return String::formatted("[{},{} {}x{}]", x(), y(), width(), height());
}
}
namespace IPC {
bool encode(Encoder& encoder, Gfx::IntRect const& rect)
{
encoder << rect.location() << rect.size();
return true;
}
ErrorOr<void> decode(Decoder& decoder, Gfx::IntRect& rect)
{
Gfx::IntPoint point;
Gfx::IntSize size;
TRY(decoder.decode(point));
TRY(decoder.decode(size));
rect = { point, size };
return {};
}
}
template class Gfx::Rect<int>;
template class Gfx::Rect<float>;