Exemplo n.º 1
0
            private void CreateLayout()
            {
                if (layout != null)
                {
                    layout.Dispose();
                }

                layout = PangoUtil.CreateLayout(this, null);
                if (use_markup)
                {
                    layout.Markup = brokentext != null ? brokentext : (text ?? string.Empty);
                }
                else
                {
                    layout.Text = brokentext != null ? brokentext : (text ?? string.Empty);
                }
                layout.Trimming = wrapMode;
                if (width >= 0)
                {
                    layout.Width = width;
                }
                else
                {
                    layout.Width = -1;
                }
                QueueForReallocate();
            }
Exemplo n.º 2
0
        public TextLayout GetLayout()
        {
            if (mAlignmentChanged)
            {
                if (mLayout != null)
                {
                    mLayout.TextAlignment      = mHorizontalAlignment;
                    mLayout.ParagraphAlignment = mVerticalAlignment;
                }
                mAlignmentChanged = false;
            }

            if (mChanged == false)
            {
                return(mLayout);
            }

            var font = Fonts.Cache[mFontFamily, mFontSize, mWeight];

            if (mLayout != null)
            {
                mLayout.Dispose();
            }
            mLayout = new TextLayout(mFactory, mText, font, mSize.Width,
                                     mSize.Height)
            {
                TextAlignment      = mHorizontalAlignment,
                ParagraphAlignment = mVerticalAlignment,
            };

            mChanged          = false;
            mAlignmentChanged = false;
            return(mLayout);
        }
Exemplo n.º 3
0
 public override void UnloadContent()
 {
     if (textLayout != null)
     {
         textLayout.Dispose();
     }
 }
Exemplo n.º 4
0
        public void DrawValueInCircle()
        {
            float   offset = calculateOffset(planet.population);
            Vector2 temp   = new Vector2(offset, 12.0f);

            position = planet.position - temp;
            textLayout.Dispose();
            textLayout = new TextLayout(planet.game.factoryWrite, planet.population.ToString(), textFormat, 36.0f, 24.0f);
            planet.game.target.DrawTextLayout(position, textLayout, brush);
            //planet.game.target.DrawRectangle(new RectangleF(position.X, position.Y, 36.0f, 24.0f), brush);
        }
Exemplo n.º 5
0
        /// <summary>
        ///     Do not buffer text if you draw i.e. FPS. Use buffer for player names, rank....
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="font">The font.</param>
        /// <param name="brush">The brush.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <param name="bufferText">if set to <c>true</c> [buffer text].</param>
        public void DrawText(string text, int font, int brush, int x, int y, bool bufferText = true)
        {
            if (bufferText)
            {
                var bufferPos = -1;

                for (var i = 0; i < _layoutContainer.Count; i++)
                {
                    if ((_layoutContainer[i].Text.Length != text.Length) || (_layoutContainer[i].Text != text))
                    {
                        continue;
                    }
                    bufferPos = i;
                    break;
                }

                if (bufferPos == -1)
                {
                    _layoutContainer.Add(new TextLayoutBuffer(text,
                                                              new TextLayout(_fontFactory, text, _fontContainer[font], float.MaxValue, float.MaxValue)));
                    bufferPos = _layoutContainer.Count - 1;
                }

                _device.DrawTextLayout(new RawVector2(x, y), _layoutContainer[bufferPos].TextLayout,
                                       _brushContainer[brush], DrawTextOptions.NoSnap);
            }
            else
            {
                var layout = new TextLayout(_fontFactory, text, _fontContainer[font], float.MaxValue, float.MaxValue);
                _device.DrawTextLayout(new RawVector2(x, y), layout, _brushContainer[brush]);
                layout.Dispose();
            }
        }
