From f4b8e4966ffa07f250e4952060791b1606aa10f2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 18 Mar 2019 04:53:09 +0100 Subject: [PATCH] SharedGraphics: Add Color::to_string(). This generates a string in the format "rgba(%d, %d, %d, %d)". --- SharedGraphics/Color.cpp | 5 +++++ SharedGraphics/Color.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/SharedGraphics/Color.cpp b/SharedGraphics/Color.cpp index aac4ad2c76..5e4102d2f2 100644 --- a/SharedGraphics/Color.cpp +++ b/SharedGraphics/Color.cpp @@ -25,3 +25,8 @@ Color::Color(NamedColor named) m_value = 0xff000000 | (rgb.r << 16) | (rgb.g << 8) | rgb.b; } + +String Color::to_string() const +{ + return String::format("rgba(%d, %d, %d, %d)", red(), green(), blue(), alpha()); +} diff --git a/SharedGraphics/Color.h b/SharedGraphics/Color.h index eb9ed1ee88..9e4dbb0321 100644 --- a/SharedGraphics/Color.h +++ b/SharedGraphics/Color.h @@ -1,5 +1,6 @@ #pragma once +#include #include typedef dword RGBA32; @@ -66,6 +67,8 @@ public: RGBA32 value() const { return m_value; } + String to_string() const; + private: explicit Color(RGBA32 rgba) : m_value(rgba) { }