I want to make a grid via OnPaint.
I’m currently working on a plugin for learning and i have trouble finding tutorials. Like any tutorials^^…
I’m not talking about the Blueprints Version, i want to override it for a Custom Asset. My Goal is to make a grid which dynamicly resizes when changing width and height, on which i can draw with mouse over. Something like a Binary Draw Editor. I don’t really know how OnPaint works at all, so anything would be helpfull.
Thanks for any help in advance. Code is below & Editor tab is just a white screen.
Have a good day!
.H
DECLARE_DELEGATE_OneParam(FOnChangedWidth,uint8)
DECLARE_DELEGATE_OneParam(FOnChangedHeight,uint8)
class DUNGEONCREATOREDITOR_API SDungeonRoomBrushWidget : public SCompoundWidget
{
public:
SLATE_BEGIN_ARGS(SDungeonRoomBrushWidget)
: _BrushWidth(12)
, _BrushHeight(12)
{}
SLATE_ATTRIBUTE(uint8, BrushWidth)
SLATE_ATTRIBUTE(uint8, BrushHeight)
SLATE_EVENT(FOnChangedWidth,OnChangedWidth)
SLATE_EVENT(FOnChangedHeight,OnChangedHeight)
SLATE_END_ARGS()
void Construct(const FArguments& InArgs);
int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const override;
private:
TAttribute<uint8> BrushWidth;
TAttribute<uint8> BrushHeight;
FOnChangedHeight OnChangedHeight;
FOnChangedWidth OnChangedWidth;
};
.CPP
void SDungeonRoomBrushWidget::Construct(const FArguments& InArgs)
{
BrushWidth = InArgs._BrushWidth;
BrushHeight = InArgs._BrushHeight;
OnChangedWidth = InArgs._OnChangedWidth;
OnChangedHeight = InArgs._OnChangedHeight;
}
int32 SDungeonRoomBrushWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled) const
{
for(uint8 x = 0; x < BrushWidth.Get(); x++){
for(uint8 y = 0; y < BrushHeight.Get(); y++){
FSlateBrush* Rect = new FSlateBrush();
Rect->OutlineSettings.Width = 1;
Rect->DrawAs = ESlateBrushDrawType::Box;
Rect->TintColor = FColor().FromHex("#626665");
Rect->Margin = FMargin(10,10,0,0);
FSlateDrawElement::MakeBox(OutDrawElements,LayerId,AllottedGeometry.ToPaintGeometry(),Rect);
}
}
return LayerId;
}