private void DoAggregateUpdatedForEffect(List <UIElementState> uistate, GeneralSystemWideMessage msg)
        {
            var found = _renderTree.Where(
                x =>
                x.Type == eRenderType.Effect &&
                x.EffectDTO.AggregateId == msg.AggregateId
                );

            if (found != null && found.Count() > 0 && uistate != null && uistate.Count > 0)
            {
                RenderDTO renderItem = found.First();

                //update for the effects that are "grouped", which means they are children to a parent effect
                if (renderItem != null && !string.IsNullOrEmpty(renderItem.EffectDTO.Grouping1))
                {
                    UpdateRenderItemWithUIElement_Effect(uistate[0], renderItem);
                }
            }
        }
Beispiel #2
0
        private void DoAggregateUpdatedForText(List <UIElementState> uistate, GeneralSystemWideMessage msg)
        {
            RenderDTO found = _renderTree.Where(x => x.Type == eRenderType.Text && x.TextDTO.AggregateId == msg.AggregateId).FirstOrDefault();

            if (found != null)
            {
                found.TextDTO.IsRenderable    = uistate[0].IsRenderable;
                found.TextDTO.MainTranslation = new Vector3((float)uistate[0].Left, (float)uistate[0].Top, (float)0);
                found.TextDTO.MainScale       = new Vector3((float)uistate[0].Scale, (float)uistate[0].Scale, 0);

                found.TextDTO.LayoutRect = new RectangleF(0, 0, (float)uistate[0].Width, (float)uistate[0].Height);

                found.TextDTO.TextFormat = new SharpDX.DirectWrite.TextFormat(
                    _deviceManager.FactoryDirectWrite,
                    uistate[0].udfString2,
                    SharpDX.DirectWrite.FontWeight.Light,
                    SharpDX.DirectWrite.FontStyle.Normal,
                    SharpDX.DirectWrite.FontStretch.Normal,
                    (float)uistate[0].udfDouble1);

                found.TextDTO.Text = string.IsNullOrEmpty(uistate[0].udfString1) ? "Lorem Ipsum" : uistate[0].udfString1;
            }
        }
