コード例 #1
0
        /// <summary>
        /// Converts this property to Global scoped C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public override string ToCSharpGlobal(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Make base
            sourceCode += $"// Global property {Name}\n";

            // Take action based on usage
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode += $"public static SKShader {ElementName} " +
                              "{get; set;}" +
                              $" = {Value.ElementName};\n";
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += $"public static KimonoPropertyGradient {ElementName} " +
                              "{get; set;}" +
                              $" = {ToKimonoCore()}\n";
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #2
0
        /// <summary>
        /// Converts this property to Parameter scoped C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public override string ToCSharpParameter(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = $"KimonoPropertyGradient {ElementName}";

            // Return results
            return(sourceCode);
        }
コード例 #3
0
        /// <summary>
        /// Converts this property to Global scoped C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public override string ToCSharpGlobal(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Make base
            sourceCode += $"// Global property {Name}\n";

            // Take action based on usage
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode += $"public static SKRect {ElementName} " +
                              "{get; set;}" +
                              $" = new SKRect({Value.Left}f, {Value.Top}f, {Value.Right}f, {Value.Bottom}f);\n";
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += $"public static KimonoPropertyRect {ElementName} " +
                              "{get; set;}" +
                              $" = {ToKimonoCore()}\n";
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #4
0
ファイル: KimonoShape.cs プロジェクト: yjpark/KimonoDesigner
 /// <summary>
 /// Gets the style frame paint for code.
 /// </summary>
 /// <value>The style frame paint for code.</value>
 public string StyleFramePaintForCode(CodeOutputLibrary outputLibrary)
 {
     // Is this shape using a custom style?
     if (outputLibrary == CodeOutputLibrary.SkiaSharp || Style.StyleType == KimonoStyleType.Custom || Style.StyleType == KimonoStyleType.Custom)
     {
         return($"{Style.ElementName}FramePaint");
     }
     else
     {
         return($"{Style.ElementName}.Frame");
     }
 }
コード例 #5
0
        /// <summary>
        /// Returns the source code for all of the supporting styles used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoGradients`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string CodeForSupportStyles(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all gradients
            foreach (KimonoStyle supportingStyle in SupportingStyles)
            {
                // Accumulate gradient
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += supportingStyle.ToCSharp(outputLibrary);
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #6
0
        /// <summary>
        /// Converts this property to Parameter scoped C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public virtual string ToCSharpParameter(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Take action based on usage
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                break;

            case CodeOutputLibrary.KimonoCore:
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #7
0
        /// <summary>
        /// Returns the source code for all of the sketches used in generating
        /// a higher level Kimono object as a public computed propert.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string PropertyForSketches(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process sketches
            foreach (KimonoSketch sketch in ObiScriptPortfolio.Portfolio.Sketches)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Global sketch {sketch.Name}\n";
                sourceCode += $"public static KimonoSketch {sketch.ElementName} " +
                              "{get; set;}\n";
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #8
0
        /// <summary>
        /// Converts this property to Local scoped C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public override string ToCSharpLocal(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Take action based on usage
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += $"// Local property {Name}\n" +
                              $"var {ElementName} = {ToKimonoCore()}\n";
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #9
0
ファイル: KimonoShape.cs プロジェクト: yjpark/KimonoDesigner
        /// <summary>
        /// Conforms the attached gradient to the shapes bounds for code.
        /// </summary>
        /// <returns>The frame gradient conformed in code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public string ConformedFrameGradientCode(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Anything to process?
            if (Style.FrameGradient != null)
            {
                // Get conforming coordinates
                var startPoint = new SKPoint();
                var endPoint   = new SKPoint();
                CalculateConfromingGradientCoordinates(Style.FrameGradient, out startPoint, out endPoint);

                // Conform gradient
                sourceCode += $"{StyleFramePaintForCode(outputLibrary)}.Shader = {Style.FrameGradient.ToCSharp(outputLibrary, startPoint, endPoint)};";
            }

            // Return code
            return(sourceCode);
        }
