Ejemplo n.º 1
0
        public static CachedStringRender GetCachedStringRender(string text,
                                                               BitmapFont font,
                                                               Rectangle destinationRectangle,
                                                               Color color,
                                                               bool wrap,
                                                               bool stroke,
                                                               int strokeDistance = 1,
                                                               HorizontalAlignment horizontalAlignment = HorizontalAlignment.Left,
                                                               VerticalAlignment verticalAlignment     = VerticalAlignment.Middle)
        {
            var checkCsr = new CachedStringRender(text, font, destinationRectangle, color, wrap, stroke, strokeDistance, horizontalAlignment, verticalAlignment);

            int csrHash = checkCsr.GetHashCode();

            bool containsCachedCsr = _cachedStringRenders.ContainsKey(csrHash);

            if (containsCachedCsr && _cachedStringRenders.TryGetValue(csrHash, out var existingCsr))
            {
                checkCsr.Dispose();
                return(existingCsr);
            }

            if (!containsCachedCsr)
            {
                _cachedStringRenders.TryAdd(csrHash, checkCsr);
            }

            GameService.Graphics.QueueMainThreadRender(checkCsr.InitRender);

            return(checkCsr);
        }
Ejemplo n.º 2
0
        public override void RecalculateLayout()
        {
            int lblRegionWidth  = _size.X;
            int lblRegionHeight = _size.Y;

            if (_autoSizeWidth || _autoSizeHeight)
            {
                var textSize = GetTextDimensions();

                if (_autoSizeWidth)
                {
                    lblRegionWidth = (int)Math.Ceiling(textSize.Width + (_showShadow || _strokeText ? 1 : 0));
                }

                if (_autoSizeHeight)
                {
                    lblRegionHeight = (int)Math.Ceiling(textSize.Height + (_showShadow || _strokeText ? 1 : 0));
                }
            }

            LabelRegion = new Point(lblRegionWidth, lblRegionHeight);

            if (_cacheLabel)
            {
                _labelRender = CachedStringRender.GetCachedStringRender(_text,
                                                                        _font,
                                                                        new Rectangle(Point.Zero, LabelRegion),
                                                                        _textColor,
                                                                        false,
                                                                        _strokeText,
                                                                        1,
                                                                        _horizontalAlignment,
                                                                        _verticalAlignment);
            }
        }
Ejemplo n.º 3
0
 protected bool Equals(CachedStringRender other)
 {
     return(string.Equals(this.Text, other.Text) && Equals(this.Font, other.Font) && this.DestinationRectangle.Equals(other.DestinationRectangle) && this.Color.Equals(other.Color) && this.Wrap == other.Wrap && this.Stroke == other.Stroke && this.StrokeDistance == other.StrokeDistance && this.HorizontalAlignment == other.HorizontalAlignment && this.VerticalAlignment == other.VerticalAlignment);
 }