示例#1
0
            protected override void AssignDefaultValuesToSceneNode(SceneNode2D node)
            {
                var t = node as TextNode2D;

                t.Text          = Text == null ? "" : Text;
                t.FontFamily    = FontFamily == null ? DefaultFont : FontFamily;
                t.FontWeight    = FontWeight.ToDXFontWeight();
                t.FontStyle     = FontStyle.ToDXFontStyle();
                t.FontSize      = FontSize;
                t.TextAlignment = TextAlignment.ToD2DTextAlignment();
                t.FlowDirection = FlowDirection.ToD2DFlowDir();
            }
        /// <summary>
        /// Called when [draw texture].
        /// </summary>
        /// <param name="deviceResources">The device resources.</param>
        protected override void OnUpdateTextureAndBillboardVertices(IDeviceResources deviceResources)
        {
            if (TextInfo != null && !string.IsNullOrEmpty(TextInfo.Text))
            {
                var w = Width;
                var h = Height;
#if CORE
                Texture = TextInfo.Text.ToBitmapStream(FontSize, Color.White, Color.Black, FontFamily, FontWeight, FontStyle,
                                                       new Vector4((float)Padding.Left, (float)Padding.Top, (float)Padding.Right, (float)Padding.Bottom), ref w, ref h, predefinedSize, deviceResources);
#else
                Texture = TextInfo.Text.ToBitmapStream(FontSize, Color.White, Color.Black, FontFamily, FontWeight.ToDXFontWeight(), FontStyle.ToDXFontStyle(),
                                                       new Vector4((float)Padding.Left, (float)Padding.Top, (float)Padding.Right, (float)Padding.Bottom), ref w, ref h, predefinedSize, deviceResources);
#endif
                if (!predefinedSize)
                {
                    Width  = w;
                    Height = h;
                }
                DrawCharacter(TextInfo.Text, TextInfo.Origin, Width, Height, TextInfo);
            }
            else
            {
                Texture = null;
                if (!predefinedSize)
                {
                    Width  = 0;
                    Height = 0;
                }
            }
            TextInfo?.UpdateTextInfo(Width, Height);
        }