00001
00013 #ifndef __color__
00014 #define __color__
00015
00016 #include <math.h>
00017 #include <Qcolor>
00018 #include "globals.h"
00019 #include <QtDebug>
00020
00027 class Color
00028 {
00029 public:
00030
00031 inline Color(void) { r=0;g=0;b=0; a=0;}
00032 inline Color(int r, int g, int b, int a) { this->r = r; this->g = g; this->b = b; this->a = a; }
00034 inline Color(const Color& v) { r = v.r; g = v.g; b = v.b; a = v.a; }
00035
00036
00037
00038 inline Color operator-(void) const { return Color(-r,-g,-b,-a); }
00040 inline int operator==(const Color& v) const { return (r==v.r && g==v.g && b==v.b && a==v.a); }
00042 inline int operator!=(const Color& v) const { return !(*this==v); }
00044 inline Color operator+(const Color& v) const { return Color(r+v.r, g+v.g, b+v.b, a+v.a); }
00046 inline Color operator-(const Color& v) const { return Color(r-v.r, g-v.g, b-v.b, a-v.a); }
00048 inline Color operator*(float fl) const {
00049 Color c = Color(((float)r) * fl, ((float)g) * fl, ((float)b) * fl, ((float)a) * fl);
00050 return c;
00051 }
00054 inline Color operator/(float fl) const { return Color(r/fl, g/fl, b/fl, a/fl); }
00057 inline unsigned int rgba(void) {
00058
00059 return QColor(
00060 (int)clampTo(0,255,this->r),
00061 (int)clampTo(0,255,this->g),
00062 (int)clampTo(0,255,this->b),
00063 (int)clampTo(0,255,this->a)
00064 ).rgba();
00065
00066 }
00069 inline Color betrag(void) const {
00070
00071 return Color(abs(this->r), abs(this->g), abs(this->b), this->a);
00072
00073 }
00077
00078
00079 inline static float clampTo(float min, float mar, float Val)
00080 {
00081
00082 if (Val > mar)
00083 Val = mar;
00084 else if(Val < min)
00085 Val = min;
00086 return Val;
00087 };
00088
00089
00090 int r, g, b, a;
00091 };
00092
00093 #endif