DrawText() public method

Draws the specified text using the format information provided by an T:SharpDX.DirectWrite.TextFormat object.
To create an T:SharpDX.DirectWrite.TextFormat object, create an T:SharpDX.DirectWrite.Factory and call its {{CreateTextFormat}} method. This method doesn't return an error code if it fails. To determine whether a drawing operation (such as {{DrawText}}) failed, check the result returned by the M:SharpDX.Direct2D1.RenderTarget.EndDraw(System.Int64@,System.Int64@) or M:SharpDX.Direct2D1.RenderTarget.Flush(System.Int64@,System.Int64@) methods.
public DrawText ( string text, SharpDX.DirectWrite.TextFormat textFormat, RawRectangleF layoutRect, Brush defaultForegroundBrush ) : void
text string A reference to an array of Unicode characters to draw.
textFormat SharpDX.DirectWrite.TextFormat An object that describes formatting details of the text to draw, such as the font, the font size, and flow direction.
layoutRect RawRectangleF The size and position of the area in which the text is drawn.
defaultForegroundBrush Brush The brush used to paint the text.
return void
Exemplo n.º 1
2
 public override void Render(RenderTarget pRender, float pPercent)
 {
     pRender.Transform = Matrix3x2.Identity;
     pRender.DrawText("dx:" + dx + "  dy:" + dy + "  da:" + da, Constants.SmallFont, new RectangleF(0, 0, 200, 50), new SolidColorBrush(pRender, Color4.Black));
     pRender.Transform = Matrix3x2.Rotation(MathUtil.DegreesToRadians(-a + 180)) * Matrix3x2.Translation(x, y);
     pRender.DrawBitmap(ShipBitmap, new RectangleF(-17, -17, 34, 34), 1.0f, BitmapInterpolationMode.Linear);
 }
Exemplo n.º 2
0
        protected void DrawHintAndInput()
        {
            if (!Paradigm.Config.Gui.InputBarVisibility)
            {
                return;
            }

            /* Draw Hint */
            if (HintText != null)
            {
                SharedBrush.Color = new Color(ForegroundColor.R, ForegroundColor.G, ForegroundColor.B, 0.7F);
                RenderTarget.DrawText(HintText, InputTextFormat, new RawRectangleF(10, 0, Width - 10, InputBoxHeight / 2),
                                      SharedBrush, D2D1.DrawTextOptions.None);
            }

            /* Draw user input text */
            if (InputTextLayout != null)
            {
                var rect = HintText == null
                    ? new RawRectangleF(10, 5, Width - 10, InputBoxHeight - 5)
                    : new RawRectangleF(10, InputBoxHeight / 2, Width - 10, InputBoxHeight);
                InputTextLayout.MaxWidth  = rect.Right - rect.Left;
                InputTextLayout.MaxHeight = rect.Bottom - rect.Top;
                InputTextLayout.Draw(_customColorRenderer, rect.Left, rect.Top);
            }

            /* Draw Input Box Bottom Line */
            SharedBrush.Color = ForegroundColor;
            RenderTarget.DrawLine(new RawVector2(10, InputBoxHeight + 2), new RawVector2(Width - 10, InputBoxHeight + 2), SharedBrush, 2);
        }