Beispiel #3
0
        private void DoAggregateUpdatedForImage(UIElementState uistate, bool resetTransforms = true)
        {
            //we only care about images that are the root parent, effects that are children are handled in the Effect class
            RenderDTO found = _renderTree.Where(
                x => x.Type == eRenderType.Effect &&
                x.EffectDTO.AggregateId == uistate.AggregateId &&
                string.IsNullOrEmpty(x.EffectDTO.Grouping1)
                ).FirstOrDefault();

            if (found != null)
            {
                found.EffectDTO.IsRenderable    = uistate.IsRenderable;
                found.EffectDTO.MainTranslation = new Vector3((float)uistate.Left, (float)uistate.Top, (float)0);
                found.EffectDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 0);


                //update linked effects (parent got changed so update the children where applicable)
                if (found.HasLinkedEffects)
                {
                    var linkedRenderTreeItems = _renderTree.Where(x => x.Type == eRenderType.Effect && x.EffectDTO.Grouping1 == uistate.AggregateId);
                    foreach (var linkedRenderTreeItem in linkedRenderTreeItems)
                    {
                        linkedRenderTreeItem.EffectDTO.MainScale       = found.EffectDTO.MainScale;
                        linkedRenderTreeItem.EffectDTO.MainTranslation = found.EffectDTO.MainTranslation;
                        //linkedRenderTreeItem.EffectDTO.IsRenderable = found.EffectDTO.IsRenderable;
                    }
                }

                //udfBool1 is used to trigger an update of the image
                if (!string.IsNullOrEmpty(uistate.udfString1) && uistate.udfBool1)
                {
                    var layoutDetail = AppDatabase.Current.GetLayoutDetail(uistate.LayoutStyle);
                    UpdateImageByUri(uistate, layoutDetail, resetTransforms);
                }
            }
        }
        private async Task<RenderDTO> AddUpdateUIElementState_Path(UIElementState uistate, RenderDTO rDto)
        {
            if (rDto == null)
            {
                ShapePathDTO dto = new ShapePathDTO();
                dto.AggregateId = uistate.AggregateId;

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

                rDto.ShapePathDTO.ShapeDatas.Add("M6.33675,26.318 L32.1257,26.318 C32.1257,26.318 44.2178,18.6175 32.1257,10.8489 C32.1257,10.8489 31.7393,1.25822 23.4461,0.582515 C23.4461,0.582515 16.6888,-0.631889 13.9267,6.25699 C13.9267,6.25699 11.8669,4.43488 8.52113,5.78424 C8.52113,5.78424 6.01503,6.73083 5.88855,10.6481 C5.88855,10.6481 0.609425,11.1868 0.547688,17.8748 C0.547688,17.8748 -0.417516,25.1005 6.33675,26.318 z");
                rDto.ShapePathDTO.Shapes.Add(_pathD2DConverter.parse(dto.ShapeDatas[0], _deviceManager.FactoryDirect2D));

                _renderTree.Add(rDto);
            }

        

            //stroke stuff
            rDto.ShapePathDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapePathDTO.DashOffset = float.Parse(strokeParts[0]);
                    rDto.ShapePathDTO.MiterLimit = float.Parse(strokeParts[1]);
                    rDto.ShapePathDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapePathDTO.DashStyleIndex < 0) rDto.ShapePathDTO.DashStyleIndex = 0;
                    if (rDto.ShapePathDTO.DashStyleIndex == 5) rDto.ShapePathDTO.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.ShapePathDTO.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.ShapePathDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }

            rDto.ShapePathDTO.IsRenderable = true;
            rDto.ShapePathDTO.MainScale = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapePathDTO.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.ShapePathDTO.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]))
                        );
                }
            }


            

            NumberFramesToRender = 3;

            //TurnOnRenderingBecauseThereAreRenderableEffects();


            return rDto;
        }
        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;
        }
        private async Task<RenderDTO> CreateRenderItemWithUIElement_Effect(UIElementState uies, string effectClass, RenderDTO parentRenderTreeItem)
        {

            EffectDTO edto = new EffectDTO();
            edto.IsRenderable = uies.IsRenderable;
            edto.AggregateId = uies.AggregateId;
            edto.Grouping1 = uies.Grouping1;
            if (parentRenderTreeItem != null)
            {
                edto.MainTranslation = parentRenderTreeItem.EffectDTO.MainTranslation;
                edto.MainScale = parentRenderTreeItem.EffectDTO.MainScale;
            }
            else
            {
                edto.MainTranslation = new Vector3(0);
                edto.MainScale = new Vector3(1);
            }

            switch (effectClass)
            {
                case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;
                case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;
                case "SharpDX.Direct2D1.Effects.Atlas": break;
                case "SharpDX.Direct2D1.Effects.BitmapSourceEffect":
                    #region bitmap source

                    try
                    {

                        if (uies.udfString2 == "PicturesLibrary")
                        {
                            var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path: "PicturesLibrary");
                            edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                            edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                            uies.Width = asset.Item2.Width;
                            uies.Height = asset.Item2.Height;
                        }
                        else if (uies.udfString2 == "PublicPicturesLibrary")
                        {
                            var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path: "PublicPicturesLibrary");
                            edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                            edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                            uies.Width = asset.Item2.Width;
                            uies.Height = asset.Item2.Height;
                        }
                        else
                        {
                            var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);
                            edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                            edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                            uies.Width = asset.Item2.Width;
                            uies.Height = asset.Item2.Height;
                        }
                    }
                    catch {
                        var asset = LoadAssetAsync(_deviceManager.WICFactory, "Assets\\StartDemo\\Backgrounds\\green1.jpg", uies.AggregateId);
                        
                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Result.Item1);
                        uies.Width = asset.Result.Item2.Width;
                        uies.Height = asset.Result.Item2.Height;
                    }

                    
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Blend": break;
                case "SharpDX.Direct2D1.Effects.Border": break;
                case "SharpDX.Direct2D1.Effects.Brightness":
                    #region brightness
                    edto.Effect = new SharpDX.Direct2D1.Effects.Brightness(_deviceManager.ContextDirect2D);
                    ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                    ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);

                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.ColorManagement": break;
                case "SharpDX.Direct2D1.Effects.ColorMatrix": break;
                case "SharpDX.Direct2D1.Effects.Composite": 
                    #region composite
                    if (!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2))
                    {
                        edto.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);

                        if (!string.IsNullOrEmpty(uies.Grouping2))
                        {
                            var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                            if (found != null && found.Count() > 0)
                                edto.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                            else
                                edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                        else edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);

                        if (!string.IsNullOrEmpty(uies.udfString2))
                        {
                            var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                            if (found != null && found.Count() > 0)
                                edto.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                            else
                                edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                        else edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                    }
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.ConvolveMatrix":                     
                    #region convolve matrix
                    
                    edto.Effect = new SharpDX.Direct2D1.Effects.ConvolveMatrix(_deviceManager.ContextDirect2D);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);

                    if (!string.IsNullOrEmpty(uies.udfString2)) //matrix
                    {
                        var parts = uies.udfString2.Split("|".ToCharArray());
                        if (parts.Length == 9)
                        {
                            float[] matrix = new float[9]{
                                float.Parse(parts[0]),
                                float.Parse(parts[1]),
                                float.Parse(parts[2]),
                                float.Parse(parts[3]),
                                float.Parse(parts[4]),
                                float.Parse(parts[5]),
                                float.Parse(parts[6]),
                                float.Parse(parts[7]),
                                float.Parse(parts[8]),
                            };
                            ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = matrix;
                        }
                        //edto.Effect.SetInput(0, parentRenderTreeItem.EffectDTO.Effect.Output, true);
                        //var kernelmatrix = new float[9] { 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
                        //((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = kernelmatrix;
                    }
                    else
                    {
                        ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = new float[9] { 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
                    }
                        
                    
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.Crop": 
                    #region crop
                    edto.Effect = new SharpDX.Direct2D1.Effects.Crop(_deviceManager.ContextDirect2D);
                    ((SharpDX.Direct2D1.Effects.Crop)edto.Effect).Rectangle  = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                    #region directional blur
                    edto.Effect = new SharpDX.Direct2D1.Effects.DirectionalBlur(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                    edto.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;
                case "SharpDX.Direct2D1.Effects.DisplacementMap": break;
                case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;
                case "SharpDX.Direct2D1.Effects.DistantSpecular": break;
                case "SharpDX.Direct2D1.Effects.DpiCompensation": break;
                case "SharpDX.Direct2D1.Effects.Flood": 
                    #region flood
                    edto.Effect = new SharpDX.Direct2D1.Effects.Flood(_deviceManager.ContextDirect2D);
                    ((SharpDX.Direct2D1.Effects.Flood)edto.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.GammaTransfer": break;
                case "SharpDX.Direct2D1.Effects.GaussianBlur":
                    #region gaussian blur
                    edto.Effect = new SharpDX.Direct2D1.Effects.GaussianBlur(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Histogram": break;
                case "SharpDX.Direct2D1.Effects.HueRotate": 
                    #region hue rotate
                    edto.Effect = new SharpDX.Direct2D1.Effects.HueRotation(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValue(0, (float)uies.udfDouble1);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.LinearTransfer": break;
                case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;
                case "SharpDX.Direct2D1.Effects.Morphology": break;
                case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;
                case "SharpDX.Direct2D1.Effects.PointDiffuse": break;
                case "SharpDX.Direct2D1.Effects.PointSpecular": break;
                case "SharpDX.Direct2D1.Effects.Premultiply": break;
                case "SharpDX.Direct2D1.Effects.Saturation":
                    #region saturation
                    edto.Effect = new SharpDX.Direct2D1.Effects.Saturation(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValue(0, (float)uies.udfDouble1);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Scale": 
                    #region scale

                    SharpDX.Direct2D1.Effects.Scale ef = new SharpDX.Direct2D1.Effects.Scale(_deviceManager.ContextDirect2D);
                    ef.BorderMode = SharpDX.Direct2D1.BorderMode.Soft;
                    ef.Cached = false;
                    ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                    ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                    edto.Effect = ef;

                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Shadow": 
                    #region shadow
                    edto.Effect = new SharpDX.Direct2D1.Effects.Shadow(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValue(0, (float)uies.udfDouble1);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;
                case "SharpDX.Direct2D1.Effects.SpotSpecular": break;
                case "SharpDX.Direct2D1.Effects.TableTransfer": break;
                case "SharpDX.Direct2D1.Effects.Tile": 
                    #region tile
                    edto.Effect = new SharpDX.Direct2D1.Effects.Tile(_deviceManager.ContextDirect2D);
                    ((SharpDX.Direct2D1.Effects.Tile)edto.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                    #endregion                    
                    break;
                case "SharpDX.Direct2D1.Effects.Transform3D": break;
                case "SharpDX.Direct2D1.Effects.Turbulence": break;
                case "SharpDX.Direct2D1.Effects.UnPremultiply": break;

            }


            RenderDTO _newRenderDto;

            if(parentRenderTreeItem!=null)
                _newRenderDto = new RenderDTO() { EffectDTO = edto, Type = eRenderType.Effect , Order = parentRenderTreeItem.Order };
            else
                _newRenderDto = new RenderDTO() { EffectDTO = edto, Type = eRenderType.Effect, Order = 1};

            _renderTree.Add(_newRenderDto);

            return _newRenderDto;
        }
        private async Task<bool> UpdateRenderItemWithUIElement_Effect(UIElementState uies, RenderDTO renderItem)
        {
            if (_renderTree == null || _renderTree.Count == 0) return true;

            UIElementState uiesParent = AppDatabase.Current.RetrieveUIElementState(renderItem.EffectDTO.Grouping1).First();

            string[] parts = uies.udfString1.Split("|".ToCharArray());


            //child got changed so re update from the parent where applicable
            renderItem.EffectDTO.IsRenderable = uies.IsRenderable;

            renderItem.EffectDTO.MainTranslation = new Vector3(
                (float)uiesParent.Left,
                (float)uiesParent.Top,
                (float)0);

            renderItem.EffectDTO.MainScale = new Vector3(
                (float)uiesParent.Scale,
                (float)uiesParent.Scale,
                0);

            if (string.IsNullOrEmpty(uies.Grouping2))
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping1).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }
            else
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }

            //SharpDX.Direct2D1.Effects.Blend

            //now just update child based on new values from child UIElementState
            switch (parts[0])
            {
                case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;
                case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;
                case "SharpDX.Direct2D1.Effects.Atlas": break;
                case "SharpDX.Direct2D1.Effects.BitmapSourceEffect": 
                    #region bitmap source
                    var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);
                    ((SharpDX.Direct2D1.Effects.BitmapSource)renderItem.EffectDTO.Effect).SetValueByName("WicBitmapSource", asset.Item1);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Blend": break;
                case "SharpDX.Direct2D1.Effects.Border": break;
                case "SharpDX.Direct2D1.Effects.Brightness":
                    #region brightness
                    ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                    ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.ColorManagement": break;
                case "SharpDX.Direct2D1.Effects.ColorMatrix": break;
                case "SharpDX.Direct2D1.Effects.Composite": 
                    #region composite
                    if(!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2)){
                        //renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);

                        if (renderItem.EffectDTO.Effect == null)
                            renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                        //else
                        //{
                        //    renderItem.EffectDTO.Effect.Dispose();
                        //    renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                        //}

                        if (!string.IsNullOrEmpty(uies.Grouping2))
                        {
                            var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                            if (found != null && found.Count() > 0)
                                renderItem.EffectDTO.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                        }

                        if (!string.IsNullOrEmpty(uies.udfString2))
                        {
                            var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                            if (found != null && found.Count() > 0)
                                renderItem.EffectDTO.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                        }

                    }
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.ConvolveMatrix":                     
                    #region convolve matrix
                    if (!string.IsNullOrEmpty(uies.udfString2)) //matrix
                    {
                        var matrixParts = uies.udfString2.Split("|".ToCharArray());
                        if (matrixParts.Length == 9)
                        {
                            float[] matrix = new float[9]{
                                   float.Parse(matrixParts[0]),
                                   float.Parse(matrixParts[1]),
                                   float.Parse(matrixParts[2]),
                                   float.Parse(matrixParts[3]),
                                   float.Parse(matrixParts[4]),
                                   float.Parse(matrixParts[5]),
                                   float.Parse(matrixParts[6]),
                                   float.Parse(matrixParts[7]),
                                   float.Parse(matrixParts[8]),
                               };
                            ((SharpDX.Direct2D1.Effects.ConvolveMatrix)renderItem.EffectDTO.Effect).KernelMatrix = matrix;
                        }
                    }
                    
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Crop":
                    #region Crop
                    ((SharpDX.Direct2D1.Effects.Crop)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                    #region directional blur
                    renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                    renderItem.EffectDTO.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;
                case "SharpDX.Direct2D1.Effects.DisplacementMap": break;
                case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;
                case "SharpDX.Direct2D1.Effects.DistantSpecular": break;
                case "SharpDX.Direct2D1.Effects.DpiCompensation": break;
                case "SharpDX.Direct2D1.Effects.Flood": 
                    #region flood
                    ((SharpDX.Direct2D1.Effects.Flood)renderItem.EffectDTO.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.GammaTransfer": break;
                case "SharpDX.Direct2D1.Effects.GaussianBlur":
                    #region gaussian blur
                    renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Histogram": break;
                case "SharpDX.Direct2D1.Effects.HueRotate": 
                    #region hue rotate
                    renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.LinearTransfer": break;
                case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;
                case "SharpDX.Direct2D1.Effects.Morphology": break;
                case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;
                case "SharpDX.Direct2D1.Effects.PointDiffuse": break;
                case "SharpDX.Direct2D1.Effects.PointSpecular": break;
                case "SharpDX.Direct2D1.Effects.Premultiply": break;
                case "SharpDX.Direct2D1.Effects.Saturation":
                    #region saturation
                    renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Scale": 
                    #region scale
                    SharpDX.Direct2D1.Effects.Scale ef = (SharpDX.Direct2D1.Effects.Scale)renderItem.EffectDTO.Effect;
                    ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                    ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Shadow": 
                    #region shadow
                    renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;
                case "SharpDX.Direct2D1.Effects.SpotSpecular": break;
                case "SharpDX.Direct2D1.Effects.TableTransfer": break;
                case "SharpDX.Direct2D1.Effects.Tile": 
                    #region tile
                    ((SharpDX.Direct2D1.Effects.Tile)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                    #endregion
                    break;
                case "SharpDX.Direct2D1.Effects.Transform3D": break;
                case "SharpDX.Direct2D1.Effects.Turbulence": break;
                case "SharpDX.Direct2D1.Effects.UnPremultiply": break;

            }

            return true;


        }
Beispiel #8
0
        private async Task <RenderDTO> AddUpdateUIElementState_Path(UIElementState uistate, RenderDTO rDto)
        {
            if (rDto == null)
            {
                ShapePathDTO dto = new ShapePathDTO();
                dto.AggregateId = uistate.AggregateId;

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

                rDto.ShapePathDTO.ShapeDatas.Add("M6.33675,26.318 L32.1257,26.318 C32.1257,26.318 44.2178,18.6175 32.1257,10.8489 C32.1257,10.8489 31.7393,1.25822 23.4461,0.582515 C23.4461,0.582515 16.6888,-0.631889 13.9267,6.25699 C13.9267,6.25699 11.8669,4.43488 8.52113,5.78424 C8.52113,5.78424 6.01503,6.73083 5.88855,10.6481 C5.88855,10.6481 0.609425,11.1868 0.547688,17.8748 C0.547688,17.8748 -0.417516,25.1005 6.33675,26.318 z");
                rDto.ShapePathDTO.Shapes.Add(_pathD2DConverter.parse(dto.ShapeDatas[0], _deviceManager.FactoryDirect2D));

                _renderTree.Add(rDto);
            }



            //stroke stuff
            rDto.ShapePathDTO.StrokeWidth = (float)uistate.udfDouble3;
            if (!string.IsNullOrEmpty(uistate.udfString4))
            {
                var strokeParts = uistate.udfString4.Split("|".ToCharArray());
                if (strokeParts.Length > 0)
                {
                    rDto.ShapePathDTO.DashOffset     = float.Parse(strokeParts[0]);
                    rDto.ShapePathDTO.MiterLimit     = float.Parse(strokeParts[1]);
                    rDto.ShapePathDTO.DashStyleIndex = int.Parse(string.IsNullOrEmpty(strokeParts[2]) ? "0" : strokeParts[2]);
                    if (rDto.ShapePathDTO.DashStyleIndex < 0)
                    {
                        rDto.ShapePathDTO.DashStyleIndex = 0;
                    }
                    if (rDto.ShapePathDTO.DashStyleIndex == 5)
                    {
                        rDto.ShapePathDTO.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.ShapePathDTO.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.ShapePathDTO.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, colorToUse);
            }

            rDto.ShapePathDTO.IsRenderable    = true;
            rDto.ShapePathDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.ShapePathDTO.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.ShapePathDTO.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]))
                        );
                }
            }



            NumberFramesToRender = 3;

            //TurnOnRenderingBecauseThereAreRenderableEffects();


            return(rDto);
        }
        private async void RenderD3DDto(string assetUrl, RenderDTO rDto)
        {
            if (rDto == null) return;

            if (string.IsNullOrEmpty(assetUrl)) return;

            // Setup local variables
            var d3dDevice = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;



            // Load texture and create sampler
            //using (var bitmap = TextureLoader.LoadBitmap(_deviceManager.WICFactory, string.IsNullOrEmpty(project.AssetUrl)?"Assets\\Textures\\5.jpg": project.AssetUrl  ))
            //using (var texture2D = TextureLoader.CreateTexture2DFromBitmap(d3dDevice, bitmap))
            //    rDto.D3DPrimitiveDTO.TextureView = new ShaderResourceView(d3dDevice, texture2D);



            //Fill D2D THEN push D2D -> D3D
            var fc = await this.LoadAssetAsync(_deviceManager.WICFactory, assetUrl, Guid.NewGuid().ToString());



            //using (SharpDX.WIC.BitmapSource bitmap = TextureLoader.LoadBitmap(_deviceManager.WICFactory, assetUrl))
            using (SharpDX.WIC.BitmapSource bitmap = (SharpDX.WIC.BitmapSource)fc.Item1)
            {
                d2dContext.Transform = Matrix.Identity;

                rDto.D3DPrimitiveDTO.Texture2D = AllocateTextureReturnSurface(d3dDevice, new Size2F(bitmap.Size.Width, bitmap.Size.Height));
                d2dContext.Target = new SharpDX.Direct2D1.Bitmap1(d2dContext, rDto.D3DPrimitiveDTO.Texture2D.QueryInterface<SharpDX.DXGI.Surface>());
                rDto.D3DPrimitiveDTO.TextureView = new ShaderResourceView(d3dDevice, rDto.D3DPrimitiveDTO.Texture2D);

                d2dContext.BeginDraw();
                SharpDX.Direct2D1.Effects.BitmapSource effectBitmapSource = new SharpDX.Direct2D1.Effects.BitmapSource(d2dContext);

                effectBitmapSource.WicBitmapSource = bitmap;



                //SharpDX.Direct2D1.Effects.Shadow shadowEffect = new SharpDX.Direct2D1.Effects.Shadow(d2dContext);
                //shadowEffect.SetInputEffect(0, effectBitmapSource, true);
                //shadowEffect.BlurStandardDeviation = 10.0f;
                //d2dContext.DrawImage(shadowEffect);

                d2dContext.DrawImage(effectBitmapSource);
                //d2dContext.FillRectangle(new RectangleF(0, bitmap.Size.Height - 90, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColorLightBy2Degree));



                //if (project.Title != null)
                //{
                //    SharpDX.DirectWrite.TextFormat tf = new SharpDX.DirectWrite.TextFormat(_deviceManager.FactoryDirectWrite, "segoe ui", 28.0f);
                //    d2dContext.DrawText(project.Title, tf, new RectangleF(10, bitmap.Size.Height - 90 + 10, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White));
                //}

                //if (project.Description != null)
                //{
                //    SharpDX.DirectWrite.TextFormat tf = new SharpDX.DirectWrite.TextFormat(_deviceManager.FactoryDirectWrite, "segoe ui", 21.0f);
                //    d2dContext.DrawText(project.Description, tf, new RectangleF(10, bitmap.Size.Height - 90 + 40, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White));
                //}

                //PathToD2DPathGeometryConverter pathConverter = new PathToD2DPathGeometryConverter();

                //if (!string.IsNullOrEmpty(project.PathResource))
                //{
                //    var resourceFound = App.Current.Resources[project.PathResource];
                //    var pathGeometryCreated = pathConverter.parse((string)resourceFound, _deviceManager.FactoryDirect2D);
                //    var pathGeometryCreatedSize = pathGeometryCreated.GetBounds();
                //    d2dContext.FillRectangle(
                //        new RectangleF(bitmap.Size.Width - pathGeometryCreatedSize.Width - 20, 0, bitmap.Size.Width, pathGeometryCreatedSize.Height + 20)
                //        , new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColor)
                //        );
                //    d2dContext.Transform = Matrix.Translation(bitmap.Size.Width - pathGeometryCreatedSize.Width - 10, 10, 0);
                //    //d2dContext.StrokeWidth = 2.0f;
                //    d2dContext.FillGeometry(pathGeometryCreated, new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColorLightBy2Degree));
                //    //d2dContext.DrawGeometry(pathGeometryCreated, new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColor));
                //}

                d2dContext.EndDraw();

            }



        }
        private void CreateD3D_rDto(string assetUrl)
        {
            RenderDTO rDto = new RenderDTO();

            rDto.D3DPrimitiveDTO = new D3DPrimitiveDTO();

            //SafeDispose(ref rDto.D3DPrimitiveDTO.VertexBuffer);
            //rDto.D3DPrimitiveDTO.IsRenderable = true;
            // Remove previous buffer
            //SafeDispose(ref rDto.D3DPrimitiveDTO.ConstantBuffer);

            // Setup local variables
            var d3dDevice = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_VS.fxo");

            rDto.D3DPrimitiveDTO.VertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            rDto.D3DPrimitiveDTO.PixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            rDto.D3DPrimitiveDTO.Layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
                    {
                        new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                        new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
                    });


            // Instantiate Vertex buffer from vertex data
            float thicknessToUse = 0.15f;
            thicknessToUse = 1.0f; //project.Thickness;

            rDto.D3DPrimitiveDTO.VertexCount = 36; //6 * 6
            rDto.D3DPrimitiveDTO.VertexBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, sizeof(float) * 6, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            rDto.D3DPrimitiveDTO.VertexBuffer = GenerateVertexBuffer6Sided(d3dDevice, thicknessToUse);

            //vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);
            rDto.D3DPrimitiveDTO.VertexBufferBinding = new VertexBufferBinding(rDto.D3DPrimitiveDTO.VertexBuffer, sizeof(float) * 6, 0);

            // Create Constant Buffer
            rDto.D3DPrimitiveDTO.ConstantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            //TextureView
            RenderD3DDto(assetUrl, rDto);

            rDto.D3DPrimitiveDTO.Sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter = Filter.MinMagMipLinear,
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                AddressW = TextureAddressMode.Wrap,
                BorderColor = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy = 16,
                MipLodBias = 0,
                MinimumLod = 0,
                MaximumLod = 16,
            });

            BlendStateDescription1 blendDesc = new BlendStateDescription1();
            blendDesc.AlphaToCoverageEnable = true;  //set to true to get nice blending betweent sprites
            blendDesc.IndependentBlendEnable = false;
            blendDesc.RenderTarget[0].IsBlendEnabled = false;
            blendDesc.RenderTarget[0].IsLogicOperationEnabled = false;
            blendDesc.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
            blendDesc.RenderTarget[0].DestinationBlend = BlendOption.SourceAlphaSaturate;
            blendDesc.RenderTarget[0].BlendOperation = BlendOperation.Maximum;
            blendDesc.RenderTarget[0].SourceAlphaBlend = BlendOption.One;
            blendDesc.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
            blendDesc.RenderTarget[0].AlphaBlendOperation = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other
            blendDesc.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.All;
            rDto.D3DPrimitiveDTO.BlendState = new BlendState1(d3dDevice, blendDesc);

            _renderTree.Add(rDto);

        }
