private async Task<RenderDTO> AddUpdateUIElementState_Rectangle(UIElementState uistate, RenderDTO rDto)
        {

            if (rDto == null)
            {
                ShapeDTO dto = new ShapeDTO();
                dto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO() { ShapeDTO = dto, Type = eRenderType.Shape, Order = _renderTree.Count() + 1 };

                _renderTree.Add(rDto);
            }



            switch (uistate.udfString1)
            {
                case "Rectangle":
                    RectangleF newGeometry1 = new RectangleF(0, 0, (float)uistate.Width, (float)uistate.Height);
                    rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.RectangleGeometry(_deviceManager.FactoryDirect2D, newGeometry1);
                    rDto.ShapeDTO.Type = uistate.udfInt1;
                    break;
                case "Ellipse":
                    SharpDX.Direct2D1.Ellipse newGeometry2 = new SharpDX.Direct2D1.Ellipse(
                        new Vector2(((float)uistate.Width / 2), ((float)uistate.Height / 2)),
                        (float)uistate.Width,
                        (float)uistate.Height
                        );
                    rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.EllipseGeometry(_deviceManager.FactoryDirect2D, newGeometry2);
                    rDto.ShapeDTO.Type = uistate.udfInt1;
                    break;

            }




            //stroke stuff
            rDto.ShapeDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.DashOffset = float.Parse(strokeParts[0]);
                    rDto.ShapeDTO.MiterLimit = float.Parse(strokeParts[1]);
                    rDto.ShapeDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapeDTO.DashStyleIndex < 0) rDto.ShapeDTO.DashStyleIndex = 0;
                    if (rDto.ShapeDTO.DashStyleIndex == 5) rDto.ShapeDTO.DashStyleIndex = 0;
                }
            }


            

            if (uistate.udfInt2 == 1)
            {
                var parts1 = uistate.udfString2.Split("|".ToCharArray());
                var parts2 = uistate.udfString3.Split("|".ToCharArray());

                Color4 colorToUse1;
                Color4 colorToUse2;
                try
                {
                    colorToUse1 = new Color4(
                        float.Parse(parts1[0]) / 255,
                        float.Parse(parts1[1]) / 255,
                        float.Parse(parts1[2]) / 255,
                        parts1.Length > 6 ? float.Parse(parts1[6]) / 255 : float.Parse(parts1[3]) / 255
                        );

                    colorToUse2 = new Color4(
                        float.Parse(parts2[0]) / 255,
                        float.Parse(parts2[1]) / 255,
                        float.Parse(parts2[2]) / 255,
                        parts2.Length > 6 ? float.Parse(parts2[6]) / 255 : float.Parse(parts2[3]) / 255
                        );
                }
                catch
                {
                    colorToUse1 = Color.Black;
                    colorToUse2 = Color.White;
                }

                rDto.ShapeDTO.Brush = CreateRadialGradientBrush(_deviceManager.ContextDirect2D, (float)uistate.Width, (float)uistate.Height, colorToUse1, colorToUse2, (float)uistate.udfDouble1 / 100, (float)uistate.udfDouble2 / 100);

            }
            else
            {
                var parts = uistate.udfString2.Split("|".ToCharArray());

                Color4 colorToUse;
                try
                {
                    colorToUse = new Color4(
                        float.Parse(parts[0]) / 255,
                        float.Parse(parts[1]) / 255,
                        float.Parse(parts[2]) / 255,
                        parts.Length > 6 ? float.Parse(parts[6]) / 255 : float.Parse(parts[3]) / 255
                        );
                }
                catch
                {
                    colorToUse = Color.Black;
                }

                rDto.ShapeDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }



            rDto.ShapeDTO.IsRenderable = uistate.IsRenderable; //true
            rDto.ShapeDTO.MainScale = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapeDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, 0);


           


            //ROTATION
            if (!string.IsNullOrEmpty(uistate.udfString5))
            {
                var strokeParts = uistate.udfString5.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.MainRotation = new Vector3(
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[0]) ? "0" : strokeParts[0])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[1]) ? "0" : strokeParts[1])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]))
                        );
                }
            }




            if (NumberFramesToRender < 1) NumberFramesToRender = 1;

            //TurnOnRenderingBecauseThereAreRenderableEffects();

            return rDto;
        }
