Ejemplo n.º 1
0
        private void uploadBitmapToOpenGl()
        {
            _texture = createTexture();
            IBitmap bitmap = _bitmapPool.Acquire(_draw.BitmapWidth, _draw.BitmapHeight);

            try
            {
                IBitmapTextDraw textDraw = bitmap.GetTextDraw();
                using (var context = textDraw.CreateContext())
                {
                    textDraw.DrawText(_draw.Text, _draw.Config, _draw.TextSize, _draw.BaseSize, _draw.MaxWidth, (int)_draw.HeightF, 0f);
                    drawCaret(_draw.OriginalText, _draw.TextSize, _draw.HeightF, _draw.BaseSize, textDraw, _draw.Config, _draw.MaxWidth);
                }
                // Upload the Bitmap to OpenGL.
                // Do this only when text changes.
                bitmap.LoadTexture(_texture);
            }
            catch (InvalidOperationException e)
            {
                Debug.WriteLine(e.ToString());
                throw;
            }
            finally
            {
                releaseBitmap(bitmap);
            }
        }
Ejemplo n.º 2
0
        private void drawToBitmap()
        {
            string originalText = _text ?? "";
            string text         = _text;

            var   config           = AGSTextConfig.ScaleConfig(_config, TextResolutionFactorX);
            int   maxWidth         = _maxWidth == int.MaxValue ? _maxWidth : _maxWidth * TextResolutionFactorX;
            SizeF originalTextSize = config.Font.MeasureString(text, _cropText ? int.MaxValue : maxWidth);
            SizeF textSize         = originalTextSize;

            if (_cropText && textSize.Width > maxWidth)
            {
                textSize = cropText(maxWidth, config, ref text);
            }

            float widthOffset  = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetX));
            float heightOffset = Math.Max(config.OutlineWidth, Math.Abs(config.ShadowOffsetY));
            float widthF       = textSize.Width + widthOffset + config.PaddingLeft + config.PaddingRight;
            float heightF      = textSize.Height + heightOffset + config.PaddingTop + config.PaddingBottom;
            SizeF baseSize     = new SizeF(_baseSize.Width == EmptySize.Width ? widthF : _baseSize.Width * TextResolutionFactorX,
                                           _baseSize.Height == EmptySize.Height ? heightF : _baseSize.Height * TextResolutionFactorY);

            Width  = (widthF / GLText.TextResolutionFactorX);
            Height = (heightF / GLText.TextResolutionFactorY);
            int     bitmapWidth  = MathUtils.GetNextPowerOf2(Math.Max((int)widthF + 1, (int)baseSize.Width + 1));
            int     bitmapHeight = MathUtils.GetNextPowerOf2(Math.Max((int)heightF + 1, (int)baseSize.Height + 1));
            IBitmap bitmap       = _bitmap;

            if (bitmap == null || bitmap.Width != bitmapWidth || bitmap.Height != bitmapHeight)
            {
                if (bitmap != null)
                {
                    _bitmapPool.Release(bitmap);
                }
                _bitmap = _bitmapPool.Acquire(bitmapWidth, bitmapHeight);
                bitmap  = _bitmap;
            }
            IBitmapTextDraw textDraw = bitmap.GetTextDraw();

            using (var context = textDraw.CreateContext())
            {
                textDraw.DrawText(text, config, textSize, baseSize, maxWidth, (int)heightF, 0f);
                drawCaret(originalText, textSize, heightF, baseSize, textDraw, config, maxWidth);
            }

            _renderChanged = true;
        }