소스 검색

LibGfx: Add Color::to_string_without_alpha()

This simply returns an "#rrggbb" string and ignores the alpha value.
Andreas Kling 5 년 전
부모
커밋
17e76b4760
2개의 변경된 파일7개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      Libraries/LibGfx/Color.cpp
  2. 1 0
      Libraries/LibGfx/Color.h

+ 6 - 1
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<Color> parse_rgb_color(const StringView& string)

+ 1 - 0
Libraries/LibGfx/Color.h

@@ -170,6 +170,7 @@ public:
     }
 
     String to_string() const;
+    String to_string_without_alpha() const;
     static Optional<Color> from_string(const StringView&);
 
     HSV to_hsv() const