Пример #1
0
        /// <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;
        }
Пример #2
0
        private void RenderSelection(EditText editText, UIRenderingContext context, int start, int length, Color color, out float offsetTextStart, out float offsetAlignment, out float selectionSize)
        {
            // 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;

            // determine the image to draw in background of the edit text
            var fontScale = editText.LayoutingContext.RealVirtualResolutionRatio;
            var provider  = editText.IsSelectionActive ? editText.ActiveImage : editText.MouseOverState == MouseOverState.MouseOverElement ? editText.MouseOverImage : editText.InactiveImage;
            var image     = provider?.GetSprite();

            var fontSize = new Vector2(fontScale.Y * editText.ActualTextSize);

            offsetTextStart = font.MeasureString(editText.TextToDisplay, ref fontSize, start).X;
            selectionSize   = font.MeasureString(editText.TextToDisplay, ref fontSize, start + length).X - offsetTextStart;
            var lineSpacing = font.GetTotalLineSpacing(editText.ActualTextSize);

            if (font.FontType == SpriteFontType.Dynamic)
            {
                offsetTextStart /= fontScale.X;
                selectionSize   /= fontScale.X;
            }

            var scaleRatio = editText.ActualTextSize / font.Size;

            if (font.FontType == SpriteFontType.SDF)
            {
                offsetTextStart *= scaleRatio;
                selectionSize   *= scaleRatio;
                lineSpacing     *= editText.ActualTextSize / font.Size;
            }


            offsetAlignment = -textRegionSize.X / 2f;
            if (editText.TextAlignment != TextAlignment.Left)
            {
                var textWidth = font.MeasureString(editText.TextToDisplay, ref fontSize).X;
                if (font.FontType == SpriteFontType.Dynamic)
                {
                    textWidth /= fontScale.X;
                }
                if (font.FontType == SpriteFontType.SDF)
                {
                    textWidth *= scaleRatio;
                }

                offsetAlignment = editText.TextAlignment == TextAlignment.Center ? -textWidth / 2 : -textRegionSize.X / 2f + (textRegionSize.X - textWidth);
            }

            var selectionWorldMatrix = editText.WorldMatrixInternal;

            selectionWorldMatrix.M41 += offsetTextStart + selectionSize / 2 + offsetAlignment;
            var selectionScaleVector = new Vector3(selectionSize, editText.LineCount * lineSpacing, 0);

            Batch.DrawRectangle(ref selectionWorldMatrix, ref selectionScaleVector, ref color, context.DepthBias + 1);
        }
Пример #3
0
        public override void RenderColor(UIElement element, UIRenderingContext context)
        {
            base.RenderColor(element, context);

            var htmlControl = (HtmlControl)element;

            if (htmlControl == null)
            {
                return;
            }

            if (htmlControl.SessionGuid == Guid.Empty && !string.IsNullOrEmpty(htmlControl.Url))
            {
                htmlControl.SessionGuid = Guid.NewGuid();
                uint width  = (uint)context.Resolution.X;
                uint height = (uint)context.Resolution.Y;

                UltralightThreaded.CreateSession(htmlControl.SessionGuid, width, height);
                UltralightThreaded.LoadUrl(htmlControl.SessionGuid, htmlControl.Url);
                htmlControl.InitSession();
            }

            if (!UltralightThreaded.IsSessionReady(htmlControl.SessionGuid))
            {
                return;
            }

            var view = UltralightThreaded.GetSessionView(htmlControl.SessionGuid);

            if (view == null)
            {
                return;
            }

            var cachedTexture = htmlControl.GetCacheTexture(view, GraphicsDevice, context.GraphicsContext);

            if (cachedTexture != null)
            {
                var sourceRect = new RectangleF(0, 0, cachedTexture.Width, cachedTexture.Height);

                var colorTint   = Color.White;
                var worldMatrix = element.WorldMatrix;
                var renderSize  = element.RenderSize;
                var borderSize  = Vector4.Zero;

                Batch.DrawImage(cachedTexture, ref worldMatrix, ref sourceRect,
                                ref renderSize, ref borderSize,
                                ref colorTint, context.DepthBias, ImageOrientation.AsIs);
            }
        }
Пример #4
0
        public override void RenderColor(UIElement element, UIRenderingContext context)
        {
            base.RenderColor(element, context);

            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);
        }
Пример #5
0
        /// <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.RenderOpacity * 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;
        }
