コード例 #1
0
        private PointF getTextLocation(string text, ISayConfig config, float x, float y)
        {
            SizeF labelSize = (config.LabelSize.Width - config.TextConfig.PaddingLeft - config.TextConfig.PaddingRight,
                               config.LabelSize.Height - config.TextConfig.PaddingTop - config.TextConfig.PaddingBottom);

            AGS.API.SizeF size          = config.TextConfig.GetTextSize(text, labelSize);
            float         width         = size.Width + config.TextConfig.PaddingLeft + config.TextConfig.PaddingRight;
            float         height        = size.Height + config.TextConfig.PaddingTop + config.TextConfig.PaddingBottom;
            float         horizontalGap = (config.LabelSize.Width - width) / 2f;

            y = MathUtils.Clamp(y, 0f, Math.Min(_settings.VirtualResolution.Height,
                                                _settings.VirtualResolution.Height - height));
            y -= config.PortraitConfig == null ? 0f : config.PortraitConfig.TextOffset.Y;
            y  = MathUtils.Clamp(y, 0f, Math.Min(_settings.VirtualResolution.Height,
                                                 _settings.VirtualResolution.Height - height));
            y += config.TextOffset.Y;

            float rightPortraitX = _settings.VirtualResolution.Width - 100;

            x += config.PortraitConfig == null?getTextXOffset(config.LabelSize.Width, config.TextConfig.Alignment) :
                     (x > rightPortraitX ? -config.PortraitConfig.TextOffset.X - getTextXOffsetPortrait(horizontalGap, config.TextConfig.Alignment)
                                           : config.PortraitConfig.TextOffset.X - getTextXOffsetPortrait(horizontalGap, config.TextConfig.Alignment));

            float maxX = y > _settings.VirtualResolution.Height - 100 && x > rightPortraitX?
                         Math.Min(x, _settings.VirtualResolution.Width) : _settings.VirtualResolution.Width;

            x += config.TextOffset.X;
            x  = clampX(x, config.TextConfig.Alignment, horizontalGap, maxX, width);

            return(new PointF(x, y));
        }
コード例 #2
0
        private PointF getTextLocation(string text, ISayConfig config, float x, float y)
        {
            //todo: need to account for alignment
            AGS.API.SizeF size   = config.TextConfig.GetTextSize(text, config.LabelSize);
            float         width  = size.Width + config.TextConfig.PaddingLeft + config.TextConfig.PaddingRight;
            float         height = size.Height + config.TextConfig.PaddingTop + config.TextConfig.PaddingBottom;

            y = MathUtils.Clamp(y, 0f, Math.Min(_settings.VirtualResolution.Height,
                                                _settings.VirtualResolution.Height - height));
            y -= config.PortraitConfig == null ? 0f : config.PortraitConfig.TextOffset.Y;
            y  = MathUtils.Clamp(y, 0f, Math.Min(_settings.VirtualResolution.Height,
                                                 _settings.VirtualResolution.Height - height));
            y += config.TextOffset.Y;

            float rightPortraitX = _settings.VirtualResolution.Width - 100;

            x += config.PortraitConfig == null ? 0f : (x > rightPortraitX ? -config.PortraitConfig.TextOffset.X
                                                       : config.PortraitConfig.TextOffset.X);
            float maxX = y > _settings.VirtualResolution.Height - 100 && x > rightPortraitX?
                         Math.Min(x, _settings.VirtualResolution.Width) : _settings.VirtualResolution.Width;

            x  = MathUtils.Clamp(x, 0f, Math.Max(0f, maxX - width - 10f));
            x += config.TextOffset.X;

            return(new PointF(x, y));
        }
コード例 #3
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
		public void SetProperties(AGS.API.SizeF baseSize, string text = null, ITextConfig config = null, int? maxWidth = null, 
            int caretPosition = 0, bool renderCaret = false, bool? cropText = null)
		{
			bool changeNeeded = 
				(text != null && text != _text)
				|| (config != null && config != _config)
				|| (maxWidth != null && maxWidth.Value != _maxWidth)
				|| !baseSize.Equals(_baseSize)
                || _caretPosition != caretPosition
                || _renderCaret != renderCaret
                || (cropText != null && cropText.Value != _cropText);
			if (!changeNeeded) return;

			_text = text;
            if (config != null && config != _config)
            {
                _config = config;
                _spaceWidth = measureSpace();
            }
			if (maxWidth != null) _maxWidth = maxWidth.Value;
            if (cropText != null) _cropText = cropText.Value;
			_baseSize = baseSize;
            _caretPosition = caretPosition;
            _renderCaret = renderCaret;

			drawToBitmap();
		}
