Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

ColorC.h

00001 //-------------------------------------------------------------------------
00002 //
00003 // File:        ColorC.h
00004 // Desc:        RGBA color class.
00005 // Author:      memon <memon@inside.org>
00006 //
00007 //-------------------------------------------------------------------------
00008 //  Copyright (c) 2000-2002 Moppi Productions. All Rights Reserved.
00009 //  This file is part of Moppi Demopaja SDK. For conditions of 
00010 //  distribution and use, see the accompanying license.txt file.
00011 //  http://moppi.inside.org/demopaja/
00012 //-------------------------------------------------------------------------
00013 
00014 
00015 #ifndef __DEMOPAJA_COLORC_H__
00016 #define __DEMOPAJA_COLORC_H__
00017 
00018 #include "PajaTypes.h"
00019 #include <assert.h>
00020 
00021 
00022 namespace PajaTypes {
00023 
00025 
00033     class ColorC
00034     {
00035     public:
00036         
00038         ColorC( const ColorC& rCol );
00039         
00041         ColorC( float32 f32R = 0, float32 f32G = 0, float32 f32B = 0, float32 f32A = 1.0f );
00042 
00044         ~ColorC();
00045 
00047 
00048         void            convert_from_uint8( uint8 ui8R, uint8 ui8G, uint8 ui8B, uint8 ui8A = 255 );
00049 
00051                         operator const float32*();
00052 
00054 
00058         float32&        operator[]( int32 i );
00059 
00061 
00065         const float32&  operator[]( int32 i ) const;
00066 
00068         ColorC          operator-() const;
00069 
00071         bool            operator==( const ColorC& rCol ) const;
00072 
00074         bool            operator!=( const ColorC& rCol ) const;
00075 
00077         ColorC&         operator-=( const ColorC& rCol );
00078 
00080         ColorC&         operator+=( const ColorC& rCol );
00081 
00083         ColorC&         operator*=( float32 f32S );
00084 
00086         ColorC&         operator/=( float32 f32S );
00087 
00089         ColorC          operator*( float32 f32S ) const;
00090 
00092         ColorC          operator/( float32 f32S ) const;
00093 
00095         ColorC          operator-( const ColorC& rCol ) const;
00096 
00098         ColorC          operator+( const ColorC& rCol ) const;
00099 
00101         ColorC          operator*( const ColorC& rCol ) const;
00102 
00104         friend ColorC   operator*( float32 f32S, const ColorC& rCol );
00105 
00106     private:
00107         float32     m_col[4];
00108     };
00109 
00110 
00111     //
00112     //
00113     // Inlines
00114     //
00115     //
00116 
00117     inline
00118     ColorC::operator const float*()
00119     {
00120         return m_col;
00121     }
00122 
00123     inline
00124     float&
00125     ColorC::operator[]( int i )
00126     {
00127         assert( i >= 0 && i < 4 );
00128         return m_col[i];
00129     }
00130 
00131     inline
00132     const float&
00133     ColorC::operator[]( int i ) const
00134     {
00135         assert( i >= 0 && i < 4 );
00136         return m_col[i];
00137     }
00138 
00139     inline
00140     ColorC
00141     ColorC::operator-() const
00142     {
00143         return ColorC( -m_col[0], -m_col[1], -m_col[2], -m_col[3] );
00144     }
00145 
00146     inline
00147     ColorC&
00148     ColorC::operator-=( const ColorC& a )
00149     {
00150         m_col[0] -= a.m_col[0];
00151         m_col[1] -= a.m_col[1];
00152         m_col[2] -= a.m_col[2];
00153         m_col[3] -= a.m_col[3];
00154         return *this;
00155     }
00156 
00157     inline
00158     ColorC&
00159     ColorC::operator+=( const ColorC& a )
00160     {
00161         m_col[0] += a.m_col[0];
00162         m_col[1] += a.m_col[1];
00163         m_col[2] += a.m_col[2];
00164         m_col[3] += a.m_col[3];
00165         return *this;
00166     }
00167 
00168     inline
00169     ColorC&
00170     ColorC::operator*=( float s )
00171     {
00172         m_col[0] *= s;
00173         m_col[1] *= s;
00174         m_col[2] *= s;
00175         m_col[3] *= s;
00176         return *this;
00177     }
00178 
00179     inline
00180     ColorC&
00181     ColorC::operator/=( float s )
00182     {
00183         s = 1.0f / s;
00184         m_col[0] *= s;
00185         m_col[1] *= s;
00186         m_col[2] *= s;
00187         m_col[3] *= s;
00188         return *this;
00189     }
00190 
00191     inline
00192     ColorC
00193     ColorC::operator*( float s ) const
00194     {
00195         return ColorC( m_col[0] * s, m_col[1] * s, m_col[2] * s, m_col[3] * s );
00196     }
00197 
00198 
00199     inline
00200     ColorC
00201     ColorC::operator/( float s ) const
00202     {
00203         s = 1.0f / s;
00204         return ColorC( m_col[0] * s, m_col[1] * s, m_col[2] * s, m_col[3] * s );
00205     }
00206 
00207     inline
00208     ColorC
00209     ColorC::operator-( const ColorC& a ) const
00210     {
00211         return ColorC( m_col[0] - a.m_col[0], m_col[1] - a.m_col[1], m_col[2] - a.m_col[2], m_col[3] - a.m_col[3] );
00212     }
00213 
00214     inline
00215     ColorC
00216     ColorC::operator+( const ColorC& a ) const
00217     {
00218         return ColorC( m_col[0] + a.m_col[0], m_col[1] + a.m_col[1], m_col[2] + a.m_col[2], m_col[3] + a.m_col[3] );
00219     }
00220 
00221     inline
00222     ColorC
00223     ColorC::operator*( const ColorC& a ) const
00224     {
00225         return ColorC( m_col[0] * a.m_col[0], m_col[1] * a.m_col[1], m_col[2] * a.m_col[2], m_col[3] * a.m_col[3] );
00226     }
00227 
00228     inline
00229     ColorC
00230     operator*( float s, const ColorC& v )
00231     {
00232         return ColorC( v.m_col[0] * s, v.m_col[1] * s, v.m_col[2] * s, v.m_col[3] * s );
00233     }
00234 
00235 
00236 };  // namespace PajaTypes
00237 
00238 #endif  // __DEMOPAJA_COLORC_H_

Moppi Demopaja SDK Documentation -- Copyright © 2000-2002 Moppi Productions