public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var textBlock = (TextBlock)element; if (textBlock.Font == null || textBlock.TextToDisplay == null) { return; } var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = textBlock.RenderOpacity * textBlock.TextColor, DepthBias = context.DepthBias, FontScale = element.LayoutingContext.RealVirtualResolutionRatio, FontSize = textBlock.TextSize, Batch = Batch, SnapText = context.ShouldSnapText && !textBlock.DoNotSnapText, Matrix = textBlock.WorldMatrixInternal, Alignment = textBlock.TextAlignment, Size = new Vector2(textBlock.ActualWidth, textBlock.ActualHeight) }; Batch.DrawString(textBlock.Font, textBlock.TextToDisplay, ref drawCommand); }
/// <summary> /// Render the clipping region of the provided <see cref="UIElement"/>. /// </summary> /// <param name="element">The element to render.</param> /// <param name="context">The rendering context containing information how to draw the element.</param> /// <remarks>The render target, the depth stencil buffer and the depth stencil state are already correctly set when entering this function. /// If the user wants to perform some intermediate rendering, it is his responsibility to bind them back correctly before the final rendering.</remarks> public virtual void RenderClipping(UIElement element, UIRenderingContext context) { // Default implementation: render an back-face cube Batch.DrawBackground(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias); // increase the context depth bias for next elements. context.DepthBias += 1; }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var scrollingText = (ScrollingText)element; if (scrollingText.Font == null || scrollingText.TextToDisplay == null) { return; } var offset = scrollingText.ScrollingOffset; var textWorldMatrix = element.WorldMatrix; textWorldMatrix.M41 += textWorldMatrix.M11 * offset; textWorldMatrix.M42 += textWorldMatrix.M12 * offset; textWorldMatrix.M43 += textWorldMatrix.M13 * offset; textWorldMatrix.M44 += textWorldMatrix.M14 * offset; // create the scrolling text draw command var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = scrollingText.RenderOpacity * scrollingText.TextColor, DepthBias = context.DepthBias + 1, FontScale = element.RealSizeVirtualResolutionRatio, FontSize = scrollingText.TextSize, Batch = Batch, SnapText = scrollingText.SnapText, WorldMatrix = textWorldMatrix, Alignment = TextAlignment.Left, Size = new Vector2(scrollingText.ActualWidth, scrollingText.ActualHeight) }; // flush the current content of the UI image batch Batch.End(); // draw a clipping mask Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, IncreaseStencilValueState, context.StencilTestReferenceValue); Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias); Batch.End(); // draw the element it-self with stencil test value of "Context.Value + 1" Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue + 1); Batch.DrawString(scrollingText.Font, scrollingText.TextToDisplay, ref drawCommand); Batch.End(); // undraw the clipping mask Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.ColorDisabled, DecreaseStencilValueState, context.StencilTestReferenceValue + 1); Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias + 2); Batch.End(); // restart the Batch session Batch.Begin(ref UI.ViewProjectionInternal, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var image = (ImageElement)element; var imageColor = element.RenderOpacity * Color.White; if(image.Source == null) return; Batch.DrawImage(image.Source.Texture, image.Source.TextureAlpha, ref image.WorldMatrixInternal, ref image.Source.RegionInternal, ref element.RenderSizeInternal, ref image.Source.BordersInternal, ref imageColor, context.DepthBias, image.Source.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var toggleButton = (ToggleButton)element; var color = toggleButton.RenderOpacity * Color.White; var image = GetToggleStateImage(toggleButton); if (image == null || image.Texture == null) return; Batch.DrawImage(image.Texture, image.TextureAlpha, ref toggleButton.WorldMatrixInternal, ref image.RegionInternal, ref toggleButton.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var scrollingText = (ScrollingText)element; if (scrollingText.Font == null || scrollingText.TextToDisplay == null) return; var offset = scrollingText.ScrollingOffset; var textWorldMatrix = element.WorldMatrix; textWorldMatrix.M41 += textWorldMatrix.M11 * offset; textWorldMatrix.M42 += textWorldMatrix.M12 * offset; textWorldMatrix.M43 += textWorldMatrix.M13 * offset; textWorldMatrix.M44 += textWorldMatrix.M14 * offset; // create the scrolling text draw command var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = scrollingText.RenderOpacity * scrollingText.TextColor, DepthBias = context.DepthBias + 1, FontScale = element.LayoutingContext.RealVirtualResolutionRatio, FontSize = scrollingText.TextSize, Batch = Batch, SnapText = context.ShouldSnapText && !scrollingText.DoNotSnapText, Matrix = textWorldMatrix, Alignment = TextAlignment.Left, Size = new Vector2(scrollingText.ActualWidth, scrollingText.ActualHeight) }; // flush the current content of the UI image batch Batch.End(); // draw a clipping mask Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.ColorDisabled, IncreaseStencilValueState, context.StencilTestReferenceValue); Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias); Batch.End(); // draw the element it-self with stencil test value of "Context.Value + 1" Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue + 1); Batch.DrawString(scrollingText.Font, scrollingText.TextToDisplay, ref drawCommand); Batch.End(); // un-draw the clipping mask Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.ColorDisabled, DecreaseStencilValueState, context.StencilTestReferenceValue + 1); Batch.DrawRectangle(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref blackColor, context.DepthBias+2); Batch.End(); // restart the Batch session Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue); }
/// <summary> /// Render the provided <see cref="UIElement"/>. /// </summary> /// <param name="element">The element to render.</param> /// <param name="context">The rendering context containing information how to draw the element.</param> /// <remarks>The render target, the depth stencil buffer and the depth stencil state are already correctly set when entering this function. /// If the user wants to perform some intermediate rendering, it is his responsibility to bind them back correctly before the final rendering.</remarks> public virtual void RenderColor(UIElement element, UIRenderingContext context) { var backgroundColor = element.Opacity * element.BackgroundColor; // optimization: don't draw the background if transparent if (backgroundColor == new Color()) return; // Default implementation: render an back-face cube with background color Batch.DrawBackground(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref backgroundColor, context.DepthBias); // increase depth bias value so that next elements renders on top of it. context.DepthBias += 1; }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var bar = (ScrollBar)element; // round the size of the bar to nearest pixel modulo to avoid to have a bar varying by one pixel length while scrolling var barSize = bar.RenderSizeInternal; var realVirtualRatio = bar.LayoutingContext.RealVirtualResolutionRatio; for (int i = 0; i < 2; i++) barSize[i] = (float)(Math.Ceiling(barSize[i] * realVirtualRatio[i]) / realVirtualRatio[i]); Batch.DrawRectangle(ref element.WorldMatrixInternal, ref barSize, ref bar.BarColorInternal, context.DepthBias); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var decorator = (ContentDecorator)element; if (decorator.BackgroundImage == null) return; var image = decorator.BackgroundImage; var color = decorator.RenderOpacity * Color.White; Batch.DrawImage(image.Texture, ref decorator.WorldMatrixInternal, ref image.RegionInternal, ref decorator.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var image = (ImageElement)element; var imageColor = element.RenderOpacity * Color.White; if (image.Source == null) { return; } Batch.DrawImage(image.Source.Texture, image.Source.TextureAlpha, ref image.WorldMatrixInternal, ref image.Source.RegionInternal, ref element.RenderSizeInternal, ref image.Source.BordersInternal, ref imageColor, context.DepthBias, image.Source.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var bar = (ScrollBar)element; // round the size of the bar to nearest pixel modulo to avoid to have a bar varying by one pixel length while scrolling var barSize = bar.RenderSizeInternal; for (int i = 0; i < 2; i++) { barSize[i] = (float)(Math.Ceiling(barSize[i] * bar.RealSizeVirtualResolutionRatio[i]) / bar.RealSizeVirtualResolutionRatio[i]); } Batch.DrawRectangle(ref element.WorldMatrixInternal, ref barSize, ref bar.BarColorInternal, context.DepthBias); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var toggleButton = (ToggleButton)element; var color = toggleButton.RenderOpacity * Color.White; var image = GetToggleStateImage(toggleButton); if (image == null || image.Texture == null) { return; } Batch.DrawImage(image.Texture, image.TextureAlpha, ref toggleButton.WorldMatrixInternal, ref image.RegionInternal, ref toggleButton.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var button = (Button)element; var color = button.RenderOpacity * Color.White; var image = button.PressedImage; if(!button.IsPressed) image = button.MouseOverState == MouseOverState.MouseOverElement? button.MouseOverImage : button.NotPressedImage; if(image == null || image.Texture == null) return; Batch.DrawImage(image.Texture, image.TextureAlpha, ref button.WorldMatrixInternal, ref image.RegionInternal, ref button.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
/// <summary> /// Render the provided <see cref="UIElement"/>. /// </summary> /// <param name="element">The element to render.</param> /// <param name="context">The rendering context containing information how to draw the element.</param> /// <remarks>The render target, the depth stencil buffer and the depth stencil state are already correctly set when entering this function. /// If the user wants to perform some intermediate rendering, it is his responsibility to bind them back correctly before the final rendering.</remarks> public virtual void RenderColor(UIElement element, UIRenderingContext context) { var backgroundColor = element.Opacity * element.BackgroundColor; // optimization: don't draw the background if transparent if (backgroundColor == new Color()) { return; } // Default implementation: render an back-face cube with background color Batch.DrawBackground(ref element.WorldMatrixInternal, ref element.RenderSizeInternal, ref backgroundColor, context.DepthBias); // increase depth bias value so that next elements renders on top of it. context.DepthBias += 1; }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var decorator = (ContentDecorator)element; if (decorator.BackgroundImage == null) { return; } var image = decorator.BackgroundImage; var color = decorator.RenderOpacity * Color.White; Batch.DrawImage(image.Texture, null, ref decorator.WorldMatrixInternal, ref image.RegionInternal, ref decorator.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { var modalElement = (ModalElement)element; // end the current UI image batching so that the overlay is written over it with correct transparency Batch.End(); var uiResolution = new Vector3(context.Resolution.X, context.Resolution.Y, 0); Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.AlphaBlend, noStencilNoDepth, 0); Batch.DrawRectangle(ref identity, ref uiResolution, ref modalElement.OverlayColorInternal, context.DepthBias); Batch.End(); // ensure that overlay is written before possible next transparent element. // restart the image batch session Batch.Begin(ref context.ViewProjectionMatrix, GraphicsDevice.BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue); context.DepthBias += 1; base.RenderColor(element, context); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var button = (Button)element; var color = button.RenderOpacity * Color.White; var image = button.PressedImage; if (!button.IsPressed) { image = button.MouseOverState == MouseOverState.MouseOverElement? button.MouseOverImage : button.NotPressedImage; } if (image == null || image.Texture == null) { return; } Batch.DrawImage(image.Texture, image.TextureAlpha, ref button.WorldMatrixInternal, ref image.RegionInternal, ref button.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var textBlock = (TextBlock)element; if (textBlock.Font == null || textBlock.TextToDisplay == null) return; var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = textBlock.RenderOpacity * textBlock.TextColor, DepthBias = context.DepthBias, FontScale = element.LayoutingContext.RealVirtualResolutionRatio, FontSize = textBlock.TextSize, Batch = Batch, SnapText = context.ShouldSnapText && !textBlock.DoNotSnapText, Matrix = textBlock.WorldMatrixInternal, Alignment = textBlock.TextAlignment, Size = new Vector2(textBlock.ActualWidth, textBlock.ActualHeight) }; Batch.DrawString(textBlock.Font, textBlock.TextToDisplay, ref drawCommand); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var slider = (Slider)element; if(slider.Orientation == Orientation.InDepth) return; // No rendering for in-depth slider for the moment. var axis = (int)slider.Orientation; var axisPrime = (axis + 1) % 2; var color = slider.RenderOpacity * Color.White; var isGaugeReverted = axis == 1 ? !slider.IsDirectionReversed : slider.IsDirectionReversed; // we want the track going up from the bottom in vertical mode by default var sliderRatio = slider.Value / (slider.Maximum - slider.Minimum); var trackOffsets = new Vector2(slider.TrackStartingOffsets[axis], slider.TrackStartingOffsets[axisPrime]); var fullGaugeSize = slider.RenderSizeInternal[axis] - trackOffsets.X - trackOffsets.Y; var trackIdealSize = slider.TrackBackgroundImage != null ? new Vector2?(slider.TrackBackgroundImage.SizeInPixels) : null; // draws the track background var image = slider.TrackBackgroundImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, (axis & imageAxis) == 1); Batch.DrawImage(image.Texture, null, ref worldMatrix, ref image.RegionInternal, ref slider.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draw the track foreground image = slider.TrackForegroundImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = sliderRatio * fullGaugeSize; size[axisPrime] = image.SizeInPixels.Y; if (trackIdealSize.HasValue) size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); var halfSizeLeft = (slider.RenderSizeInternal[axis] - size[axis]) / 2; var worldTranslation = GetAdjustedTranslation(isGaugeReverted ? halfSizeLeft - trackOffsets.Y : trackOffsets.X - halfSizeLeft, shouldRotate180Degrees); worldMatrix.M41 += worldTranslation * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += worldTranslation * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += worldTranslation * worldMatrix[(axis << 2) + 2]; var borders = image.BordersInternal; var borderStartIndex = (imageAxis <<1 ) + (slider.IsDirectionReversed? 1 : 0); var borderStopIndex = (imageAxis << 1) + (slider.IsDirectionReversed ? 0 : 1); borders[borderStartIndex] = Math.Min(borders[borderStartIndex], size[axis]); borders[borderStopIndex] = Math.Max(0, size[axis] - fullGaugeSize + borders[borderStopIndex]); var position = image.RegionInternal.Location; var oldRegionSize = new Vector2(image.RegionInternal.Width, image.RegionInternal.Height); var originalBordersSize = image.BordersInternal[borderStartIndex] + image.BordersInternal[borderStopIndex]; var newRegionSize = oldRegionSize; newRegionSize[imageAxis] = borders[borderStartIndex] + borders[borderStopIndex] + (oldRegionSize[imageAxis] - originalBordersSize) * Math.Min(1, (size[axis] - borders[borderStartIndex]) / (fullGaugeSize - originalBordersSize)); if (slider.IsDirectionReversed) { position[imageAxis] = position[imageAxis] + oldRegionSize[imageAxis] - newRegionSize[imageAxis]; } var region = new RectangleF(position.X, position.Y, newRegionSize.X, newRegionSize.Y); Batch.DrawImage(image.Texture, null, ref worldMatrix, ref region, ref size, ref borders, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draws the ticks image = slider.TickImage; if (slider.AreTicksDisplayed && image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = image.SizeInPixels.X; size[axisPrime] = image.SizeInPixels.Y; if (trackIdealSize.HasValue) size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; var startOffset = new Vector2(GetAdjustedTranslation(slider.TickOffset, shouldRotate180Degrees)); startOffset[axis] = GetAdjustedTranslation(- fullGaugeSize / 2, shouldRotate180Degrees); if (trackIdealSize.HasValue) startOffset[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; var stepOffset = GetAdjustedTranslation(fullGaugeSize / slider.TickFrequency, shouldRotate180Degrees); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); worldMatrix.M41 += startOffset[axis] * worldMatrix[(axis << 2) + 0] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 0]; worldMatrix.M42 += startOffset[axis] * worldMatrix[(axis << 2) + 1] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 1]; worldMatrix.M43 += startOffset[axis] * worldMatrix[(axis << 2) + 2] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 2]; for (int i = 0; i < slider.TickFrequency + 1; i++) { Batch.DrawImage(image.Texture, null, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation, SwizzleMode.None, true); worldMatrix.M41 += stepOffset * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += stepOffset * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += stepOffset * worldMatrix[(axis << 2) + 2]; } context.DepthBias += 1; } //draws the thumb image = slider.MouseOverState == MouseOverState.MouseOverElement ? slider.MouseOverThumbImage : slider.ThumbImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = image.SizeInPixels.X; size[axisPrime] = image.SizeInPixels.Y; if (trackIdealSize.HasValue) size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; var revertedRatio = isGaugeReverted ? 1 - sliderRatio : sliderRatio; var offset = GetAdjustedTranslation((revertedRatio - 0.5f) * fullGaugeSize, shouldRotate180Degrees); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); worldMatrix.M41 += offset * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += offset * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += offset * worldMatrix[(axis << 2) + 2]; Batch.DrawImage(image.Texture, null, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var editText = (EditText)element; if (editText.Font == null) { return; } // determine the image to draw in background of the edit text var fontScale = element.LayoutingContext.RealVirtualResolutionRatio; var color = editText.RenderOpacity * Color.White; var image = editText.ActiveImage; if (!editText.IsSelectionActive) { image = editText.MouseOverState == MouseOverState.MouseOverElement? editText.MouseOverImage : editText.InactiveImage; } if (image != null && image.Texture != null) { Batch.DrawImage(image.Texture, null, ref editText.WorldMatrixInternal, ref image.RegionInternal, ref editText.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); } // calculate the size of the text region by removing padding var textRegionSize = new Vector2(editText.ActualWidth - editText.Padding.Left - editText.Padding.Right, editText.ActualHeight - editText.Padding.Top - editText.Padding.Bottom); var font = editText.Font; var selectionColor = editText.RenderOpacity * editText.SelectionColor; var caretColor = editText.RenderOpacity * editText.CaretColor; var offsetTextStart = 0f; var offsetAlignment = 0f; var selectionSize = 0f; // Draw the selection if (editText.IsSelectionActive) { var fontSize = new Vector2(fontScale.Y * editText.TextSize); offsetTextStart = font.MeasureString(editText.TextToDisplay, ref fontSize, editText.SelectionStart).X; selectionSize = font.MeasureString(editText.TextToDisplay, ref fontSize, editText.SelectionStart + editText.SelectionLength).X - offsetTextStart; if (font.IsDynamic) { offsetTextStart /= fontScale.X; selectionSize /= fontScale.X; } offsetAlignment = -textRegionSize.X / 2f; if (editText.TextAlignment != TextAlignment.Left) { var textWidth = font.MeasureString(editText.TextToDisplay, ref fontSize).X; if (font.IsDynamic) { textWidth /= fontScale.X; } offsetAlignment = editText.TextAlignment == TextAlignment.Center ? -textWidth / 2 : -textRegionSize.X / 2f + (textRegionSize.X - textWidth); } var selectionWorldMatrix = element.WorldMatrixInternal; selectionWorldMatrix.M41 += offsetTextStart + selectionSize / 2 + offsetAlignment; var selectionScaleVector = new Vector3(selectionSize, editText.LineCount * editText.Font.GetTotalLineSpacing(editText.TextSize), 0); Batch.DrawRectangle(ref selectionWorldMatrix, ref selectionScaleVector, ref selectionColor, context.DepthBias + 1); } // create the text draw command var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = editText.RenderOpacity * editText.TextColor, DepthBias = context.DepthBias + 2, FontScale = fontScale, FontSize = editText.TextSize, Batch = Batch, SnapText = context.ShouldSnapText && !editText.DoNotSnapText, Matrix = editText.WorldMatrixInternal, Alignment = editText.TextAlignment, Size = textRegionSize }; // Draw the text Batch.DrawString(font, editText.TextToDisplay, ref drawCommand); // Draw the cursor if (editText.IsCaretVisible) { var sizeCaret = editText.CaretWidth / fontScale.X; var caretWorldMatrix = element.WorldMatrixInternal; caretWorldMatrix.M41 += offsetTextStart + offsetAlignment + (editText.CaretPosition > editText.SelectionStart? selectionSize: 0); var caretScaleVector = new Vector3(sizeCaret, editText.LineCount * editText.Font.GetTotalLineSpacing(editText.TextSize), 0); Batch.DrawRectangle(ref caretWorldMatrix, ref caretScaleVector, ref caretColor, context.DepthBias + 3); } }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var slider = (Slider)element; if (slider.Orientation == Orientation.InDepth) { return; // No rendering for in-depth slider for the moment. } var axis = (int)slider.Orientation; var axisPrime = (axis + 1) % 2; var color = slider.RenderOpacity * Color.White; var isGaugeReverted = axis == 1 ? !slider.IsDirectionReversed : slider.IsDirectionReversed; // we want the track going up from the bottom in vertical mode by default var sliderRatio = slider.Value / (slider.Maximum - slider.Minimum); var trackOffsets = new Vector2(slider.TrackStartingOffsets[axis], slider.TrackStartingOffsets[axisPrime]); var fullGaugeSize = slider.RenderSizeInternal[axis] - trackOffsets.X - trackOffsets.Y; var trackIdealSize = slider.TrackBackgroundImage != null ? new Vector2?(slider.TrackBackgroundImage.ImageIdealSize) : null; // draws the track background var image = slider.TrackBackgroundImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, (axis & imageAxis) == 1); Batch.DrawImage(image.Texture, image.TextureAlpha, ref worldMatrix, ref image.RegionInternal, ref slider.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draw the track foreground image = slider.TrackForegroundImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = sliderRatio * fullGaugeSize; size[axisPrime] = image.ImageIdealSize.Y; if (trackIdealSize.HasValue) { size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; } var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); var halfSizeLeft = (slider.RenderSizeInternal[axis] - size[axis]) / 2; var worldTranslation = GetAdjustedTranslation(isGaugeReverted ? halfSizeLeft - trackOffsets.Y : trackOffsets.X - halfSizeLeft, shouldRotate180Degrees); worldMatrix.M41 += worldTranslation * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += worldTranslation * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += worldTranslation * worldMatrix[(axis << 2) + 2]; var borders = image.BordersInternal; var borderStartIndex = (imageAxis << 1) + (slider.IsDirectionReversed? 1 : 0); var borderStopIndex = (imageAxis << 1) + (slider.IsDirectionReversed ? 0 : 1); borders[borderStartIndex] = Math.Min(borders[borderStartIndex], size[axis]); borders[borderStopIndex] = Math.Max(0, size[axis] - fullGaugeSize + borders[borderStopIndex]); var position = image.RegionInternal.Location; var oldRegionSize = new Vector2(image.RegionInternal.Width, image.RegionInternal.Height); var originalBordersSize = image.BordersInternal[borderStartIndex] + image.BordersInternal[borderStopIndex]; var newRegionSize = oldRegionSize; newRegionSize[imageAxis] = borders[borderStartIndex] + borders[borderStopIndex] + (oldRegionSize[imageAxis] - originalBordersSize) * Math.Min(1, (size[axis] - borders[borderStartIndex]) / (fullGaugeSize - originalBordersSize)); if (slider.IsDirectionReversed) { position[imageAxis] = position[imageAxis] + oldRegionSize[imageAxis] - newRegionSize[imageAxis]; } var region = new RectangleF(position.X, position.Y, newRegionSize.X, newRegionSize.Y); Batch.DrawImage(image.Texture, image.TextureAlpha, ref worldMatrix, ref region, ref size, ref borders, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draws the ticks image = slider.TickImage; if (slider.AreTicksDisplayed && image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = image.ImageIdealSize.X; size[axisPrime] = image.ImageIdealSize.Y; if (trackIdealSize.HasValue) { size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; } var startOffset = new Vector2(GetAdjustedTranslation(slider.TickOffset, shouldRotate180Degrees)); startOffset[axis] = GetAdjustedTranslation(-fullGaugeSize / 2, shouldRotate180Degrees); if (trackIdealSize.HasValue) { startOffset[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; } var stepOffset = GetAdjustedTranslation(fullGaugeSize / slider.TickFrequency, shouldRotate180Degrees); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); worldMatrix.M41 += startOffset[axis] * worldMatrix[(axis << 2) + 0] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 0]; worldMatrix.M42 += startOffset[axis] * worldMatrix[(axis << 2) + 1] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 1]; worldMatrix.M43 += startOffset[axis] * worldMatrix[(axis << 2) + 2] + startOffset[axisPrime] * worldMatrix[(axisPrime << 2) + 2]; for (int i = 0; i < slider.TickFrequency + 1; i++) { Batch.DrawImage(image.Texture, image.TextureAlpha, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation, SwizzleMode.None, true); worldMatrix.M41 += stepOffset * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += stepOffset * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += stepOffset * worldMatrix[(axis << 2) + 2]; } context.DepthBias += 1; } //draws the thumb image = slider.MouseOverState == MouseOverState.MouseOverElement ? slider.MouseOverThumbImage : slider.ThumbImage; if (image != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = image.ImageIdealSize.X; size[axisPrime] = image.ImageIdealSize.Y; if (trackIdealSize.HasValue) { size[axisPrime] *= slider.RenderSizeInternal[axisPrime] / trackIdealSize.Value.Y; } var revertedRatio = isGaugeReverted ? 1 - sliderRatio : sliderRatio; var offset = GetAdjustedTranslation((revertedRatio - 0.5f) * fullGaugeSize, shouldRotate180Degrees); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, shouldRotate180Degrees); worldMatrix.M41 += offset * worldMatrix[(axis << 2) + 0]; worldMatrix.M42 += offset * worldMatrix[(axis << 2) + 1]; worldMatrix.M43 += offset * worldMatrix[(axis << 2) + 2]; Batch.DrawImage(image.Texture, image.TextureAlpha, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation); context.DepthBias += 1; } }
private void DrawBorder(Border border, ref Vector3 offsets, ref Vector3 borderSize, UIRenderingContext context) { var worldMatrix = border.WorldMatrixInternal; worldMatrix.M41 += worldMatrix.M11 * offsets.X + worldMatrix.M21 * offsets.Y + worldMatrix.M31 * offsets.Z; worldMatrix.M42 += worldMatrix.M12 * offsets.X + worldMatrix.M22 * offsets.Y + worldMatrix.M32 * offsets.Z; worldMatrix.M43 += worldMatrix.M13 * offsets.X + worldMatrix.M23 * offsets.Y + worldMatrix.M33 * offsets.Z; Batch.DrawCube(ref worldMatrix, ref borderSize, ref border.BorderColorInternal, context.DepthBias); }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); Vector3 offsets; Vector3 borderSize; var border = (Border)element; var borderThickness = border.BorderThickness; var elementHalfBorders = borderThickness / 2; var elementSize = element.RenderSizeInternal; var elementHalfSize = elementSize / 2; // left/front offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, 0, -elementHalfSize.Z + elementHalfBorders.Back); borderSize = new Vector3(borderThickness.Left, elementSize.Y, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // right/front offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, 0, -elementHalfSize.Z + elementHalfBorders.Back); borderSize = new Vector3(borderThickness.Right, elementSize.Y, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // top/front offsets = new Vector3(0, -elementHalfSize.Y + elementHalfBorders.Top, -elementHalfSize.Z + elementHalfBorders.Back); borderSize = new Vector3(elementSize.X, borderThickness.Top, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // bottom/front offsets = new Vector3(0, elementHalfSize.Y - elementHalfBorders.Bottom, -elementHalfSize.Z + elementHalfBorders.Back); borderSize = new Vector3(elementSize.X, borderThickness.Bottom, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // if the element is 3D draw the extra borders if (element.ActualDepth > MathUtil.ZeroTolerance) { // left/back offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, 0, elementHalfSize.Z - elementHalfBorders.Front); borderSize = new Vector3(borderThickness.Left, elementSize.Y, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // right/back offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, 0, elementHalfSize.Z - elementHalfBorders.Front); borderSize = new Vector3(borderThickness.Right, elementSize.Y, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // top/back offsets = new Vector3(0, -elementHalfSize.Y + elementHalfBorders.Top, elementHalfSize.Z - elementHalfBorders.Front); borderSize = new Vector3(elementSize.X, borderThickness.Top, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // bottom/back offsets = new Vector3(0, elementHalfSize.Y - elementHalfBorders.Bottom, elementHalfSize.Z - elementHalfBorders.Front); borderSize = new Vector3(elementSize.X, borderThickness.Bottom, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // left/top offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, -elementHalfSize.Y + elementHalfBorders.Top, 0); borderSize = new Vector3(borderThickness.Left, borderThickness.Top, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // right/top offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, -elementHalfSize.Y + elementHalfBorders.Top, 0); borderSize = new Vector3(borderThickness.Right, borderThickness.Top, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // left/bottom offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, elementHalfSize.Y - elementHalfBorders.Bottom, 0); borderSize = new Vector3(borderThickness.Left, borderThickness.Bottom, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // right/bottom offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, elementHalfSize.Y - elementHalfBorders.Bottom, 0); borderSize = new Vector3(borderThickness.Right, borderThickness.Bottom, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); } }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); var editText = (EditText)element; if (editText.Font == null) return; // determine the image to draw in background of the edit text var fontScale = element.LayoutingContext.RealVirtualResolutionRatio; var color = editText.RenderOpacity * Color.White; var image = editText.ActiveImage; if(!editText.IsSelectionActive) image = editText.MouseOverState == MouseOverState.MouseOverElement? editText.MouseOverImage : editText.InactiveImage; if (image != null && image.Texture != null) { Batch.DrawImage(image.Texture, null, ref editText.WorldMatrixInternal, ref image.RegionInternal, ref editText.RenderSizeInternal, ref image.BordersInternal, ref color, context.DepthBias, image.Orientation); } // calculate the size of the text region by removing padding var textRegionSize = new Vector2(editText.ActualWidth - editText.Padding.Left - editText.Padding.Right, editText.ActualHeight - editText.Padding.Top - editText.Padding.Bottom); var font = editText.Font; var selectionColor = editText.RenderOpacity * editText.SelectionColor; var caretColor = editText.RenderOpacity * editText.CaretColor; var offsetTextStart = 0f; var offsetAlignment = 0f; var selectionSize = 0f; // Draw the selection if(editText.IsSelectionActive) { var fontSize = new Vector2(fontScale.Y * editText.TextSize); offsetTextStart = font.MeasureString(editText.TextToDisplay, ref fontSize, editText.SelectionStart).X; selectionSize = font.MeasureString(editText.TextToDisplay, ref fontSize, editText.SelectionStart + editText.SelectionLength).X - offsetTextStart; if (font.IsDynamic) { offsetTextStart /= fontScale.X; selectionSize /= fontScale.X; } offsetAlignment = -textRegionSize.X / 2f; if (editText.TextAlignment != TextAlignment.Left) { var textWidth = font.MeasureString(editText.TextToDisplay, ref fontSize).X; if (font.IsDynamic) textWidth /= fontScale.X; offsetAlignment = editText.TextAlignment == TextAlignment.Center ? -textWidth / 2 : -textRegionSize.X / 2f + (textRegionSize.X - textWidth); } var selectionWorldMatrix = element.WorldMatrixInternal; selectionWorldMatrix.M41 += offsetTextStart + selectionSize / 2 + offsetAlignment; var selectionScaleVector = new Vector3(selectionSize, editText.LineCount * editText.Font.GetTotalLineSpacing(editText.TextSize), 0); Batch.DrawRectangle(ref selectionWorldMatrix, ref selectionScaleVector, ref selectionColor, context.DepthBias + 1); } // create the text draw command var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = editText.RenderOpacity * editText.TextColor, DepthBias = context.DepthBias + 2, FontScale = fontScale, FontSize = editText.TextSize, Batch = Batch, SnapText = context.ShouldSnapText && !editText.DoNotSnapText, Matrix = editText.WorldMatrixInternal, Alignment = editText.TextAlignment, Size = textRegionSize }; // Draw the text Batch.DrawString(font, editText.TextToDisplay, ref drawCommand); // Draw the cursor if (editText.IsCaretVisible) { var sizeCaret = editText.CaretWidth / fontScale.X; var caretWorldMatrix = element.WorldMatrixInternal; caretWorldMatrix.M41 += offsetTextStart + offsetAlignment + (editText.CaretPosition > editText.SelectionStart? selectionSize: 0); var caretScaleVector = new Vector3(sizeCaret, editText.LineCount * editText.Font.GetTotalLineSpacing(editText.TextSize), 0); Batch.DrawRectangle(ref caretWorldMatrix, ref caretScaleVector, ref caretColor, context.DepthBias + 3); } }
public override void RenderColor(UIElement element, UIRenderingContext context) { base.RenderColor(element, context); Vector3 offsets; Vector3 borderSize; var border = (Border)element; var borderThickness = border.BorderThickness; var elementHalfBorders = borderThickness / 2; var elementSize = element.RenderSizeInternal; var elementHalfSize = elementSize / 2; // left/front offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, 0, -elementHalfSize.Z + elementHalfBorders.Front); borderSize = new Vector3(borderThickness.Left, elementSize.Y, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // right/front offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, 0, -elementHalfSize.Z + elementHalfBorders.Front); borderSize = new Vector3(borderThickness.Right, elementSize.Y, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // top/front offsets = new Vector3(0, -elementHalfSize.Y + elementHalfBorders.Top, -elementHalfSize.Z + elementHalfBorders.Front); borderSize = new Vector3(elementSize.X, borderThickness.Top, borderThickness.Front); DrawBorder(border, ref offsets, ref borderSize, context); // bottom/front offsets = new Vector3(0, elementHalfSize.Y - elementHalfBorders.Bottom, -elementHalfSize.Z + elementHalfBorders.Front); borderSize = new Vector3(elementSize.X, borderThickness.Bottom, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // if the element is 3D draw the extra borders if (element.ActualDepth > MathUtil.ZeroTolerance) { // left/back offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, 0, elementHalfSize.Z - elementHalfBorders.Back); borderSize = new Vector3(borderThickness.Left, elementSize.Y, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // right/back offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, 0, elementHalfSize.Z - elementHalfBorders.Back); borderSize = new Vector3(borderThickness.Right, elementSize.Y, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // top/back offsets = new Vector3(0, -elementHalfSize.Y + elementHalfBorders.Top, elementHalfSize.Z - elementHalfBorders.Back); borderSize = new Vector3(elementSize.X, borderThickness.Top, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // bottom/back offsets = new Vector3(0, elementHalfSize.Y - elementHalfBorders.Bottom, elementHalfSize.Z - elementHalfBorders.Back); borderSize = new Vector3(elementSize.X, borderThickness.Bottom, borderThickness.Back); DrawBorder(border, ref offsets, ref borderSize, context); // left/top offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, -elementHalfSize.Y + elementHalfBorders.Top, 0); borderSize = new Vector3(borderThickness.Left, borderThickness.Top, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // right/top offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, -elementHalfSize.Y + elementHalfBorders.Top, 0); borderSize = new Vector3(borderThickness.Right, borderThickness.Top, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // left/bottom offsets = new Vector3(-elementHalfSize.X + elementHalfBorders.Left, elementHalfSize.Y - elementHalfBorders.Bottom, 0); borderSize = new Vector3(borderThickness.Left, borderThickness.Bottom, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); // right/bottom offsets = new Vector3(elementHalfSize.X - elementHalfBorders.Right, elementHalfSize.Y - elementHalfBorders.Bottom, 0); borderSize = new Vector3(borderThickness.Right, borderThickness.Bottom, elementSize.Z); DrawBorder(border, ref offsets, ref borderSize, context); } }