Beispiel #11
0
        private async void RenderD3DDto(string assetUrl, RenderDTO rDto)
        {
            if (rDto == null)
            {
                return;
            }

            if (string.IsNullOrEmpty(assetUrl))
            {
                return;
            }

            // Setup local variables
            var d3dDevice  = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice  = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;



            // Load texture and create sampler
            //using (var bitmap = TextureLoader.LoadBitmap(_deviceManager.WICFactory, string.IsNullOrEmpty(project.AssetUrl)?"Assets\\Textures\\5.jpg": project.AssetUrl  ))
            //using (var texture2D = TextureLoader.CreateTexture2DFromBitmap(d3dDevice, bitmap))
            //    rDto.D3DPrimitiveDTO.TextureView = new ShaderResourceView(d3dDevice, texture2D);



            //Fill D2D THEN push D2D -> D3D
            var fc = await this.LoadAssetAsync(_deviceManager.WICFactory, assetUrl, Guid.NewGuid().ToString());



            //using (SharpDX.WIC.BitmapSource bitmap = TextureLoader.LoadBitmap(_deviceManager.WICFactory, assetUrl))
            using (SharpDX.WIC.BitmapSource bitmap = (SharpDX.WIC.BitmapSource)fc.Item1)
            {
                d2dContext.Transform = Matrix.Identity;

                rDto.D3DPrimitiveDTO.Texture2D = AllocateTextureReturnSurface(d3dDevice, new Size2F(bitmap.Size.Width, bitmap.Size.Height));
                d2dContext.Target = new SharpDX.Direct2D1.Bitmap1(d2dContext, rDto.D3DPrimitiveDTO.Texture2D.QueryInterface <SharpDX.DXGI.Surface>());
                rDto.D3DPrimitiveDTO.TextureView = new ShaderResourceView(d3dDevice, rDto.D3DPrimitiveDTO.Texture2D);

                d2dContext.BeginDraw();
                SharpDX.Direct2D1.Effects.BitmapSource effectBitmapSource = new SharpDX.Direct2D1.Effects.BitmapSource(d2dContext);

                effectBitmapSource.WicBitmapSource = bitmap;



                //SharpDX.Direct2D1.Effects.Shadow shadowEffect = new SharpDX.Direct2D1.Effects.Shadow(d2dContext);
                //shadowEffect.SetInputEffect(0, effectBitmapSource, true);
                //shadowEffect.BlurStandardDeviation = 10.0f;
                //d2dContext.DrawImage(shadowEffect);

                d2dContext.DrawImage(effectBitmapSource);
                //d2dContext.FillRectangle(new RectangleF(0, bitmap.Size.Height - 90, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColorLightBy2Degree));



                //if (project.Title != null)
                //{
                //    SharpDX.DirectWrite.TextFormat tf = new SharpDX.DirectWrite.TextFormat(_deviceManager.FactoryDirectWrite, "segoe ui", 28.0f);
                //    d2dContext.DrawText(project.Title, tf, new RectangleF(10, bitmap.Size.Height - 90 + 10, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White));
                //}

                //if (project.Description != null)
                //{
                //    SharpDX.DirectWrite.TextFormat tf = new SharpDX.DirectWrite.TextFormat(_deviceManager.FactoryDirectWrite, "segoe ui", 21.0f);
                //    d2dContext.DrawText(project.Description, tf, new RectangleF(10, bitmap.Size.Height - 90 + 40, bitmap.Size.Width, bitmap.Size.Height), new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White));
                //}

                //PathToD2DPathGeometryConverter pathConverter = new PathToD2DPathGeometryConverter();

                //if (!string.IsNullOrEmpty(project.PathResource))
                //{
                //    var resourceFound = App.Current.Resources[project.PathResource];
                //    var pathGeometryCreated = pathConverter.parse((string)resourceFound, _deviceManager.FactoryDirect2D);
                //    var pathGeometryCreatedSize = pathGeometryCreated.GetBounds();
                //    d2dContext.FillRectangle(
                //        new RectangleF(bitmap.Size.Width - pathGeometryCreatedSize.Width - 20, 0, bitmap.Size.Width, pathGeometryCreatedSize.Height + 20)
                //        , new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColor)
                //        );
                //    d2dContext.Transform = Matrix.Translation(bitmap.Size.Width - pathGeometryCreatedSize.Width - 10, 10, 0);
                //    //d2dContext.StrokeWidth = 2.0f;
                //    d2dContext.FillGeometry(pathGeometryCreated, new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColorLightBy2Degree));
                //    //d2dContext.DrawGeometry(pathGeometryCreated, new SharpDX.Direct2D1.SolidColorBrush(d2dContext, this.AccentColor));
                //}

                d2dContext.EndDraw();
            }
        }
