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

            var bounds = ActualBounds;

            var color = TextColor;

            if (!Enabled && DisabledTextColor != null)
            {
                color = DisabledTextColor.Value;
            }
            else if (IsPressed && PressedTextColor != null)
            {
                color = PressedTextColor.Value;
            }
            else if (IsMouseOver && OverTextColor != null)
            {
                color = OverTextColor.Value;
            }

            _formattedText.Draw(context.Batch, bounds.Location, context.View, color, context.Opacity);
        }
示例#2
0
文件: TextField.cs 项目: dstiert/Myra
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            var textColor = TextColor;

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

            var centeredBounds = LayoutUtils.Align(bounds.Size, _formattedText.Size, HorizontalAlignment.Left, VerticalAlignment.Center);

            centeredBounds.Offset(bounds.Location);
            _formattedText.Draw(context.Batch, centeredBounds, 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 x           = bounds.X;
                var y           = bounds.Y;
                var glyphRender = _formattedText.GetGlyphInfoByIndex(_cursorIndex - 1);
                if (glyphRender != null && glyphRender.TextRun.RenderedPosition != null)
                {
                    x = glyphRender.TextRun.RenderedPosition.Value.X + glyphRender.Bounds.Right;
                    y = glyphRender.TextRun.RenderedPosition.Value.Y;
                }

                context.Draw(Cursor, new Rectangle(x,
                                                   y,
                                                   Cursor.Size.X,
                                                   _formattedText.Font.LineSpacing));
            }
        }
示例#3
0
文件: TextBox.cs 项目: mystborn/Myra
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            RenderSelection(context);

            var textColor = TextColor;

            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, p, context.View, textColor, false, context.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)));
            }
        }
示例#4
0
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            _formattedText.Draw(context.Batch, bounds, Enabled ? TextColor : DisabledTextColor);
        }
示例#5
0
        public override void InternalRender(RenderContext context)
        {
            if (_formattedText.Font == null)
            {
                return;
            }

            var bounds = ActualBounds;

            _formattedText.Draw(context.Batch, bounds, TextColor);

            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 x           = bounds.X;
                var y           = bounds.Y;
                var glyphRender = _formattedText.GetGlyphRenderByIndex(_cursorIndex - 1);
                if (glyphRender != null &&
                    glyphRender.RenderedBounds.HasValue &&
                    glyphRender.Run.RenderedBounds.HasValue)
                {
                    x = glyphRender.RenderedBounds.Value.Right;
                    y = glyphRender.Run.RenderedBounds.Value.Top;
                }

                context.Batch.Draw(Cursor, new Rectangle(x,
                                                         y,
                                                         (int)Cursor.Size.Width,
                                                         _formattedText.Font.LineHeight));
            }
        }
示例#6
0
        protected override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            if (graphics.PreferredBackBufferWidth != Window.ClientBounds.Width ||
                graphics.PreferredBackBufferHeight != Window.ClientBounds.Height)
            {
                graphics.PreferredBackBufferWidth  = Window.ClientBounds.Width;
                graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
                graphics.ApplyChanges();
            }

            var device = GraphicsDevice;

            device.Clear(Color.Black);

            _batch.Begin();

            _formattedText.Draw(_batch, Point.Zero, Color.LightBlue);

            _batch.End();
        }