Fixed COLOR4D( EDA_COLOR_T aColor ) and added asserts.

This commit is contained in:
Maciej Suminski 2013-09-11 10:30:39 +02:00
parent 6d15131231
commit 7d4aed1099
2 changed files with 16 additions and 3 deletions

View File

@ -30,9 +30,9 @@ using namespace KiGfx;
COLOR4D::COLOR4D( EDA_COLOR_T aColor ) COLOR4D::COLOR4D( EDA_COLOR_T aColor )
{ {
r = g_ColorRefs[aColor].m_Red; r = g_ColorRefs[aColor].m_Red / 255.0;
g = g_ColorRefs[aColor].m_Green; g = g_ColorRefs[aColor].m_Green / 255.0;
b = g_ColorRefs[aColor].m_Blue; b = g_ColorRefs[aColor].m_Blue / 255.0;
a = 1.0; a = 1.0;
} }

View File

@ -28,6 +28,7 @@
#define COLOR4D_H_ #define COLOR4D_H_
#include <colors.h> #include <colors.h>
#include <cassert>
namespace KiGfx namespace KiGfx
{ {
@ -55,6 +56,10 @@ public:
COLOR4D( double aRed, double aGreen, double aBlue, double aAlpha ) : COLOR4D( double aRed, double aGreen, double aBlue, double aAlpha ) :
r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha ) r( aRed ), g( aGreen ), b( aBlue ), a( aAlpha )
{ {
assert( r >= 0.0 && r <= 1.0 );
assert( g >= 0.0 && g <= 1.0 );
assert( b >= 0.0 && b <= 1.0 );
assert( a >= 0.0 && a <= 1.0 );
} }
/** /**
@ -82,6 +87,8 @@ public:
*/ */
COLOR4D& Brighten( double aFactor ) COLOR4D& Brighten( double aFactor )
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 );
r = r * ( 1.0 - aFactor ) + aFactor; r = r * ( 1.0 - aFactor ) + aFactor;
g = g * ( 1.0 - aFactor ) + aFactor; g = g * ( 1.0 - aFactor ) + aFactor;
b = b * ( 1.0 - aFactor ) + aFactor; b = b * ( 1.0 - aFactor ) + aFactor;
@ -97,6 +104,8 @@ public:
*/ */
COLOR4D& Darken( double aFactor ) COLOR4D& Darken( double aFactor )
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 );
r = r * ( 1.0 - aFactor ); r = r * ( 1.0 - aFactor );
g = g * ( 1.0 - aFactor ); g = g * ( 1.0 - aFactor );
b = b * ( 1.0 - aFactor ); b = b * ( 1.0 - aFactor );
@ -126,6 +135,8 @@ public:
*/ */
COLOR4D Brightened( double aFactor ) const COLOR4D Brightened( double aFactor ) const
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 );
return COLOR4D( r * ( 1.0 - aFactor ) + aFactor, return COLOR4D( r * ( 1.0 - aFactor ) + aFactor,
g * ( 1.0 - aFactor ) + aFactor, g * ( 1.0 - aFactor ) + aFactor,
b * ( 1.0 - aFactor ) + aFactor, b * ( 1.0 - aFactor ) + aFactor,
@ -140,6 +151,8 @@ public:
*/ */
COLOR4D Darkened( double aFactor ) const COLOR4D Darkened( double aFactor ) const
{ {
assert( aFactor >= 0.0 && aFactor <= 1.0 );
return COLOR4D( r * ( 1.0 - aFactor ), return COLOR4D( r * ( 1.0 - aFactor ),
g * ( 1.0 - aFactor ), g * ( 1.0 - aFactor ),
b * ( 1.0 - aFactor ), b * ( 1.0 - aFactor ),