OpenGL-utility/include/color.hpp

144 lines
3.4 KiB
C++
Raw Permalink Normal View History

2021-01-21 14:30:48 +00:00
/*****************************************************************//**
* @file color.hpp
* @brief Contains convenience for working with colors.
*
* @author Robert
* @date January 2021
*********************************************************************/
2021-01-19 18:25:46 +00:00
#ifndef COLOR_HPP
#define COLOR_HPP
#include <core.hpp>
2021-01-19 18:25:46 +00:00
#include <glad/glad.h>
namespace oglu
{
2021-01-21 14:30:48 +00:00
/**
* Convenience class for storing and working with color
*/
2021-01-19 18:25:46 +00:00
class OGLU_API Color
{
public:
2021-01-21 14:30:48 +00:00
/**
* Constructs a transparent black
*/
2021-01-19 18:25:46 +00:00
Color();
2021-01-21 14:30:48 +00:00
/**
* Constructs a new color
*
* @param red Red component
* @param blue Blue component
* @param green Green component
* @param alpha Red component
*/
2021-01-25 19:53:28 +00:00
Color(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha = 0.f);
2021-01-19 18:25:46 +00:00
public:
2021-01-21 14:30:48 +00:00
GLfloat r; ///< Red channel
GLfloat g; ///< Green channel
GLfloat b; ///< Blue channel
GLfloat a; ///< Alpha channel
static const Color Black; ///< Predefined Black
static const Color White; ///< Predefined White
static const Color Red; ///< Predefined Red
static const Color Green; ///< Predefined Green
static const Color Blue; ///< Predefined Blue
static const Color Yellow; ///< Predefined Yellow
static const Color Magenta; ///< Predefined Magenta
static const Color Cyan; ///< Predefined Cyan
static const Color Transparent; ///< Predefined Transparent
2021-01-19 18:25:46 +00:00
};
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Checks if two colors are equal.
*
* @param left Left operand
* @param right Right operand
*
* @returns True if every color channel is equal
*/
2021-01-19 18:25:46 +00:00
OGLU_API bool operator==(const Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Checks if two colors are different.
*
* @param left Left operand
* @param right Right operand
*
* @returns True if not every color channel is equal
*/
2021-01-19 18:25:46 +00:00
OGLU_API bool operator!=(const Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Sums two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns The sum of @p left and @p right. The result is clamped to the OpenGL color range.
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color operator+(const Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Subtracts two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns The difference of @p left and @p right. The result is clamped to the OpenGL color range.
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color operator-(const Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Multiplies two colors component-wise
*
* @param left Left operand
* @param right Right operand
*
* @returns The componen-wise product of @p left and @p right.
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color operator*(const Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Sums two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color& operator+=(Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Subtracts two colors
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color& operator-=(Color& left, const Color& right);
2021-01-21 14:30:48 +00:00
/**
* @relates Color
* @brief Multiplies two colors component-wise
*
* @param left Left operand
* @param right Right operand
*
* @returns Reference to @p left
*/
2021-01-19 18:25:46 +00:00
OGLU_API Color& operator*=(Color& left, const Color& right);
}
#endif