public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); var button = (Button)element; var sprite = button.ButtonImage; if (sprite?.Texture == null) { return; } var color = element.RenderOpacity * Color.White; Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); var toggleButton = (ToggleButton)element; var sprite = GetToggleStateImage(toggleButton); if (sprite?.Texture == null) { return; } var color = new Color4(toggleButton.RenderOpacity); Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); var decorator = (ContentDecorator)element; var sprite = decorator.BackgroundImage?.GetSprite(); if (sprite?.Texture == null) { return; } var color = new Color4(element.RenderOpacity); Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); var image = (ImageElement)element; var sprite = image.Source?.GetSprite(); if (sprite?.Texture == null) { return; } var color = element.RenderOpacity * image.Color; Batch.DrawImage(sprite.Texture, ref element.WorldMatrixInternal, ref sprite.RegionInternal, ref element.RenderSizeInternal, ref sprite.BordersInternal, ref color, context.DepthBias, sprite.Orientation); }
public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); 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 provider = editText.IsSelectionActive ? editText.ActiveImage : editText.MouseOverState == MouseOverState.MouseOverElement ? editText.MouseOverImage : editText.InactiveImage; var image = provider?.GetSprite(); if (image?.Texture != null) { Batch.DrawImage(image.Texture, 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 caretColor = editText.RenderOpacity * editText.CaretColor; var offsetTextStart = 0f; var offsetAlignment = 0f; var selectionSize = 0f; // Draw the composition selection if (editText.Composition.Length > 0) { var imeSelectionColor = editText.RenderOpacity * editText.IMESelectionColor; RenderSelection(editText, context, editText.SelectionStart, editText.Composition.Length, imeSelectionColor, out offsetTextStart, out offsetAlignment, out selectionSize, Batch); } // Draw the regular selection else if (editText.IsSelectionActive) { var selectionColor = editText.RenderOpacity * editText.SelectionColor; RenderSelection(editText, context, editText.SelectionStart, editText.SelectionLength, selectionColor, out offsetTextStart, out offsetAlignment, out selectionSize, Batch); } // create the text draw command var drawCommand = new SpriteFont.InternalUIDrawCommand { Color = editText.RenderOpacity * editText.TextColor, DepthBias = context.DepthBias + 2, RealVirtualResolutionRatio = fontScale, RequestedFontSize = editText.ActualTextSize, Batch = Batch, SnapText = context.ShouldSnapText && !editText.DoNotSnapText, Matrix = editText.WorldMatrixInternal, Alignment = editText.TextAlignment, TextBoxSize = textRegionSize }; if (editText.Font.FontType == SpriteFontType.SDF) { Batch.End(); Batch.BeginCustom(context.GraphicsContext, 1); } // Draw the text Batch.DrawString(font, editText.TextToDisplay, ref drawCommand); if (editText.Font.FontType == SpriteFontType.SDF) { Batch.End(); Batch.BeginCustom(context.GraphicsContext, 0); } // Draw the cursor if (editText.IsCaretVisible) { var lineSpacing = editText.Font.GetTotalLineSpacing(editText.ActualTextSize); if (editText.Font.FontType != SpriteFontType.Dynamic) { lineSpacing *= editText.ActualTextSize / font.Size; } 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 * lineSpacing, 0); Batch.DrawRectangle(ref caretWorldMatrix, ref caretScaleVector, ref caretColor, context.DepthBias + 3); } }
public override void RenderColor(UIElement element, UIRenderingContext context, UIBatch Batch) { base.RenderColor(element, context, Batch); 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 isGaugeReverted = axis == 1 ? !slider.IsDirectionReversed : slider.IsDirectionReversed; // we want the track going up from the bottom in vertical mode by default var sliderRatio = MathUtil.InverseLerp(slider.Minimum, slider.Maximum, slider.Value); var trackOffsets = new Vector2(slider.TrackStartingOffsets[axis], slider.TrackStartingOffsets[axisPrime]); var fullGaugeSize = slider.RenderSizeInternal[axis] - trackOffsets.X - trackOffsets.Y; var image = slider.TrackBackgroundImage?.GetSprite(); // draws the track background if (image?.Texture != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var worldMatrix = GetAdjustedWorldMatrix(ref slider.WorldMatrixInternal, (axis & imageAxis) == 1); Color tbt = slider.TrackBackgroundTint * slider.RenderOpacity; Batch.DrawImage(image.Texture, ref worldMatrix, ref image.RegionInternal, ref slider.RenderSizeInternal, ref image.BordersInternal, ref tbt, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draw the track foreground image = slider.TrackForegroundImage?.GetSprite(); if (image?.Texture != 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] = slider.TrackForegroundHeightScale * slider.RenderSizeInternal[axisPrime]; 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) + (slider.IsDirectionReversed? 2 : 0); var borderStopIndex = (imageAxis) + (slider.IsDirectionReversed ? 0 : 2); 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); Color tft = slider.TrackForegroundTint * slider.RenderOpacity; Batch.DrawImage(image.Texture, ref worldMatrix, ref region, ref size, ref borders, ref tft, context.DepthBias, imageOrientation); context.DepthBias += 1; } // draws the ticks image = slider.TickImage?.GetSprite(); if (slider.AreTicksDisplayed && image?.Texture != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = slider.RenderSizeInternal[axis] * slider.TickWidthScale; size[axisPrime] = slider.RenderSizeInternal[axisPrime] * slider.TickHeightScale; var startOffset = new Vector2(GetAdjustedTranslation(slider.TickOffset, shouldRotate180Degrees)); startOffset[axis] = GetAdjustedTranslation(-fullGaugeSize / 2, shouldRotate180Degrees); 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]; Color tclr = slider.TickTint * slider.RenderOpacity; for (var i = 0; i < slider.TickFrequency + 1; i++) { Batch.DrawImage(image.Texture, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref tclr, 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)?.GetSprite(); if (image?.Texture != null) { var imageAxis = (int)image.Orientation; var imageOrientation = (ImageOrientation)(axis ^ imageAxis); var shouldRotate180Degrees = (axis & imageAxis) == 1; var size = new Vector3(); size[axis] = slider.RenderSizeInternal[axis] * slider.ThumbWidthScale; size[axisPrime] = slider.RenderSizeInternal[axisPrime] * slider.ThumbHeightScale; 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]; Color tc = slider.ThumbTint * slider.RenderOpacity; Batch.DrawImage(image.Texture, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref tc, context.DepthBias, imageOrientation); context.DepthBias += 1; } }