Download

Using FSlateLayoutTransform

I’ve been wanting to draw custom boxes using FSlateDrawElement::DrawBox(). Nevertheless, the previous way of passing paint geometry PaintContext.AllottedGeometry.ToPaintGeometry(FVector2D, FVector2D) has been deprecated and no longer compiles (which is a bit strange given the WidgetBlueprintLibrary does it this way, but anyhow…). In other words, a function like this no longer compiles:

void UMyWidget::DrawCustomBox(FPaintContext& PaintContext, class USlateBrushAsset* Brush, FVector2D Size, FVector2D Position)
{
        PaintContext.MaxLayer++;
		FSlateDrawElement::MakeBox(
			PaintContext.OutDrawElements,
			PaintContext.MaxLayer,
			PaintContext.AllottedGeometry.ToPaintGeometry(Position, Size),
			&Brush->Brush,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
}

Instead, I imagine I would require something which looks like this:

void UMyWidget::DrawCustomBox(FPaintContext& PaintContext, class USlateBrushAsset* Brush, FVector2D Size, FVector2D Position)
{
        FSlateLayoutTransform SlateLayoutTransform(??); // What goes here? 
        PaintContext.MaxLayer++;
		FSlateDrawElement::MakeBox(
			PaintContext.OutDrawElements,
			PaintContext.MaxLayer,
			PaintContext.AllottedGeometry.ToPaintGeometry(SlateLayoutTransform),
			&Brush->Brush,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
}

In other words, how do you construct a FSlateLayoutTransform from a position and a size? It wants a translation and a scale. I’m assuming that the translation = position, but the scale is a float… so I’m assuming we’re working with transform matrices. Would I have to set the TransformVector afterward to multiply the scale by my desired X/Y box size?