89 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| // Copyright (c) 2022 Dominic Masters
 | |
| // 
 | |
| // This software is released under the MIT License.
 | |
| // https://opensource.org/licenses/MIT
 | |
| 
 | |
| #pragma once
 | |
| #include "dawnlibs.hpp"
 | |
| 
 | |
| namespace Dawn {
 | |
|   struct ColorU8 {
 | |
|     uint8_t r, g, b, a;
 | |
|   };
 | |
| 
 | |
|   struct Color final {
 | |
|     /**
 | |
|      * Returns a color from a string.
 | |
|      * 
 | |
|      * @param str String to parse.
 | |
|      * @return Color parsed.
 | |
|      */
 | |
|     static struct Color fromString(const std::string str);
 | |
| 
 | |
|     float_t r, g, b, a;
 | |
| 
 | |
|     const struct Color& operator = (const struct Color &val) {
 | |
|       this->r = val.r;
 | |
|       this->g = val.g;
 | |
|       this->b = val.b;
 | |
|       this->a = val.a;
 | |
|       return *this;
 | |
|     }
 | |
| 
 | |
|     struct Color operator * (const float_t &x) {
 | |
|       return {
 | |
|         r * x,
 | |
|         g * x,
 | |
|         b * x,
 | |
|         a * x
 | |
|       };
 | |
|     }
 | |
| 
 | |
|     struct Color operator - (const struct Color &color) {
 | |
|       return {
 | |
|         r - color.r,
 | |
|         g - color.g,
 | |
|         b - color.b,
 | |
|         a - color.a
 | |
|       };
 | |
|     }
 | |
| 
 | |
|     struct Color operator + (const struct Color &color) {
 | |
|       return {
 | |
|         r + color.r,
 | |
|         g + color.g,
 | |
|         b + color.b,
 | |
|         a + color.a
 | |
|       };
 | |
|     }
 | |
| 
 | |
|     const bool_t operator == (const struct Color &other) {
 | |
|       return r == other.r && g == other.g && b == other.b && a == other.a;
 | |
|     }
 | |
| 
 | |
|     operator struct ColorU8() const {
 | |
|       return {
 | |
|         (uint8_t)(r * 255),
 | |
|         (uint8_t)(g * 255),
 | |
|         (uint8_t)(b * 255),
 | |
|         (uint8_t)(a * 255)
 | |
|       };
 | |
|     }
 | |
|   };
 | |
| 
 | |
|   #define COLOR_DEF(r,g,b,a)          { r, g, b, a }
 | |
|   #define COLOR_WHITE                 COLOR_DEF(1.0f, 1.0f, 1.0f, 1.0f)
 | |
|   #define COLOR_RED                   COLOR_DEF(1.0f, 0, 0, 1.0f)
 | |
|   #define COLOR_GREEN                 COLOR_DEF(0, 1.0f, 0, 1.0f)
 | |
|   #define COLOR_BLUE                  COLOR_DEF(0, 0, 1.0f, 1.0f)
 | |
|   #define COLOR_BLACK                 COLOR_DEF(0, 0, 0, 1.0f)
 | |
|   #define COLOR_MAGENTA               COLOR_DEF(1.0f, 0, 1.0f, 1.0f)
 | |
|   #define COLOR_DARK_GREY             COLOR_DEF(0.2f, 0.2f, 0.2f, 1.0f)
 | |
|   #define COLOR_LIGHT_GREY            COLOR_DEF(0.8f, 0.8f, 0.8f, 1.0f)
 | |
|   #define COLOR_CORNFLOWER_BLUE       COLOR_DEF(0.4f, 0.6f, 0.9f, 1.0f)
 | |
|   #define COLOR_WHITE_TRANSPARENT     COLOR_DEF(1.0f, 1.0f, 1.0f, 0.0f)
 | |
|   #define COLOR_BLACK_TRANSPARENT     COLOR_DEF(0.0f, 0.0f, 0.0f, 0.0f)
 | |
|   #define COLOR_YELLOW                COLOR_DEF(1.0f, 1.0f, 0.0f, 1.0f)
 | |
|   #define COLOR_CYAN                  COLOR_DEF(0.0f, 1.0f, 1.0f, 1.0f)
 | |
|   #define COLOR_TRANSPARENT           COLOR_WHITE_TRANSPARENT
 | |
| } |