SetDrawingEffect() 공개 메소드

Sets the application-defined drawing effect.
An SharpDX.Direct2D1.Brush, such as a color or gradient brush, can be set as a drawing effect if you are using the RenderTarget.DrawTextLayout(System.Drawing.PointF,SharpDX.DirectWrite.TextLayout,SharpDX.Direct2D1.Brush,SharpDX.Direct2D1.DrawTextOptions) to draw text and that brush will be used to draw the specified range of text. This drawing effect is associated with the specified range and will be passed back to the application by way of the callback when the range is drawn at drawing time.
public SetDrawingEffect ( SharpDX drawingEffect, SharpDX textRange ) : void
drawingEffect SharpDX Application-defined drawing effects that apply to the range. This data object will be passed back to the application's drawing callbacks for final rendering.
textRange SharpDX The text range to which this change applies.
리턴 void
예제 #1
0
 private void DrawText(string text, float locX, float locY, D2D1.Brush fg, D2D1.Brush bg, string font = "", float size = 0)
 {
     using (TextFormat = new DW.TextFormat(DWFactory, font == "" ? Config.CooldownBarTextFont : font, size == 0 ? Config.CooldownBarTextFontSize : size)) {
         TextFormat.WordWrapping = DW.WordWrapping.NoWrap;
         using (DW.TextLayout TextLayout = new DW.TextLayout(DWFactory, text, TextFormat, 500, 500)) {
             using (TextBrush = new TextBrush(fg, bg)) {
                 using (TextRenderer = new TextRenderer(Render, TextBrush)) {
                     TextLayout.SetDrawingEffect(TextBrush, new DW.TextRange(10, 20));
                     TextLayout.Draw(TextRenderer, locX, locY);
                 }
             }
         }
     }
 }
예제 #2
0
 protected void UpdateInputTextLayout()
 {
     if (InputText?.IsEmpty() ?? true)
     {
         InputTextLayout = null;
     }
     else
     {
         var textLayout = new DW.TextLayout(DwFactory, InputText, InputTextFormat, 0, 0);
         if (HintText != null)
         {
             var len = Math.Min(InputText.Length, HintText.Length);
             for (var i = 0; i < len; i++)
             {
                 var brush = InputText[i] == HintText[i] ? CorrectColorBrush : WrongColorBrush;
                 textLayout.SetDrawingEffect(brush, new DW.TextRange(i, 1));
             }
         }
         InputTextLayout = textLayout;
     }
 }
        /// <summary>
        /// Inits the font family names from DirectWrite
        /// </summary>
        private void InitTextFormatLayout()
        {
            FontFamilyName = "Gabriola";
            FontSize = 72;
            FontText = "Client Drawing Effect Example!";

            // Initialize a TextFormat
            CurrentTextFormat = new TextFormat(FactoryDWrite, FontFamilyName, FontSize) { TextAlignment = TextAlignment.Center, ParagraphAlignment = ParagraphAlignment.Center };

            CurrentTextLayout = new TextLayout(FactoryDWrite, FontText, CurrentTextFormat, ClientRectangle.Width, ClientRectangle.Height);

            RedDrawingeffect = new ColorDrawingEffect(new Color4(1, 1, 0, 0));
            BlueDrawingEffect = new ColorDrawingEffect(new Color4(1, 0, 0, 1));
            GreenDrawingEffect = new ColorDrawingEffect(new Color4(1, 0, 1, 0));

            CurrentTextLayout.SetDrawingEffect(RedDrawingeffect, new TextRange(0, 14));
            CurrentTextLayout.SetDrawingEffect(BlueDrawingEffect, new TextRange(14, 7));
            CurrentTextLayout.SetDrawingEffect(GreenDrawingEffect, new TextRange(21, 8));

            // Set a stylistic typography
            var typo = new Typography(FactoryDWrite);
            typo.AddFontFeature(new FontFeature(FontFeatureTag.StylisticSet7, 1));
            CurrentTextLayout.SetTypography(typo, CurrentTextRange);
            typo.Release();
        }
예제 #4
0
        static void Main(string[] args)
        {
            mainForm = new RenderForm("Advanced Text rendering demo");

            d2dFactory = new D2DFactory();
            dwFactory = new DWriteFactory(SharpDX.DirectWrite.FactoryType.Shared);
            
            textRenderer = new CustomColorRenderer();

            CreateResources();

            var bgcolor = new Color4(0.1f,0.1f,0.1f,1.0f);

            //This is the offset where we start our text layout
            Vector2 offset = new Vector2(202.0f,250.0f);

            textFormat = new TextFormat(dwFactory, "Arial", FontWeight.Regular, FontStyle.Normal, 16.0f);
            textLayout = new TextLayout(dwFactory, introText, textFormat, 300.0f, 200.0f);

            //Apply various modifications to text
            textLayout.SetUnderline(true, new TextRange(0, 5));
            textLayout.SetDrawingEffect(greenBrush, new TextRange(10, 20));
            textLayout.SetFontSize(24.0f, new TextRange(6, 4));
            textLayout.SetFontFamilyName("Comic Sans MS", new TextRange(11,7));

            //Measure full layout
            var textSize = textLayout.Metrics;
            fullTextBackground = new RectangleF(textSize.Left + offset.X, textSize.Top + offset.Y, textSize.Width, textSize.Height);

            //Measure text to apply background to
            var metrics = textLayout.HitTestTextRange(53, 4, 0.0f, 0.0f)[0];
            textRegionRect = new RectangleF(metrics.Left + offset.X, metrics.Top + offset.Y, metrics.Width, metrics.Height);

            //Assign render target and brush to our custom renderer
            textRenderer.AssignResources(renderTarget, defaultBrush);

            RenderLoop.Run(mainForm, () =>
            {
                renderTarget.BeginDraw();
                renderTarget.Clear(bgcolor);

                renderTarget.FillRectangle(fullTextBackground, backgroundBrush);

                renderTarget.FillRectangle(textRegionRect, redBrush);

                textLayout.Draw(textRenderer, offset.X, offset.Y);

                try
                {
                    renderTarget.EndDraw();
                }
                catch
                {
                    CreateResources();
                }
            });

            d2dFactory.Dispose();
            dwFactory.Dispose();
            renderTarget.Dispose();
        }