Example #1
0
 /// <summary>
 /// Draws a circle with an outline.
 /// </summary>
 /// <param name="center">The center.</param>
 /// <param name="radius">The radius.</param>
 /// <param name="outlineRadius">The outline radius.</param>
 /// <param name="slices">The slices.</param>
 /// <param name="borderSize">Size of the border.</param>
 /// <param name="color">The color.</param>
 /// <param name="borderColor">Color of the border.</param>
 /// <returns>A full Circular ShapeDescriptor object.</returns>
 public static ShapeDescriptor DrawFullCircle(Vector2 center, float radius, float outlineRadius,
                                              int slices, int borderSize, Color color, Color borderColor)
 {
     return(ShapeDescriptor.Join(
                DrawCircle(center, radius, slices, color),
                DrawCircularOutline(center, outlineRadius, slices, borderSize, borderColor)));
 }
Example #2
0
        public override void CreateShape()
        {
            base.CreateShape();

            switch (buttonType)
            {
            default:
            case CaptionButtonType.Close:
                buttonDescriptor = ShapeDescriptor.ComputeShape(this, Shape.Rectangle);
                crossDescriptor  = ShapeDescriptor.Join(
                    Shapes.DrawLine(4, Color.AntiqueWhite,
                                    crossTopLeftAbsolutePosition,
                                    crossTopLeftAbsolutePosition + new Vector2(DefaultCrossWidth, DefaultCrossWidth)),
                    Shapes.DrawLine(4, Color.AntiqueWhite,
                                    crossTopLeftAbsolutePosition + new Vector2(0, DefaultCrossWidth),
                                    crossTopLeftAbsolutePosition + new Vector2(DefaultCrossWidth, 0)
                                    )
                    );
                buttonDescriptor.Depth = depth;
                crossDescriptor.Depth  = Depth.AsChildOf(depth);

                shapeDescriptors[0] = buttonDescriptor;
                shapeDescriptors[1] = crossDescriptor;
                break;
            }
        }
Example #3
0
        public static ShapeDescriptor DrawPolyLine(int width, Color color, bool closed, params Vector2[] points)
        {
            CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[4];
            ShapeDescriptor[] segments;

            int col1 = color.ToArgb();

            if (closed)
            {
                segments = new ShapeDescriptor[points.Length];
                for (int i = 0; i < points.Length - 1; i++)
                {
                    segments[i] = DrawLine(width, color, points[i], points[i + 1]);
                }
                segments[points.Length - 1] = DrawLine(width, color, points[points.Length - 1], points[0]);
            }
            else
            {
                segments = new ShapeDescriptor[points.Length - 1];
                for (int i = 0; i < points.Length - 1; i++)
                {
                    segments[i] = DrawLine(width, color, points[i], points[i + 1]);
                }
            }
            return(ShapeDescriptor.Join(segments));
        }
Example #4
0
 public override void UpdateShape()
 {
     switch (buttonType)
     {
     default:
     case CaptionButtonType.Close:
         if (buttonDescriptor != null)
         {
             buttonDescriptor.UpdateShape(ShapeDescriptor.ComputeShape(this, Shape.Rectangle));
         }
         if (crossDescriptor != null)
         {
             crossDescriptor.UpdateShape(ShapeDescriptor.Join(
                                             Shapes.DrawLine(4, Color.AntiqueWhite,
                                                             crossTopLeftAbsolutePosition,
                                                             crossTopLeftAbsolutePosition +
                                                             new Vector2(DefaultCrossWidth, DefaultCrossWidth)),
                                             Shapes.DrawLine(4, Color.AntiqueWhite,
                                                             crossTopLeftAbsolutePosition +
                                                             new Vector2(0, DefaultCrossWidth),
                                                             crossTopLeftAbsolutePosition +
                                                             new Vector2(DefaultCrossWidth, 0)
                                                             ))
                                         );
         }
         break;
     }
 }
Example #5
0
        private void Displaying(ElementDisplayContext context, ShapeDescriptor shapeDescriptor)
        {
            var shapeType = shapeDescriptor.ShapeType;
            var shape     = _shapeFactory.Value.Create(shapeType);

            context.ElementShape.Snippet = shape;
        }