Exemplo n.º 3
0
        public void Draw(ServiceResult serviceResult, float currentTime, float duration)
        {
            if (!uiInitialized)
            {
                return;
            }
            if (!redraw)
            {
                return;
            }
            redraw = false;

            target2d.BeginDraw();
            target2d.Clear(new Color4(0, 0, 0, 0.7f));

            target2d.DrawLine(new Vector2(0, 1), new Vector2(1024, 1), blueBrush, 2);
            target2d.DrawLine(new Vector2(0, 511), new Vector2(1024, 511), blueBrush, 2);

            textFormat.TextAlignment      = SharpDX.DirectWrite.TextAlignment.Center;
            textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;

            if (serviceResult.contentType == ServiceResult.ContentType.video)
            {
                target2d.DrawText("now playing:", textFormatSmall, new RectangleF(0, 0, 1024, 100), textBrush);
                target2d.DrawText(serviceResult.TitleWithFallback, textFormat, new RectangleF(0, 50, 1024, 100), textBrush);

                var barLength     = 1024 - 265;
                var currentLength = barLength * (currentTime / duration);

                target2d.DrawLine(new Vector2(128, 384), new Vector2(1024 - 128, 384), textBrush, 6);
                target2d.DrawLine(new Vector2(128, 384), new Vector2(128 + currentLength, 384), blueBrush, 6);
                var ellipse = new DX2D.Ellipse(new Vector2(128 + currentLength + 3.5f, 384), 7, 7);
                target2d.FillEllipse(ellipse, blueBrush);

                target2d.DrawEllipse(new DX2D.Ellipse(new Vector2(512, 256), 48, 48), textBrush, 2);
                var dist = 8;
                var len  = 10;
                target2d.DrawLine(new Vector2(512 - dist, 256 - len), new Vector2(512 - dist, 256 + len), textBrush, 2);
                target2d.DrawLine(new Vector2(512 + dist, 256 - len), new Vector2(512 + dist, 256 + len), textBrush, 2);

                textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Trailing;
                target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(duration))).ToString(), textFormatSmall, new Rectangle(1024 - 128 - 150, 384, 150, 50), textBrush);


                int positionx = (int)(128 + currentLength - 74 / 2);
                positionx = MathUtil.Clamp(positionx, 128, 1024 - 128 - 74);
                textFormatSmall.TextAlignment = SharpDX.DirectWrite.TextAlignment.Center;
                target2d.DrawText((new TimeSpan(0, 0, (int)Math.Floor(currentTime))).ToString(), textFormatSmall, new Rectangle(positionx, 340, 74, 32), textBrush);
            }

            target2d.EndDraw();
        }
Exemplo n.º 4
0
        protected override void Draw(D2D1.RenderTarget renderTarget)
        {
            /* Clear canvas */
            renderTarget.Clear(_backgroundColor);

            /* Draw blocks */
            if (_paradigmStarted)
            {
                var secsPassed = (CurrentTime - _stageUpdatedAt) / 1000.0;
                foreach (var block in _blocks)
                {
                    /* Draw block border */
                    if (block.BorderRect != null)
                    {
                        SolidColorBrush.Color = _blockBorderColor;
                        renderTarget.FillRectangle(block.BorderRect.Value, SolidColorBrush);
                    }

                    /* Fill block content */
                    if (!_trialStarted || block.Pattern == null)
                    {
                        SolidColorBrush.Color = _blockNormalColor;
                        renderTarget.FillRectangle(block.ContentRect, SolidColorBrush);
                    }
                    else
                    {
                        _presenter.Present(renderTarget, block, secsPassed);
                    }

                    /* Draw block text */
                    if (block.Text != null)
                    {
                        SolidColorBrush.Color = _blockFontColor;
                        renderTarget.DrawText(block.Text, _blockTextFormat, block.ContentRect,
                                              SolidColorBrush, D2D1.DrawTextOptions.None);
                    }

                    /* Draw block fixation */
                    if (block.FixationEllipse != null)
                    {
                        SolidColorBrush.Color = _blockFixationPointColor;
                        renderTarget.FillEllipse(block.FixationEllipse.Value, SolidColorBrush);
                    }
                }
            }
            else if (_displayText != null) // Draw text
            {
                SolidColorBrush.Color = _fontColor;
                renderTarget.DrawText(_displayText, _cueTextFormat, new RawRectangleF(0, 0, Width, Height),
                                      SolidColorBrush, D2D1.DrawTextOptions.None);
            }
        }
