52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <cstdlib>
|
|
#include <cmath>
|
|
#include <ostream>
|
|
#include <type_traits>
|
|
#include "SDL_pixels.h"
|
|
|
|
struct Color : SDL_Color
|
|
{
|
|
|
|
Color();
|
|
Color(const SDL_Color&);
|
|
void set_percent(const float&, const float&, const float&);
|
|
void set_percent(const float&, const float&, const float&, const float&);
|
|
void set_hsv(const float&, const float& = 1.0f, const float& = 1.0f);
|
|
float get_hue() const;
|
|
void shift_hue(float);
|
|
operator std::uint32_t() const;
|
|
operator std::uint16_t() const;
|
|
operator std::uint8_t() const;
|
|
bool operator==(const Color&) const;
|
|
bool operator!=(const Color&) const;
|
|
bool operator<(const Color&) const;
|
|
|
|
template <typename T>
|
|
Color(T red, T green, T blue, T alpha = 255)
|
|
{
|
|
if (std::is_floating_point<T>())
|
|
{
|
|
red = std::round(red);
|
|
green = std::round(green);
|
|
blue = std::round(blue);
|
|
alpha = std::round(alpha);
|
|
}
|
|
r = static_cast<int>(red) & 255;
|
|
g = static_cast<int>(green) & 255;
|
|
b = static_cast<int>(blue) & 255;
|
|
a = static_cast<int>(alpha) & 255;
|
|
}
|
|
|
|
};
|
|
|
|
void RGBtoHSV(const float&, const float&, const float&, float&, float&, float&);
|
|
void HSVtoRGB(float&, float&, float&, const float&, const float&, const float&);
|
|
|
|
namespace std
|
|
{
|
|
std::ostream& operator<<(std::ostream&, const Color&);
|
|
}
|