From 34b5ff7c29fbd9f72922710042577aa0d906592b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 15 Feb 2020 00:58:14 +0100 Subject: LibGfx: Move a bunch of LogStream::operator<< to cpp files --- Libraries/LibGfx/ImageDecoder.cpp | 6 ++++++ Libraries/LibGfx/ImageDecoder.h | 2 +- Libraries/LibGfx/Makefile | 5 ++++- Libraries/LibGfx/Painter.h | 1 + Libraries/LibGfx/Point.cpp | 42 +++++++++++++++++++++++++++++++++++++++ Libraries/LibGfx/Point.h | 11 ++++------ Libraries/LibGfx/Rect.cpp | 11 ++++++++++ Libraries/LibGfx/Rect.h | 10 +++------- Libraries/LibGfx/Size.cpp | 42 +++++++++++++++++++++++++++++++++++++++ Libraries/LibGfx/Size.h | 10 +++------- Libraries/LibGfx/Triangle.cpp | 42 +++++++++++++++++++++++++++++++++++++++ Libraries/LibGfx/Triangle.h | 8 +++----- 12 files changed, 162 insertions(+), 28 deletions(-) create mode 100644 Libraries/LibGfx/Point.cpp create mode 100644 Libraries/LibGfx/Size.cpp create mode 100644 Libraries/LibGfx/Triangle.cpp diff --git a/Libraries/LibGfx/ImageDecoder.cpp b/Libraries/LibGfx/ImageDecoder.cpp index 87a9f79ca1..54796b40fa 100644 --- a/Libraries/LibGfx/ImageDecoder.cpp +++ b/Libraries/LibGfx/ImageDecoder.cpp @@ -37,4 +37,10 @@ ImageDecoder::ImageDecoder(const u8* data, size_t size) ImageDecoder::~ImageDecoder() { } + +RefPtr ImageDecoder::bitmap() const +{ + return m_plugin->bitmap(); +} + } diff --git a/Libraries/LibGfx/ImageDecoder.h b/Libraries/LibGfx/ImageDecoder.h index dd3d901173..6feb4e693b 100644 --- a/Libraries/LibGfx/ImageDecoder.h +++ b/Libraries/LibGfx/ImageDecoder.h @@ -57,7 +57,7 @@ public: Size size() const { return m_plugin->size(); } int width() const { return size().width(); } int height() const { return size().height(); } - RefPtr bitmap() const { return m_plugin->bitmap(); } + RefPtr bitmap() const; void set_volatile() { m_plugin->set_volatile(); } [[nodiscard]] bool set_nonvolatile() { return m_plugin->set_nonvolatile(); } diff --git a/Libraries/LibGfx/Makefile b/Libraries/LibGfx/Makefile index 96fc1a064d..e02371bfe9 100644 --- a/Libraries/LibGfx/Makefile +++ b/Libraries/LibGfx/Makefile @@ -10,9 +10,12 @@ OBJS = \ PNGLoader.o \ Painter.o \ Palette.o \ + Point.o \ Rect.o \ + Size.o \ StylePainter.o \ - SystemTheme.o + SystemTheme.o \ + Triangle.o LIBRARY = libgfx.a diff --git a/Libraries/LibGfx/Painter.h b/Libraries/LibGfx/Painter.h index 168c31e5f6..efc2f64ab8 100644 --- a/Libraries/LibGfx/Painter.h +++ b/Libraries/LibGfx/Painter.h @@ -27,6 +27,7 @@ #pragma once #include +#include #include #include #include diff --git a/Libraries/LibGfx/Point.cpp b/Libraries/LibGfx/Point.cpp new file mode 100644 index 0000000000..8a42878dce --- /dev/null +++ b/Libraries/LibGfx/Point.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Gfx { + +String Point::to_string() const +{ + return String::format("[%d,%d]", x(), y()); +} + +const LogStream& operator<<(const LogStream& stream, const Point& value) +{ + return stream << value.to_string(); +} + +} diff --git a/Libraries/LibGfx/Point.h b/Libraries/LibGfx/Point.h index bfc57ca21d..854e442668 100644 --- a/Libraries/LibGfx/Point.h +++ b/Libraries/LibGfx/Point.h @@ -26,8 +26,8 @@ #pragma once -#include -#include +#include +#include #include namespace Gfx { @@ -105,7 +105,7 @@ public: } Point operator+(const Point& other) const { return { m_x + other.m_x, m_y + other.m_y }; } - String to_string() const { return String::format("[%d,%d]", x(), y()); } + String to_string() const; bool is_null() const { return !m_x && !m_y; } @@ -156,9 +156,6 @@ private: int m_y { 0 }; }; -inline const LogStream& operator<<(const LogStream& stream, const Point& value) -{ - return stream << value.to_string(); -} +const LogStream& operator<<(const LogStream&, const Point&); } diff --git a/Libraries/LibGfx/Rect.cpp b/Libraries/LibGfx/Rect.cpp index af663bfc09..7e33576077 100644 --- a/Libraries/LibGfx/Rect.cpp +++ b/Libraries/LibGfx/Rect.cpp @@ -25,6 +25,7 @@ */ #include +#include #include #include @@ -130,4 +131,14 @@ void Rect::align_within(const Rect& other, TextAlignment alignment) } } +String Rect::to_string() const +{ + return String::format("[%d,%d %dx%d]", x(), y(), width(), height()); +} + +const LogStream& operator<<(const LogStream& stream, const Rect& value) +{ + return stream << value.to_string(); +} + } diff --git a/Libraries/LibGfx/Rect.h b/Libraries/LibGfx/Rect.h index 103df2b8ec..968208516f 100644 --- a/Libraries/LibGfx/Rect.h +++ b/Libraries/LibGfx/Rect.h @@ -26,8 +26,7 @@ #pragma once -#include -#include +#include #include #include #include @@ -313,7 +312,7 @@ public: set_y(other.center().y() - height() / 2); } - String to_string() const { return String::format("[%d,%d %dx%d]", x(), y(), width(), height()); } + String to_string() const; private: Point m_location; @@ -332,9 +331,6 @@ inline void Point::constrain(const Rect& rect) set_y(rect.bottom()); } -inline const LogStream& operator<<(const LogStream& stream, const Rect& value) -{ - return stream << value.to_string(); -} +const LogStream& operator<<(const LogStream&, const Rect&); } diff --git a/Libraries/LibGfx/Size.cpp b/Libraries/LibGfx/Size.cpp new file mode 100644 index 0000000000..1c278d7306 --- /dev/null +++ b/Libraries/LibGfx/Size.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, Andreas Kling + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Gfx { + +String Size::to_string() const +{ + return String::format("[%dx%d]", m_width, m_height); +} + +const LogStream& operator<<(const LogStream& stream, const Size& value) +{ + return stream << value.to_string(); +} + +} diff --git a/Libraries/LibGfx/Size.h b/Libraries/LibGfx/Size.h index fbb9cc0a2a..c228ffe6a3 100644 --- a/Libraries/LibGfx/Size.h +++ b/Libraries/LibGfx/Size.h @@ -26,8 +26,7 @@ #pragma once -#include -#include +#include #include namespace Gfx { @@ -102,16 +101,13 @@ public: set_height(value); } - String to_string() const { return String::format("[%dx%d]", m_width, m_height); } + String to_string() const; private: int m_width { 0 }; int m_height { 0 }; }; -inline const LogStream& operator<<(const LogStream& stream, const Size& value) -{ - return stream << value.to_string(); -} +const LogStream& operator<<(const LogStream&, const Size&); } diff --git a/Libraries/LibGfx/Triangle.cpp b/Libraries/LibGfx/Triangle.cpp new file mode 100644 index 0000000000..d36ad50f0f --- /dev/null +++ b/Libraries/LibGfx/Triangle.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, Shannon Booth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +namespace Gfx { + +String Triangle::to_string() const +{ + return String::format("(%s,%s,%s)", m_a.to_string().characters(), m_b.to_string().characters(), m_c.to_string().characters()); +} + +const LogStream& operator<<(const LogStream& stream, const Triangle& value) +{ + return stream << value.to_string(); +} + +} diff --git a/Libraries/LibGfx/Triangle.h b/Libraries/LibGfx/Triangle.h index 3974f655a6..72a566a08f 100644 --- a/Libraries/LibGfx/Triangle.h +++ b/Libraries/LibGfx/Triangle.h @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include namespace Gfx { @@ -64,7 +65,7 @@ public: return true; } - String to_string() const { return String::format("(%s,%s,%s)", m_a.to_string().characters(), m_b.to_string().characters(), m_c.to_string().characters()); } + String to_string() const; private: int m_det; @@ -73,9 +74,6 @@ private: Point m_c; }; -inline const LogStream& operator<<(const LogStream& stream, const Triangle& value) -{ - return stream << value.to_string(); -} +const LogStream& operator<<(const LogStream&, const Triangle&); } -- cgit v1.2.3