Exemplo n.º 5
0
        protected override void Draw(D2D1.RenderTarget renderTarget)
        {
            renderTarget.Clear(_backgroundColor);

            if (_experimentStarted)
            {
                // Draw fixation
                SolidColorBrush.Color = _fixationColor;
                renderTarget.FillEllipse(_fixationPoint, SolidColorBrush);

                if (_trialStarted && _stimPos != 0)
                {
                    SolidColorBrush.Color = _fontColor;
                    foreach (var stimulusPoint in _stimulusPoints)
                    {
                        renderTarget.FillEllipse(stimulusPoint, SolidColorBrush);
                    }
                }
            }
            else if (!string.IsNullOrWhiteSpace(_displayText)) // Draw text
            {
                SolidColorBrush.Color = _fontColor;
                renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height),
                                      SolidColorBrush, D2D1.DrawTextOptions.None);
            }
        }
Exemplo n.º 6
0
        private void OnRender()
        {
            lock (_renderContextLock)
            {
                if (_renderTarget?.IsDisposed ?? true)
                {
                    return;
                }

                _renderTarget.BeginDraw();
                _renderTarget.Clear(_backgroundColor);

                if (_paradigmStarted) // Draw blocks
                {
                    foreach (var block in _blocks)
                    {
                        if (block.BorderWidth > 0)
                        {
                            _solidColorBrush.Color = _blockBorderColor;
                            _renderTarget.FillRectangle(block.BorderRect, _solidColorBrush);
                        }

                        if (_bitmap != null)
                        {
                            _solidColorBrush.Color = _blockNormalColor;
                            _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush);
                            if (block.Actived)
                            {
                                _renderTarget.DrawBitmap(_bitmap, block.ContentRect, 1, D2D1.BitmapInterpolationMode.Linear);
                            }
                        }
                        else
                        {
                            _solidColorBrush.Color = block.Actived ? _blockActivedColor : _blockNormalColor;
                            _renderTarget.FillRectangle(block.ContentRect, _solidColorBrush);
                        }

                        if (block.Target)
                        {
                            _solidColorBrush.Color = _blockBorderColor;
                            _renderTarget.FillEllipse(block.CenterPointEllipse, _solidColorBrush);
                        }
                    }
                }
                else if (!(_displayText?.IsBlank() ?? true)) // Draw text
                {
                    _solidColorBrush.Color = _fontColor;
                    _renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height),
                                           _solidColorBrush, D2D1.DrawTextOptions.None);
                }

                _renderTarget.EndDraw();

                _swapChain.Present(1, DXGI.PresentFlags.None, _presentParameters);
            }
        }
Exemplo n.º 7
0
        private void OnRender()
        {
            lock (_renderContextLock)
            {
                if (_renderTarget?.IsDisposed ?? true)
                {
                    return;
                }

                _renderTarget.BeginDraw();
                _renderTarget.Clear(_backgroundColor);

                if (_paradigmStarted && _trialStarted) // Draw blocks
                {
                    var borderRect  = SharpDXUtils.CenteredRect(Width / 2f, Height / 2f, _paradigm.Config.Gui.ButtonSize);
                    var buttonRect  = borderRect.Shrink(Math.Max((float)_paradigm.Config.Gui.ButtonBorder.Width, 0));
                    var paddings    = _paradigm.Config.Gui.ButtonPaddings;
                    var contentRect = buttonRect.Shrink((float)paddings.Left, (float)paddings.Top, (float)paddings.Right, (float)paddings.Bottom);

                    if (_paradigm.Config.Gui.ButtonBorder.Width > 0)
                    {
                        _solidColorBrush.Color = _blockBorderColor;
                        _renderTarget.FillRectangle(borderRect, _solidColorBrush);
                    }

                    _solidColorBrush.Color = _blockNormalColor;
                    _renderTarget.FillRectangle(buttonRect, _solidColorBrush);

                    _solidColorBrush.Color = _foregroundColor;
                    _renderTarget.DrawText(_displayText, _textFormat, contentRect, _solidColorBrush, D2D1.DrawTextOptions.None);
                }
                else if (_displayText?.IsNotBlank() ?? false) // Draw text
                {
                    _solidColorBrush.Color = _foregroundColor;
                    _renderTarget.DrawText(_displayText, _textFormat, new RawRectangleF(0, 0, Width, Height),
                                           _solidColorBrush, D2D1.DrawTextOptions.None);
                }

                _renderTarget.EndDraw();

                _swapChain.Present(1, DXGI.PresentFlags.None, _presentParameters);
            }
        }
