srctree

Robin Linden parent 31e252f9 b9a5492b
gfx: Accept uint32 instead of int32 in the Color contructors

inlinesplit
gfx/color.h added: 7, removed: 7, total 0
@@ -10,7 +10,7 @@
namespace gfx {
 
struct Color {
constexpr static Color from_rgb(std::int32_t rgb) {
constexpr static Color from_rgb(std::uint32_t rgb) {
return Color{
.r = static_cast<std::uint8_t>((rgb & 0xFF0000) >> 16),
.g = static_cast<std::uint8_t>((rgb & 0x00FF00) >> 8),
@@ -18,7 +18,7 @@ struct Color {
};
}
 
constexpr static Color from_rgba(std::int32_t rgba) {
constexpr static Color from_rgba(std::uint32_t rgba) {
auto alpha = static_cast<std::uint8_t>(rgba & 0xFF);
auto color = from_rgb((rgba & 0xFF'FF'FF'00) >> 8);
color.a = alpha;
 
gfx/color_test.cpp added: 7, removed: 7, total 0
@@ -29,7 +29,7 @@ int main() {
expect_eq(Color{0x12, 0x34, 0x56, 0x78}.as_rgba_u32(), 0x12'34'56'78u);
 
auto c = Color{0x12, 0x34, 0x56, 0x78};
expect_eq(Color::from_rgba(static_cast<std::int32_t>(c.as_rgba_u32())), c);
expect_eq(Color::from_rgba(c.as_rgba_u32()), c);
});
 
return etest::run_all_tests();
 
render/render.cpp added: 7, removed: 7, total 0
@@ -223,7 +223,7 @@ std::optional<gfx::Color> try_from_hex_chars(std::string_view hex_chars) {
}
 
hex_chars.remove_prefix(1);
std::int32_t hex{};
std::uint32_t hex{};
if (hex_chars.length() == 6) {
std::from_chars(hex_chars.data(), hex_chars.data() + hex_chars.size(), hex, /*base*/ 16);
} else if (hex_chars.length() == 3) {