Exemplo n.º 6
0
 public void Draw()
 {
     brush      = ship.game.brushes[ship.team];
     nose       = ship.position + 15 * ship.direction;
     middle     = ship.position;
     firstWing  = ship.position - 7 * ship.direction - 7 * normal;
     secondWing = ship.position - 7 * ship.direction + 7 * normal;
     ship.game.target.DrawLine(nose, firstWing, brush);
     ship.game.target.DrawLine(nose, secondWing, brush);
     ship.game.target.DrawLine(middle, firstWing, brush);
     ship.game.target.DrawLine(middle, secondWing, brush);
     // text
     textLayout.Dispose();
     textLayout = new TextLayout(ship.game.factoryWrite, ship.population.ToString(), textFormat, 36.0f, 24.0f);
     ship.game.target.DrawTextLayout(ship.position + new Vector2(5.0f, -20.0f), textLayout, brush);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Do not buffer text if you draw i.e. FPS. Use buffer for player names, rank....
        /// </summary>
        public void DrawText(string text, int font, int brush, int x, int y, bool bufferText = true)
        {
            if (bufferText)
            {
                int bufferPos = -1;

                for (int i = 0; i < this.LayoutContainer.Count; i++)
                {
                    if (this.LayoutContainer[i].Text.Length == text.Length && this.LayoutContainer[i].Text == text)
                    {
                        bufferPos = i;
                        break;
                    }
                }

                if (bufferPos == -1)
                {
                    this.LayoutContainer.Add(new LayoutBuffer(text, new TextLayout(this.fontFactory, text, this.FontContainer[font], float.MaxValue, float.MaxValue)));
                    bufferPos = this.LayoutContainer.Count - 1;
                }

                device.DrawTextLayout(new Vector2(x, y), this.LayoutContainer[bufferPos].TextLayout, this.BrushContainer[brush], DrawTextOptions.NoSnap);
            }
            else
            {
                TextLayout layout = new TextLayout(this.fontFactory, text, this.FontContainer[font], float.MaxValue, float.MaxValue);
                device.DrawTextLayout(new Vector2(x, y), layout, this.BrushContainer[brush]);
                layout.Dispose();
            }
        }
Exemplo n.º 8
0
        protected override void DrawCurrentTimeString(string s, float x, float y)
        {
            var tl = new TextLayout(_fdw, s, formatNear, Width, Height);

            _rt.DrawTextLayout(new Vector2(x - Radius + Width / 2, 0), tl, brushRed, DrawTextOptions.None);
            tl.Dispose();
        }
Exemplo n.º 9
0
        protected override void DrawClockString(string s, float x, float y)
        {
            var tl = new TextLayout(_fdw, s, formatCenter, Width, Height);

            _rt.DrawTextLayout(new Vector2(Width / 2 - x, Height / 2 - y), tl, brush, DrawTextOptions.None);
            tl.Dispose();
        }
Exemplo n.º 10
0
 protected override void OnCleanUpDeviceIndependentResources()
 {
     base.OnCleanUpDeviceIndependentResources();
     _textAnalyzer.Dispose();
     _textLayout.Dispose();
     _textFormat.Dispose();
 }
Exemplo n.º 11
0
 public override void Dispose()
 {
     Click       = null;
     TextChanged = null;
     text?.Dispose();
     base.Dispose();
 }
Exemplo n.º 12
0
Arquivo: Base.cs Projeto: TETYYS/socon
            public static Tuple <TextLayout, TextFormat> RebaseText(TextLayout Tl, TextFormat Tf, string Text)
            {
                Tf.Dispose();
                var tfNew = new TextFormat(
                    Base.DWFactory,
                    Tl.FontFamilyName,
                    Tl.FontCollection,
                    Tl.FontWeight,
                    Tl.FontStyle,
                    Tl.FontStretch,
                    Tl.FontSize,
                    Tl.LocaleName
                    )
                {
                    TextAlignment      = Tl.TextAlignment,
                    ParagraphAlignment = Tl.ParagraphAlignment,
                    FlowDirection      = Tl.FlowDirection,
                    IncrementalTabStop = Tl.IncrementalTabStop,
                    ReadingDirection   = Tl.ReadingDirection,
                    WordWrapping       = Tl.WordWrapping
                };

                var tlNew = new TextLayout(
                    Base.DWFactory,
                    Text,
                    tfNew,
                    Tl.MaxWidth,
                    Tl.MaxHeight);

                Tl.Dispose();
                return(Tuple.Create(tlNew, tfNew));
            }
Exemplo n.º 13
0
        protected override void Dispose(bool disposing)
        {
            layout.Dispose();
            informLayout.Dispose();

            base.Dispose(disposing);
        }
Exemplo n.º 14
0
 public void Dispose()
 {
     try
     {
         textLayout.Dispose();
     }
     catch { }
 }
Exemplo n.º 15
0
        public void DrawText(float x, float y, string text, Color color)
        {
            this.brush.Color = new RawColor4(color.R, color.G, color.B, color.A / 255.0f);
            var layout = new TextLayout(this.fontFactory, text, this.font, float.MaxValue, float.MaxValue);

            this.device.DrawTextLayout(new RawVector2(x, y), layout, this.brush);
            layout.Dispose();
        }
Exemplo n.º 16
0
    public static float MeasureStringWidth(string str, TextFormat format)
    {
        TextLayout l = new TextLayout(defaultWriteFactory, str, format, float.MaxValue, float.MaxValue);
        float      w = l.Metrics.Width;

        l.Dispose();
        return(w);
    }
Exemplo n.º 17
0
    public static float MeasureStringHeight(string str, TextFormat format)
    {
        TextLayout l = new TextLayout(defaultWriteFactory, str, format, float.MaxValue, float.MaxValue);
        float      h = l.Metrics.Height;

        l.Dispose();
        return(h);
    }
Exemplo n.º 18
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         layout.Dispose();
     }
     base.Dispose(disposing);
 }
        public static void DrawSimpleTip(this MusicCanvasControl canvas, string text, RawVector2?pos = new RawVector2?())
        {
            if (MusicCanvasControl.EnableControlTip && canvas.IsAltKeyPressed())
            {
                Trimming     trimming;
                InlineObject obj2;
                if (!pos.HasValue)
                {
                    Point point = canvas.PointToClient(Control.MousePosition);
                    pos = new RawVector2((float)(point.X + 0x18), (float)(point.Y - 0x18));
                }
                RenderTarget renderTarget = canvas.RenderTarget2D;
                SharpDX.DirectWrite.Factory factoryDWrite = canvas.FactoryDWrite;
                TextFormat textFormat = new TextFormat(factoryDWrite, "微软雅黑", FontWeight.Bold, SharpDX.DirectWrite.FontStyle.Normal, FontStretch.Normal, 12f);
                textFormat.GetTrimming(out trimming, out obj2);
                trimming.Granularity = TrimmingGranularity.Word;
                textFormat.SetTrimming(trimming, obj2);
                textFormat.TextAlignment      = TextAlignment.Center;
                textFormat.ParagraphAlignment = ParagraphAlignment.Center;
                TextLayout layout = new TextLayout(factoryDWrite, text, textFormat, 1920f, 1080f);
                textFormat.TextAlignment      = TextAlignment.Leading;
                textFormat.ParagraphAlignment = ParagraphAlignment.Far;
                TextLayout textLayout = new TextLayout(factoryDWrite, text, textFormat, layout.Metrics.Width, layout.Metrics.Height);
                layout.Dispose();
                RawVector2 origin = new RawVector2(pos.Value.X, pos.Value.Y);
                switch (textFormat.TextAlignment)
                {
                case TextAlignment.Trailing:
                    origin.X = pos.Value.X - textLayout.Metrics.Width;
                    break;

                case TextAlignment.Center:
                case TextAlignment.Justified:
                    origin.X = pos.Value.X - (textLayout.Metrics.Width / 2f);
                    break;
                }
                switch (textFormat.ParagraphAlignment)
                {
                case ParagraphAlignment.Far:
                    origin.Y = pos.Value.Y - textLayout.Metrics.Height;
                    break;

                case ParagraphAlignment.Center:
                    origin.Y = pos.Value.Y - (textLayout.Metrics.Height / 2f);
                    break;
                }
                origin.X += 4f;
                origin.Y += 4f;
                textFormat.Dispose();
                RawRectangleF rectF = new RawRectangleF(pos.Value.X, pos.Value.Y - textLayout.Metrics.Height, (pos.Value.X + textLayout.Metrics.Width) + 8f, pos.Value.Y + 8f);
                canvas.FillRoundedRectangle(rectF, 4f, Color.FromArgb(150, 0x1f, 0x1f, 0x22));
                canvas.DrawRoundedRectangle(rectF, 4f, Color.FromArgb(150, 0xe9, 0xe9, 0xe9), 2f);
                SolidColorBrush defaultForegroundBrush = new SolidColorBrush(renderTarget, Color.FromArgb(250, Color.DarkGray).ToRawColor4(1f));
                renderTarget.DrawTextLayout(origin, textLayout, defaultForegroundBrush, DrawTextOptions.Clip);
                defaultForegroundBrush.Dispose();
                textLayout.Dispose();
            }
        }
