Added GPLv3 headers all over the place.
[fail.git] / src / math / Vector4u8.h
blob860f9b12276cb62eb1c9e5c8c6511f251992ed4e
1 /*
2 Fail game engine
3 Copyright 2007 Antoine Chavasse <a.chavasse@gmail.com>
5 This file is part of Fail.
7 Fail is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 3
9 as published by the Free Software Foundation.
11 Fail is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef FAIL_MATH_VECTOR4U8_H_
20 #define FAIL_MATH_VECTOR4U8_H_
22 #include "core/core.h"
24 namespace fail { namespace math
26 struct Vector4u8
28 Vector4u8() :
29 m_r( 0 ),
30 m_g( 0 ),
31 m_b( 0 ),
32 m_a( 255 )
36 Vector4u8( uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255 ) :
37 m_r( r ),
38 m_g( g ),
39 m_b( b ),
40 m_a( a )
44 uint8_t& r() { return m_r; }
45 uint8_t& g() { return m_g; }
46 uint8_t& b() { return m_b; }
47 uint8_t& a() { return m_a; }
48 const uint8_t& r() const { return m_r; }
49 const uint8_t& g() const { return m_g; }
50 const uint8_t& b() const { return m_b; }
51 const uint8_t& a() const { return m_a; }
53 Vector4u8 operator+( const Vector4u8& b ) const
55 return Vector4u8( m_r + b.m_r,
56 m_g + b.m_g,
57 m_b + b.m_b,
58 m_a + b.m_a );
61 Vector4u8 operator-( const Vector4u8& b ) const
63 return Vector4u8( m_r - b.m_r,
64 m_g - b.m_g,
65 m_b - b.m_b,
66 m_a - b.m_a );
69 const Vector4u8& operator+=( const Vector4u8& b )
71 m_r += b.m_r;
72 m_g += b.m_g;
73 m_b += b.m_b;
74 m_a += b.m_a;
75 return *this;
78 const Vector4u8& operator-=( const Vector4u8& b )
80 m_r -= b.m_r;
81 m_g -= b.m_g;
82 m_b -= b.m_b;
83 m_a -= b.m_a;
84 return *this;
87 bool operator==( const Vector4u8& b ) const
89 return m_r == b.m_r &&
90 m_g == b.m_g &&
91 m_b == b.m_b &&
92 m_a == b.m_a;
95 bool operator!=( const Vector4u8& b ) const
97 return m_r != b.m_r ||
98 m_g != b.m_g ||
99 m_b != b.m_b ||
100 m_a != b.m_a;
103 bool operator<( const Vector4u8& b_ ) const
105 uint32_t a = ( m_r << 24 ) | ( m_g << 16 ) | ( m_b << 8 ) | m_a;
106 uint32_t b = ( b_.m_r << 24 ) | ( b_.m_g << 16 ) | ( b_.m_b << 8 ) | b_.m_a;
107 return a < b;
110 private:
111 uint8_t m_r;
112 uint8_t m_g;
113 uint8_t m_b;
114 uint8_t m_a;
118 #endif