Beispiel #12
0
        private void CreateD3D_rDto(string assetUrl)
        {
            RenderDTO rDto = new RenderDTO();

            rDto.D3DPrimitiveDTO = new D3DPrimitiveDTO();

            //SafeDispose(ref rDto.D3DPrimitiveDTO.VertexBuffer);
            //rDto.D3DPrimitiveDTO.IsRenderable = true;
            // Remove previous buffer
            //SafeDispose(ref rDto.D3DPrimitiveDTO.ConstantBuffer);

            // Setup local variables
            var d3dDevice  = _deviceManager.DeviceDirect3D;
            var d3dContext = _deviceManager.ContextDirect3D;
            var d2dDevice  = _deviceManager.DeviceDirect2D;
            var d2dContext = _deviceManager.ContextDirect2D;

            var path = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;

            // Loads vertex shader bytecode
            var vertexShaderByteCode = NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_VS.fxo");

            rDto.D3DPrimitiveDTO.VertexShader = new VertexShader(d3dDevice, vertexShaderByteCode);

            // Loads pixel shader bytecode
            rDto.D3DPrimitiveDTO.PixelShader = new PixelShader(d3dDevice, NativeFile.ReadAllBytes(path + "\\Assets\\MiniCubeTexture_PS.fxo"));

            // Layout from VertexShader input signature
            rDto.D3DPrimitiveDTO.Layout = new InputLayout(d3dDevice, vertexShaderByteCode, new[]
            {
                new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0),
                new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0)
            });


            // Instantiate Vertex buffer from vertex data
            float thicknessToUse = 0.15f;

            thicknessToUse = 1.0f;                  //project.Thickness;

            rDto.D3DPrimitiveDTO.VertexCount  = 36; //6 * 6
            rDto.D3DPrimitiveDTO.VertexBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, sizeof(float) * 6, ResourceUsage.Default, BindFlags.VertexBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));
            rDto.D3DPrimitiveDTO.VertexBuffer = GenerateVertexBuffer6Sided(d3dDevice, thicknessToUse);

            //vertexBufferBinding = new VertexBufferBinding(vertices, Utilities.SizeOf<Vector4>() * 2, 0);
            rDto.D3DPrimitiveDTO.VertexBufferBinding = new VertexBufferBinding(rDto.D3DPrimitiveDTO.VertexBuffer, sizeof(float) * 6, 0);

            // Create Constant Buffer
            rDto.D3DPrimitiveDTO.ConstantBuffer = ToDispose(new SharpDX.Direct3D11.Buffer(d3dDevice, Utilities.SizeOf <Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None, 0));

            //TextureView
            RenderD3DDto(assetUrl, rDto);

            rDto.D3DPrimitiveDTO.Sampler = new SamplerState(d3dDevice, new SamplerStateDescription()
            {
                Filter             = Filter.MinMagMipLinear,
                AddressU           = TextureAddressMode.Wrap,
                AddressV           = TextureAddressMode.Wrap,
                AddressW           = TextureAddressMode.Wrap,
                BorderColor        = Color.Black,
                ComparisonFunction = Comparison.Never,
                MaximumAnisotropy  = 16,
                MipLodBias         = 0,
                MinimumLod         = 0,
                MaximumLod         = 16,
            });

            BlendStateDescription1 blendDesc = new BlendStateDescription1();

            blendDesc.AlphaToCoverageEnable                   = true; //set to true to get nice blending betweent sprites
            blendDesc.IndependentBlendEnable                  = false;
            blendDesc.RenderTarget[0].IsBlendEnabled          = false;
            blendDesc.RenderTarget[0].IsLogicOperationEnabled = false;
            blendDesc.RenderTarget[0].SourceBlend             = BlendOption.SourceAlpha;
            blendDesc.RenderTarget[0].DestinationBlend        = BlendOption.SourceAlphaSaturate;
            blendDesc.RenderTarget[0].BlendOperation          = BlendOperation.Maximum;
            blendDesc.RenderTarget[0].SourceAlphaBlend        = BlendOption.One;
            blendDesc.RenderTarget[0].DestinationAlphaBlend   = BlendOption.One;
            blendDesc.RenderTarget[0].AlphaBlendOperation     = BlendOperation.Maximum; // set to maximum to blend 2 sprites nicely over each other
            blendDesc.RenderTarget[0].RenderTargetWriteMask   = ColorWriteMaskFlags.All;
            rDto.D3DPrimitiveDTO.BlendState                   = new BlendState1(d3dDevice, blendDesc);

            _renderTree.Add(rDto);
        }
