5fe590f627
- aggiunti materiali e loro gestione - aggiunta gestione libreria materiali.
98 lines
2.8 KiB
C++
98 lines
2.8 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : Color.cpp Data : 12.03.14 Versione : 1.5a5
|
|
// Contenuto : Implementazione funzioni per gestione colori.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 12.03.14 DS Creazione modulo.
|
|
// 24.04.14 DS Agg. GetSurfBackColor.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "/EgtDev/Include/EGkColor.h"
|
|
#include "/EgtDev/Include/EGnStringUtils.h"
|
|
|
|
using namespace std ;
|
|
|
|
//------------------------- Constants ----------------------------------------
|
|
struct NamedColor {
|
|
const char* szName ;
|
|
Color colC ;
|
|
} ;
|
|
static const NamedColor StdColor[] = {
|
|
{ "WHITE", WHITE},
|
|
{ "LGRAY", LGRAY},
|
|
{ "GRAY", GRAY},
|
|
{ "BLACK", BLACK},
|
|
{ "RED", RED},
|
|
{ "MAROON", MAROON},
|
|
{ "YELLOW", YELLOW},
|
|
{ "OLIVE", OLIVE},
|
|
{ "LIME", LIME},
|
|
{ "GREEN", GREEN},
|
|
{ "AQUA", AQUA},
|
|
{ "TEAL", TEAL},
|
|
{ "BLUE", BLUE},
|
|
{ "NAVY", NAVY},
|
|
{ "FUCHSIA", FUCHSIA},
|
|
{ "PURPLE", PURPLE},
|
|
{ "ORANGE", ORANGE},
|
|
{ "BROWN", BROWN}
|
|
} ;
|
|
static const int NUM_STDCOLOR = ( sizeof(StdColor) / sizeof(StdColor[0]) ) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetStdColor( const string& sName, Color& cCol)
|
|
{
|
|
string sCol = sName ;
|
|
ToUpper( sCol) ;
|
|
for ( int i = 0 ; i < NUM_STDCOLOR ; ++ i) {
|
|
if ( sCol == StdColor[i].szName) {
|
|
cCol = StdColor[i].colC ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
GetNameOfStdColor( Color cCol, string& sName)
|
|
{
|
|
for ( int i = 0 ; i < NUM_STDCOLOR ; ++ i) {
|
|
if ( cCol == StdColor[i].colC) {
|
|
sName = StdColor[i].szName ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Color
|
|
GetOppositeColor( Color cCol)
|
|
{
|
|
return Color( MAX_RGB - cCol.GetIntRed(),
|
|
MAX_RGB - cCol.GetIntGreen(),
|
|
MAX_RGB - cCol.GetIntBlue(),
|
|
cCol.GetIntAlpha()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Color
|
|
GetSurfBackColor( Color cCol)
|
|
{
|
|
float fLum = ( cCol.GetRed() + cCol.GetGreen() + cCol.GetBlue()) / 3 ;
|
|
return Color( 0.4 * fLum + 0.2 * cCol.GetRed(),
|
|
0.4 * fLum + 0.2 * cCol.GetGreen(),
|
|
0.4 * fLum + 0.2 * cCol.GetBlue(),
|
|
cCol.GetAlpha()) ;
|
|
}
|