Esempio n. 1
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Update any attached properties
            EvaluateConnectedProperties();

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.MoveTo({Left}f ,{Top}f);\n" +
                          $"{pathName}.LineTo({Right}f, {Bottom}f);\n";

            // Return code
            return(sourceCode);
        }
Esempio n. 2
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 = "";

            // 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);
        }
Esempio n. 3
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Update any attached properties
            EvaluateConnectedProperties();

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.MoveTo(new SKPoint({Points[0].EndPoint.X}f, {Points[0].EndPoint.Y}f));\n";
            for (int n = 1; n < Points.Count; n++)
            {
                sourceCode += $"{pathName}.QuadTo(new SKPoint({Points[n].ControlPoint.X}f, {Points[n].ControlPoint.Y}f), new SKPoint({Points[n].EndPoint.X}f, {Points[n].EndPoint.Y}f));\n";
            }
            if (Closed)
            {
                sourceCode += $"{pathName}.QuadTo(new SKPoint({Points[0].ControlPoint.X}f, {Points[0].ControlPoint.Y}f), new SKPoint({Points[0].EndPoint.X}f, {Points[0].EndPoint.Y}f));\n";
            }

            // Return code
            return(sourceCode);
        }
Esempio n. 4
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.MoveTo(new SKPoint({Points[0].X}f, {Points[0].Y}f));\n";
            for (int n = 1; n < Points.Count; n++)
            {
                sourceCode += $"{pathName}.LineTo(new SKPoint({Points[n].X}f, {Points[n].Y}f));\n";
            }
            if (Closed)
            {
                sourceCode += $"{pathName}.LineTo(new SKPoint({Points[0].X}f, {Points[0].Y}f));\n";
            }

            // Return code
            return(sourceCode);
        }
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Define star points
            var points = MakeSidePoints(-Math.PI / 2, NumberOfSides, Rect);

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.MoveTo(new SKPoint({points[0].X}f, {points[0].Y}f));\n";
            for (int n = 1; n < points.Length; n++)
            {
                sourceCode += $"{pathName}.LineTo(new SKPoint({points[n].X}f, {points[n].Y}f));\n";
            }
            sourceCode += $"{pathName}.LineTo(new SKPoint({points[0].X}f, {points[0].Y}f));\n";

            // Return code
            return(sourceCode);
        }
Esempio n. 6
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 virtual string ToCode(CodeOutputOS outputOS, CodeOutputLanguage outputLanguage, CodeOutputLibrary outputLibrary)
        {
            var sourceCode = $"// Create new {Name}\n";

            // Take action based on language
            switch (outputLanguage)
            {
            case CodeOutputLanguage.CSharp:
                sourceCode += $"var {KimonoCodeGenerator.MakeElementName(Name)} = " +
                              ToCSharp(outputLibrary) +
                              ";\n";
                break;

            case CodeOutputLanguage.ObiScript:
                sourceCode += $"Return.Color(\"{Name}\");\n";
                break;
            }

            // Return resulting code
            return(sourceCode);
        }
Esempio n. 7
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);
        }
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Update any attached properties
            EvaluateConnectedProperties();

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.AddRoundedRect(new SKRect({Rect.Left}f ,{Rect.Top}f, {Rect.Right}f, {Rect.Bottom}f), {CornerRadius}f, {CornerRadius}f, SKPathDirection.Clockwise);\n";

            // Return code
            return(sourceCode);
        }
Esempio n. 9
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Update any attached properties
            EvaluateConnectedProperties();

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            // TODO: Create text code paths

            // Return code
            return(sourceCode);
        }
Esempio n. 10
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Define path
            sourceCode += $"{pathName}.MoveTo(new SKPoint({HorizontalCenter}f, {Top}f));\n" +
                          $"{pathName}.LineTo(new SKPoint({Right}f, {Bottom}f));\n" +
                          $"{pathName}.LineTo(new SKPoint({Left}f, {Bottom}f));\n" +
                          $"{pathName}.LineTo(new SKPoint({HorizontalCenter}f, {Top}f));\n";

            // Return code
            return(sourceCode);
        }
Esempio n. 11
0
        /// <summary>
        /// Converts the shapes path to C# Skia based code.
        /// </summary>
        /// <returns>The path as code.</returns>
        public override string ToSkiaSharpPath()
        {
            var sourceCode = "";

            // Assemble path name
            if (ElementName == "")
            {
                KimonoCodeGenerator.MakeElementName(Name);
            }
            var pathName = $"{ElementName}Path";

            // Define path with Skia
            sourceCode += $"// Define {Name} shape path\n" +
                          $"var {pathName} = new SKPath();\n";

            // Calculate sizes
            var innerSize     = Width * (HeadInnerRatio * .01f);
            var outerSize     = Width * (HeadOuterRatio * .01f);
            var bodyThickness = Height / 4;

            // Is this a streamlined arrow?
            if (IsStreamlined)
            {
                // Yes, start streamlined arrow
                sourceCode += $"{pathName}.MoveTo(new SKPoint({Left}f, {VerticalCenter}f));\n";

                // Has starting head?
                if (HasStartHead)
                {
                    // Draw head
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Left + outerSize}f, {Top}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left + innerSize}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left + outerSize}f, {Bottom}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.MoveTo(new SKPoint({Left + innerSize}f, {VerticalCenter}f));\n";
                }

                // Has ending head?
                if (HasEndHead)
                {
                    // Draw body
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Right - innerSize}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.MoveTo(new SKPoint({Right}f, {VerticalCenter}f));\n";

                    // Draw head
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Right - outerSize}f, {Top}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right - innerSize}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right - outerSize}f, {Bottom}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right}f, {VerticalCenter}f));\n";
                }
                else
                {
                    // Draw body
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Right}f, {VerticalCenter}f));\n";
                }
            }
            else
            {
                // No, start thick arrow
                if (HasStartHead)
                {
                    // Draw head
                    sourceCode += $"{pathName}.MoveTo(new SKPoint({Left + innerSize}f, {VerticalCenter + bodyThickness}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left + outerSize}f, {Bottom}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left + outerSize}f, {Top}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left + innerSize}f, {VerticalCenter - bodyThickness}f));\n";
                }
                else
                {
                    // Draw flat end
                    sourceCode += $"{pathName}.MoveTo(new SKPoint({Left}f, {VerticalCenter + bodyThickness}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Left}f, {VerticalCenter - bodyThickness}f));\n";
                }

                // Has ending head?
                if (HasEndHead)
                {
                    // Draw Head
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Right - innerSize}f, {VerticalCenter - bodyThickness}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right - outerSize}f, {Top}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right}f, {VerticalCenter}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right - outerSize}f, {Bottom}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right - innerSize}f, {VerticalCenter + bodyThickness}f));\n";
                }
                else
                {
                    // Draw flat end
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Right}f, {VerticalCenter - bodyThickness}f));\n" +
                                  $"{pathName}.LineTo(new SKPoint({Right}f, {VerticalCenter + bodyThickness}f));\n";
                }

                // Terminate
                if (HasStartHead)
                {
                    // Close head
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Left + innerSize}f, {VerticalCenter + bodyThickness}f));\n";
                }
                else
                {
                    // Close flat end
                    sourceCode += $"{pathName}.LineTo(new SKPoint({Left}f, {VerticalCenter + bodyThickness}f));\n";
                }
            }

            // Return code
            return(sourceCode);
        }