# Fix Color Code

- Fix extreme stupid bug in color.hpp (returing m_r for all...)
- Fix Collor::Hex  with int cast to make sure to have valid hex output (u8 gets interpreted as char)
This commit is contained in:
tobid7 2025-06-01 18:07:14 +02:00
parent ea76a304d4
commit 271defffca
2 changed files with 302 additions and 301 deletions

View File

@ -141,7 +141,7 @@ class PD_CORE_API Color {
* Getter for Green
* @return Green Value
*/
u8 g() const { return m_r; }
u8 g() const { return m_g; }
/**
* Setter for Blue
* @param v value
@ -155,7 +155,7 @@ class PD_CORE_API Color {
* Getter for Blue
* @return Blue Value
*/
u8 b() const { return m_r; }
u8 b() const { return m_b; }
/**
* Setter for Alpha
* @param v value
@ -169,7 +169,7 @@ class PD_CORE_API Color {
* Getter for Alpha
* @return Alpha Value
*/
u8 a() const { return m_r; }
u8 a() const { return m_a; }
/**
* Fade from Current to another Color

View File

@ -59,13 +59,14 @@ PD_CORE_API Color& Color::Hex(const std::string& hex) {
}
PD_CORE_API std::string Color::Hex(bool rgba) const {
/** Need to int cast (so it is used as num and not char...) */
std::stringstream s;
s << "#";
s << std::hex << std::setw(2) << std::setfill('0') << m_r;
s << std::hex << std::setw(2) << std::setfill('0') << m_g;
s << std::hex << std::setw(2) << std::setfill('0') << m_b;
s << std::hex << std::setw(2) << std::setfill('0') << (int)m_r;
s << std::hex << std::setw(2) << std::setfill('0') << (int)m_g;
s << std::hex << std::setw(2) << std::setfill('0') << (int)m_b;
if (rgba) {
s << std::hex << std::setw(2) << std::setfill('0') << m_a;
s << std::hex << std::setw(2) << std::setfill('0') << (int)m_a;
}
return s.str();
}