private void RenderSelection(RenderContext context) { var bounds = ActualBounds; if (string.IsNullOrEmpty(Text) || Selection == null) { return; } var selectStart = Math.Min(SelectStart, SelectEnd); var selectEnd = Math.Max(SelectStart, SelectEnd); if (selectStart >= selectEnd) { return; } var startGlyph = _formattedText.GetGlyphInfoByIndex(selectStart); if (startGlyph == null) { return; } var lineIndex = startGlyph.TextChunk.LineIndex; var i = selectStart; var lineHeight = _formattedText.Font.FontSize; while (true) { startGlyph = _formattedText.GetGlyphInfoByIndex(i); var startPosition = GetRenderPositionByIndex(i); var line = _formattedText.Lines[startGlyph.TextChunk.LineIndex]; if (selectEnd < line.TextStartIndex + line.Count) { var endPosition = GetRenderPositionByIndex(selectEnd); Selection.Draw(context, new Rectangle(startPosition.X - _internalScrolling.X, startPosition.Y - _internalScrolling.Y, endPosition.X - startPosition.X, lineHeight)); break; } Selection.Draw(context, new Rectangle(startPosition.X - _internalScrolling.X, startPosition.Y - _internalScrolling.Y, bounds.Left + startGlyph.TextChunk.Size.X - startPosition.X, lineHeight)); ++lineIndex; if (lineIndex >= _formattedText.Lines.Count) { break; } i = _formattedText.Lines[lineIndex].TextStartIndex; } }
public override void InternalRender(RenderContext context) { if (_formattedText.Font == null) { return; } var bounds = ActualBounds; RenderSelection(context); var textColor = TextColor; var oldOpacity = context.Opacity; if (HintTextEnabled) { context.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, TextAlign.Left, new Rectangle(p.X, p.Y, bounds.Width, bounds.Height), context.View, textColor, false); 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; Cursor.Draw(context, new Rectangle(p.X, p.Y, Cursor.Size.X, _formattedText.Font.FontSize)); } context.Opacity = oldOpacity; }
private void RenderSelection(RenderContext context) { var bounds = ActualBounds; switch (GridSelectionMode) { case GridSelectionMode.None: break; case GridSelectionMode.Row: { if (HoverRowIndex != null && HoverRowIndex != SelectedRowIndex && SelectionHoverBackground != null) { var rect = Rectangle.Intersect(new Rectangle(bounds.Left, _cellLocationsY[HoverRowIndex.Value] + bounds.Top - RowSpacing / 2, bounds.Width, _rowHeights[HoverRowIndex.Value] + RowSpacing), context.View); SelectionHoverBackground.Draw(context, rect); } if (SelectedRowIndex != null && SelectionBackground != null) { var rect = Rectangle.Intersect(new Rectangle(bounds.Left, _cellLocationsY[SelectedRowIndex.Value] + bounds.Top - RowSpacing / 2, bounds.Width, _rowHeights[SelectedRowIndex.Value] + RowSpacing), context.View); SelectionBackground.Draw(context, rect); } } break; case GridSelectionMode.Column: { if (HoverColumnIndex != null && HoverColumnIndex != SelectedColumnIndex && SelectionHoverBackground != null) { var rect = Rectangle.Intersect(new Rectangle( _cellLocationsX[HoverColumnIndex.Value] + bounds.Left - ColumnSpacing / 2, bounds.Top, _colWidths[HoverColumnIndex.Value] + ColumnSpacing, bounds.Height), context.View); SelectionHoverBackground.Draw(context, rect); } if (SelectedColumnIndex != null && SelectionBackground != null) { var rect = Rectangle.Intersect(new Rectangle( _cellLocationsX[SelectedColumnIndex.Value] + bounds.Left - ColumnSpacing / 2, bounds.Top, _colWidths[SelectedColumnIndex.Value] + ColumnSpacing, bounds.Height), context.View); SelectionBackground.Draw(context, rect); } } break; case GridSelectionMode.Cell: { if (HoverRowIndex != null && HoverColumnIndex != null && (HoverRowIndex != SelectedRowIndex || HoverColumnIndex != SelectedColumnIndex) && SelectionHoverBackground != null) { var rect = Rectangle.Intersect(new Rectangle( _cellLocationsX[HoverColumnIndex.Value] + bounds.Left - ColumnSpacing / 2, _cellLocationsY[HoverRowIndex.Value] + bounds.Top - RowSpacing / 2, _colWidths[HoverColumnIndex.Value] + ColumnSpacing, _rowHeights[HoverRowIndex.Value] + RowSpacing), context.View); SelectionHoverBackground.Draw(context, rect); } if (SelectedRowIndex != null && SelectedColumnIndex != null && SelectionBackground != null) { var rect = Rectangle.Intersect(new Rectangle( _cellLocationsX[SelectedColumnIndex.Value] + bounds.Left - ColumnSpacing / 2, _cellLocationsY[SelectedRowIndex.Value] + bounds.Top - RowSpacing / 2, _colWidths[SelectedColumnIndex.Value] + ColumnSpacing, _rowHeights[SelectedRowIndex.Value] + RowSpacing), context.View); SelectionBackground.Draw(context, rect); } } break; } }