Beispiel #13
0
        private async Task <RenderDTO> AddUpdateUIElementState_Text(UIElementState uistate, RenderDTO rDto, Color color)
        {
            TextDTO textDto = null;

            if (rDto == null || rDto.TextDTO == null)
            {
                textDto             = new TextDTO();
                textDto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO()
                {
                    TextDTO = textDto, Type = eRenderType.Text, Order = _renderTree.Count() + 1
                };

                _renderTree.Add(rDto);
            }
            else
            {
                textDto = rDto.TextDTO;
            }



            textDto.TextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                uistate.udfString2,
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                (float)uistate.udfDouble1);

            textDto.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, color);
            textDto.Text  = uistate.udfString1;
            textDto.TextFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
            textDto.LayoutRect = new RectangleF(0, 0, (float)uistate.Width, (float)uistate.Height);



            rDto.TextDTO.IsRenderable    = uistate.IsRenderable; //true
            rDto.TextDTO.MainScale       = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.TextDTO.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);
        }
        private async Task <bool> UpdateRenderItemWithUIElement_Effect(UIElementState uies, RenderDTO renderItem)
        {
            if (_renderTree == null || _renderTree.Count == 0)
            {
                return(true);
            }

            UIElementState uiesParent = AppDatabase.Current.RetrieveUIElementState(renderItem.EffectDTO.Grouping1).First();

            string[] parts = uies.udfString1.Split("|".ToCharArray());


            //child got changed so re update from the parent where applicable
            renderItem.EffectDTO.IsRenderable = uies.IsRenderable;

            renderItem.EffectDTO.MainTranslation = new Vector3(
                (float)uiesParent.Left,
                (float)uiesParent.Top,
                (float)0);

            renderItem.EffectDTO.MainScale = new Vector3(
                (float)uiesParent.Scale,
                (float)uiesParent.Scale,
                0);

            if (string.IsNullOrEmpty(uies.Grouping2))
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping1).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }
            else
            {
                if (renderItem.EffectDTO.Effect != null)
                {
                    RenderDTO renderItemParent = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2).First();
                    renderItem.EffectDTO.Effect.SetInputEffect(0, renderItemParent.EffectDTO.Effect, true);
                }
            }

            //SharpDX.Direct2D1.Effects.Blend

            //now just update child based on new values from child UIElementState
            switch (parts[0])
            {
            case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;

            case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;

            case "SharpDX.Direct2D1.Effects.Atlas": break;

            case "SharpDX.Direct2D1.Effects.BitmapSourceEffect":
                #region bitmap source
                var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);

                ((SharpDX.Direct2D1.Effects.BitmapSource)renderItem.EffectDTO.Effect).SetValueByName("WicBitmapSource", asset.Item1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Blend": break;

            case "SharpDX.Direct2D1.Effects.Border": break;

            case "SharpDX.Direct2D1.Effects.Brightness":
                #region brightness
                ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ((SharpDX.Direct2D1.Effects.Brightness)renderItem.EffectDTO.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ColorManagement": break;

            case "SharpDX.Direct2D1.Effects.ColorMatrix": break;

            case "SharpDX.Direct2D1.Effects.Composite":
                #region composite
                if (!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2))
                {
                    //renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);

                    if (renderItem.EffectDTO.Effect == null)
                    {
                        renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                    }
                    //else
                    //{
                    //    renderItem.EffectDTO.Effect.Dispose();
                    //    renderItem.EffectDTO.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);
                    //}

                    if (!string.IsNullOrEmpty(uies.Grouping2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                        if (found != null && found.Count() > 0)
                        {
                            renderItem.EffectDTO.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                        }
                    }

                    if (!string.IsNullOrEmpty(uies.udfString2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                        if (found != null && found.Count() > 0)
                        {
                            renderItem.EffectDTO.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                        }
                    }
                }
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ConvolveMatrix":
                #region convolve matrix
                if (!string.IsNullOrEmpty(uies.udfString2))     //matrix
                {
                    var matrixParts = uies.udfString2.Split("|".ToCharArray());
                    if (matrixParts.Length == 9)
                    {
                        float[] matrix = new float[9] {
                            float.Parse(matrixParts[0]),
                            float.Parse(matrixParts[1]),
                            float.Parse(matrixParts[2]),
                            float.Parse(matrixParts[3]),
                            float.Parse(matrixParts[4]),
                            float.Parse(matrixParts[5]),
                            float.Parse(matrixParts[6]),
                            float.Parse(matrixParts[7]),
                            float.Parse(matrixParts[8]),
                        };
                        ((SharpDX.Direct2D1.Effects.ConvolveMatrix)renderItem.EffectDTO.Effect).KernelMatrix = matrix;
                    }
                }

                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Crop":
                #region Crop
                ((SharpDX.Direct2D1.Effects.Crop)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                #region directional blur
                renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                renderItem.EffectDTO.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;

            case "SharpDX.Direct2D1.Effects.DisplacementMap": break;

            case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;

            case "SharpDX.Direct2D1.Effects.DistantSpecular": break;

            case "SharpDX.Direct2D1.Effects.DpiCompensation": break;

            case "SharpDX.Direct2D1.Effects.Flood":
                #region flood
                ((SharpDX.Direct2D1.Effects.Flood)renderItem.EffectDTO.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.GammaTransfer": break;

            case "SharpDX.Direct2D1.Effects.GaussianBlur":
                #region gaussian blur
                renderItem.EffectDTO.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Histogram": break;

            case "SharpDX.Direct2D1.Effects.HueRotate":
                #region hue rotate
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.LinearTransfer": break;

            case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;

            case "SharpDX.Direct2D1.Effects.Morphology": break;

            case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;

            case "SharpDX.Direct2D1.Effects.PointDiffuse": break;

            case "SharpDX.Direct2D1.Effects.PointSpecular": break;

            case "SharpDX.Direct2D1.Effects.Premultiply": break;

            case "SharpDX.Direct2D1.Effects.Saturation":
                #region saturation
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Scale":
                #region scale
                SharpDX.Direct2D1.Effects.Scale ef = (SharpDX.Direct2D1.Effects.Scale)renderItem.EffectDTO.Effect;
                ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Shadow":
                #region shadow
                renderItem.EffectDTO.Effect.SetValue(0, (float)uies.udfDouble1);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;

            case "SharpDX.Direct2D1.Effects.SpotSpecular": break;

            case "SharpDX.Direct2D1.Effects.TableTransfer": break;

            case "SharpDX.Direct2D1.Effects.Tile":
                #region tile
                ((SharpDX.Direct2D1.Effects.Tile)renderItem.EffectDTO.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Transform3D": break;

            case "SharpDX.Direct2D1.Effects.Turbulence": break;

            case "SharpDX.Direct2D1.Effects.UnPremultiply": break;
            }

            return(true);
        }
Beispiel #15
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);
        }
        private async Task <RenderDTO> CreateRenderItemWithUIElement_Effect(UIElementState uies, string effectClass, RenderDTO parentRenderTreeItem)
        {
            EffectDTO edto = new EffectDTO();

            edto.IsRenderable = uies.IsRenderable;
            edto.AggregateId  = uies.AggregateId;
            edto.Grouping1    = uies.Grouping1;
            if (parentRenderTreeItem != null)
            {
                edto.MainTranslation = parentRenderTreeItem.EffectDTO.MainTranslation;
                edto.MainScale       = parentRenderTreeItem.EffectDTO.MainScale;
            }
            else
            {
                edto.MainTranslation = new Vector3(0);
                edto.MainScale       = new Vector3(1);
            }

            switch (effectClass)
            {
            case "SharpDX.Direct2D1.Effects.AffineTransform2D": break;

            case "SharpDX.Direct2D1.Effects.ArithmeticComposite": break;

            case "SharpDX.Direct2D1.Effects.Atlas": break;

            case "SharpDX.Direct2D1.Effects.BitmapSourceEffect":
                #region bitmap source

                try
                {
                    if (uies.udfString2 == "PicturesLibrary")
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path : "PicturesLibrary");

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                    else if (uies.udfString2 == "PublicPicturesLibrary")
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId, path : "PublicPicturesLibrary");

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                    else
                    {
                        var asset = await LoadAssetAsync(_deviceManager.WICFactory, uies.udfString1, uies.AggregateId);

                        edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                        edto.Effect.SetValueByName("WicBitmapSource", asset.Item1);
                        uies.Width  = asset.Item2.Width;
                        uies.Height = asset.Item2.Height;
                    }
                }
                catch {
                    var asset = LoadAssetAsync(_deviceManager.WICFactory, "Assets\\StartDemo\\Backgrounds\\green1.jpg", uies.AggregateId);

                    edto.Effect = new SharpDX.Direct2D1.Effects.BitmapSource(_deviceManager.ContextDirect2D);
                    edto.Effect.SetValueByName("WicBitmapSource", asset.Result.Item1);
                    uies.Width  = asset.Result.Item2.Width;
                    uies.Height = asset.Result.Item2.Height;
                }


                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Blend": break;

            case "SharpDX.Direct2D1.Effects.Border": break;

            case "SharpDX.Direct2D1.Effects.Brightness":
                #region brightness
                edto.Effect = new SharpDX.Direct2D1.Effects.Brightness(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).WhitePoint = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ((SharpDX.Direct2D1.Effects.Brightness)edto.Effect).BlackPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);

                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ColorManagement": break;

            case "SharpDX.Direct2D1.Effects.ColorMatrix": break;

            case "SharpDX.Direct2D1.Effects.Composite":
                #region composite
                if (!string.IsNullOrEmpty(uies.Grouping2) && !string.IsNullOrEmpty(uies.udfString2))
                {
                    edto.Effect = new SharpDX.Direct2D1.Effects.Composite(_deviceManager.ContextDirect2D);

                    if (!string.IsNullOrEmpty(uies.Grouping2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.Grouping2);
                        if (found != null && found.Count() > 0)
                        {
                            edto.Effect.SetInputEffect(0, found.First().EffectDTO.Effect, true);
                        }
                        else
                        {
                            edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                    }
                    else
                    {
                        edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                    }

                    if (!string.IsNullOrEmpty(uies.udfString2))
                    {
                        var found = _renderTree.Where(x => x.EffectDTO != null && x.EffectDTO.AggregateId == uies.udfString2);
                        if (found != null && found.Count() > 0)
                        {
                            edto.Effect.SetInputEffect(1, found.First().EffectDTO.Effect, true);
                        }
                        else
                        {
                            edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                        }
                    }
                    else
                    {
                        edto.Effect.SetInputEffect(1, parentRenderTreeItem.EffectDTO.Effect, true);
                    }
                }
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.ConvolveMatrix":
                #region convolve matrix

                edto.Effect = new SharpDX.Direct2D1.Effects.ConvolveMatrix(_deviceManager.ContextDirect2D);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);

                if (!string.IsNullOrEmpty(uies.udfString2))     //matrix
                {
                    var parts = uies.udfString2.Split("|".ToCharArray());
                    if (parts.Length == 9)
                    {
                        float[] matrix = new float[9] {
                            float.Parse(parts[0]),
                            float.Parse(parts[1]),
                            float.Parse(parts[2]),
                            float.Parse(parts[3]),
                            float.Parse(parts[4]),
                            float.Parse(parts[5]),
                            float.Parse(parts[6]),
                            float.Parse(parts[7]),
                            float.Parse(parts[8]),
                        };
                        ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = matrix;
                    }
                    //edto.Effect.SetInput(0, parentRenderTreeItem.EffectDTO.Effect.Output, true);
                    //var kernelmatrix = new float[9] { 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f };
                    //((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = kernelmatrix;
                }
                else
                {
                    ((SharpDX.Direct2D1.Effects.ConvolveMatrix)edto.Effect).KernelMatrix = new float[9] {
                        0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f
                    };
                }


                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Crop":
                #region crop
                edto.Effect = new SharpDX.Direct2D1.Effects.Crop(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Crop)edto.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DirectionalBlur":
                #region directional blur
                edto.Effect = new SharpDX.Direct2D1.Effects.DirectionalBlur(_deviceManager.ContextDirect2D);
                edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                edto.Effect.SetValueByName("Angle", (float)uies.udfDouble2);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.DiscreteTransfer": break;

            case "SharpDX.Direct2D1.Effects.DisplacementMap": break;

            case "SharpDX.Direct2D1.Effects.DistantDiffuse": break;

            case "SharpDX.Direct2D1.Effects.DistantSpecular": break;

            case "SharpDX.Direct2D1.Effects.DpiCompensation": break;

            case "SharpDX.Direct2D1.Effects.Flood":
                #region flood
                edto.Effect = new SharpDX.Direct2D1.Effects.Flood(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Flood)edto.Effect).Color = new Color4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.GammaTransfer": break;

            case "SharpDX.Direct2D1.Effects.GaussianBlur":
                #region gaussian blur
                edto.Effect = new SharpDX.Direct2D1.Effects.GaussianBlur(_deviceManager.ContextDirect2D);
                edto.Effect.SetValueByName("StandardDeviation", (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Histogram": break;

            case "SharpDX.Direct2D1.Effects.HueRotate":
                #region hue rotate
                edto.Effect = new SharpDX.Direct2D1.Effects.HueRotation(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.LinearTransfer": break;

            case "SharpDX.Direct2D1.Effects.LuminanceToAlpha": break;

            case "SharpDX.Direct2D1.Effects.Morphology": break;

            case "SharpDX.Direct2D1.Effects.NamespaceDoc": break;

            case "SharpDX.Direct2D1.Effects.PointDiffuse": break;

            case "SharpDX.Direct2D1.Effects.PointSpecular": break;

            case "SharpDX.Direct2D1.Effects.Premultiply": break;

            case "SharpDX.Direct2D1.Effects.Saturation":
                #region saturation
                edto.Effect = new SharpDX.Direct2D1.Effects.Saturation(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Scale":
                #region scale

                SharpDX.Direct2D1.Effects.Scale ef = new SharpDX.Direct2D1.Effects.Scale(_deviceManager.ContextDirect2D);
                ef.BorderMode  = SharpDX.Direct2D1.BorderMode.Soft;
                ef.Cached      = false;
                ef.ScaleAmount = new Vector2((float)uies.udfDouble1, (float)uies.udfDouble2);
                ef.CenterPoint = new Vector2((float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect    = ef;

                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Shadow":
                #region shadow
                edto.Effect = new SharpDX.Direct2D1.Effects.Shadow(_deviceManager.ContextDirect2D);
                edto.Effect.SetValue(0, (float)uies.udfDouble1);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.SpotDiffuse": break;

            case "SharpDX.Direct2D1.Effects.SpotSpecular": break;

            case "SharpDX.Direct2D1.Effects.TableTransfer": break;

            case "SharpDX.Direct2D1.Effects.Tile":
                #region tile
                edto.Effect = new SharpDX.Direct2D1.Effects.Tile(_deviceManager.ContextDirect2D);
                ((SharpDX.Direct2D1.Effects.Tile)edto.Effect).Rectangle = new Vector4((float)uies.udfDouble1, (float)uies.udfDouble2, (float)uies.udfDouble3, (float)uies.udfDouble4);
                edto.Effect.SetInputEffect(0, parentRenderTreeItem.EffectDTO.Effect, true);
                #endregion
                break;

            case "SharpDX.Direct2D1.Effects.Transform3D": break;

            case "SharpDX.Direct2D1.Effects.Turbulence": break;

            case "SharpDX.Direct2D1.Effects.UnPremultiply": break;
            }


            RenderDTO _newRenderDto;

            if (parentRenderTreeItem != null)
            {
                _newRenderDto = new RenderDTO()
                {
                    EffectDTO = edto, Type = eRenderType.Effect, Order = parentRenderTreeItem.Order
                }
            }
            ;
            else
            {
                _newRenderDto = new RenderDTO()
                {
                    EffectDTO = edto, Type = eRenderType.Effect, Order = 1
                }
            };

            _renderTree.Add(_newRenderDto);

            return(_newRenderDto);
        }
        private async Task<RenderDTO> AddUpdateUIElementState_Text(UIElementState uistate, RenderDTO rDto, Color color)
        {
            TextDTO textDto = null;

            if (rDto == null || rDto.TextDTO == null)
            {
                textDto = new TextDTO();
                textDto.AggregateId = uistate.AggregateId;

                rDto = new RenderDTO() { TextDTO = textDto, Type = eRenderType.Text, Order = _renderTree.Count() + 1 };

                _renderTree.Add(rDto);
            }
            else
            {
                textDto = rDto.TextDTO;
            }
            


            textDto.TextFormat = new SharpDX.DirectWrite.TextFormat(
                _deviceManager.FactoryDirectWrite,
                uistate.udfString2,
                SharpDX.DirectWrite.FontWeight.Light,
                SharpDX.DirectWrite.FontStyle.Normal,
                SharpDX.DirectWrite.FontStretch.Normal,
                (float)uistate.udfDouble1);

            textDto.Brush = new SharpDX.Direct2D1.SolidColorBrush(_deviceManager.ContextDirect2D, color);
            textDto.Text = uistate.udfString1;
            textDto.TextFormat.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
            textDto.LayoutRect = new RectangleF(0, 0, (float)uistate.Width, (float)uistate.Height);





            rDto.TextDTO.IsRenderable = uistate.IsRenderable; //true
            rDto.TextDTO.MainScale = new Vector3((float)uistate.Scale, (float)uistate.Scale, 1);
            rDto.TextDTO.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;
        }