//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * 四要素キャラクタカラー実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Core/Primitive/Color4c.h"
#include "Core/Primitive/Color3c.h"
#include "Core/Primitive/Color3f.h"
#include "Core/Primitive/Color4f.h"

namespace Lamp{

//------------------------------------------------------------------------------
// 定数
//------------------------------------------------------------------------------
// 白
const Color4c Color4c::white(255, 255, 255);

// 灰色
const Color4c Color4c::gray(128, 128, 128);

// 黒
const Color4c Color4c::black(0, 0, 0);

// 赤
const Color4c Color4c::red(255, 0, 0);

// 緑
const Color4c Color4c::green(0, 255, 0);

// 青
const Color4c Color4c::blue(0, 0, 255);

// 黄
const Color4c Color4c::yellow(255, 255, 0);

// 青緑
const Color4c Color4c::cyan(0, 255, 255);

// 赤紫
const Color4c Color4c::magenta(255, 0, 255);

//------------------------------------------------------------------------------
// コンストラクタ
Color4c::Color4c(const Color3c& source) :
	r(source.r), g(source.g), b(source.b), a(255){
}
//------------------------------------------------------------------------------
// コンストラクタ
Color4c::Color4c(const Color3f& source){
	set(source);
}
//------------------------------------------------------------------------------
// コンストラクタ
Color4c::Color4c(const Color4f& source){
	set(source);
}
//------------------------------------------------------------------------------
// 三要素キャラクタカラーの設定
void Color4c::set(const Color3c& source){
	set(source.r, source.g, source.b, 255);
}
//------------------------------------------------------------------------------
// 三要素実数カラーの設定
void Color4c::set(const Color3f& source){
	int srcR = (int)(source.r * 255.f);
	if(srcR > 255){ srcR = 255; }
	else if(srcR < 0){ srcR = 0; }

	int srcG = (int)(source.g * 255.f);
	if(srcG > 255){ srcG = 255; }
	else if(srcG < 0){ srcG = 0; }

	int srcB = (int)(source.b * 255.f);
	if(srcB > 255){ srcB = 255; }
	else if(srcB < 0){ srcB = 0; }

	set(srcR, srcG, srcB, 255);
}
//------------------------------------------------------------------------------
// 四要素実数カラーの設定
void Color4c::set(const Color4f& source){
	int srcR = (int)(source.r * 255.f);
	if(srcR > 255){ srcR = 255; }
	else if(srcR < 0){ srcR = 0; }

	int srcG = (int)(source.g * 255.f);
	if(srcG > 255){ srcG = 255; }
	else if(srcG < 0){ srcG = 0; }

	int srcB = (int)(source.b * 255.f);
	if(srcB > 255){ srcB = 255; }
	else if(srcB < 0){ srcB = 0; }

	int srcA = (int)(source.a * 255.f);
	if(srcA > 255){ srcA = 255; }
	else if(srcA < 0){ srcA = 0; }

	set(srcR, srcG, srcB, srcA);
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