Exemplo n.º 20
0
 public void Dispose()
 {
     brush.Dispose();
     brushRed.Dispose();
     _tyNear.Dispose();
     _tyCenter.Dispose();
     formatNear.Dispose();
     formatCenter.Dispose();
 }
Exemplo n.º 21
0
    public static RectangleF StringBoundingBox(string str, TextFormat format)
    {
        TextLayout l = new TextLayout(defaultWriteFactory, str, format, float.MaxValue, float.MaxValue);
        float      h = l.Metrics.Height;
        float      w = l.Metrics.Width;

        l.Dispose();
        return(new RectangleF(0, 0, w, h));
    }
Exemplo n.º 22
0
 public override void Dispose()
 {
     if (TextLayout != null)
     {
         TextLayout.Dispose();
     }
     TextLayout = null;
     base.Dispose();
 }
 protected override void OnCleanUpDeviceIndependentResources()
 {
     base.OnCleanUpDeviceIndependentResources();
     _textFormat.Dispose();
     _textLayout.Dispose();
     _blueColorDrawingEffect.Dispose();
     _redColorDrawingEffect.Dispose();
     _greenColorDrawingEffect.Dispose();
 }
Exemplo n.º 24
0
    public static System.Drawing.SizeF MeasureString(string str, TextFormat format)
    {
        TextLayout l = new TextLayout(defaultWriteFactory, str, format, float.MaxValue, float.MaxValue);
        float      h = l.Metrics.Height;
        float      w = l.Metrics.Width;

        l.Dispose();
        return(new System.Drawing.SizeF(w, h));
    }
