MercuryColor.cpp

Go to the documentation of this file.
00001 #include "MercuryLog.h"
00002 #include "MercuryColor.h"
00003 #include "MercuryMath.h"
00004 
00005 MercuryColor::MercuryColor( float ir, float ig, float ib, float ia  )
00006 {
00007     m_rgba[0] = ir;
00008     m_rgba[1] = ig;
00009     m_rgba[2] = ib;
00010     m_rgba[3] = ia;
00011 }
00012 
00013 MercuryColor::MercuryColor()
00014 {
00015     m_rgba[0] = 1;
00016     m_rgba[1] = 1;
00017     m_rgba[2] = 1;
00018     m_rgba[3] = 1;
00019 }
00020 
00021 void MercuryColor::FromString(const MString& str)
00022 {
00023     if (sscanf(str, "%f,%f,%f,%f", &m_rgba[0],&m_rgba[1],&m_rgba[2],&m_rgba[3]) != 4)
00024         LOG.Warn(str + " not a valid color string");
00025 }
00026 
00027 const MercuryColor MercuryColor::operator-(const MercuryColor& c)
00028 {
00029     MercuryColor n;
00030     Sub4f(m_rgba, c.m_rgba, n.m_rgba);
00031     return n;
00032 }
00033 
00034 const MercuryColor& MercuryColor::operator-=(const MercuryColor& c)
00035 {
00036     Sub4f(m_rgba, c.m_rgba, m_rgba);
00037     return *this;
00038 }
00039 
00040 const MercuryColor MercuryColor::operator+(const MercuryColor& c)
00041 {
00042     MercuryColor n;
00043     Add4f(m_rgba, c.m_rgba, n.m_rgba);
00044     return n;
00045 }
00046 
00047 const MercuryColor& MercuryColor::operator+=(const MercuryColor& c)
00048 {
00049     Add4f(m_rgba, c.m_rgba, m_rgba);
00050     return *this;
00051 }
00052 
00053 const MercuryColor MercuryColor::operator*(const MercuryColor& c)
00054 {
00055     MercuryColor n;
00056     Mul4f(m_rgba, c.m_rgba, n.m_rgba);
00057     return n;
00058 }
00059 
00060 const MercuryColor& MercuryColor::operator*=(const MercuryColor& c)
00061 {
00062     Mul4f(m_rgba, c.m_rgba, m_rgba);
00063     return *this;
00064 }
00065 
00066 
00067 const MercuryColor MercuryColor::operator*(const float f)
00068 {
00069     MercuryColor n;
00070     n.m_rgba[0] = m_rgba[0] * f;
00071     n.m_rgba[1] = m_rgba[1] * f;
00072     n.m_rgba[2] = m_rgba[2] * f;
00073     n.m_rgba[3] = m_rgba[3] * f;
00074     return n;
00075 }
00076 
00077 /* 
00078  * Copyright (c) 2005-2006, Joshua Allen
00079  * All rights reserved.
00080  *
00081  * Redistribution and use in source and binary forms, with or
00082  * without modification, are permitted provided that the following
00083  * conditions are met:
00084  *  -   Redistributions of source code must retain the above
00085  *      copyright notice, this list of conditions and the following disclaimer.
00086  *  -   Redistributions in binary form must reproduce the above copyright
00087  *      notice, this list of conditions and the following disclaimer in
00088  *      the documentation and/or other materials provided with the distribution.
00089  *  -   Neither the name of the Mercury Engine nor the names of its
00090  *      contributors may be used to endorse or promote products derived from
00091  *      this software without specific prior written permission.
00092  *
00093  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00094  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00095  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00096  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00097  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00098  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00099  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00100  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00101  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00102  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00103  */

Hosted by SourceForge.net Logo