Example #6
0
        public void UpdateControl(ShapeDescriptor shapeDescriptor, BaseControl ctl)
        {
            if (disposed)
            {
                return;
            }

            if (vertexBuffer == null)
            {
                return;
            }

            if (shapeDescriptor == null)
            {
                return;
            }

            if (shapeDescriptor.ArrayOffset == 0)
            {
                //DebugManager.LogError("UpdateControl","Control with AOffset 0", ctl.ID);
            }
            GraphicsStream vbStream = vertexBuffer.Lock(
                CustomVertex.TransformedColored.StrideSize * shapeDescriptor.ArrayOffset,
                CustomVertex.TransformedColored.StrideSize * shapeDescriptor.Vertices.Length,
                LockFlags.None);

            if (shapeDescriptor.Vertices.Length == 0)
            {
                DebugManager.LogToScreen("Updating an empty shapedescriptor!");
            }

            vbStream.Write(shapeDescriptor.Vertices);
            vertexBuffer.Unlock();
        }
Example #7
0
        public void RenderPreCalculatedShape()
        {
            var displayManager = _serviceProvider.GetService <IDisplayManager>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo"
                }
            };

            shape.Metadata.OnDisplaying(
                context =>
            {
                context.ChildContent = new HtmlString("Bar");
            });

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            descriptor.Bindings["Foo"] = new ShapeBinding
            {
                BindingName = "Foo",
                Binding     = ctx => new HtmlString("Hi there!"),
            };

            AddShapeDescriptor(descriptor);

            var result = displayManager.Execute(CreateDisplayContext(shape));

            Assert.Equal("Bar", result.ToString());
        }
        public void RenderAlternateShapeByMostRecentlyAddedMatchingAlternate()
        {
            var displayManager = _container.Resolve <IDisplayManager>();

            var shape = new Shape {
                Metadata = new ShapeMetadata {
                    Type = "Foo"
                }
            };

            shape.Metadata.Alternates.Add("Foo__1");
            shape.Metadata.Alternates.Add("Foo__2");
            shape.Metadata.Alternates.Add("Foo__3");

            var descriptor = new ShapeDescriptor {
                ShapeType = "Foo",
            };

            AddBinding(descriptor, "Foo", ctx => new HtmlString("Hi there!"));
            AddBinding(descriptor, "Foo__1", ctx => new HtmlString("Hello (1)!"));
            AddBinding(descriptor, "Foo__2", ctx => new HtmlString("Hello (2)!"));
            AddShapeDescriptor(descriptor);

            var result = displayManager.Execute(CreateDisplayContext(shape));

            Assert.That(result.ToString(), Is.EqualTo("Hello (2)!"));
        }
        public void SelectSwatchForTexture(ShapeDescriptor shapeDescriptor, bool invokeToggleEvents = false)
        {
            var matchingSwatch = currentSwatches.First(swatch => swatch.GetComponent <Swatch_Texture>().ShapeDescriptor.Equals(shapeDescriptor));
            var matchingToggle = matchingSwatch.GetComponent <Toggle>();

            ActivateToggle(matchingToggle, invokeToggleEvents);
        }
        private static Material GetTrackedMaterial(ShapeDescriptor shapeDescriptor, Texture2D textureToUse, Shader shaderToUse, IDictionary <ShapeDescriptor, Material> trackedMaterials)
        {
            Material material;

            if (trackedMaterials.ContainsKey(shapeDescriptor))
            {
                material = trackedMaterials[shapeDescriptor];
            }
            else
            {
                material = new Material(shaderToUse);
                trackedMaterials[shapeDescriptor] = material;

                if (shaderToUse == MediaShader)
                {
                    var fastAverageTextureColor = textureToUse.GetPixelBilinear(0f, 0f);
                    fastAverageTextureColor += textureToUse.GetPixelBilinear(0.25f, 0.75f);
                    fastAverageTextureColor += textureToUse.GetPixelBilinear(0.66f, 0.33f);
                    fastAverageTextureColor *= 1f / 3f;

                    Color.RGBToHSV(fastAverageTextureColor, out float hue, out float saturation, out _);
                    fastAverageTextureColor = Color.HSVToRGB(hue, saturation, 1f);

                    material.SetColor(mediaSubColorPropertyId, fastAverageTextureColor);
                }
            }

            if (material.mainTexture != textureToUse)
            {
                material.mainTexture = textureToUse;
                material.name        = $"Collection({shapeDescriptor.Collection}) Bitmap({shapeDescriptor.Bitmap})";
            }

            return(material);
        }
        public async Task RenderSimpleShape()
        {
            var displayManager = _serviceProvider.GetService <IHtmlDisplay>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo"
                }
            };

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            descriptor.Bindings["Foo"] = new ShapeBinding
            {
                BindingName  = "Foo",
                BindingAsync = ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hi there!")),
            };
            AddShapeDescriptor(descriptor);

            var result = await displayManager.ExecuteAsync(CreateDisplayContext(shape));

            Assert.Equal("Hi there!", result.ToString());
        }
        public static Texture2D GetTexture(ShapeDescriptor shapeDescriptor, bool returnPlaceholderIfNotFound = false)
        {
            Texture2D textureToUse;

            if (Textures.ContainsKey(shapeDescriptor))
            {
                textureToUse = Textures[shapeDescriptor];
            }
            else
            {
                textureToUse = ShapesLoading.Instance.GetShape(shapeDescriptor);

                if (textureToUse)
                {
                    textureToUse.name         = $"Collection({shapeDescriptor.Collection}) Bitmap({shapeDescriptor.Bitmap})";
                    Textures[shapeDescriptor] = textureToUse;
                }
            }

            if (textureToUse == null && returnPlaceholderIfNotFound)
            {
                textureToUse = GridTexture;
            }

            return(textureToUse);
        }
        public async Task DisplayingEventFiresEarlyEnoughToAddAlternateShapeBindingNames()
        {
            var htmlDisplay = _serviceProvider.GetService <IHtmlDisplay>();

            var shapeFoo = new Shape();

            shapeFoo.Metadata.Type = "Foo";

            var descriptorFoo = new ShapeDescriptor
            {
                ShapeType = "Foo"
            };

            AddBinding(descriptorFoo, "Foo", ctx => Task.FromResult <IHtmlContent>(new HtmlString("alpha")));
            AddShapeDescriptor(descriptorFoo);

            var descriptorBar = new ShapeDescriptor
            {
                ShapeType = "Bar"
            };

            AddBinding(descriptorBar, "Bar", ctx => Task.FromResult <IHtmlContent>(new HtmlString("beta")));
            AddShapeDescriptor(descriptorBar);

            var resultNormally = await htmlDisplay.ExecuteAsync(CreateDisplayContext(shapeFoo));

            shapeFoo = new Shape();
            shapeFoo.Metadata.Type        = "Foo";
            descriptorFoo.DisplayingAsync = new Func <ShapeDisplayContext, Task>[] { ctx => { ctx.Shape.Metadata.Alternates.Add("Bar"); return(Task.CompletedTask); } };
            var resultWithOverride = await htmlDisplay.ExecuteAsync(CreateDisplayContext(shapeFoo));

            Assert.Equal("alpha", resultNormally.ToString());
            Assert.Equal("beta", resultWithOverride.ToString());
        }
        public static int GetTextureArrayIndex(
            ShapeDescriptor shapeDescriptor,
            short transferMode,
            bool isOpaqueSurface,
            SurfaceTypes surfaceType)
        {
            if (shapeDescriptor.IsEmpty())
            {
                return(0);
            }

            var landscapeTransferMode = transferMode == 9 || shapeDescriptor.UsesLandscapeCollection();

            var collectionKey =
                GetTexture2DArrayKeyDictionary(
                    shapeDescriptor,
                    landscapeTransferMode: landscapeTransferMode,
                    isOpaqueSurface: isOpaqueSurface,
                    surfaceType)
                [shapeDescriptor];

            var collection = Texture2DArrays[collectionKey];

            return(collection.GetBitmapIndex(shapeDescriptor));
        }
        public async Task RenderPreCalculatedShape()
        {
            var displayManager = _serviceProvider.GetService <IHtmlDisplay>();

            var shape = new Shape();

            shape.Metadata.Type = "Foo";
            shape.Metadata.OnDisplaying(
                context =>
            {
                context.ChildContent = new HtmlString("Bar");
            });

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo"
            };

            descriptor.Bindings["Foo"] = new ShapeBinding
            {
                BindingName  = "Foo",
                BindingAsync = ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hi there!"))
            };
            AddShapeDescriptor(descriptor);

            var result = await displayManager.ExecuteAsync(CreateDisplayContext(shape));

            Assert.Equal("Bar", result.ToString());
        }
        public async Task RenderAlternateShapeExplicitly()
        {
            var displayManager = _serviceProvider.GetService <IHtmlDisplay>();

            var shape = new Shape();

            shape.Metadata.Type = "Foo__2";

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo"
            };

            descriptor.Bindings["Foo"] = new ShapeBinding
            {
                BindingName  = "Foo",
                BindingAsync = ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hi there!"))
            };
            descriptor.Bindings["Foo__2"] = new ShapeBinding
            {
                BindingName  = "Foo__2",
                BindingAsync = ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hello again!"))
            };
            AddShapeDescriptor(descriptor);

            var result = await displayManager.ExecuteAsync(CreateDisplayContext(shape));

            Assert.Equal("Hello again!", result.ToString());
        }
        public void DisplayingEventFiresEarlyEnoughToAddAlternateShapeBindingNames()
        {
            var displayManager = _container.Resolve <IDisplayManager>();

            var shapeFoo = new Shape {
                Metadata = new ShapeMetadata {
                    Type = "Foo"
                }
            };
            var descriptorFoo = new ShapeDescriptor {
                ShapeType = "Foo",
            };

            AddBinding(descriptorFoo, "Foo", ctx => new HtmlString("alpha"));
            AddShapeDescriptor(descriptorFoo);

            var descriptorBar = new ShapeDescriptor {
                ShapeType = "Bar",
            };

            AddBinding(descriptorBar, "Bar", ctx => new HtmlString("beta"));
            AddShapeDescriptor(descriptorBar);


            var resultNormally = displayManager.Execute(CreateDisplayContext(shapeFoo));

            descriptorFoo.Displaying = new Action <ShapeDisplayingContext>[] { ctx => ctx.ShapeMetadata.Alternates.Add("Bar") };
            var resultWithOverride = displayManager.Execute(CreateDisplayContext(shapeFoo));

            Assert.That(resultNormally.ToString(), Is.EqualTo("alpha"));
            Assert.That(resultWithOverride.ToString(), Is.EqualTo("beta"));
        }
        public void IShapeDisplayEventsIsCalled()
        {
            var displayManager = _container.Resolve <IDisplayManager>();

            var shape = new Shape {
                Metadata = new ShapeMetadata {
                    Type = "Foo"
                }
            };

            var descriptor = new ShapeDescriptor {
                ShapeType = "Foo",
            };

            AddBinding(descriptor, "Foo", ctx => new HtmlString("yarg"));
            AddShapeDescriptor(descriptor);

            var displayingEventCount = 0;
            var displayedEventCount  = 0;

            _container.Resolve <TestDisplayEvents>().Displaying = ctx => { ++displayingEventCount; };
            _container.Resolve <TestDisplayEvents>().Displayed  = ctx => { ++displayedEventCount; ctx.ChildContent = new HtmlString("[" + ctx.ChildContent.ToHtmlString() + "]"); };

            var result = displayManager.Execute(CreateDisplayContext(shape));

            Assert.That(displayingEventCount, Is.EqualTo(1));
            Assert.That(displayedEventCount, Is.EqualTo(1));
            Assert.That(result.ToString(), Is.EqualTo("[yarg]"));
        }
 private static void AddBinding(ShapeDescriptor descriptor, string bindingName, Func <DisplayContext, IHtmlString> binding)
 {
     descriptor.Bindings[bindingName] = new ShapeBinding {
         BindingName = bindingName,
         Binding     = binding,
     };
 }