コード例 #4
0
 public AGSSayConfig()
 {
     TextConfig      = new AGSTextConfig(font: AGSGame.Game?.Settings.Defaults.SpeechFont, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, alignment: Alignment.BottomLeft);
     TextDelay       = 70;
     LabelSize       = new AGS.API.SizeF(250f, 200f);
     SkipText        = SkipText.ByTimeAndMouse;
     BackgroundColor = Colors.Transparent;
 }
コード例 #5
0
ファイル: AGSSayConfig.cs プロジェクト: tzachshabtay/MonoAGS
		public AGSSayConfig()
		{
			TextConfig = new AGSTextConfig(font : AGSGameSettings.DefaultSpeechFont, autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, alignment: Alignment.BottomLeft);
			TextDelay = 70;
			LabelSize = new AGS.API.SizeF (250f, 200f);
			SkipText = SkipText.ByTimeAndMouse;
			BackgroundColor = Colors.Transparent;
		}
コード例 #6
0
ファイル: AGSSayConfig.cs プロジェクト: brianjlacy/MonoAGS
 public AGSSayConfig(IGame game)
 {
     //todo: should the factory provide speech config?
     if (game != null)
     {
         TextConfig = game.Factory.Fonts.GetTextConfig(font: game.Settings.Defaults.SpeechFont,
                                                       autoFit: AutoFit.TextShouldWrapAndLabelShouldFitHeight, alignment: Alignment.BottomCenter);
         LabelSize = new AGS.API.SizeF(game.Settings.VirtualResolution.Width * (7f / 10f), game.Settings.VirtualResolution.Height);
     }
     TextDelay       = 70;
     SkipText        = SkipText.ByTimeAndMouse;
     BackgroundColor = Colors.Transparent;
 }
コード例 #7
0
ファイル: GLText.cs プロジェクト: jeancallisti/MonoAGS
        public bool SetProperties(AGS.API.SizeF baseSize, string text = null, ITextConfig config = null, int?maxWidth = null,
                                  PointF?scaleUp = null, PointF?scaleDown  = null, int caretPosition = 0, bool renderCaret = false,
                                  bool cropText  = false, bool measureOnly = false)
        {
            bool configIsDifferent = config != null && !config.Equals(_config);
            bool changeNeeded      =
                (text != null && text != _text) ||
                configIsDifferent ||
                (maxWidth != null && maxWidth.Value != _maxWidth) ||
                !baseSize.Equals(_baseSize) ||
                _caretPosition != caretPosition ||
                _renderCaret != renderCaret ||
                cropText != _cropText ||
                measureOnly != _measureOnly ||
                (scaleUp != null && !scaleUp.Value.Equals(_scaleUp)) ||
                (scaleDown != null && !scaleDown.Value.Equals(_scaleDown));

            if (!changeNeeded)
            {
                return(false);
            }

            _text = text;
            if (configIsDifferent)
            {
                _config     = AGSTextConfig.Clone(config);
                _spaceWidth = measureSpace();
            }
            if (maxWidth != null)
            {
                _maxWidth = maxWidth.Value;
            }
            _cropText    = cropText;
            _measureOnly = measureOnly;
            if (scaleUp != null)
            {
                _scaleUp = scaleUp.Value;
            }
            if (scaleDown != null)
            {
                _scaleDown = scaleDown.Value;
            }

            _baseSize      = baseSize;
            _caretPosition = caretPosition;
            _renderCaret   = renderCaret;

            prepareBitmapDraw();

            return(true);
        }
