From 767ff06f56e7fb609f943e2de22fd7db8fbef454 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 7 Feb 2021 16:51:17 +0100 Subject: [PATCH] LibGfx: Make Color(NamedColor) inline and constexpr --- Userland/Libraries/LibGfx/Color.cpp | 85 ------------------ Userland/Libraries/LibGfx/Color.h | 87 ++++++++++++++++++- .../SyntaxHighlighter.cpp} | 0 .../SyntaxHighlighter.h} | 0 4 files changed, 86 insertions(+), 86 deletions(-) rename Userland/Libraries/{LibGUI/JSSyntaxHighlighter.cpp => LibJS/SyntaxHighlighter.cpp} (100%) rename Userland/Libraries/{LibGUI/JSSyntaxHighlighter.h => LibJS/SyntaxHighlighter.h} (100%) diff --git a/Userland/Libraries/LibGfx/Color.cpp b/Userland/Libraries/LibGfx/Color.cpp index f8a0f244f4f..5e4af7a12b7 100644 --- a/Userland/Libraries/LibGfx/Color.cpp +++ b/Userland/Libraries/LibGfx/Color.cpp @@ -38,91 +38,6 @@ namespace Gfx { -Color::Color(NamedColor named) -{ - if (named == Transparent) { - m_value = 0; - return; - } - - struct { - u8 r; - u8 g; - u8 b; - } rgb; - - switch (named) { - case Black: - rgb = { 0, 0, 0 }; - break; - case White: - rgb = { 255, 255, 255 }; - break; - case Red: - rgb = { 255, 0, 0 }; - break; - case Green: - rgb = { 0, 255, 0 }; - break; - case Cyan: - rgb = { 0, 255, 255 }; - break; - case DarkCyan: - rgb = { 0, 127, 127 }; - break; - case MidCyan: - rgb = { 0, 192, 192 }; - break; - case Blue: - rgb = { 0, 0, 255 }; - break; - case Yellow: - rgb = { 255, 255, 0 }; - break; - case Magenta: - rgb = { 255, 0, 255 }; - break; - case DarkGray: - rgb = { 64, 64, 64 }; - break; - case MidGray: - rgb = { 127, 127, 127 }; - break; - case LightGray: - rgb = { 192, 192, 192 }; - break; - case MidGreen: - rgb = { 0, 192, 0 }; - break; - case MidBlue: - rgb = { 0, 0, 192 }; - break; - case MidRed: - rgb = { 192, 0, 0 }; - break; - case MidMagenta: - rgb = { 192, 0, 192 }; - break; - case DarkGreen: - rgb = { 0, 128, 0 }; - break; - case DarkBlue: - rgb = { 0, 0, 128 }; - break; - case DarkRed: - rgb = { 128, 0, 0 }; - break; - case WarmGray: - rgb = { 212, 208, 200 }; - break; - default: - ASSERT_NOT_REACHED(); - break; - } - - m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b; -} - String Color::to_string() const { return String::format("#%02x%02x%02x%02x", red(), green(), blue(), alpha()); diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h index e30cacba6c5..5e5ff85ee62 100644 --- a/Userland/Libraries/LibGfx/Color.h +++ b/Userland/Libraries/LibGfx/Color.h @@ -77,7 +77,7 @@ public: }; constexpr Color() { } - Color(NamedColor); + constexpr Color(NamedColor); constexpr Color(u8 r, u8 g, u8 b) : m_value(0xff000000 | (r << 16) | (g << 8) | b) { @@ -310,6 +310,91 @@ private: RGBA32 m_value { 0 }; }; +inline constexpr Color::Color(NamedColor named) +{ + if (named == Transparent) { + m_value = 0; + return; + } + + struct { + u8 r; + u8 g; + u8 b; + } rgb; + + switch (named) { + case Black: + rgb = { 0, 0, 0 }; + break; + case White: + rgb = { 255, 255, 255 }; + break; + case Red: + rgb = { 255, 0, 0 }; + break; + case Green: + rgb = { 0, 255, 0 }; + break; + case Cyan: + rgb = { 0, 255, 255 }; + break; + case DarkCyan: + rgb = { 0, 127, 127 }; + break; + case MidCyan: + rgb = { 0, 192, 192 }; + break; + case Blue: + rgb = { 0, 0, 255 }; + break; + case Yellow: + rgb = { 255, 255, 0 }; + break; + case Magenta: + rgb = { 255, 0, 255 }; + break; + case DarkGray: + rgb = { 64, 64, 64 }; + break; + case MidGray: + rgb = { 127, 127, 127 }; + break; + case LightGray: + rgb = { 192, 192, 192 }; + break; + case MidGreen: + rgb = { 0, 192, 0 }; + break; + case MidBlue: + rgb = { 0, 0, 192 }; + break; + case MidRed: + rgb = { 192, 0, 0 }; + break; + case MidMagenta: + rgb = { 192, 0, 192 }; + break; + case DarkGreen: + rgb = { 0, 128, 0 }; + break; + case DarkBlue: + rgb = { 0, 0, 128 }; + break; + case DarkRed: + rgb = { 128, 0, 0 }; + break; + case WarmGray: + rgb = { 212, 208, 200 }; + break; + default: + ASSERT_NOT_REACHED(); + break; + } + + m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b; +} + const LogStream& operator<<(const LogStream&, Color); } diff --git a/Userland/Libraries/LibGUI/JSSyntaxHighlighter.cpp b/Userland/Libraries/LibJS/SyntaxHighlighter.cpp similarity index 100% rename from Userland/Libraries/LibGUI/JSSyntaxHighlighter.cpp rename to Userland/Libraries/LibJS/SyntaxHighlighter.cpp diff --git a/Userland/Libraries/LibGUI/JSSyntaxHighlighter.h b/Userland/Libraries/LibJS/SyntaxHighlighter.h similarity index 100% rename from Userland/Libraries/LibGUI/JSSyntaxHighlighter.h rename to Userland/Libraries/LibJS/SyntaxHighlighter.h