Example #20
0
        public void ShapeDescriptorDisplayingAndDisplayedAreCalled()
        {
            var displayManager = _serviceProvider.GetService <IDisplayManager>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo"
                }
            };

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            AddBinding(descriptor, "Foo", ctx => new HtmlString("yarg"));
            AddShapeDescriptor(descriptor);

            var displayingEventCount = 0;
            var displayedEventCount  = 0;

            descriptor.Displaying = new Action <ShapeDisplayingContext>[] { ctx => { ++displayingEventCount; } };
            descriptor.Displayed  = new Action <ShapeDisplayedContext>[] { ctx => { ++displayedEventCount; ctx.ChildContent = new HtmlString("[" + ctx.ChildContent.ToString() + "]"); } };

            var result = displayManager.Execute(CreateDisplayContext(shape));

            Assert.Equal(1, displayingEventCount);
            Assert.Equal(1, displayedEventCount);
            Assert.Equal("[yarg]", result.ToString());
        }
Example #21
0
        private async Task<IHtmlContent> RenderAsync(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            }
            IHtmlContent result;

            if (displayContext.ViewContext.View != null)
            {
                var htmlHelper = MakeHtmlHelper(displayContext.ViewContext, displayContext.ViewContext.ViewData);
                result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
            }
            else
            {
                // If the View is null, it means that the shape is being executed from a non-view origin / where no ViewContext was established by the view engine, but manually.
                // Manually creating a ViewContext works when working with Shape methods, but not when the shape is implemented as a Razor view template.
                // Horrible, but it will have to do for now.
                result = await RenderRazorViewAsync(harvestShapeInfo.TemplateVirtualPath, displayContext);
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            }
            return result;
        }
        public async Task RenderAlternateShapeByMostRecentlyAddedMatchingAlternate()
        {
            var displayManager = _serviceProvider.GetService <IHtmlDisplay>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo"
                }
            };

            shape.Metadata.Alternates.Add("Foo__1");
            shape.Metadata.Alternates.Add("Foo__2");
            shape.Metadata.Alternates.Add("Foo__3");

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            AddBinding(descriptor, "Foo", ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hi there!")));
            AddBinding(descriptor, "Foo__1", ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hello (1)!")));
            AddBinding(descriptor, "Foo__2", ctx => Task.FromResult <IHtmlContent>(new HtmlString("Hello (2)!")));
            AddShapeDescriptor(descriptor);

            var result = await displayManager.ExecuteAsync(CreateDisplayContext(shape));

            Assert.Equal("Hello (2)!", result.ToString());
        }
Example #23
0
        public void TemplateResolutionWorks()
        {
            AddEnabledFeature("Alpha");

            _testViewEngine.Add("~/Modules/Alpha/Styles/AlphaShape.css", null);
            _testViewEngine.Add("~/Modules/Alpha/Styles/alpha-shape.css", null);
            var strategy = _container.Resolve <IShapeTableProvider>();

            var builder = new ShapeTableBuilder(null);

            strategy.Discover(builder);
            var alterations = builder.BuildAlterations();

            Assert.That(alterations.Any(alteration => alteration.ShapeType == "Style"));

            var descriptor = new ShapeDescriptor {
                ShapeType = "Style"
            };

            alterations.Aggregate(descriptor, (d, alteration) => {
                alteration.Alter(d);
                return(d);
            });

            var keys = descriptor.Bindings.Select(b => b.Key);

            Assert.That(keys.Count() == keys.Select(k => k.ToLowerInvariant()).Distinct().Count(), "Descriptors should never vary by case only.");
        }
        public async Task ShapeDescriptorDisplayingAndDisplayedAreCalled()
        {
            var displayManager = _serviceProvider.GetService <IHtmlDisplay>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo"
                }
            };

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            AddBinding(descriptor, "Foo", ctx => Task.FromResult <IHtmlContent>(new HtmlString("yarg")));
            AddShapeDescriptor(descriptor);

            var displayingEventCount = 0;
            var displayedEventCount  = 0;

            descriptor.DisplayingAsync = new Func <ShapeDisplayContext, Task>[] { ctx => { ++displayingEventCount; return(Task.CompletedTask); } };
            descriptor.DisplayedAsync  = new Func <ShapeDisplayContext, Task>[] { ctx => { ++displayedEventCount; ctx.ChildContent = new HtmlString("[" + ctx.ChildContent.ToString() + "]"); return(Task.CompletedTask); } };

            var result = await displayManager.ExecuteAsync(CreateDisplayContext(shape));

            Assert.Equal(1, displayingEventCount);
            Assert.Equal(1, displayedEventCount);
            Assert.Equal("[yarg]", result.ToString());
        }
 public void AddBitmap(ShapeDescriptor shapeDescriptor)
 {
     if (!indicesByShapeDescriptor.ContainsKey(shapeDescriptor))
     {
         indicesByShapeDescriptor[shapeDescriptor] = indicesByShapeDescriptor.Count;
     }
 }
        public static Material GetMaterial(
            ShapeDescriptor shapeDescriptor,
            short transferMode,
            bool isOpaqueSurface,
            SurfaceTypes surfaceType,
            bool incrementUsageCounter)
        {
            if (!shapeDescriptor.IsEmpty())
            {
                if (TextureUsageCounter.ContainsKey(shapeDescriptor))
                {
                    if (incrementUsageCounter)
                    {
                        TextureUsageCounter[shapeDescriptor]++;
                    }
                }
                else
                {
                    TextureUsageCounter[shapeDescriptor] = 1;
                }

                var landscapeTransferMode = transferMode == 9 || shapeDescriptor.UsesLandscapeCollection();

                return(GetTrackedMaterial(shapeDescriptor,
                                          landscapeTransferMode,
                                          isOpaqueSurface,
                                          surfaceType));
            }
            else
            {
                return(UnassignedMaterial);
            }
        }