コード例 #10
0
ファイル: KimonoColor.cs プロジェクト: yjpark/KimonoDesigner
        /// <summary>
        /// Converts this shape to C# code.
        /// </summary>
        /// <returns>The shape as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public virtual string ToCSharp(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Take action based on the output library
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode += ToSkiaSharp();
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += ToKimonoCore();
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #11
0
        /// <summary>
        /// Converts the given point to code using the given library.
        /// </summary>
        /// <returns>The point as code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to encode to.</param>
        /// <param name="point">The `KimonoHandle` to encode.</param>
        public static string PointToCode(CodeOutputLibrary outputLibrary, KimonoHandle point)
        {
            var sourceCode = "";

            // Take action based on the language type
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode = $"new SKPoint({point.X}f, {point.Y}f)";
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode = $"new KimonoHandle({point.X}f, {point.Y}f)";
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #12
0
        /// <summary>
        /// Converts the given color to code using the given library.
        /// </summary>
        /// <returns>The color as code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to encode to.</param>
        /// <param name="color">The `SKColor` to create code for.</param>
        public static string ColorToCode(CodeOutputLibrary outputLibrary, SKColor color)
        {
            var sourceCode = "";

            // Take action based on the language type
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode = $"new SKColor({color.Red}, {color.Green}, {color.Blue}, {color.Alpha})";
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode = $"new KimonoColor({color.Red}, {color.Green}, {color.Blue}, {color.Alpha})";
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #13
0
        /// <summary>
        /// Converts this shape to C# code.
        /// </summary>
        /// <returns>The shape as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public override string ToCSharp(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = base.ToCode(CodeOutputOS.CrossPlatform, CodeOutputLanguage.CSharp, outputLibrary);

            // Define element name
            ElementName = KimonoCodeGenerator.MakeElementName(Name);

            // Take action based on the library
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode += ToSkiaSharp();
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += ToKimonoCore();
                break;
            }

            // Return code
            return(sourceCode);
        }
