示例#1
0
        public ITextBox GetTextBox(string id, float x, float y, IObject parent = null, string watermark = "", ITextConfig config = null,
                                   bool addToUi = true, float width = -1F, float height = -1F)
        {
            TypedParameter idParam = new TypedParameter(typeof(string), id);
            ITextBox       textbox = _resolver.Container.Resolve <ITextBox>(idParam);

            textbox.LabelRenderSize = new SizeF(width, height);
            textbox.X = x;
            textbox.Y = y;
            if (config == null)
            {
                config = new AGSTextConfig(autoFit: AutoFit.TextShouldCrop);
            }
            textbox.TextConfig = config;
            textbox.Text       = "";
            setParent(textbox, parent);
            if (!string.IsNullOrEmpty(watermark))
            {
                var watermarkConfig = AGSTextConfig.Clone(config);
                watermarkConfig.Brush = _graphics.Brushes.LoadSolidBrush(Colors.LightGray);
                var watermarkLabel = GetLabel($"{id}_watermark", watermark, width, height, 0f, 0f, textbox, watermarkConfig, addToUi);
                watermarkLabel.Opacity = 50;
                textbox.Watermark      = watermarkLabel;
            }

            if (addToUi)
            {
                _gameState.UI.Add(textbox);
            }

            return(textbox);
        }
示例#2
0
        public bool SetProperties(SizeF baseSize, string text = null, ITextConfig config = null, int?maxWidth = null,
                                  PointF?scaleUp = null, PointF?scaleDown  = null, int caretPosition          = 0, int caretXOffset = 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 ||
                _caretXOffset != caretXOffset ||
                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;
            _caretXOffset  = caretXOffset;
            _renderCaret   = renderCaret;

            prepareBitmapDraw();

            return(true);
        }