コード例 #8
0
ファイル: AGSUIFactory.cs プロジェクト: tzachshabtay/MonoAGS
		public ILabel GetLabel(string id, string text, float width, float height, float x, float y, ITextConfig config = null, bool addToUi = true)
		{
			AGS.API.SizeF baseSize = new AGS.API.SizeF(width, height);			
			TypedParameter idParam = new TypedParameter (typeof(string), id);
			ILabel label = _resolver.Resolve<ILabel>(idParam);
            label.LabelRenderSize = baseSize;
			label.Text = text;
			label.X = x;
			label.Y = y;
			label.Tint =  Colors.Transparent;
			label.TextConfig = config ?? new AGSTextConfig();
			if (addToUi)
				_gameState.UI.Add(label);
			return label;
		}
コード例 #9
0
        public ILabel GetLabel(string id, string text, float width, float height, float x, float y, ITextConfig config = null, bool addToUi = true)
        {
            AGS.API.SizeF  baseSize = new AGS.API.SizeF(width, height);
            TypedParameter idParam  = new TypedParameter(typeof(string), id);
            ILabel         label    = _resolver.Resolve <ILabel>(idParam);

            label.LabelRenderSize = baseSize;
            label.Text            = text;
            label.X          = x;
            label.Y          = y;
            label.Tint       = Colors.Transparent;
            label.TextConfig = config ?? new AGSTextConfig();
            if (addToUi)
            {
                _gameState.UI.Add(label);
            }
            return(label);
        }
コード例 #10
0
        public static float AlignX(this ITextConfig config, float width, AGS.API.SizeF baseSize)
        {
            switch (config.Alignment)
            {
            case Alignment.TopLeft:
            case Alignment.MiddleLeft:
            case Alignment.BottomLeft:
                return(config.PaddingLeft);

            case Alignment.TopCenter:
            case Alignment.MiddleCenter:
            case Alignment.BottomCenter:
                float left  = config.PaddingLeft;
                float right = baseSize.Width - config.PaddingRight;
                return(left + (right - left) / 2f - width / 2f);

            default:
                return(baseSize.Width - width - config.PaddingRight);
            }
        }
コード例 #11
0
        public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset)
        {
            //_height = height; todo: support height
            _text     = text;
            _config   = config;
            _maxWidth = maxWidth;

            TextPaint paint = getPaint(_config.Brush);

            float centerX = xOffset + _config.AlignX(textSize.Width, baseSize);
            float centerY = _config.AlignY(_bitmap.Height, textSize.Height, baseSize);
            float left    = centerX - _config.OutlineWidth / 2f;
            float top     = centerY - _config.OutlineWidth / 2f;
            float right   = left + _config.OutlineWidth;
            float bottom  = top + _config.OutlineWidth;

            var canvas = _canvas;

            if (_config.OutlineWidth > 0f)
            {
                TextPaint         outlinePaint  = getPaint(_config.OutlineBrush);
                AndroidTextLayout outlineLayout = new AndroidTextLayout(outlinePaint);
                drawString(canvas, outlineLayout, left, top);
                drawString(canvas, outlineLayout, centerX, top);
                drawString(canvas, outlineLayout, right, top);

                drawString(canvas, outlineLayout, left, centerY);
                drawString(canvas, outlineLayout, right, centerY);

                drawString(canvas, outlineLayout, left, bottom);
                drawString(canvas, outlineLayout, centerX, bottom);
                drawString(canvas, outlineLayout, right, bottom);
            }
            if (_config.ShadowBrush != null)
            {
                TextPaint shadowPaint = getPaint(_config.ShadowBrush);
                drawString(canvas, new AndroidTextLayout(shadowPaint), centerX + _config.ShadowOffsetX,
                           centerY + _config.ShadowOffsetY);
            }
            drawString(canvas, new AndroidTextLayout(paint), centerX, centerY);
        }
コード例 #12
0
        private void drawCaret(string text, SizeF textSize, float heightF, SizeF baseSize, IBitmapTextDraw textDraw, ITextConfig config, int maxWidth)
        {
            if (!_renderCaret)
            {
                return;
            }
            var caretPosition = _caretPosition;

            if (caretPosition > text.Length)
            {
                caretPosition = text.Length;
            }
            string untilCaret = text.Substring(0, caretPosition);

            AGS.API.SizeF caretOffset = config.Font.MeasureString(untilCaret, maxWidth);
            float         spaceOffset = 0f;

            if (untilCaret.EndsWith(" ", StringComparison.Ordinal))
            {
                spaceOffset = _spaceWidth * (untilCaret.Length - untilCaret.TrimEnd().Length);
            }
            textDraw.DrawText("|", config, textSize, baseSize, maxWidth, (int)heightF, caretOffset.Width + spaceOffset - 1f);
        }
