Creating a SlateBoxBrush

Hi,

I am trying to create a boxbrush in slate. But I can’t find anything on creating the brush.

How to link the images and how to set which image is which margin. Can any one link me any example on creating a slate brush?

Not 100% sure if this helps you but I am drawing pictures in my plugin like this :

in my SMyPluginHelper::Construct()

I use this slate syntax to place my picture


// Picture
SNew(SImage)
.Image(this, &SMyHelper::GetMyPictureBrush)

where this is how I define my c++ code associated with the brush


const FSlateBrush* SMyHelper::GetMyPictureBrush() const
{
	return FMyPlugin_PluginStyle::Get().GetBrush(TEXT("myPicture"));
}

class FMyPlugin_PluginStyle 
{
public:
	static void Initialize();
	static void Shutdown();

	static const ISlateStyle& Get();

private:
	static TSharedPtr<class ISlateStyle> StylePtr;
};

#define IMAGE_BRUSH(RelativePath, ...)	FSlateImageBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define BOX_BRUSH(RelativePath, ...)	FSlateBoxBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define BORDER_BRUSH(RelativePath, ...) FSlateBorderBrush(Style->RootToContentDir(RelativePath, TEXT(".png")), __VA_ARGS__)
#define TTF_FONT(RelativePath, ...)		FSlateFontInfo(Style->RootToContentDir(RelativePath, TEXT(".ttf")), __VA_ARGS__)
#define OTF_FONT(RelativePath, ...)		FSlateFontInfo(Style->RootToContentDir(RelativePath, TEXT(".otf")), __VA_ARGS__)

TSharedPtr<ISlateStyle> CreateStyle()
{
	TSharedPtr<FSlateStyleSet> Style = MakeShareable(new FSlateStyleSet("MyPlugin_PluginStyle"));
	Style->SetContentRoot(FPaths::GamePluginsDir() / "MyPluginHelper" / "Content"/ "Slate");

	Style->Set("myPicture", new IMAGE_BRUSH("myPicture", FVector2D(120, 120)));

       //add any pictures you want here
       //Style->Set(.........)

	return Style;
}

#undef IMAGE_BRUSH
#undef BOX_BRUSH
#undef BORDER_BRUSH
#undef TTF_FONT
#undef OTF_FONT

TSharedPtr<ISlateStyle> FMyPlugin_PluginStyle::StylePtr;

void FMyPlugin_PluginStyle::Initialize()
{
	check(!StylePtr.IsValid());

	StylePtr = CreateStyle();
	FSlateStyleRegistry::RegisterSlateStyle(*StylePtr);
}

void FMyPlugin_PluginStyle::Shutdown()
{
	check(StylePtr.IsUnique());

	FSlateStyleRegistry::UnRegisterSlateStyle(*StylePtr);
	StylePtr.Reset();
}

const ISlateStyle& FMyPlugin_PluginStyle::Get()
{
	return *StylePtr;
}

make sure your pictures are in (or any other relevant directory in case you aren’t writing a plugin it might be your game content folder


(FPaths::GamePluginsDir() / "MyPluginHelper" / "Content"/ "Slate");

hope this helps,

please ask if you need more info

Chrys