paysages3d/src/basics/Color.h

67 lines
1.7 KiB
C
Raw Normal View History

#pragma once
2013-11-13 19:07:35 +00:00
#include "basics_global.h"
namespace paysages {
namespace basics {
class BASICSSHARED_EXPORT Color {
public:
Color() = default;
Color(const Color &col);
Color(double r, double g, double b, double a = 1.0);
2013-11-13 19:07:35 +00:00
void save(PackStream *stream) const;
void load(PackStream *stream);
2013-11-13 19:07:35 +00:00
unsigned int to32BitRGBA() const;
unsigned int to32BitBGRA() const;
unsigned int to32BitARGB() const;
unsigned int to32BitABGR() const;
static Color from32BitRGBA(unsigned int col);
static Color from32BitBGRA(unsigned int col);
static Color from32BitARGB(unsigned int col);
static Color from32BitABGR(unsigned int col);
void mask(const Color &mask);
2013-11-13 19:07:35 +00:00
double normalize();
Color normalized();
2013-11-13 19:07:35 +00:00
double getValue() const;
double getPower() const;
void limitPower(double max_power);
2016-01-10 16:14:54 +00:00
/**
* Scale the RGB components by a factor.
*/
void scale(double factor);
/**
* Return a copy, with RGB components scaled by a factor.
*/
Color scaled(double factor) const;
Color add(const Color &other) const;
Color lerp(const Color &other, double f) const;
2015-12-16 00:32:25 +00:00
inline bool operator==(const Color &other) const {
return r == other.r and g == other.g and b == other.b and a == other.a;
}
public:
2015-12-16 00:32:25 +00:00
// TODO Make private
2013-11-13 19:07:35 +00:00
double r;
double g;
double b;
double a;
};
BASICSSHARED_EXPORT extern const Color COLOR_TRANSPARENT;
BASICSSHARED_EXPORT extern const Color COLOR_BLACK;
BASICSSHARED_EXPORT extern const Color COLOR_RED;
BASICSSHARED_EXPORT extern const Color COLOR_GREEN;
BASICSSHARED_EXPORT extern const Color COLOR_BLUE;
BASICSSHARED_EXPORT extern const Color COLOR_WHITE;
BASICSSHARED_EXPORT extern const Color COLOR_GREY;
}
}