/// <inheritdoc/> protected override void OnRender(UIRenderContext context) { // Make sure the layout is up-to-date. UpdateLayout(); var originalScissorRectangle = Renderer.GraphicsDevice.ScissorRectangle; // The renderer uses scissor test. We need to set a default rectangle. // (In MonoGame with OpenGL, the default scissor rectangle might not cover the full screen.) Renderer.GraphicsDevice.ScissorRectangle = ActualBounds.ToRectangle(true); // Start the rendering process. Renderer.BeginBatch(); Renderer.Render(this, context); Renderer.EndBatch(); Renderer.GraphicsDevice.ScissorRectangle = originalScissorRectangle; }
/// <inheritdoc/> protected override void OnRender(UIRenderContext context) { if (!IsVisualValid) { // ----- Store VisualLines as info for the renderer. int lineCount = _wrappedLines.Count; // The total number of lines. int startLine = ComputeStartWrappedLine(); // The index of the first visual line. int endLine = Math.Min(lineCount, startLine + _numberOfLines); // The exclusive end line. VisualLines.Clear(); for (int i = startLine; i < endLine; i++) VisualLines.Add(_wrappedLines[i]); // ----- Determine the position for the caret line. // The number of lines for the wrapped current text. int numberOfLinesInCurrentText = (int)Math.Ceiling((float)(Prompt.Length + Text.Length) / _numberOfColumns); // The line index of the cursor relative to the wrapped current text. int cursorLineInCurrentText = (Prompt.Length + CaretIndex) / _numberOfColumns; // If the cursor is exactly in the last column of the last line, then it should not skip // to the next line (because there is no VisualLine for that). if (cursorLineInCurrentText * _numberOfColumns == (Prompt.Length + Text.Length)) cursorLineInCurrentText--; // The line index of the cursor relative to startLine. VisualCaretY = lineCount - numberOfLinesInCurrentText + cursorLineInCurrentText - startLine; // The column index of the cursor. VisualCaretX = Prompt.Length + CaretIndex - cursorLineInCurrentText * _numberOfColumns; if (VisualCaretY < 0 || VisualCaretY >= _numberOfLines) VisualCaretX = VisualCaretY = -1; } base.OnRender(context); }