コード例 #14
0
        /// <summary>
        /// Converts this property to C# code.
        /// </summary>
        /// <returns>The property as C# code.</returns>
        /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
        public virtual string ToCSharp(CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Take action based on usage
            switch (Usage)
            {
            case KimonoPropertyUsage.GlobalVariable:
                sourceCode = ToCSharpGlobal(outputLibrary);
                break;

            case KimonoPropertyUsage.LocalVariable:
                sourceCode = ToCSharpLocal(outputLibrary);
                break;

            case KimonoPropertyUsage.Parameter:
                sourceCode = ToCSharpParameter(outputLibrary);
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #15
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object as a public computed propert.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string PropertyForSupportingStyles(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all colors
            foreach (KimonoStyle supportingStyle in SupportingStyles)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Global style {supportingStyle.Name}\n";

                // Take action based on library
                switch (outputLibrary)
                {
                case CodeOutputLibrary.SkiaSharp:
                    if (supportingStyle.HasFill)
                    {
                        sourceCode += $"public static SKPaint {supportingStyle.ElementName}FillPaint " +
                                      "{get; set;}\n";
                    }

                    if (supportingStyle.HasFill)
                    {
                        sourceCode += $"public static SKPaint {supportingStyle.ElementName}FramePaint " +
                                      "{get; set;}\n";
                    }
                    break;

                case CodeOutputLibrary.KimonoCore:
                    sourceCode += $"public static KimonoStyle {supportingStyle.ElementName} " +
                                  "{get; set;}\n";
                    break;
                }
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #16
0
        /// <summary>
        /// Returns the source code for all of the supporting gradients used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoGradients`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string InitializerForSupportGradients(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all gradients
            foreach (KimonoGradient supportingGradient in SupportingGradients)
            {
                // Accumulate gradient
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += supportingGradient.ToCSharpInitializer(outputLibrary);
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #17
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object as a public computed propert.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string PropertyForSupportingGradients(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";
            var classType  = (outputLibrary == CodeOutputLibrary.SkiaSharp) ? "SKShader" : "KimonoGradient";

            // Process all colors
            foreach (KimonoGradient supportingGradient in SupportingGradients)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Global gradient {supportingGradient.Name}\n";
                sourceCode += $"public static {classType} {supportingGradient.ElementName} " +
                              "{get; set;}\n";
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #18
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object as a public computed propert.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string PrivateVariablesForSupportingGradients(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all colors
            foreach (KimonoGradient supportingGradient in SupportingGradients)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Private gradient {supportingGradient.Name} vairables\n";
                sourceCode += $"private SKColor[] {supportingGradient.ElementName}Colors;\n" +
                              $"private float[] {supportingGradient.ElementName}Weights;\n";
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #19
0
        /// <summary>
        /// Returns the initializers for all of the supporting properties used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoProperty`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string CodeForInitializeParameterProperties(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all properties
            foreach (KimonoProperty supportProperty in ParameterProperties)
            {
                // Accumulate property
                if (sourceCode != "")
                {
                    sourceCode += ", ";
                }
                sourceCode += supportProperty.ElementName;
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #20
0
 /// <summary>
 /// Converts this shape to C# code.
 /// </summary>
 /// <returns>The shape as C# code.</returns>
 /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
 public virtual string ToCSharp(CodeOutputLibrary outputLibrary)
 {
     return("");
 }
コード例 #21
0
        /// <summary>
        /// Returns the source code for all of the supporting properties used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoProperty`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string CodeForSupportLocalProperties(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all properties
            foreach (KimonoProperty supportProperty in LocalProperties)
            {
                // Accumulate property
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += supportProperty.ToCode(CodeOutputOS.CrossPlatform, outputLanguage, outputLibrary);
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #22
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string InitializerForSupportColors(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Only valid for KimonoCode generation
            if (outputLibrary != CodeOutputLibrary.KimonoCore)
            {
                return("");
            }

            // Process all colors
            foreach (KimonoColor supportColor in SupportingColors)
            {
                // Accumulate gradient
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += supportColor.ConnectionsToKimonoCore();
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #23
0
ファイル: KimonoShape.cs プロジェクト: yjpark/KimonoDesigner
 /// <summary>
 /// Converts this shape to C# code.
 /// </summary>
 /// <returns>The shape as C# code.</returns>
 /// <param name="outputLibrary">The `CodeOutputLibrary` to use.</param>
 public override string ToCSharp(CodeOutputLibrary outputLibrary)
 {
     return("");
 }
コード例 #24
0
ファイル: KimonoShape.cs プロジェクト: yjpark/KimonoDesigner
        /// <summary>
        /// Converts this object to source code for the given OS, Language and Library.
        /// </summary>
        /// <returns>The object represented as source code in a `string`.</returns>
        /// <param name="outputOS">The `CodeOutputOS`.</param>
        /// <param name="outputLanguage">The `CodeOutputLanguage`.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary`.</param>
        public override string ToCode(CodeOutputOS outputOS, CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Is this shape using a custom style?
            if (Style.StyleType == KimonoStyleType.Custom || Style.StyleType == KimonoStyleType.CustomText)
            {
                // Yes, include it in the source code
                Style.Name        = $"{Name} Style";
                Style.ElementName = KimonoCodeGenerator.MakeElementName(Style.Name);

                // Take action based on the output language
                switch (outputLanguage)
                {
                case CodeOutputLanguage.CSharp:
                    sourceCode += Style.ToCSharp(outputLibrary);
                    break;

                case CodeOutputLanguage.ObiScript:
                    sourceCode += Style.ToObiScript();
                    break;
                }
            }
            else
            {
                // Accumulate linked styles
                KimonoCodeGenerator.AddSupportingStyle(Style);
            }

            // Return results
            return(sourceCode);
        }
コード例 #25
0
        /// <summary>
        /// Converts this object to source code for the given OS, Language and Library.
        /// </summary>
        /// <returns>The object represented as source code in a `string`.</returns>
        /// <param name="outputOS">The `CodeOutputOS`.</param>
        /// <param name="outputLanguage">The `CodeOutputLanguage`.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary`.</param>
        public string ToCode(CodeOutputOS outputOS, CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Take action based on the library
            switch (outputLibrary)
            {
            case CodeOutputLibrary.SkiaSharp:
                sourceCode += ToSkiaSharp();
                break;

            case CodeOutputLibrary.KimonoCore:
                sourceCode += ToKimonoCore();
                break;
            }

            // Return resulting code
            return(sourceCode);
        }
コード例 #26
0
        /// <summary>
        /// Returns the source code for all of the supporting properties used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoProperty`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string CodeForSupportParameterProperties(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all properties
            foreach (KimonoProperty supportProperty in ParameterProperties)
            {
                // Accumulate property
                if (sourceCode != "")
                {
                    sourceCode += ", ";
                }
                sourceCode += supportProperty.ToCode(CodeOutputOS.CrossPlatform, outputLanguage, outputLibrary);
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #27
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string CodeForSupportingColors(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Process all colors
            foreach (KimonoColor supportColor in SupportingColors)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Create new {supportColor.Name}\n";
                sourceCode += $"var {supportColor.ElementName} = {supportColor.ToCSharp(outputLibrary)};\n";
            }

            // Return generated source
            return(sourceCode);
        }
コード例 #28
0
        /// <summary>
        /// Converts this object to source code for the given OS, Language and Library.
        /// </summary>
        /// <returns>The object represented as source code in a `string`.</returns>
        /// <param name="outputOS">The `CodeOutputOS`.</param>
        /// <param name="outputLanguage">The `CodeOutputLanguage`.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary`.</param>
        public override string ToCode(CodeOutputOS outputOS, CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";

            // Accumulate color
            if (Value != null)
            {
                // Yes, add as a supporting gradient
                KimonoCodeGenerator.AddSupportingGradient(Value);
            }

            // Take action based on the output language
            switch (outputLanguage)
            {
            case CodeOutputLanguage.CSharp:
                sourceCode = ToCSharp(outputLibrary);
                break;
            }

            // Return results
            return(sourceCode);
        }
コード例 #29
0
        /// <summary>
        /// Converts this object to source code for the given OS, Language and Library.
        /// </summary>
        /// <returns>The object represented as source code in a `string`.</returns>
        /// <param name="outputOS">The `CodeOutputOS`.</param>
        /// <param name="outputLanguage">The `CodeOutputLanguage`.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary`.</param>
        public override string ToCode(CodeOutputOS outputOS, CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";
            var preCode    = "";

            // Take action based on the language
            switch (outputLanguage)
            {
            case CodeOutputLanguage.CSharp:
                sourceCode += ToCSharp(outputLibrary);
                break;

            case CodeOutputLanguage.ObiScript:
                sourceCode += "// Shapes are not supported in ObiScript\n";
                break;
            }

            // Assemble precode items in reverse order to ensure dependencies are registered first
            preCode = KimonoCodeGenerator.CodeForSupportStyles(outputLanguage, outputLibrary);
            preCode = KimonoCodeGenerator.CodeForSupportGradients(outputLanguage, outputLibrary) + preCode;
            preCode = KimonoCodeGenerator.CodeForSupportingColors(outputLanguage, outputLibrary) + preCode;

            // Include any supporting elements
            sourceCode = preCode + sourceCode;

            // Return code
            return(sourceCode);
        }
コード例 #30
0
        /// <summary>
        /// Returns the source code for all of the supporting colors used in generating
        /// a higher level Kimono object as a public computed propert.
        /// </summary>
        /// <returns>The source code for the supporting `KimonoColors`.</returns>
        /// <param name="outputLanguage">The `CodeOutputLanguage` for the generated code.</param>
        /// <param name="outputLibrary">The `CodeOutputLibrary` of the generated code.</param>
        public static string PropertyForSupportingColors(CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = "";
            var classType  = (outputLibrary == CodeOutputLibrary.SkiaSharp) ? "SKColor" : "KimonoColor";

            // Process all colors
            foreach (KimonoColor supportColor in SupportingColors)
            {
                // Accumulate color code
                sourceCode  = AddCarriageIfNeeded(sourceCode);
                sourceCode += $"// Global color {supportColor.Name}\n";
                sourceCode += $"public static {classType} {supportColor.ElementName} " +
                              "{get; set;} " +
                              $"= {supportColor.ToCSharp(outputLibrary)};\n";
            }

            // Return generated source
            return(sourceCode);
        }