Пример #6
0
        public override void RenderColor(UIElement element, UIRenderingContext context)
        {
            base.RenderColor(element, context);

            var decorator = (ContentDecorator)element;
            var sprite    = decorator.BackgroundImage?.GetSprite();

            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);
        }
Пример #7
0
        public override void RenderColor(UIElement element, UIRenderingContext context)
        {
            base.RenderColor(element, context);

            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)
        {
            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 (var 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);
        }
Пример #9
0
        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(context.GraphicsContext, ref context.ViewProjectionMatrix, 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(context.GraphicsContext, ref context.ViewProjectionMatrix, BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue);

            context.DepthBias += 1;

            base.RenderColor(element, context);
        }
Пример #10
0
        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,
                RealVirtualResolutionRatio = element.LayoutingContext.RealVirtualResolutionRatio,
                RequestedFontSize          = textBlock.ActualTextSize,
                Batch       = Batch,
                SnapText    = context.ShouldSnapText && !textBlock.DoNotSnapText,
                Matrix      = textBlock.WorldMatrixInternal,
                Alignment   = textBlock.TextAlignment,
                TextBoxSize = new Vector2(textBlock.ActualWidth, textBlock.ActualHeight)
            };

            if (textBlock.Font.FontType == SpriteFontType.SDF)
            {
                Batch.End();

                Batch.BeginCustom(context.GraphicsContext, 1);
            }

            Batch.DrawString(textBlock.Font, textBlock.TextToDisplay, ref drawCommand);

            if (textBlock.Font.FontType == SpriteFontType.SDF)
            {
                Batch.End();

                Batch.BeginCustom(context.GraphicsContext, 0);
            }
        }
Пример #11
0
        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,
                RealVirtualResolutionRatio = element.LayoutingContext.RealVirtualResolutionRatio,
                RequestedFontSize          = scrollingText.ActualTextSize,
                Batch       = Batch,
                SnapText    = context.ShouldSnapText && !scrollingText.DoNotSnapText,
                Matrix      = textWorldMatrix,
                Alignment   = TextAlignment.Left,
                TextBoxSize = new Vector2(scrollingText.ActualWidth, scrollingText.ActualHeight)
            };

            // flush the current content of the UI image batch
            Batch.End();

            // draw a clipping mask
            Batch.Begin(context.GraphicsContext, ref context.ViewProjectionMatrix, 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(context.GraphicsContext, ref context.ViewProjectionMatrix, BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue + 1);
            if (scrollingText.Font.FontType == SpriteFontType.SDF)
            {
                Batch.End();

                Batch.BeginCustom(context.GraphicsContext, 1);
            }

            Batch.DrawString(scrollingText.Font, scrollingText.TextToDisplay, ref drawCommand);
            Batch.End();

            // un-draw the clipping mask
            Batch.Begin(context.GraphicsContext, ref context.ViewProjectionMatrix, 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(context.GraphicsContext, ref context.ViewProjectionMatrix, BlendStates.AlphaBlend, KeepStencilValueState, context.StencilTestReferenceValue);
        }
Пример #12
0
        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 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);
            }
            // 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);
            }

            // 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.SDF)
                {
                    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);
            }
        }
Пример #13
0
        public override void RenderColor(UIElement element, UIRenderingContext context)
        {
            base.RenderColor(element, context);

            Vector3 offsets;
            Vector3 borderSize;

            var border = (Border)element;

            var borderColor = border.RenderOpacity * border.BorderColorInternal;

            // optimization: don't draw the border if transparent
            if (borderColor == new Color())
            {
                return;
            }

            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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, 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, ref borderColor, context);
            }
        }
Пример #14
0
        private void DrawBorder(Border border, ref Vector3 offsets, ref Vector3 borderSize, ref Color borderColor, 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 borderColor, context.DepthBias);
        }
Пример #15
0
        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     = 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();
            var trackIdealSize = image != null ? new Vector2?(image.SizeInPixels) : null;

            // 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);

                Batch.DrawImage(image.Texture, 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?.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] = 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) + (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);

                Batch.DrawImage(image.Texture, ref worldMatrix, ref region, ref size, ref borders, ref color, 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]      = 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 (var i = 0; i < slider.TickFrequency + 1; i++)
                {
                    Batch.DrawImage(image.Texture, 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)?.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]      = 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, ref worldMatrix, ref image.RegionInternal, ref size, ref image.BordersInternal, ref color, context.DepthBias, imageOrientation);

                context.DepthBias += 1;
            }
        }