Example #1
0
 public void ConvXFormText(XFormText xft)
 {
     _currentNode.AddComponent(new FusXFormText
     {
         Height = xft.Height,
         Width  = xft.Width,
         Name   = xft.Name,
         HorizontalAlignment =
             xft.HorizontalAlignment == Scene.HorizontalTextAlignment.Center
         ? Serialization.V1.HorizontalTextAlignment.Center
         : xft.HorizontalAlignment == Scene.HorizontalTextAlignment.Left
         ? Serialization.V1.HorizontalTextAlignment.Left
         : Serialization.V1.HorizontalTextAlignment.Right,
         VerticalAlignment = xft.VerticalAlignment == Scene.VerticalTextAlignment.Center
         ? Serialization.V1.VerticalTextAlignment.Center
         : xft.VerticalAlignment == Scene.VerticalTextAlignment.Bottom
         ? Serialization.V1.VerticalTextAlignment.Bottom
         : Serialization.V1.VerticalTextAlignment.Top
     });
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextNode"/> class.
        /// </summary>
        /// <param name="text">The text you want to display.</param>
        /// <param name="name">The name of the SceneNode.</param>
        /// <param name="vs">The vertex shader you want to use..</param>
        /// <param name="ps">The pixel shader you want to use.</param>
        /// <param name="anchors">Anchors for the mesh. Influences the scaling of the object if the enclosing canvas is resized.</param>
        /// <param name="offsets">The offsets.</param>
        /// <param name="fontMap">Offsets for the mesh. Defines the position of the object relative to its enclosing UI element.</param>
        /// <param name="color">The color.</param>
        /// <param name="horizontalAlignment">The <see cref="HorizontalTextAlignment"/> defines the text's placement along the enclosing <see cref="MinMaxRect"/>'s x-axis.</param>
        /// <param name="verticalTextAlignment">The <see cref="HorizontalTextAlignment"/> defines the text's placement along the enclosing <see cref="MinMaxRect"/>'s y-axis.</param>
        public TextNode(string text, string name, string vs, string ps, MinMaxRect anchors, MinMaxRect offsets,
                        FontMap fontMap, float4 color, HorizontalTextAlignment horizontalAlignment = HorizontalTextAlignment.Left, VerticalTextAlignment verticalTextAlignment = VerticalTextAlignment.Top)
        {
            var textMesh = new GUIText(fontMap, text, horizontalAlignment)
            {
                Name = name + "textMesh"
            };

            var xFormText = new XFormText
            {
                Width  = textMesh.Width,
                Height = textMesh.Height,
                HorizontalAlignment = textMesh.HorizontalAlignment,
                VerticalAlignment   = verticalTextAlignment
            };

            Name       = name;
            Components = new List <SceneComponent>
            {
                new RectTransform
                {
                    Name    = name + "_RectTransform",
                    Anchors = anchors,
                    Offsets = offsets
                },
                new XForm
                {
                    Name = name + "_XForm",
                }
            };

            Children = new ChildList()
            {
                new SceneNode()
                {
                    Components = new List <SceneComponent>()
                    {
                        xFormText,
                        new ShaderEffect(new[]
                        {
                            new EffectPassDeclaration
                            {
                                VS       = vs,
                                PS       = ps,
                                StateSet = new RenderStateSet
                                {
                                    AlphaBlendEnable = true,
                                    SourceBlend      = Blend.SourceAlpha,
                                    DestinationBlend = Blend.InverseSourceAlpha,
                                    BlendOperation   = BlendOperation.Add,
                                    ZEnable          = false
                                }
                            }
                        },
                                         new[]
                        {
                            new EffectParameterDeclaration
                            {
                                Name  = "DiffuseTexture",
                                Value = new Texture(fontMap.Image)
                            },
                            new EffectParameterDeclaration
                            {
                                Name = "DiffuseColor", Value = color
                            },
                            new EffectParameterDeclaration {
                                Name = "DiffuseMix", Value = 0.0f
                            },
                            new EffectParameterDeclaration {
                                Name = "FUSEE_ITMV", Value = float4x4.Identity
                            },
                            new EffectParameterDeclaration {
                                Name = "FUSEE_MVP", Value = float4x4.Identity
                            },
                        }),
                        textMesh
                    }
                }
            };
        }