X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Fdali-swig%2Fmanual%2Fcsharp%2FColor.cs;h=abcb02015ccc9282d55c269d599d43bbe774552e;hb=1bce7020a14529b22c72b115f0ba63122d1413a6;hp=56112e7045369c99c28740427977567d444e8ff1;hpb=ee431c9e2b342243f9e0e2b6bafca7505d321457;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/plugins/dali-swig/manual/csharp/Color.cs b/plugins/dali-swig/manual/csharp/Color.cs index 56112e7..abcb020 100644 --- a/plugins/dali-swig/manual/csharp/Color.cs +++ b/plugins/dali-swig/manual/csharp/Color.cs @@ -1,238 +1,381 @@ -namespace Dali { - namespace CSharp { +namespace Dali +{ + using System; - using System; + public enum Colors + { + Red, + White, + Blue, + Green, + Black, + Yellow, + Magenta, + Cyan + } + + + public class Color + { - public enum Colors + private float r; + private float g; + private float b; + private float a; + + /** + * @brief constructor + * + * @since 1.0.0 + */ + public Color() { - Red, - White, - Blue, - Green, - Black, - Grey, - Yellow, - Azure, - Rose + r = 0.0f; + g = 0.0f; + b = 0.0f; + a = 0.0f; } - public class Color + /** + * @brief constructor + * + * @since 1.0.0 + * @param [in] red The Color r. + * @param [in] green The Color g. + * @param [in] blue The Color b. + * @param [in] alpha The Color a. + */ + public Color(float red, float green, float blue, float alpha) { + r = red; + g = green; + b = blue; + a = alpha; + } - public float[] v; + /** + * @brief constructor + * + * @since 1.0.0 + * @param [in] o The Vector4 having r g b a components + */ + public Color(Vector4 o) + { + r = o.r; + g = o.g; + b = o.b; + a = o.a; + } - /** - * @brief constructor - * - * @since 1.0.0 - */ - public Color() - { - v = new float[4]; - } - /** - * @brief constructor - * - * @since 1.0.0 - * @param [in] red The Color r. - * @param [in] green The Color g. - * @param [in] blue The Color b. - * @param [in] alpha The Color a. - */ - public Color(float red, float green, float blue, float alpha):this() + /** + * @brief constructor + * + * @since 1.0.0 + * @param [in] color as enum Colors. + */ + public Color(Colors color) + { + switch (color) { - v[0] = red; - v[1] = green; - v[2] = blue; - v[3] = alpha; + case Colors.Red: + SetColor(1.0f, 0.0f, 0.0f, 1.0f); + break; + case Colors.White: + SetColor(1.0f, 1.0f, 1.0f, 1.0f); + break; + case Colors.Blue: + SetColor(0.0f, 0.0f, 1.0f, 1.0f); + break; + case Colors.Green: + SetColor(0.0f, 1.0f, 0.0f, 1.0f); + break; + case Colors.Black: + SetColor(0.0f, 0.0f, 0.0f, 1.0f); + break; + case Colors.Yellow: + SetColor(1.0f, 1.0f, 0.0f, 1.0f); + break; + case Colors.Cyan: + SetColor(0.0f, 1.0f, 1.0f, 1.0f); + break; + case Colors.Magenta: + SetColor(1.0f, 0.0f, 1.0f, 1.0f); + break; } + } - /** - * @brief constructor - * - * @since 1.0.0 - * @param [in] color as enum Colors. - */ - public Color(Colors color) - : this(0, 0, 0, 0) - { - switch (color) - { - case Colors.Red: - SetColor(255, 0, 0, 255); - break; - case Colors.White: - SetColor(255, 255, 255, 255); - break; - case Colors.Blue: - SetColor(0, 0, 255, 255); - break; - case Colors.Green: - SetColor(0, 255, 0, 255); - break; - case Colors.Black: - SetColor(0, 0, 0, 255); - break; - case Colors.Grey: - SetColor(128, 128, 128, 255); - break; - case Colors.Yellow: - SetColor(255, 255, 0, 255); - break; - case Colors.Azure: - SetColor(0, 255, 255, 255); - break; - case Colors.Rose: - SetColor(255, 0, 255, 255); - break; - } - } + /** + * @brief SetColor + * + * @since 1.0.0 + * @param [in] red The Color r. + * @param [in] green The Color g. + * @param [in] blue The Color b. + * @param [in] alpha The Color a. + */ + public void SetColor(float red, float green, float blue, float alpha) + { + r = red; + g = green; + b = blue; + a = alpha; + } + /** + * @brief name "R", type float (Color's Red component) + * @SINCE_1_0.0 + */ + public float R + { + get { return r; } + set { r = value; } + } - /** - * @brief SetColor - * - * @since 1.0.0 - * @param [in] red The Color r. - * @param [in] green The Color g. - * @param [in] blue The Color b. - * @param [in] alpha The Color a. - */ - public void SetColor(float red, float green, float blue, float alpha) - { - R = red; - G = green; - B = blue; - A = alpha; - } + /** + * @brief name "G", type float (Color's Green component) + * @SINCE_1_0.0 + */ + public float G + { + get { return g; } + set { g = value; } + } - /** - * @brief name "R", type float (Color's Red component) - * @SINCE_1_0.0 - */ + /** + * @brief name "B", type float (Color's Blue component) + * @SINCE_1_0.0 + */ + public float B + { + get { return b; } + set { b = value; } + } - public float R - { - get { return v[0]; } - set { v[0] = value; } - } + /** + * @brief name "A", type float (Color's Alpha value) + * @SINCE_1_0.0 + */ + public float A + { + get { return a; } + set { a = value; } + } - /** - * @brief name "G", type float (Color's Green component) - * @SINCE_1_0.0 - */ - public float G - { - get { return v[1]; } - set { v[1] = value; } - } + /** + * @brief operator+ + * + * @since 1.0.0 + * @param [in] l The Color to add. + * @param [in] r The Color to add + * @return A reference to this + */ + public static Color operator +(Color l, Color r) + { + return new Color(l.R + r.R, l.G + r.G, l.B + r.B, l.A + r.A); + } - /** - * @brief name "B", type float (Color's Blue component) - * @SINCE_1_0.0 - */ - public float B + /** + * @brief operator- + * + * @since 1.0.0 + * @param [in] l The Color to substract. + * @param [in] r The Color to substract + * @return A reference to this + */ + public static Color operator -(Color l, Color r) + { + return new Color(l.R - r.R, l.G - r.G, l.B - r.B, l.A - r.A); + } + + /** + * @brief operator* + * + * @since 1.0.0 + * @param [in] a The Color to multiply. + * @param [in] b The constant double to multiply. + * @return A reference to this + */ + public static Color operator *(Color a, double b) + { + return new Color((float)(a.R * b), (float)(a.G * b), (float)(a.B * b), (float)(a.A * b)); + } + + /** + * @brief operator/ + * + * @since 1.0.0 + * @param [in] a The Color to divide. + * @param [in] b The Color to divide + * @return float value of division operation + */ + public static float operator /(Color a, Color b) + { + return (float)System.Math.Sqrt((a.R / b.R) * (a.G / b.G) * (a.B / b.B) * (a.A / b.A)); + } + + /** + * @brief Operator == + * + * @since 1.0.0 + * @param [in] x The Color object to compare. + * @param [in] y The Color object to compare. + * @return bool, whether colors are equal or not + */ + public static bool operator == (Color x, Color y) + { + return x.R == y.R && x.G == y.G && x.B == y.B && x.A == y.A; + } + + /** + * @brief Operator != + * + * @since 1.0.0 + * @param [in] x The Color object to compare. + * @param [in] y The Color object to compare. + * @return bool, whether colors are equal or not + */ + public static bool operator != (Color x, Color y) + { + return x.R != y.R || x.G != y.G || x.B != y.B || x.A != y.A; + } + + /** + * @brief GetHashCode + * + * @since 1.0.0 + * @return int, hascode of Color + */ + public override int GetHashCode() + { + return base.GetHashCode(); + } + + /** + * @brief Clone + * + * @since 1.0.0 + * @return Color object + */ + public Color Clone() + { + Color copy = new Color(R, G, B, A); + return copy; + } + + // Create a color for RGBA values ranging from 0..255, useful when dealing with HTML colors + static Color FromRgbaByte( byte red, byte green, byte blue, byte alpha ) + { + return new Color ( red / 255, green / 255, blue / 255, alpha / 255 ); + } + + // User-defined conversion from Color to Vector4 + public static implicit operator Vector4(Color color) + { + return new Vector4(color.r, color.g, color.b, color.a); + } + + public static implicit operator Color(Vector4 vec) + { + return new Color(vec.r, vec.g, vec.b, vec.a); + } + + /** + * @brief name "White", type Color (White Color object) + * @SINCE_1_0.0 + */ + public static Color White + { + get { - get { return v[2]; } - set { v[2] = value; } + return new Color(Colors.White); } + } - /** - * @brief name "A", type float (Color's Alpha value) - * @SINCE_1_0.0 - */ - public float A + /** + * @brief name "Black", type Color (Black Color object) + * @SINCE_1_0.0 + */ + public static Color Black + { + get { - get { return v[3]; } - set { v[3] = value; } + return new Color(Colors.Black); } + } - /** - * @brief operator+ - * - * @since 1.0.0 - * @param [in] l The Color to add. - * @param [in] r The Color to add - * @return A reference to this - */ - public static Color operator +(Color l, Color r) + /** + * @brief name "Red", type Color (Red Color object) + * @SINCE_1_0.0 + */ + public static Color Red + { + get { - return new Color(l.R + r.R, l.G + r.G, l.B + r.B, l.A + r.A); + return new Color(Colors.Red); } + } - /** - * @brief operator- - * - * @since 1.0.0 - * @param [in] l The Color to substract. - * @param [in] r The Color to substract - * @return A reference to this - */ - public static Color operator -(Color l, Color r) + /** + * @brief name "Green", type Color (Green Color object) + * @SINCE_1_0.0 + */ + public static Color Green + { + get { - return new Color(l.R - r.R, l.G - r.G, l.B - r.B, l.A - r.A); + return new Color(Colors.Green); } + } - /** - * @brief operator* - * - * @since 1.0.0 - * @param [in] a The Color to multiply. - * @param [in] b The Color to multiply - * @return A reference to this - */ - public static Color operator *(Color a, double b) + /** + * @brief name "Blue", type Color (Blue Color object) + * @SINCE_1_0.0 + */ + public static Color Blue + { + get { - return new Color((float)(a.R * b),(float)(a.G * b), (float)(a.B * b), (float)(a.A * b)); + return new Color(Colors.Blue); } + } - /** - * @brief operator/ - * - * @since 1.0.0 - * @param [in] a The Color to divide. - * @param [in] b The Color to divide - * @return float value of division operation - */ - public static float operator /(Color a, Color b) + /** + * @brief name "Yellow", type Color (Yellow Color object) + * @SINCE_1_0.0 + */ + public static Color Yellow + { + get { - return (float)System.Math.Sqrt((a.R / b.R) * (a.G / b.G) * (a.B / b.B) * (a.A / b.A)); + return new Color(Colors.Yellow); } + } - /** - * @brief Equals - * - * @since 1.0.0 - * @param [in] o The Color object to compare. - * @param [in] r The Color to add - * @return bool, whether object equal or not - */ - public override bool Equals(object obj) + /** + * @brief name "Magenta", type Color (Magenta Color object) + * @SINCE_1_0.0 + */ + public static Color Magenta + { + get { - Color l = this; - Color r = obj as Color; - if (r == null) - { - return false; - } - return l.R == r.R && l.G == r.G && l.B == r.B && l.A == r.A; + return new Color(Colors.Magenta); } + } - /** - * @brief Clone - * - * @since 1.0.0 - * @return Color object - */ - public Color Clone() + /** + * @brief name "Cyan", type Color (Cyan Color object) + * @SINCE_1_0.0 + */ + public static Color Cyan + { + get { - Color copy = new Color(R, G, B, A); - return copy; + return new Color(Colors.Cyan); } } } - }