Example #2
0
        private async Task <RenderDTO> AddUpdateUIElementState_Rectangle(UIElementState uistate, RenderDTO rDto)
        {
            if (rDto == null)
            {
                ShapeDTO dto = new ShapeDTO();
                dto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO()
                {
                    ShapeDTO = dto, Type = eRenderType.Shape, Order = _renderTree.Count() + 1
                };

                _renderTree.Add(rDto);
            }



            switch (uistate.udfString1)
            {
            case "Rectangle":
                RectangleF newGeometry1 = new RectangleF(0, 0, (float)uistate.Width, (float)uistate.Height);
                rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.RectangleGeometry(_deviceManager.FactoryDirect2D, newGeometry1);
                rDto.ShapeDTO.Type  = uistate.udfInt1;
                break;

            case "Ellipse":
                SharpDX.Direct2D1.Ellipse newGeometry2 = new SharpDX.Direct2D1.Ellipse(
                    new Vector2(((float)uistate.Width / 2), ((float)uistate.Height / 2)),
                    (float)uistate.Width,
                    (float)uistate.Height
                    );
                rDto.ShapeDTO.Shape = new SharpDX.Direct2D1.EllipseGeometry(_deviceManager.FactoryDirect2D, newGeometry2);
                rDto.ShapeDTO.Type  = uistate.udfInt1;
                break;
            }



            //stroke stuff
            rDto.ShapeDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.DashOffset     = float.Parse(strokeParts[0]);
                    rDto.ShapeDTO.MiterLimit     = float.Parse(strokeParts[1]);
                    rDto.ShapeDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapeDTO.DashStyleIndex < 0)
                    {
                        rDto.ShapeDTO.DashStyleIndex = 0;
                    }
                    if (rDto.ShapeDTO.DashStyleIndex == 5)
                    {
                        rDto.ShapeDTO.DashStyleIndex = 0;
                    }
                }
            }



            if (uistate.udfInt2 == 1)
            {
                var parts1 = uistate.udfString2.Split("|".ToCharArray());
                var parts2 = uistate.udfString3.Split("|".ToCharArray());

                Color4 colorToUse1;
                Color4 colorToUse2;
                try
                {
                    colorToUse1 = new Color4(
                        float.Parse(parts1[0]) / 255,
                        float.Parse(parts1[1]) / 255,
                        float.Parse(parts1[2]) / 255,
                        parts1.Length > 6 ? float.Parse(parts1[6]) / 255 : float.Parse(parts1[3]) / 255
                        );

                    colorToUse2 = new Color4(
                        float.Parse(parts2[0]) / 255,
                        float.Parse(parts2[1]) / 255,
                        float.Parse(parts2[2]) / 255,
                        parts2.Length > 6 ? float.Parse(parts2[6]) / 255 : float.Parse(parts2[3]) / 255
                        );
                }
                catch
                {
                    colorToUse1 = Color.Black;
                    colorToUse2 = Color.White;
                }

                rDto.ShapeDTO.Brush = CreateRadialGradientBrush(_deviceManager.ContextDirect2D, (float)uistate.Width, (float)uistate.Height, colorToUse1, colorToUse2, (float)uistate.udfDouble1 / 100, (float)uistate.udfDouble2 / 100);
            }
            else
            {
                var parts = uistate.udfString2.Split("|".ToCharArray());

                Color4 colorToUse;
                try
                {
                    colorToUse = new Color4(
                        float.Parse(parts[0]) / 255,
                        float.Parse(parts[1]) / 255,
                        float.Parse(parts[2]) / 255,
                        parts.Length > 6 ? float.Parse(parts[6]) / 255 : float.Parse(parts[3]) / 255
                        );
                }
                catch
                {
                    colorToUse = Color.Black;
                }

                rDto.ShapeDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }



            rDto.ShapeDTO.IsRenderable    = uistate.IsRenderable; //true
            rDto.ShapeDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapeDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, 0);



            //ROTATION
            if (!string.IsNullOrEmpty(uistate.udfString5))
            {
                var strokeParts = uistate.udfString5.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapeDTO.MainRotation = new Vector3(
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[0]) ? "0" : strokeParts[0])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[1]) ? "0" : strokeParts[1])),
                        MathUtil.DegreesToRadians(float.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]))
                        );
                }
            }



            if (NumberFramesToRender < 1)
            {
                NumberFramesToRender = 1;
            }

            //TurnOnRenderingBecauseThereAreRenderableEffects();

            return(rDto);
        }