From 9485bf59c285547e4d5ba97b0270f914a2b2cf63 Mon Sep 17 00:00:00 2001 From: Emil Abraham Date: Wed, 2 Nov 2016 18:40:29 +0530 Subject: [PATCH] Dali C# binding : Creating Color Constructor to accept enum Colors The Color class takes a string in the constructor, so it cannot check whether the string represents a valid color. Here we define constants for these colors as enum, so that it can do this check during compilation. Now we can use stage.BackgroundColor = new Color(Colors.White); instead of stage.BackgroundColor = new Color("white"); Change-Id: I135e4103d6f9171011ed9d4e60f486a3e237d6cd Signed-off-by: Emil Abraham --- plugins/dali-swig/examples/dali-test.cs | 2 +- plugins/dali-swig/manual/csharp/Color.cs | 59 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/plugins/dali-swig/examples/dali-test.cs b/plugins/dali-swig/examples/dali-test.cs index 27b04bf..d13b4ea 100644 --- a/plugins/dali-swig/examples/dali-test.cs +++ b/plugins/dali-swig/examples/dali-test.cs @@ -62,7 +62,7 @@ namespace MyCSharpExample Console.WriteLine("Actor name: " + actor.Name); Stage stage = Stage.GetCurrent(); - stage.BackgroundColor = new Color("white") ; + stage.BackgroundColor = new Color(Colors.White) ; Size stageSize = stage.Size; Console.WriteLine("Stage size: " + stageSize.x + ", " + stageSize.y); diff --git a/plugins/dali-swig/manual/csharp/Color.cs b/plugins/dali-swig/manual/csharp/Color.cs index 0082950..3115a71 100644 --- a/plugins/dali-swig/manual/csharp/Color.cs +++ b/plugins/dali-swig/manual/csharp/Color.cs @@ -2,6 +2,22 @@ namespace Dali { using System; + +public enum Colors +{ + Red, + White, + Blue, + Green, + Black, + Grey, + Yellow, + Azure, + Rose +} + + + public class Color : Vector4 { /** @@ -77,6 +93,49 @@ public class Color : Vector4 break; } } + + + /** + * @brief constructor + * + * @since 1.0.0 + * @param [in] color as enum Colors. + */ + public Color(Colors color) + : base(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 -- 2.7.4