Exemplo n.º 8
0
 public void Draw(RenderTarget g)
 {
     g.DrawRectangle(Bounds, Resources.SCBRUSH_RED, 2f);
     foreach(BaseEntity ent in Objects)
     {
         g.DrawText(Level.ToString(), Resources.TEXT_FORMAT, ent.Hitbox, Resources.SCBRUSH_RED);
     }
     for (int i = 0; i < Nodes.Length; i++)
     {
         if (Nodes[i] != null)
         {
             Nodes[i].Draw(g);
         }
     }
 }
Exemplo n.º 9
0
            //---------------------------------------------------------------------------------------------------------
            /// <summary>
            /// Рисование текста
            /// </summary>
            //---------------------------------------------------------------------------------------------------------
            public override void Draw()
            {
                Direct2D.RenderTarget render_target = XDirect2DManager.D2DRenderTarget;

                if (mIsFilled)
                {
                    render_target.FillRectangle(mBoundsRect.ToRawRectF(), mFill.D2DBrush);
                }

                render_target.DrawText(mText, mD2DTextFormat, mBoundsRect.ToRawRectF(), mStroke.Brush.D2DBrush);

                if (mIsStroked)
                {
                    render_target.DrawRectangle(mBoundsRect.ToRawRectF(), mStroke.Brush.D2DBrush, mStroke.Thickness, mStroke.mD2DStrokeStyle);
                }
            }
