mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:47:35 +00:00
LibGfx: Make Color use east-const
This commit is contained in:
parent
40a0a995af
commit
639c913e58
2 changed files with 15 additions and 15 deletions
|
@ -28,7 +28,7 @@ String Color::to_string_without_alpha() const
|
||||||
return String::formatted("#{:02x}{:02x}{:02x}", red(), green(), blue());
|
return String::formatted("#{:02x}{:02x}{:02x}", red(), green(), blue());
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<Color> parse_rgb_color(const StringView& string)
|
static Optional<Color> parse_rgb_color(StringView const& string)
|
||||||
{
|
{
|
||||||
VERIFY(string.starts_with("rgb("));
|
VERIFY(string.starts_with("rgb("));
|
||||||
VERIFY(string.ends_with(")"));
|
VERIFY(string.ends_with(")"));
|
||||||
|
@ -49,7 +49,7 @@ static Optional<Color> parse_rgb_color(const StringView& string)
|
||||||
return Color(r, g, b);
|
return Color(r, g, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Optional<Color> parse_rgba_color(const StringView& string)
|
static Optional<Color> parse_rgba_color(StringView const& string)
|
||||||
{
|
{
|
||||||
VERIFY(string.starts_with("rgba("));
|
VERIFY(string.starts_with("rgba("));
|
||||||
VERIFY(string.ends_with(")"));
|
VERIFY(string.ends_with(")"));
|
||||||
|
@ -73,13 +73,13 @@ static Optional<Color> parse_rgba_color(const StringView& string)
|
||||||
return Color(r, g, b, a);
|
return Color(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Color> Color::from_string(const StringView& string)
|
Optional<Color> Color::from_string(StringView const& string)
|
||||||
{
|
{
|
||||||
if (string.is_empty())
|
if (string.is_empty())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
struct ColorAndWebName {
|
struct ColorAndWebName {
|
||||||
constexpr ColorAndWebName(RGBA32 c, const char* n)
|
constexpr ColorAndWebName(RGBA32 c, char const* n)
|
||||||
: color(c)
|
: color(c)
|
||||||
, name(n)
|
, name(n)
|
||||||
{
|
{
|
||||||
|
@ -313,7 +313,7 @@ Optional<Color> Color::from_string(const StringView& string)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IPC::encode(IPC::Encoder& encoder, const Color& color)
|
bool IPC::encode(IPC::Encoder& encoder, Color const& color)
|
||||||
{
|
{
|
||||||
encoder << color.value();
|
encoder << color.value();
|
||||||
return true;
|
return true;
|
||||||
|
@ -328,7 +328,7 @@ bool IPC::decode(IPC::Decoder& decoder, Color& color)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, const Gfx::Color& value)
|
void AK::Formatter<Gfx::Color>::format(FormatBuilder& builder, Gfx::Color const& value)
|
||||||
{
|
{
|
||||||
Formatter<StringView>::format(builder, value.to_string());
|
Formatter<StringView>::format(builder, value.to_string());
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Color interpolate(const Color& other, float weight) const noexcept
|
Color interpolate(Color const& other, float weight) const noexcept
|
||||||
{
|
{
|
||||||
u8 r = red() + roundf(static_cast<float>(other.red() - red()) * weight);
|
u8 r = red() + roundf(static_cast<float>(other.red() - red()) * weight);
|
||||||
u8 g = green() + roundf(static_cast<float>(other.green() - green()) * weight);
|
u8 g = green() + roundf(static_cast<float>(other.green() - green()) * weight);
|
||||||
|
@ -212,7 +212,7 @@ public:
|
||||||
return Color(r, g, b, a);
|
return Color(r, g, b, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Color multiply(const Color& other) const
|
constexpr Color multiply(Color const& other) const
|
||||||
{
|
{
|
||||||
return Color(
|
return Color(
|
||||||
red() * other.red() / 255,
|
red() * other.red() / 255,
|
||||||
|
@ -271,26 +271,26 @@ public:
|
||||||
return Color(~red(), ~green(), ~blue(), alpha());
|
return Color(~red(), ~green(), ~blue(), alpha());
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Color xored(const Color& other) const
|
constexpr Color xored(Color const& other) const
|
||||||
{
|
{
|
||||||
return Color(((other.m_value ^ m_value) & 0x00ffffff) | (m_value & 0xff000000));
|
return Color(((other.m_value ^ m_value) & 0x00ffffff) | (m_value & 0xff000000));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr RGBA32 value() const { return m_value; }
|
constexpr RGBA32 value() const { return m_value; }
|
||||||
|
|
||||||
constexpr bool operator==(const Color& other) const
|
constexpr bool operator==(Color const& other) const
|
||||||
{
|
{
|
||||||
return m_value == other.m_value;
|
return m_value == other.m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr bool operator!=(const Color& other) const
|
constexpr bool operator!=(Color const& other) const
|
||||||
{
|
{
|
||||||
return m_value != other.m_value;
|
return m_value != other.m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
String to_string() const;
|
String to_string() const;
|
||||||
String to_string_without_alpha() const;
|
String to_string_without_alpha() const;
|
||||||
static Optional<Color> from_string(const StringView&);
|
static Optional<Color> from_string(StringView const&);
|
||||||
|
|
||||||
constexpr HSV to_hsv() const
|
constexpr HSV to_hsv() const
|
||||||
{
|
{
|
||||||
|
@ -333,7 +333,7 @@ public:
|
||||||
return from_hsv({ hue, saturation, value });
|
return from_hsv({ hue, saturation, value });
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr Color from_hsv(const HSV& hsv)
|
static constexpr Color from_hsv(HSV const& hsv)
|
||||||
{
|
{
|
||||||
VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
|
VERIFY(hsv.hue >= 0.0 && hsv.hue < 360.0);
|
||||||
VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
|
VERIFY(hsv.saturation >= 0.0 && hsv.saturation <= 1.0);
|
||||||
|
@ -499,14 +499,14 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Formatter<Gfx::Color> : public Formatter<StringView> {
|
struct Formatter<Gfx::Color> : public Formatter<StringView> {
|
||||||
void format(FormatBuilder& builder, const Gfx::Color& value);
|
void format(FormatBuilder& builder, Gfx::Color const& value);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace IPC {
|
namespace IPC {
|
||||||
|
|
||||||
bool encode(Encoder&, const Gfx::Color&);
|
bool encode(Encoder&, Gfx::Color const&);
|
||||||
bool decode(Decoder&, Gfx::Color&);
|
bool decode(Decoder&, Gfx::Color&);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue