/// <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); }
/// <summary> /// Converts all connected points to KimonoCore source code objects. /// </summary> /// <returns>The code to rebuild the connections are source code.</returns> public virtual string ConnectionsToKimonoCore() { var sourceCode = ""; // Anything to process? if (PropertyConnections.Count < 1) { return(""); } // Start list sourceCode += $"// Property connections for {Name}.\n"; // Process all connections foreach (KimonoPropertyConnection connection in PropertyConnections) { // Accumulate the connection point KimonoCodeGenerator.AddSupportingProperty(connection.ConnectedProperty); // Add code for point sourceCode += $"{ElementName}.PropertyConnections.Add(new KimonoPropertyConnection(KimonoPropertyConnectionPoint.{connection.ConnectionPoint} , {connection.ConnectedProperty.ElementName}));\n"; } // Return results return(sourceCode); }
/// <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); }
/// <summary> /// Converts this shadow to C# code using the Skia library. /// </summary> /// <returns>The shadow as code.</returns> public virtual string ToSkiaSharp() { var sourceCode = ""; var colorName = ""; // Using linked color? if (LinkedColor == null) { // Save color name colorName = $"{Name}ShadowColor"; // No, generate a one off color sourceCode += $"// Shadow color for {Name}\n" + $"var {colorName} = {KimonoCodeGenerator.ColorToCode(CodeOutputLibrary.SkiaSharp, Color)};\n\n"; } else { // Save linked color colorName = KimonoCodeGenerator.AddSupportingColor(LinkedColor); } // Assemble code sourceCode += $"// Build shadow for {Name}\n" + $"var {Name}Shadow = SKImageFilter.CreateDropShadow({HorizontalOffset}f, {VerticalOffset}f, {HorizontalBlurAmount}f, {VerticalBlurAmount}f, {colorName}, SKDropShadowImageFilterShadowMode.DrawShadowAndForeground, null, null);\n"; // Return resulting 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"; // 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); } 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); }
/// <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); }
/// <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); }
/// <summary> /// Checks to see if a property is attached to the given connection point. If so, the /// property is used in code generation, else the default code is used. /// </summary> /// <returns>The source code for the possible connection point.</returns> /// <param name="connectionPoint">The `KimonoPropertyConnectionPoint` to test for a connection.</param> /// <param name="defaultCode">The default source code that will be used if no code is attached to the given point.</param> public virtual string CheckForConnection(KimonoPropertyConnectionPoint connectionPoint, string defaultCode) { // Scan for used properties foreach (KimonoPropertyConnection connection in PropertyConnections) { // Is there an active connection to the given point? if (connection.ConnectionPoint == connectionPoint) { // Yes, add this property and return its name return(KimonoCodeGenerator.AddSupportingProperty(connection.ConnectedProperty)); } } // Not found, use the default code return(defaultCode); }
/// <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); }
/// <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); }
/// <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; } // Include any supporting colors sourceCode = KimonoCodeGenerator.CodeForSupportingColors(outputLanguage, outputLibrary) + sourceCode; // Return resulting code return(sourceCode); }
/// <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 this shadow to C# code using the KimonoCore library. /// </summary> /// <returns>The shadow as code.</returns> public virtual string ToKimonoCore() { var sourceCode = ""; // Assemble code sourceCode += $"// Build shadow for {Name}\n" + $"var {Name}Shadow = new KimonoShadow({HorizontalOffset}f, {VerticalOffset}f, {HorizontalBlurAmount}f, {VerticalBlurAmount}f);\n"; // Using linked color? if (LinkedColor == null) { // No, generate a one off color sourceCode += $"{Name}Shadow.Color = {KimonoCodeGenerator.ColorToCode(CodeOutputLibrary.SkiaSharp, Color)};\n"; } else { // Use linked color sourceCode += $"{Name}Shadow.LinkedColor = {KimonoCodeGenerator.AddSupportingColor(LinkedColor)};\n"; } // Return resulting 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); }
/// <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); }
/// <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); }
/// <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); }