Beispiel #1
0
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            if (Selection != null && !string.IsNullOrEmpty(Text))
            {
                var selectStart = Math.Min(_textEdit.SelectStart, _textEdit.SelectEnd);
                var selectEnd   = Math.Max(_textEdit.SelectStart, _textEdit.SelectEnd);

                if (selectStart < selectEnd)
                {
//					Debug.WriteLine("{0} - {1}", selectStart, selectEnd);

                    var startGlyph = _formattedText.GetGlyphInfoByIndex(selectStart);
                    var lineIndex  = startGlyph.TextLine.LineIndex;
                    var i          = selectStart;

                    while (true)
                    {
                        startGlyph = _formattedText.GetGlyphInfoByIndex(i);
                        var startPosition = GetRenderPositionByIndex(i);

                        if (selectEnd < i + startGlyph.TextLine.Count)
                        {
                            var endPosition = GetRenderPositionByIndex(selectEnd);

                            context.Draw(Selection,
                                         new Rectangle(startPosition.X,
                                                       startPosition.Y,
                                                       endPosition.X - startPosition.X,
                                                       CrossEngineStuff.LineSpacing(_formattedText.Font)));

                            break;
                        }

                        context.Draw(Selection,
                                     new Rectangle(startPosition.X,
                                                   startPosition.Y,
                                                   bounds.Left + startGlyph.TextLine.Size.X - startPosition.X,
                                                   CrossEngineStuff.LineSpacing(_formattedText.Font)));

                        ++lineIndex;
                        if (lineIndex >= _formattedText.Strings.Length)
                        {
                            break;
                        }

                        i = 0;
                        for (var k = 0; k < lineIndex; ++k)
                        {
                            i += _formattedText.Strings[k].Count;
                        }
                    }
                }
            }

            var textColor = TextColor;

            if (!Enabled && DisabledTextColor != null)
            {
                textColor = DisabledTextColor.Value;
            }
            else if (IsFocused && FocusedTextColor != null)
            {
                textColor = FocusedTextColor.Value;
            }

            var centeredBounds = LayoutUtils.Align(new Point(bounds.Width, bounds.Height), _formattedText.Size, HorizontalAlignment.Left, TextVerticalAlignment);

            centeredBounds.Offset(bounds.Location);

            _formattedText.Draw(context.Batch, centeredBounds.Location, context.View, textColor, context.Opacity);

            if (!IsFocused)
            {
                // Skip cursor rendering if the widget doesnt have the focus
                return;
            }

            var now = DateTime.Now;

            if ((now - _lastBlinkStamp).TotalMilliseconds >= BlinkIntervalInMs)
            {
                _cursorOn       = !_cursorOn;
                _lastBlinkStamp = now;
            }

            if (_cursorOn && Cursor != null)
            {
                var pos = GetRenderPositionByIndex(_textEdit.CursorIndex);
                context.Draw(Cursor, new Rectangle(pos.X,
                                                   pos.Y,
                                                   Cursor.Size.X,
                                                   CrossEngineStuff.LineSpacing(_formattedText.Font)));
            }
        }
Beispiel #2
0
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            RenderSelection(context);

            var textColor = TextColor;
            var opacity   = context.Opacity;

            if (HintTextEnabled)
            {
                opacity *= 0.5f;
            }
            else if (!Enabled && DisabledTextColor != null)
            {
                textColor = DisabledTextColor.Value;
            }
            else if (IsKeyboardFocused && FocusedTextColor != null)
            {
                textColor = FocusedTextColor.Value;
            }

            var centeredBounds = LayoutUtils.Align(new Point(bounds.Width, bounds.Height), _formattedText.Size, HorizontalAlignment.Left, TextVerticalAlignment);

            centeredBounds.Offset(bounds.Location);

            var p = new Point(centeredBounds.Location.X - _internalScrolling.X,
                              centeredBounds.Location.Y - _internalScrolling.Y);

            _formattedText.Draw(context.Batch, TextAlign.Left, bounds, context.View, textColor, false, opacity);

            if (!IsKeyboardFocused)
            {
                // Skip cursor rendering if the widget doesnt have the focus
                return;
            }

            var now = DateTime.Now;

            if ((now - _lastBlinkStamp).TotalMilliseconds >= BlinkIntervalInMs)
            {
                _cursorOn       = !_cursorOn;
                _lastBlinkStamp = now;
            }

            if (Enabled && _cursorOn && Cursor != null)
            {
                p    = GetRenderPositionByIndex(CursorPosition);
                p.X -= _internalScrolling.X;
                p.Y -= _internalScrolling.Y;
                context.Draw(Cursor,
                             new Rectangle(p.X, p.Y,
                                           Cursor.Size.X,
                                           CrossEngineStuff.LineSpacing(_formattedText.Font)));
            }
        }
Beispiel #3
0
        public virtual void UpdateLayout()
        {
            if (_layoutState == LayoutState.Normal)
            {
                return;
            }

            if (_layoutState == LayoutState.Invalid)
            {
                // Full rearrange
                Point size;
                if (HorizontalAlignment != HorizontalAlignment.Stretch ||
                    VerticalAlignment != VerticalAlignment.Stretch)
                {
                    size = Measure(_containerBounds.Size());
                }
                else
                {
                    size = _containerBounds.Size();
                }

                if (size.X > _containerBounds.Width)
                {
                    size.X = _containerBounds.Width;
                }

                if (size.Y > _containerBounds.Height)
                {
                    size.Y = _containerBounds.Height;
                }

                // Resolve possible conflict beetween Alignment set to Streth and Size explicitly set
                var containerSize = _containerBounds.Size();

                if (HorizontalAlignment == HorizontalAlignment.Stretch && Width != null && Width.Value < containerSize.X)
                {
                    containerSize.X = Width.Value;
                }

                if (VerticalAlignment == VerticalAlignment.Stretch && Height != null && Height.Value < containerSize.Y)
                {
                    containerSize.Y = Height.Value;
                }

                // Align
                var controlBounds = LayoutUtils.Align(containerSize, size, HorizontalAlignment, VerticalAlignment, Parent == null);
                controlBounds.Offset(_containerBounds.Location);

                controlBounds.Offset(Left, Top);

                _bounds       = controlBounds;
                _actualBounds = CalculateClientBounds(controlBounds);

                Arrange();

                CalculateRelativePositions();
            }
            else
            {
                // Only location
                MoveChildren(new Point(Left - _lastLocationHint.X, Top - _lastLocationHint.Y));
            }

            _lastLocationHint = new Point(Left, Top);
            _layoutState      = LayoutState.Normal;

            LayoutUpdated.Invoke(this);
        }