00001 #ifndef PHX_COLOR_H
00002 #define PHX_COLOR_H
00003
00004 namespace Phx {
00005
00010 class RgbColor {
00011 public:
00012 RgbColor() : mRed(1), mGreen(1), mBlue(1) {}
00013
00014 RgbColor(double r, double g, double b) :
00015 mRed(clamp(r)), mGreen(clamp(g)), mBlue(clamp(b)) {
00016 }
00017
00018
00019
00020 double red() const { return mRed; }
00021 double green() const { return mGreen; }
00022 double blue() const { return mBlue; }
00023
00024 void red(double red) { mRed = clamp(red); }
00025 void green(double green) { mGreen = clamp(green); }
00026 void blue(double blue) { mBlue = clamp(blue); }
00027
00028 protected:
00029 double clamp(double v) { return (v > 1.0) ? 1.0 : ((v < 0.0) ? 0.0 : v); }
00030 private:
00031 double mRed, mGreen, mBlue;
00032 };
00033
00034
00039 class RgbaColor : public RgbColor {
00040 public:
00041 RgbaColor() : RgbColor(), mAlpha(1) {}
00042
00043 RgbaColor(double r, double g, double b, double a = 1) :
00044 RgbColor(r,g,b), mAlpha(clamp(a)) {
00045 }
00046
00047 RgbaColor(const RgbColor& rgb, double a = 1) :
00048 RgbColor(rgb), mAlpha(clamp(a)) {
00049 }
00050
00051
00052
00053 double alpha() const { return mAlpha; }
00054 void alpha(double alpha) { mAlpha = clamp(alpha); }
00055
00056 private:
00057 double mAlpha;
00058 };
00059
00060
00061 };
00062
00063 #endif