// Copyright (C) 2002-2006 Nikolaus Gebhardt // This file is part of the "Irrlicht Engine". // For conditions of distribution and use, see copyright notice in irrlicht.h #pragma once namespace Irrlicht { namespace Video { /// /// Class representing a 32 bit ARGB color. /// The color values for red, green, blue /// and alpha are stored in a single System::Int32. So all four values may be between 0 and 255. /// This class is used by most parts of the Irrlicht Engine /// to specify a color. An other way is using the class Colorf, which /// stores the color values in 4 floats. /// public __value class Color { public: /// Constructor of the Color. Does nothing. /// This class has been ported directly from the native C++ Irrlicht Engine, so it may not /// be 100% complete yet and the design may not be 100% .NET like. /// inline Color() {} /// /// Constructs the color from 4 values representing the alpha, red, green and /// blue components of the color. Must be values between 0 and 255. /// inline Color (System::Int32 a, System::Int32 r, System::Int32 g, System::Int32 b) { color = ((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff); } /// /// Constructs the color from a 32 bit value. Could be another color. /// inline Color(System::Int32 clr) { color = clr; } static bool op_Equality(Color o1, Color o2) { return (o1.color == o2.color); } /// /// Returns the alpha component of the color. The alpha component /// defines how transparent a color should be. /// 0 means not transparent, 255 means fully transparent. /// __property inline System::Int32 get_Alpha() { return (color>>24) & 0xff; } /// /// Returns the red component of the color. /// /// Returns a value between 0 and 255, specifying how red the color is. /// 0 means dark, 255 means full red. __property inline System::Int32 get_Red() { return (color>>16) & 0xff; } /// /// Returns the green component of the color. /// /// Returns a value between 0 and 255, specifying how green the color is. /// 0 means dark, 255 means full green. __property inline System::Int32 get_Green() { return (color>>8) & 0xff; } /// /// Returns the blue component of the color. /// /// Returns a value between 0 and 255, specifying how blue the color is. /// 0 means dark, 255 means full blue. __property inline System::Int32 get_Blue() { return color & 0xff; } /// /// Sets the alpha comonent of the Color. The alpha component /// defines how transparent a color should be. /// /// Has to be a value between 0 and 255. /// 0 means not transparent, 255 means fully transparent. __property inline void set_Alpha(System::Int32 a) { color = ((a & 0xff)<<24) | (((color>>16)& 0xff)<<16) | ((color>>8 & 0xff)<<8) | (color & 0xff); } /// /// Sets the red comonent of the Color. /// /// Has to be a value between 0 and 255. /// 0 means dark red (=black), 255 means full red. __property inline void set_Red(System::Int32 r) { color = (((color>>24) & 0xff)<<24) | ((r & 0xff)<<16) | ((color>>8 & 0xff)<<8) | (color & 0xff); } /// /// Sets the green comonent of the Color. /// /// Has to be a value between 0 and 255. /// 0 means dark green (=black), 255 means full green. __property inline void set_Green(System::Int32 g) { color = (((color>>24) & 0xff)<<24) | (((color>>16)& 0xff)<<16) | ((g & 0xff)<<8) | (color & 0xff); } /// /// Sets the blue comonent of the Color. /// /// Has to be a value between 0 and 255. /// 0 means dark blue (=black), 255 means full blue. __property inline void set_Blue(System::Int32 b) { color = (((color>>24) & 0xff)<<24) | (((color>>16)& 0xff)<<16) | ((color>>8 & 0xff)<<8) | (b & 0xff); } /// /// Calculates a 16 bit A1R5G5B5 value of this color. /// /// Returns the 16 bit A1R5G5B5 value of this color. inline System::Int16 ToA1R5G5B5() { return ((((color>>16)>>3) & 0x1F)<<10) | ((((color>>8)>>3) & 0x1F)<<5) | ((color>>3) & 0x1F); }; /// /// Converts color to open gl color format. /// /// Returns the 32 bit openGL color value. inline System::Int32 ToOpenGLColor() { return (((color>>24) & 0xff)<<24) | (((color)& 0xff)<<16) | ((color>>8 & 0xff)<<8) | ((color>>16) & 0xff); }; /// /// Sets all four components of the color at once. /// Constructs the color from 4 values representing the alpha, red, green and /// blue components of the color. Must be values between 0 and 255. /// /// Alpha component of the color. /// The alpha component defines how transparent a color should be. /// Has to be a value between 0 and 255. /// 0 means not transparent, 255 means fully transparent. /// Sets the red comonent of the Color. /// Has to be a value between 0 and 255. /// 0 means dark red (=black), 255 means full red. /// Sets the green comonent of the Color. /// Has to be a value between 0 and 255. /// 0 means dark green (=black), 255 means full green. /// Sets the blue comonent of the Color. /// Has to be a value between 0 and 255. /// 0 means dark blue (=black), 255 means full blue. inline void Set(System::Int32 a, System::Int32 r, System::Int32 g, System::Int32 b) { color = (((a & 0xff)<<24) | ((r & 0xff)<<16) | ((g & 0xff)<<8) | (b & 0xff)); } /// /// Compares the color to another color. /// /// Returns true if the colors are the same, and false if not. bool Equals(Object* rhs) { Color* c = dynamic_cast(rhs); if(!c) return false; return c->color == color; } /// /// Compares the color to another color. /// /// Returns true if the colors are different, and false if they are the same. static bool op_Inequality(Color m1, Color m2) { return m1.color != m2.color; } /// /// Interpolates the color with a float value to an other color. The float must be between 0 and 1. /// inline Color GetInterpolated(Color other, float d) { float inv = 1.0f - d; return Color((System::Int32)(other.Alpha*inv + Alpha*d), (System::Int32)(other.Red*inv + Red*d), (System::Int32)(other.Green*inv + Green*d), (System::Int32)(other.Blue*inv + Blue*d)); } /// /// color in A8R8G8B8 Format /// System::Int32 color; }; /// /// Class representing a color with four floats. /// The color values for red, green, blue /// and alpha are each stored in a 32 bit floating point variable. /// So all four values may be between 0.0f and 1.0f. /// This class is used rarely used by the Irrlicht Engine /// to specify a color. An other, faster way is using the class Color, which /// stores the color values in a single 32 bit integer. /// This class has been ported directly from the native C++ Irrlicht Engine, so it may not /// be 100% complete yet and the design may not be 100% .NET like. /// public __value class Colorf { public: /// /// Constructs a color. All values are initialised with 0.0f, resulting /// in a black color. /// Colorf() : r(0.0f), g(0.0f), b(0.0f), a(0.0f) {}; /// /// Constructs a color from three color values: red, green and blue. /// /// Red color component. Should be a value between 0.0f meaning /// very dark red (=black) and 1.0f, meaning full red. /// Green color component. Should be a value between 0.0f meaning /// very dark green (=black) and 1.0f, meaning full green. /// Blue color component. Should be a value between 0.0f meaning /// very dark blue (=black) and 1.0f, meaning full blue. Colorf(float r, float g, float b) : r(r), g(g), b(b), a(1.0f) {}; /// /// Constructs a color from four color values: alpha, red, green and blue. /// /// Alpha color component of the color. /// The alpha component defines how transparent a color should be. /// Has to be a value between 0.0f and 1.0f, /// 0.0f means not transparent, 1.0f means fully transparent. /// Red color component. Should be a value between 0.0f meaning /// very dark red (=black) and 1.0f, meaning full red. /// Green color component. Should be a value between 0.0f meaning /// very dark green (=black) and 1.0f, meaning full green. /// Blue color component. Should be a value between 0.0f meaning /// very dark blue (=black) and 1.0f, meaning full blue. Colorf(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {}; /// /// Constructs a color from 32 bit Color. /// /// 32 bit color value from which this Colorf class is /// constructed from. Colorf(Color c) { const float inv = 1.0f / 255.0f; r = c.Red * inv; g = c.Green * inv; b = c.Blue * inv; a = c.Alpha * inv; }; /// /// Converts this color to a Color without floats. /// Color toSColor() { return Color((System::Int32)(a*255.0f), (System::Int32)(r*255.0f), (System::Int32)(g*255.0f), (System::Int32)(b*255.0f)); } /// /// Sets the three color comonents to new values at once. /// /// Red color component. Should be a value between 0.0f meaning /// very dark red (=black) and 1.0f, meaning full red. /// Green color component. Should be a value between 0.0f meaning /// very dark green (=black) and 1.0f, meaning full green. /// Blue color component. Should be a value between 0.0f meaning /// very dark blue (=black) and 1.0f, meaning full blue. void Set(float rr, float gg, float bb) { r = rr; g =gg; b = bb; } /// /// red color component /// float r; /// /// green color component /// float g; /// /// blue component /// float b; /// /// alpha color component /// float a; }; } }