Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/color.cc')
-rw-r--r--src/common/color.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/common/color.cc b/src/common/color.cc
new file mode 100644
index 0000000..85892c8
--- /dev/null
+++ b/src/common/color.cc
@@ -0,0 +1,84 @@
+/*
+ ***************************************************************************
+ * Copyright (C) 2002-2004 by Stijn Buys *
+ * stijn.buys@pandora.be *
+ * *
+ * This software is redistributed under the terms of the *
+ * GNU General Public License. Please read LICENSE.txt. *
+ ***************************************************************************
+*/
+
+#include "color.h"
+
+Color::Color() {
+ _r = _g = _b = 0.0f;
+ _a = 1.0f;
+}
+
+Color::Color(const float red, const float green , const float blue , const float alpha) {
+ _r = red;
+ _g = green;
+ _b = blue;
+ _a = alpha;
+}
+
+Color::Color(const float grey, const float alpha) {
+ _r = _g = _b = grey;
+ _a = alpha;
+}
+
+Color::Color(const Color &other) {
+ this->operator=(other);
+}
+
+const Color & Color::operator=(const Color &other) {
+ this->_r = other._r;
+ this->_g = other._g;
+ this->_b = other._b;
+ this->_a = other._a;
+ return (*this);
+}
+
+void Color::normalize() {
+ float tmp = _r;
+
+ if (_g > tmp)
+ tmp = _g;
+ if ( _b > tmp)
+ tmp = _b;
+
+ if (tmp > 1) {
+ _r /= tmp;
+ _g /= tmp;
+ _b /= tmp;
+ }
+}
+
+float Color::red() const {
+ return _r;
+}
+
+float Color::green() const {
+ return _g;
+}
+
+float Color::blue() const {
+ return _b;
+}
+
+float Color::alpha() const {
+ return _a;
+}
+
+Color Color::operator*(float scalar) const {
+ return Color(red()*scalar, green()*scalar, blue()*scalar, alpha());
+}
+
+Color operator*(float scalar, const Color& color) {
+ return color * scalar;
+}
+std::ostream &operator<<(std::ostream &os, const Color &c) {
+ os << c.red() << " " << c.green() << " " << c.blue() << " " << c.alpha();
+ return os;
+}
+