Download

Drawing a filled widget & shape

Something about this just doesn’t seem right…
Here’s how I’m drawing a filled rect:


    SMyView::SMyView() {
        myBrush = new FSlateImageBrush(
            TEXT(""),
            FVector2D(32, 32),
            FSlateColor(FColor::Red),
            ESlateBrushTileType::NoTile,
            ESlateBrushImageType::NoImage
        );
        myBrush->Margin = FMargin(0);
        myBrush->DrawAs = ESlateBrushDrawType::Image;
    }

    int32 SMyView::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry,
        const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements,
        int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const {
        //...
        FVector2D Size = FVector2D(
            rect.Max.X - rect.Min.X,
            rect.Max.Y - rect.Min.Y
        );
        FPaintGeometry PaintGeom = AllottedGeometry.ToPaintGeometry(rect.Min + DrawOffset, Size, DrawScale);
        FSlateDrawElement::MakeBox(OutDrawElements, LayerId, PaintGeom, myBrush, ESlateDrawEffect::None, myBrush->TintColor.GetSpecifiedColor());
        //...
    }

What’s the purpose of supplying the brush AND the tint color, when the brush itself already has this information? If I don’t supply the full list of arguments in FSlateDrawElement::MakeBox, then I just get a white box (regardless of the brush data)… Also, why is the tint color even a main factor? Shouldn’t it just be an “additive color”, like it is in UMG (ie, foreground color is red, tint color is blue, so color becomes magenta)?

And then there’s this:


    auto newTab = SNew(SDockTab)
        .TabRole(ETabRole::NomadTab)
        
            SNew(SBox)
            .HAlign(HAlign_Fill)
            .VAlign(VAlign_Fill)
            .Visibility(EVisibility::SelfHitTestInvisible)
            
                SNew(SSplitter)
                .Orientation(EOrientation::Orient_Horizontal)
                .ResizeMode(ESplitterResizeMode::Fill)
                .Visibility(EVisibility::Visible)
                + SSplitter::Slot()
                
                    SNew(SBox)
                    .HAlign(HAlign_Fill)
                    .VAlign(VAlign_Fill)
                    .Visibility(EVisibility::SelfHitTestInvisible)
                    
                        SNew(SMyView)
                        .Visibility(EVisibility::Visible)
                    ]
                ]
                + SSplitter::Slot()
                
                    SNew(SBorder)
                    .HAlign(HAlign_Fill)
                    .VAlign(VAlign_Fill)
                    .ColorAndOpacity(FLinearColor(0.f, 1.f, 0.f, 1.f))
                    .ForegroundColor(FSlateColor(FLinearColor(0.f, 1.f, 0.f, 1.f)))
                    .BorderBackgroundColor(FSlateColor(FLinearColor(0.f, 1.f, 0.f, 1.f)))
                    .Visibility(EVisibility::Visible)
                    .Content()
                    
                        SNew(SBox)
                        .HAlign(HAlign_Fill)
                        .VAlign(VAlign_Fill)
                        .Visibility(EVisibility::Visible)
                    ]
                ]
            ]
        ];

Which produces the following image:
SlateIssues.png

What am I doing wrong? All I want to do is draw color-filled widgets and rects.
I figured this would be basic functionality in Slate, but maybe I’m missing something.