Exemplo n.º 25
0
        private void DrawTextCenter(int X, int Y, int W, int H, string text, Color color)
        {
            solidColorBrush.Color = color;
            TextLayout layout = new TextLayout(fontFactory, text, fontSmall, W, H);

            layout.TextAlignment = TextAlignment.Center;
            device.DrawTextLayout(new Vector2(X, Y), layout, solidColorBrush);
            layout.Dispose();
        }
Exemplo n.º 26
0
        internal protected override void OptionsChanged()
        {
            var layout = new TextLayout(Editor);

            layout.Font = Editor.Options.Font;
            layout.Text = string.Format("0{0:X}", Data.Length) + "_";
//			int height;
            width = layout.GetSize().Width;
            layout.Dispose();
        }
Exemplo n.º 27
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (layout != null)
            {
                layout.Dispose();
                layout = null;
            }
        }
Exemplo n.º 28
0
        internal protected override void OptionsChanged()
        {
            var layout = new TextLayout(Editor);

            layout.Font = Editor.Options.Font;
            layout.Text = ".";
//			int height;
            charWidth = layout.GetSize().Width;
            layout.Dispose();
        }
Exemplo n.º 29
0
        public void DrawText(string text, float x, float y, float fontSize, Direct2DFont font, Direct2DBrush brush)
        {
            var layout = new TextLayout(_fontFactory, text, font, float.MaxValue, float.MaxValue);

            layout.SetFontSize(fontSize, new TextRange(0, text.Length));

            _device.DrawTextLayout(new RawVector2(x, y), layout, brush, DrawTextOptions.NoSnap);

            layout.Dispose();
        }
 public void Dispose()
 {
     Utilities.Dispose(ref _Factory2D);
     Utilities.Dispose(ref _FactoryDWrite);
     Utilities.Dispose(ref _RenderTarget2D);
     Utilities.Dispose(ref _SceneColorBrush);
     Utilities.Dispose(ref _TextFormat);
     Utilities.Dispose(ref _TextLayout);
     _TextLayout?.Dispose();
 }
Exemplo n.º 31
0
        /// <summary>
        /// Measures the text.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <returns>The text size.</returns>
        public OxySize MeasureText(string text, string fontFamily, double fontSize, double fontWeight)
        {
            if (string.IsNullOrWhiteSpace(fontFamily))
            {
                fontFamily = "Arial";
            }

            if (text == null)
            {
                text = string.Empty;
            }

            var format = new TextFormat(this.dwtFactory, fontFamily, GetFontWeight(fontWeight), FontStyle.Normal, FontStretch.Normal, (float)fontSize);

            var layout = new TextLayout(this.dwtFactory, text, format, 1000f, 1000f);
            var res = new OxySize(layout.Metrics.Width, layout.Metrics.Height);

            format.Dispose();
            layout.Dispose();

            return res;
        }