From 17e76b47608a4b229e7315ec94f44293b24ac93d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 29 Apr 2020 15:31:45 +0200 Subject: LibGfx: Add Color::to_string_without_alpha() This simply returns an "#rrggbb" string and ignores the alpha value. --- Libraries/LibGfx/Color.cpp | 7 ++++++- Libraries/LibGfx/Color.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'Libraries') diff --git a/Libraries/LibGfx/Color.cpp b/Libraries/LibGfx/Color.cpp index 01bb3988d4..1e6d888f95 100644 --- a/Libraries/LibGfx/Color.cpp +++ b/Libraries/LibGfx/Color.cpp @@ -119,7 +119,12 @@ Color::Color(NamedColor named) String Color::to_string() const { - return String::format("#%b%b%b%b", red(), green(), blue(), alpha()); + return String::format("#%02x%02x%02x%02x", red(), green(), blue(), alpha()); +} + +String Color::to_string_without_alpha() const +{ + return String::format("#%02x%02x%02x", red(), green(), blue()); } static Optional parse_rgb_color(const StringView& string) diff --git a/Libraries/LibGfx/Color.h b/Libraries/LibGfx/Color.h index 490b3d7249..f1601aa8df 100644 --- a/Libraries/LibGfx/Color.h +++ b/Libraries/LibGfx/Color.h @@ -170,6 +170,7 @@ public: } String to_string() const; + String to_string_without_alpha() const; static Optional from_string(const StringView&); HSV to_hsv() const -- cgit v1.2.3