Example #27
0
        public void RenderAlternateShapeExplicitly()
        {
            var displayManager = _serviceProvider.GetService <IDisplayManager>();

            var shape = new Shape
            {
                Metadata = new ShapeMetadata
                {
                    Type = "Foo__2"
                }
            };

            var descriptor = new ShapeDescriptor
            {
                ShapeType = "Foo",
            };

            descriptor.Bindings["Foo"] = new ShapeBinding
            {
                BindingName = "Foo",
                Binding     = ctx => new HtmlString("Hi there!"),
            };
            descriptor.Bindings["Foo__2"] = new ShapeBinding
            {
                BindingName = "Foo__2",
                Binding     = ctx => new HtmlString("Hello again!"),
            };
            AddShapeDescriptor(descriptor);

            var result = displayManager.Execute(CreateDisplayContext(shape));

            Assert.Equal("Hello again!", result.ToString());
        }
Example #28
0
        /// <summary>
        /// This methods draws a trapezoid whose 90° angle is in the left side.
        /// </summary>
        /// <param name="position">The topLeft point of the trapezoid</param>
        /// <param name="size">The <b>whole size</b> of the trapezoid</param>
        /// <param name="triangleWidth">The extra width of the greater base side</param>
        /// <param name="isTriangleUpside">If the triangle part is to be drawn upside</param>
        /// <param name="isShaded">If shading is to be applied to the trapezoid polygons</param>
        /// <param name="color">Color of the trapezoid's inner area. The specified ShadeVertices
        /// delegate will then proceed to create a shaded version.</param>
        /// <param name="shadeMode">ShadeVertices delegate used.</param>
        /// <returns>A Trapezoidal ShapeDescriptor object.</returns>
        public static ShapeDescriptor DrawLeftTrapezoid(Vector2 position, Size size,
                                                        int triangleWidth, bool isTriangleUpside,
                                                        Color color, int borderSize,
                                                        ShadingMode shadeMode)
        {
            CustomVertex.TransformedColored[] vertices = new CustomVertex.TransformedColored[5];
            int[]   indices = new int[9];
            Vector2 topLeft = new Vector2(position.X + triangleWidth, position.Y);

            Size innerSize = new Size(size.Width - borderSize, size.Height - borderSize);

            ShapeDescriptor sTrapezoid;

            int width  = innerSize.Width;
            int height = innerSize.Height;

            int[] colors = shadeMode(color);

            int colorTopLeft     = colors[0];
            int colorTopRight    = colors[1];
            int colorBottomleft  = colors[2];
            int colorBottomRight = colors[3];

            vertices[0] =
                new CustomVertex.TransformedColored(topLeft.X + innerSize.Width, topLeft.Y, 0, 1, colorTopRight);
            vertices[1] =
                new CustomVertex.TransformedColored(topLeft.X + innerSize.Width, topLeft.Y + innerSize.Height, 0, 1,
                                                    colorBottomRight);
            vertices[2] =
                new CustomVertex.TransformedColored(topLeft.X, topLeft.Y + innerSize.Height, 0, 1, colorBottomleft);
            vertices[4] = new CustomVertex.TransformedColored(topLeft.X, topLeft.Y, 0, 1, colorTopLeft);


            if (isTriangleUpside)
            {
                vertices[3] =
                    new CustomVertex.TransformedColored(topLeft.X - triangleWidth, topLeft.Y + innerSize.Height, 0, 1,
                                                        colorBottomleft);
            }
            else
            {
                vertices[3] =
                    new CustomVertex.TransformedColored(topLeft.X - triangleWidth, topLeft.Y, 0, 1, colorTopLeft);
            }

            indices[0] = 0;
            indices[1] = 2;
            indices[2] = 4;
            indices[3] = 0;
            indices[4] = 1;
            indices[5] = 2;
            indices[6] = 3;
            indices[7] = 4;
            indices[8] = 2;


            sTrapezoid = new ShapeDescriptor(3, vertices, indices);
            return(sTrapezoid);
        }
 void AddShapeDescriptor(ShapeDescriptor shapeDescriptor)
 {
     _defaultShapeTable.Descriptors[shapeDescriptor.ShapeType] = shapeDescriptor;
     foreach (var binding in shapeDescriptor.Bindings)
     {
         _defaultShapeTable.Bindings[binding.Key] = binding.Value;
     }
 }
 private static void AddBinding(ShapeDescriptor descriptor, string bindingName, Func <DisplayContext, Task <IHtmlContent> > binding)
 {
     descriptor.Bindings[bindingName] = new ShapeBinding
     {
         BindingName  = bindingName,
         BindingAsync = binding,
     };
 }
        private Func<DisplayContext, IHtmlString> CreateDelegate(
            ShapeAttributeOccurrence attributeOccurrence,
            ShapeDescriptor descriptor) {
            return context => {
                var serviceInstance = _componentContext.Resolve(attributeOccurrence.Registration, Enumerable.Empty<Parameter>());

                // oversimplification for the sake of evolving
                return PerformInvoke(context, attributeOccurrence.MethodInfo, serviceInstance);
            };
        }
 private Func<DisplayContext, Task<IHtmlContent>> CreateDelegate(
     ShapeAttributeOccurrence attributeOccurrence,
     ShapeDescriptor descriptor)
 {
     return context =>
     {
         var serviceInstance = _componentContext.GetService(attributeOccurrence.ServiceType);
         // oversimplification for the sake of evolving
         return PerformInvokeAsync(context, attributeOccurrence.MethodInfo, serviceInstance);
     };
 }
        private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
            Logger.Information("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            IHtmlString result;

            if (displayContext.ViewContext.View != null) {
                var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
                result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
            }
            else {
                // If the View is null, it means that the shape is being executed from a non-view origin / where no ViewContext was established by the view engine, but manually.
                // Manually creating a ViewContext works when working with Shape methods, but not when the shape is implemented as a Razor view template.
                // Horrible, but it will have to do for now.
                result = RenderRazorViewToString(harvestShapeInfo.TemplateVirtualPath, displayContext);
            }

            Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            return result;
        }
        private async Task<IHtmlContent> RenderAsync(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit)
        {
            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            }
            IHtmlContent result;

            if (displayContext.ViewContext.View != null)
            {
                var htmlHelper = MakeHtmlHelper(displayContext.ViewContext, displayContext.ViewContext.ViewData);
                result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);
            }
            else
            {
                // If the View is null, it means that the shape is being executed from a non-view origin / where no ViewContext was established by the view engine, but manually.
                // Manually creating a ViewContext works when working with Shape methods, but not when the shape is implemented as a Razor view template.
                // Horrible, but it will have to do for now.
                result = await RenderRazorViewAsync(harvestShapeInfo.TemplateVirtualPath, displayContext);
            }

            if (_logger.IsEnabled(LogLevel.Information))
            {
                _logger.LogInformation("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            }
            return result;
        }
        private IHtmlString Render(ShapeDescriptor shapeDescriptor, DisplayContext displayContext, HarvestShapeInfo harvestShapeInfo, HarvestShapeHit harvestShapeHit) {
            Logger.Information("Rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);

            var htmlHelper = new HtmlHelper(displayContext.ViewContext, displayContext.ViewDataContainer);
            var result = htmlHelper.Partial(harvestShapeInfo.TemplateVirtualPath, displayContext.Value);

            Logger.Information("Done rendering template file '{0}'", harvestShapeInfo.TemplateVirtualPath);
            return result;
        }