aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2021-05-10 20:06:05 +0800
committercrupest <crupest@outlook.com>2021-05-10 20:06:05 +0800
commit704289ff1f487989138e85ebe8a77e92cdf30e14 (patch)
tree9585ef1147159df3d28717b35177a9b95ac8528a
parent32e7c37fdf831de5b3c7f2acbbadd697989f0fab (diff)
downloadcru-704289ff1f487989138e85ebe8a77e92cdf30e14.tar.gz
cru-704289ff1f487989138e85ebe8a77e92cdf30e14.tar.bz2
cru-704289ff1f487989138e85ebe8a77e92cdf30e14.zip
...
-rw-r--r--include/cru/platform/Color.hpp4
-rw-r--r--src/platform/Color.cpp14
2 files changed, 9 insertions, 9 deletions
diff --git a/include/cru/platform/Color.hpp b/include/cru/platform/Color.hpp
index efa02848..530695b2 100644
--- a/include/cru/platform/Color.hpp
+++ b/include/cru/platform/Color.hpp
@@ -20,8 +20,8 @@ struct Color {
constexpr static Color FromHexAlpha(std::uint32_t hex) {
const std::uint32_t mask = 0b11111111;
- return Color((hex >> 16) & mask, (hex >> 8) & mask, hex & mask,
- (hex >> 24) & mask);
+ return Color((hex >> 24) & mask, (hex >> 16) & mask, (hex >> 8) & mask,
+ hex & mask);
}
constexpr Color WithAlpha(std::uint8_t new_alpha) const {
diff --git a/src/platform/Color.cpp b/src/platform/Color.cpp
index d1c60217..fe512715 100644
--- a/src/platform/Color.cpp
+++ b/src/platform/Color.cpp
@@ -19,10 +19,10 @@ std::string Color::ToUtf8String() const {
};
std::string result = "#";
- result.append(to_two_hex_digit(alpha));
result.append(to_two_hex_digit(red));
result.append(to_two_hex_digit(green));
result.append(to_two_hex_digit(blue));
+ result.append(to_two_hex_digit(alpha));
return result;
}
@@ -36,10 +36,10 @@ std::u16string Color::ToString() const {
};
std::u16string result = u"#";
- result.append(to_two_hex_digit(alpha));
result.append(to_two_hex_digit(red));
result.append(to_two_hex_digit(green));
result.append(to_two_hex_digit(blue));
+ result.append(to_two_hex_digit(alpha));
return result;
}
@@ -86,14 +86,14 @@ std::optional<Color> Color::Parse(std::u16string_view string,
gsl::narrow_cast<std::uint8_t>(*b));
} else if (string_size == 9) {
if (string[0] != u'#') return std::nullopt;
- auto a = get_num_for_two_digit(string.substr(1, 2));
- if (!a) return std::nullopt;
- auto r = get_num_for_two_digit(string.substr(3, 2));
+ auto r = get_num_for_two_digit(string.substr(1, 2));
if (!r) return std::nullopt;
- auto g = get_num_for_two_digit(string.substr(5, 2));
+ auto g = get_num_for_two_digit(string.substr(3, 2));
if (!g) return std::nullopt;
- auto b = get_num_for_two_digit(string.substr(7, 2));
+ auto b = get_num_for_two_digit(string.substr(5, 2));
if (!b) return std::nullopt;
+ auto a = get_num_for_two_digit(string.substr(7, 2));
+ if (!a) return std::nullopt;
return Color(
gsl::narrow_cast<std::uint8_t>(*r), gsl::narrow_cast<std::uint8_t>(*g),
gsl::narrow_cast<std::uint8_t>(*b), gsl::narrow_cast<std::uint8_t>(*a));