Move Color.h from modules/graphics/ to common/

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-08-01 23:53:44 -03:00
parent c11a4250e8
commit b129d49a6c
15 changed files with 41 additions and 49 deletions
-159
View File
@@ -1,159 +0,0 @@
/**
* Copyright (c) 2006-2017 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_COLOR_H
#define LOVE_GRAPHICS_COLOR_H
namespace love
{
namespace graphics
{
template <typename T>
struct ColorT
{
T r;
T g;
T b;
T a;
ColorT() : r(0), g(0), b(0), a(0) {}
ColorT(T r_, T g_, T b_, T a_) : r(r_), g(g_), b(b_), a(a_) {}
void set(T r_, T g_, T b_, T a_)
{
r = r_;
g = g_;
b = b_;
a = a_;
}
bool operator==(const ColorT<T> &other) const;
bool operator!=(const ColorT<T> &other) const;
ColorT<T> operator+=(const ColorT<T> &other);
ColorT<T> operator*=(const ColorT<T> &other);
ColorT<T> operator*=(T s);
ColorT<T> operator/=(T s);
};
template <typename T>
bool ColorT<T>::operator==(const ColorT<T> &other) const
{
return r == other.r && g == other.g && b == other.b && a == other.a;
}
template <typename T>
bool ColorT<T>::operator!=(const ColorT<T> &other) const
{
return !(operator==(other));
}
template <typename T>
ColorT<T> ColorT<T>::operator+=(const ColorT<T> &other)
{
r += other.r;
g += other.g;
b += other.b;
a += other.a;
return *this;
}
template <typename T>
ColorT<T> ColorT<T>::operator*=(const ColorT<T> &other)
{
r *= other.r;
g *= other.g;
b *= other.b;
a *= other.a;
return *this;
}
template <typename T>
ColorT<T> ColorT<T>::operator*=(T s)
{
r *= s;
g *= s;
b *= s;
a *= s;
return *this;
}
template <typename T>
ColorT<T> ColorT<T>::operator/=(T s)
{
r /= s;
g /= s;
b /= s;
a /= s;
return *this;
}
template <typename T>
ColorT<T> operator+(const ColorT<T> &a, const ColorT<T> &b)
{
ColorT<T> tmp(a);
return tmp += b;
}
template <typename T>
ColorT<T> operator*(const ColorT<T> &a, const ColorT<T> &b)
{
ColorT<T> res;
res.r = a.r * b.r;
res.g = a.g * b.g;
res.b = a.b * b.b;
res.a = a.a * b.a;
return res;
}
template <typename T>
ColorT<T> operator*(const ColorT<T> &a, T s)
{
ColorT<T> tmp(a);
return tmp *= s;
}
template <typename T>
ColorT<T> operator/(const ColorT<T> &a, T s)
{
ColorT<T> tmp(a);
return tmp /= s;
}
typedef ColorT<unsigned char> Color;
typedef ColorT<float> Colorf;
inline Color toColor(Colorf cf)
{
return Color((unsigned char) (cf.r * 255.0f),
(unsigned char) (cf.g * 255.0f),
(unsigned char) (cf.b * 255.0f),
(unsigned char) (cf.a * 255.0f));
}
inline Colorf toColorf(Color c)
{
return Colorf(c.r / 255.0f, c.g / 255.0f, c.b / 255.0f, c.a / 255.0f);
}
} // graphics
} // love
#endif // LOVE_GRAPHICS_COLOR_H
+1 -1
View File
@@ -28,9 +28,9 @@
#include "common/Vector.h"
#include "common/Optional.h"
#include "common/int.h"
#include "common/Color.h"
#include "StreamBuffer.h"
#include "vertex.h"
#include "Color.h"
#include "Texture.h"
#include "Canvas.h"
#include "Font.h"
+1 -1
View File
@@ -25,8 +25,8 @@
#include "common/int.h"
#include "common/math.h"
#include "common/Vector.h"
#include "common/Color.h"
#include "Drawable.h"
#include "Color.h"
#include "Quad.h"
#include "Texture.h"
#include "Buffer.h"
+1 -1
View File
@@ -29,8 +29,8 @@
// LOVE
#include "common/math.h"
#include "common/Matrix.h"
#include "common/Color.h"
#include "Drawable.h"
#include "Color.h"
#include "Mesh.h"
#include "vertex.h"
+1 -1
View File
@@ -22,7 +22,7 @@
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
#include "common/config.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "common/int.h"
#include "graphics/Canvas.h"
#include "graphics/Volatile.h"
+1 -1
View File
@@ -31,7 +31,7 @@
// LOVE
#include "graphics/Graphics.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "image/Image.h"
#include "image/ImageData.h"
+1 -1
View File
@@ -25,7 +25,7 @@
#include "common/config.h"
#include "common/int.h"
#include "common/math.h"
#include "graphics/Color.h"
#include "common/Color.h"
#include "graphics/Texture.h"
#include "graphics/vertex.h"
#include "graphics/depthstencil.h"
+1 -1
View File
@@ -22,7 +22,7 @@
// LOVE
#include "common/int.h"
#include "Color.h"
#include "common/Color.h"
// C
#include <stddef.h>