mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-26 07:38:30 +02:00
Migrate COLOR constants to Color class & disallow implicit conversions to Color (#2093)
Co-authored-by: Xo Wang <xo@geekshavefeelings.com>
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
#include "esphome/core/color.h"
|
||||
|
||||
namespace esphome {
|
||||
|
||||
const Color Color::BLACK(0, 0, 0, 0);
|
||||
const Color Color::WHITE(255, 255, 255, 255);
|
||||
|
||||
} // namespace esphome
|
||||
+12
-6
@@ -38,10 +38,10 @@ struct Color {
|
||||
g(green),
|
||||
b(blue),
|
||||
w(white) {}
|
||||
inline Color(uint32_t colorcode) ALWAYS_INLINE : r((colorcode >> 16) & 0xFF),
|
||||
g((colorcode >> 8) & 0xFF),
|
||||
b((colorcode >> 0) & 0xFF),
|
||||
w((colorcode >> 24) & 0xFF) {}
|
||||
inline explicit Color(uint32_t colorcode) ALWAYS_INLINE : r((colorcode >> 16) & 0xFF),
|
||||
g((colorcode >> 8) & 0xFF),
|
||||
b((colorcode >> 0) & 0xFF),
|
||||
w((colorcode >> 24) & 0xFF) {}
|
||||
|
||||
inline bool is_on() ALWAYS_INLINE { return this->raw_32 != 0; }
|
||||
inline Color &operator=(const Color &rhs) ALWAYS_INLINE { // NOLINT
|
||||
@@ -143,8 +143,14 @@ struct Color {
|
||||
Color fade_to_black(uint8_t amnt) { return *this * amnt; }
|
||||
Color lighten(uint8_t delta) { return *this + delta; }
|
||||
Color darken(uint8_t delta) { return *this - delta; }
|
||||
|
||||
static const Color BLACK;
|
||||
static const Color WHITE;
|
||||
};
|
||||
|
||||
static const Color COLOR_BLACK(0, 0, 0);
|
||||
ESPDEPRECATED("Use Color::BLACK instead of COLOR_BLACK")
|
||||
static const Color COLOR_BLACK(0, 0, 0, 0);
|
||||
ESPDEPRECATED("Use Color::WHITE instead of COLOR_WHITE")
|
||||
static const Color COLOR_WHITE(255, 255, 255, 255);
|
||||
}; // namespace esphome
|
||||
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user