Class Color
Base color object.
Inheritance
Implements
Namespace: BonEngineSharp.Framework
Assembly: BonEngineSharp.dll
Syntax
public sealed class Color : ValueType, IEquatable<Color>
Constructors
Color(Single, Single, Single, Single)
Create the color component.
Declaration
public Color(float r, float g, float b, float a = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | r | |
| System.Single | g | |
| System.Single | b | |
| System.Single | a |
Fields
A
Opacity.
Declaration
public float A
Field Value
| Type | Description |
|---|---|
| System.Single |
B
Blue component.
Declaration
public float B
Field Value
| Type | Description |
|---|---|
| System.Single |
Black
Black color const.
Declaration
public static readonly Color Black
Field Value
| Type | Description |
|---|---|
| Color |
Blue
Blue color const.
Declaration
public static readonly Color Blue
Field Value
| Type | Description |
|---|---|
| Color |
Cornflower
Famous blue-ish Cornflower color (commonly used as background color).
Declaration
public static readonly Color Cornflower
Field Value
| Type | Description |
|---|---|
| Color |
G
Green component.
Declaration
public float G
Field Value
| Type | Description |
|---|---|
| System.Single |
Gray
Gray color const.
Declaration
public static readonly Color Gray
Field Value
| Type | Description |
|---|---|
| Color |
Green
Green color const.
Declaration
public static readonly Color Green
Field Value
| Type | Description |
|---|---|
| Color |
HalfTransparent
Half transparent color const.
Declaration
public static readonly Color HalfTransparent
Field Value
| Type | Description |
|---|---|
| Color |
Orange
Orange color const.
Declaration
public static readonly Color Orange
Field Value
| Type | Description |
|---|---|
| Color |
Purple
Purple color const.
Declaration
public static readonly Color Purple
Field Value
| Type | Description |
|---|---|
| Color |
R
Red component.
Declaration
public float R
Field Value
| Type | Description |
|---|---|
| System.Single |
Red
Red color const.
Declaration
public static readonly Color Red
Field Value
| Type | Description |
|---|---|
| Color |
Teal
Teal color const.
Declaration
public static readonly Color Teal
Field Value
| Type | Description |
|---|---|
| Color |
Transparent
Transparent color const.
Declaration
public static readonly Color Transparent
Field Value
| Type | Description |
|---|---|
| Color |
TransparentBlack
Transparent black color const.
Declaration
public static readonly Color TransparentBlack
Field Value
| Type | Description |
|---|---|
| Color |
White
White color const.
Declaration
public static readonly Color White
Field Value
| Type | Description |
|---|---|
| Color |
Yellow
Yellow color const.
Declaration
public static readonly Color Yellow
Field Value
| Type | Description |
|---|---|
| Color |
Properties
AByte
Opacity as byte.
Declaration
public byte AByte { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Byte |
BByte
Blue component as byte.
Declaration
public byte BByte { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Byte |
GByte
Green component as byte.
Declaration
public byte GByte { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Byte |
RByte
Red component as byte.
Declaration
public byte RByte { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Byte |
Methods
Add(Color, Boolean)
Clone self and add other color to clone.
Declaration
public Color Add(Color other, bool includeAlpha = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | other | Color to add. |
| System.Boolean | includeAlpha | If true, will include alpha component. |
Returns
| Type | Description |
|---|---|
| Color | Cloned color with added other color. |
AddSelf(Color, Boolean)
Add other color to self.
Declaration
public void AddSelf(Color other, bool includeAlpha = true)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | other | Color to add. |
| System.Boolean | includeAlpha | If true, will include alpha component. |
Clone()
Clone this color.
Declaration
public Color Clone()
Returns
| Type | Description |
|---|---|
| Color | Cloned color object. |
Decrease(Single, Boolean)
Decrease all color components and make sure in valid range (0-1).
Declaration
public void Decrease(float amount, bool includeAlpha)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | amount | Quantity to reduce. |
| System.Boolean | includeAlpha | If true, will reduce opacity as well. |
Equals(Color)
Check if this color equals to another color.
Declaration
public bool Equals(Color other)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | other |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Equals(Object)
Check if this color equals to another object.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Object | obj |
Returns
| Type | Description |
|---|---|
| System.Boolean |
FromBytes(Byte, Byte, Byte, Byte)
Create color from components.
Declaration
public static Color FromBytes(byte r, byte g, byte b, byte a = 255)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte | r | |
| System.Byte | g | |
| System.Byte | b | |
| System.Byte | a |
Returns
| Type | Description |
|---|---|
| Color |
FromRGBA(Single, Single, Single, Single)
Create color from components.
Declaration
public static Color FromRGBA(float r, float g, float b, float a = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | r | |
| System.Single | g | |
| System.Single | b | |
| System.Single | a |
Returns
| Type | Description |
|---|---|
| Color |
FromString(String)
Create color from string with byte values.
Declaration
public static Color FromString(string str)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | str |
Returns
| Type | Description |
|---|---|
| Color |
GetHashCode()
Implement hash code of color.
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| System.Int32 |
Increase(Single, Boolean)
Increase all color components and make sure in valid range (0-1).
Declaration
public void Increase(float amount, bool includeAlpha)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | amount | Quantity to reduce. |
| System.Boolean | includeAlpha | If true, will reduce opacity as well. |
Lerp(Color, Color, Single)
Lerp between two colors.
Declaration
public static Color Lerp(Color a, Color b, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | a | From color. |
| Color | b | To color. |
| System.Single | delta | Lerp factor. |
Returns
| Type | Description |
|---|---|
| Color | Lerped color. |
PutInRange(Single, Single)
Make sure all color values are in given valid range.
Declaration
public void PutInRange(float min = 0F, float max = 1F)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Single | min | Min value for color components. |
| System.Single | max | Max value for color components. |
Random()
Create and return a random color.
Declaration
public static Color Random()
Returns
| Type | Description |
|---|---|
| Color | Random color. |
ToString(Boolean)
Convert color to pretty string, either as bytes or float values.
Declaration
public string ToString(bool asByte)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | asByte |
Returns
| Type | Description |
|---|---|
| System.String |
Operators
Equality(Color, Color)
Implement == operator.
Declaration
public static bool operator ==(Color obj1, Color obj2)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | obj1 | |
| Color | obj2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |
Inequality(Color, Color)
Implement != operator.
Declaration
public static bool operator !=(Color obj1, Color obj2)
Parameters
| Type | Name | Description |
|---|---|---|
| Color | obj1 | |
| Color | obj2 |
Returns
| Type | Description |
|---|---|
| System.Boolean |