コード例 #13
0
ファイル: GLText.cs プロジェクト: ebrucucen/MonoAGS
        public void SetProperties(AGS.API.SizeF baseSize, string text = null, ITextConfig config = null, int?maxWidth = null,
                                  int caretPosition = 0, bool renderCaret = false, bool?cropText = null)
        {
            bool changeNeeded =
                (text != null && text != _text) ||
                (config != null && config != _config) ||
                (maxWidth != null && maxWidth.Value != _maxWidth) ||
                !baseSize.Equals(_baseSize) ||
                _caretPosition != caretPosition ||
                _renderCaret != renderCaret ||
                (cropText != null && cropText.Value != _cropText);

            if (!changeNeeded)
            {
                return;
            }

            _text = text;
            if (config != null && config != _config)
            {
                _config     = config;
                _spaceWidth = measureSpace();
            }
            if (maxWidth != null)
            {
                _maxWidth = maxWidth.Value;
            }
            if (cropText != null)
            {
                _cropText = cropText.Value;
            }
            _baseSize      = baseSize;
            _caretPosition = caretPosition;
            _renderCaret   = renderCaret;

            drawToBitmap();
        }
コード例 #14
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
        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, baseSize, textDraw, config, maxWidth);
            }

            _renderChanged = true;
		}
コード例 #15
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
 private SizeF cropText(int maxWidth, ITextConfig config, ref string text)
 {
     var caretPosition = _caretPosition;
     if (caretPosition >= text.Length) caretPosition = text.Length - 1;
     SizeF newTextSize = new SizeF();
     SizeF prevTextSize = newTextSize;
     StringBuilder textBuilder = new StringBuilder();
     string newText = "";
     string result = "";
     int currentPosition = caretPosition;
     while (newTextSize.Width < maxWidth)
     {
         result = newText;
         prevTextSize = newTextSize;
         if (currentPosition > caretPosition)
         {
             textBuilder.Append(text[currentPosition]);
             currentPosition++;                    
         }
         else
         {
             textBuilder.Insert(0, text[currentPosition]);
             currentPosition--;
             if (currentPosition < 0) currentPosition = caretPosition + 1;
         }
         newText = textBuilder.ToString();
         newTextSize = config.Font.MeasureString(newText, int.MaxValue);                
     }
     text = result;
     return prevTextSize;
 }
コード例 #16
0
        public static float AlignY(this ITextConfig config, float bitmapHeight, float height, AGS.API.SizeF baseSize)
        {
            const float reducePadding = 2f;

            switch (config.Alignment)
            {
            case Alignment.TopLeft:
            case Alignment.TopCenter:
            case Alignment.TopRight:
                return(bitmapHeight - baseSize.Height - reducePadding + config.PaddingTop);

            case Alignment.MiddleLeft:
            case Alignment.MiddleCenter:
            case Alignment.MiddleRight:
                return(bitmapHeight - baseSize.Height / 2f - height / 2f - reducePadding / 2f);

            default:
                return(bitmapHeight - height - reducePadding - config.PaddingBottom);
            }
        }
コード例 #17
0
ファイル: GLText.cs プロジェクト: tzachshabtay/MonoAGS
 private void drawCaret(string text, SizeF textSize, SizeF baseSize, IBitmapTextDraw textDraw, ITextConfig config, int maxWidth)
 {
     if (!_renderCaret) return;
     var caretPosition = _caretPosition;            
     
     if (caretPosition > text.Length) caretPosition = text.Length;
     string untilCaret = text.Substring(0, caretPosition);
     AGS.API.SizeF caretOffset = config.Font.MeasureString(untilCaret, maxWidth);
     float spaceOffset = 0f;
     if (untilCaret.EndsWith(" ")) spaceOffset = _spaceWidth * (untilCaret.Length - untilCaret.TrimEnd().Length);
     textDraw.DrawText("|", config, textSize, baseSize, maxWidth, (int)Height, caretOffset.Width + spaceOffset - 1f);            
 }