///////////////////////////////////////////////////////////////////////////////
//  SColor.cpp

#include <algorithm>
#include "SColor.h"

// 萔
SColor	SColor::Black(0.0f, 0.0f, 0.0f, 1.0f);
SColor	SColor::White(1.0f, 1.0f, 1.0f, 1.0f);
SColor	SColor::Zero(0.0f, 0.0f, 0.0f, 0.0f);

//
SColor::SColor(void) :
	fR(0.0f),
	fG(0.0f),
	fB(0.0f),
	fA(1.0f)
{
}

SColor::SColor(float fR_, float fG_, float fB_, float fA_) :
	fR(fR_),
	fG(fG_),
	fB(fB_),
	fA(fA_)
{
}

bool SColor::operator==(const SColor& Right) const
{
	return fR == Right.fR && fG == Right.fG && fB == Right.fB && fA == Right.fA;
}

bool SColor::operator!=(const SColor& Right) const
{
	return fR != Right.fR || fG != Right.fG || fB != Right.fB || fA != Right.fA;
}

void SColor::Set(float fR_, float fG_, float fB_, float fA_)
{
	fR = fR_;
	fG = fG_;
	fB = fB_;
	fA = fA_;
}

const SColor SColor::operator+(const SColor& Obj) const
{
	return SColor(fR + Obj.fR, fG + Obj.fG, fB + Obj.fB, fA + Obj.fA);
}

const SColor SColor::operator-(const SColor& Obj) const
{
	return SColor(fR - Obj.fR, fG - Obj.fG, fB - Obj.fB, fA - Obj.fA);
}

const SColor SColor::operator*(const SColor& Color) const
{
	return SColor(fR * Color.fR, fG * Color.fG, fB * Color.fB, fA * Color.fA);
}

const SColor SColor::operator*(float fColor) const
{
	return SColor(fR * fColor, fG * fColor, fB * fColor, fA * fColor);
}

const SColor SColor::operator/(float fColor) const
{
	return SColor(fR / fColor, fG / fColor, fB / fColor, fA / fColor);
}

SColor& SColor::operator*=(const SColor& Color)
{
	fR *= Color.fR;
	fG *= Color.fG;
	fB *= Color.fB;
	fA *= Color.fA;

	return *this;
}

unsigned int SColor::GetDWORD() const
{
	const unsigned int ulA = (unsigned int)std::max(std::min(int(fA * 255), 255), 0);
	const unsigned int ulR = (unsigned int)std::max(std::min(int(fR * 255), 255), 0);
	const unsigned int ulG = (unsigned int)std::max(std::min(int(fG * 255), 255), 0);
	const unsigned int ulB = (unsigned int)std::max(std::min(int(fB * 255), 255), 0);

	return ((ulA << 24) | (ulR << 16) | (ulG << 8) | ulB);
}

unsigned int SColor::GetRGBA() const
{
	const unsigned int ulA = (unsigned int)std::max(std::min(int(fA * 255), 255), 0);
	const unsigned int ulR = (unsigned int)std::max(std::min(int(fR * 255), 255), 0);
	const unsigned int ulG = (unsigned int)std::max(std::min(int(fG * 255), 255), 0);
	const unsigned int ulB = (unsigned int)std::max(std::min(int(fB * 255), 255), 0);

	return ((ulA << 24) | (ulB << 16) | (ulG << 8) | ulR);
}

//
SColor SColor::Lerp(const SColor& ColorA, const SColor& ColorB, float Rate)
{
	return ColorA + (ColorB - ColorA) * Rate;
}