Exemplo n.º 10
0
        internal static async Task Render(CompositionEngine compositionEngine, RenderTarget renderTarget, FrameworkElement rootElement, TextBlock textBlock)
        {
            using (var textFormat = new TextFormat(
                compositionEngine.DWriteFactory,
                textBlock.FontFamily.Source,
                (float)textBlock.FontSize)
            {
                TextAlignment = textBlock.TextAlignment.ToSharpDX(),
                ParagraphAlignment = ParagraphAlignment.Near
            })
            {
                var rect = textBlock.GetBoundingRect(rootElement).ToSharpDX();
                // For some reason we need a bigger rect for the TextBlock rendering to fit in the same boundaries
                rect.Right++;
                rect.Bottom++;

                using (
                    var textBrush = await textBlock.Foreground.ToSharpDX(renderTarget, rect))
                {
                    if (textBrush == null)
                    {
                        return;
                    }

                    var layer = textBlock.CreateAndPushLayerIfNecessary(renderTarget, rootElement);

                    // You can render the bounding rectangle to debug composition
                    //renderTarget.DrawRectangle(
                    //    rect,
                    //    textBrush);
                    renderTarget.DrawText(
                        textBlock.Text,
                        textFormat,
                        rect,
                        textBrush);

                    if (layer != null)
                    {
                        renderTarget.PopLayer();
                        layer.Dispose();
                    }
                    //}
                }
            }
        }
        internal static async Task Render(CompositionEngine compositionEngine, RenderTarget renderTarget, FrameworkElement rootElement, TextBlock textBlock)
        {
            using (var textFormat = new TextFormat(
                compositionEngine.DWriteFactory,
                textBlock.FontFamily.Source,
                (float)textBlock.FontSize)
            {
                TextAlignment = textBlock.TextAlignment.ToSharpDX(),
                ParagraphAlignment = ParagraphAlignment.Near
            })
            {
                var rect = textBlock.GetBoundingRect(rootElement).ToSharpDX();
                // For some reason we need a bigger rect for the TextBlock rendering to fit in the same boundaries
                rect.Right++;
                rect.Bottom++;

                using (
                    var textBrush = await textBlock.Foreground.ToSharpDX(renderTarget, rect))
                {
                    //using(var layer = new Layer(renderTarget))
                    //{
                    //var layerParameters = new LayerParameters();
                    //layerParameters.ContentBounds = rect;
                    //renderTarget.PushLayer(ref layerParameters, layer);

                    // You can render the bounding rectangle to debug composition
                    //renderTarget.DrawRectangle(
                    //    rect,
                    //    textBrush);
                    renderTarget.DrawText(
                        textBlock.Text,
                        textFormat,
                        rect,
                        textBrush);

                    //renderTarget.PopLayer();
                    //}
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Draws the given text on the screen.
        /// </summary>
        /// <param name="textToDraw">The text to draw.</param>
        /// <param name="textFormat">The TextFormat to be used.</param>
        /// <param name="targetRectangle">The target rectangle.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="drawOptions">Some draw options to be passed to Direct2D.</param>
        /// <param name="measuringMode">Sets the measuring mode to be passed to Direct2D.</param>
        public void DrawText(
            string textToDraw, TextFormatResource textFormat, RectangleF targetRectangle, BrushResource brush,
            DrawTextOptions drawOptions = DrawTextOptions.None,
            MeasuringMode measuringMode = MeasuringMode.Natural)
        {
            if (m_renderTarget == null)
            {
                return;
            }

            textToDraw.EnsureNotNull(nameof(textToDraw));
            targetRectangle.EnsureNotEmpty(nameof(targetRectangle));
            brush.EnsureNotNull(nameof(brush));

            D2D.DrawTextOptions drawOptionsD2D   = (D2D.DrawTextOptions)drawOptions;
            D2D.MeasuringMode   measuringModeD2D = (D2D.MeasuringMode)measuringMode;

            m_renderTarget.DrawText(
                textToDraw,
                textFormat.GetTextFormat(m_device),
                targetRectangle.ToDXRectangle(),
                brush.GetBrush(m_device),
                drawOptionsD2D);
        }
Exemplo n.º 13
0
        public void Render(RenderTarget target)
        {
            InitializeGlobalResources(target);

            foreach (var thing in _things)
                thing.Render(target);

            _skeleton.Render(target);

            target.Transform = Matrix3x2.Identity;
            target.DrawText("Player: " + Player, TextFormat, new RectangleF(5, 5, 800, 70), SceneColorBrush);
            target.DrawText("Score: " + Score, TextFormat, new RectangleF(5, 80, 800, 70), SceneColorBrush);

            if (Player != "")
                target.DrawText((60d - (DateTime.Now - PlayerStartTime).TotalSeconds).ToString("00.0"), TextFormat, new RectangleF((float)(Width / 2) - 20, 15, 800, 70), SceneColorBrush);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Draw text
 /// </summary>
 /// <param name="text">Text</param>
 /// <param name="x">Left position</param>
 /// <param name="y">Top position</param>
 /// <param name="width">Max width</param>
 /// <param name="height">Max heigh</param>
 public void DrawString(string text, int x, int y, int width = 800, int height = 600)
 {
     _direct2DRenderTarget.DrawText(text, _directWriteTextFormat, new RawRectangleF(x, y, width, height), _directWriteFontColor);
 }
Exemplo n.º 15
0
 public static void DrawText(this SharpDX.Direct2D1.RenderTarget target, string text, ID2DBrush brush, D2DFont font, float destX, float destY)
 {
     target.DrawText(text, brush, font, destX, destY, float.MaxValue, float.MaxValue);
 }
Exemplo n.º 16
0
        public static void DrawText(this SharpDX.Direct2D1.RenderTarget target, string text, ID2DBrush brush, D2DFont font, float destX, float destY, float destWidth, float destHeight)
        {
            var destRect = new RawRectangleF(destX, destY, destX + destWidth, destY + destHeight);

            target.DrawText(text, font.NativeFont, destRect, brush.NativeBrush);
        }