UE4/UE5 c++绘制编辑器场景直方图(源码包含场景中的像素获取、菜单添加ToolBar)

UE4/UE5 c++场景直方图

    • UE4/UE5 C++绘制编辑器场景直方图
    • 绘制原理:
      • 元素绘制
      • 坐标轴绘制
    • 源码处理

UE4/UE5 C++绘制编辑器场景直方图

注:源码包含场景中的像素获取、菜单添加ToolBar

实现效果
在这里插入图片描述

在这里插入图片描述

这个是用于美术统计场景中像素元素分布,类似于PS里面的直方图,比如,R值是255的像素,场景中的个数是1000个,那么就是(255,1000)。

绘制原理:

元素绘制

根据不同高度绘制了不同的Box
在这里插入图片描述

坐标轴绘制

箭头,一段段的标尺,坐标轴,均由绘制线构成

源码处理

首先创建一个Editor模块:
创建SCompoundWidget:
.h

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once
#include "CoreMinimal.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
#include "Widgets/SCompoundWidget.h"

/**
 * 
 */
class SLASHEDITOR_API SPixHistogramWidget : public SCompoundWidget
{
public:
	SLATE_BEGIN_ARGS(SPixHistogramWidget)
		{
		}

	SLATE_END_ARGS()
	virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
	virtual int32 OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyCullingRect,
	                      FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle,
	                      bool bParentEnabled) const override;
	virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
	virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;
	virtual FReply OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;
	virtual void OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
	void DrawPixelOnScreen(const TMap<int, float>& InData, const float InBarWidth,const float InBarGap,
											const FGeometry& InAllottedGeometry, FSlateWindowElementList& InOutDrawElements,
											const int32 InLayerId,const FVector2D InEdgeSize,const FLinearColor InColor) const;
	virtual bool SupportsKeyboardFocus() const override;

	void SelectionChanged(TSharedPtr<FString> NewSelection, ESelectInfo::Type SelectInfo);
	void GetScreenPixelValue();
	void RefreshData();
	void ResetMap();
	void OnScalingFactorChanged(float InScalingFactor);

	/** Constructs this widget with InArgs */
	void Construct(const FArguments& InArgs);

private:  
	TArray<TSharedPtr<FString>> Pass;
	int CurrentIndex = 0;
	FVector2D LinearScale = FVector2D(3.f, 3.f);
	FVector2D BottomSize = FVector2D(40.f,40.f);
	float HeightScale = 1.f;
	const float HeightScalingFactor = 500;
	TArray<FColor> PixelsColor;
	TMap<int,float> GrayData;
	TMap<int,float> RData;
	TMap<int,float> GData;
	TMap<int,float> BData;
	bool IsCtrlDown = false;
	float ScalingFactor = 5.f;
};

.cpp

// Fill out your copyright notice in the Description page of Project Settings.


#include "PixHistogramWidget.h"

#include "Editor.h"
#include "SlateOptMacros.h"
#include "Widgets/Input/SComboBox.h"
#include "Widgets/Input/SSpinBox.h"
#include "Widgets/Input/STextComboBox.h"

BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION

#define LOCTEXT_NAMESPACE "PixHistogramWidget"


void SPixHistogramWidget::Construct(const FArguments& InArgs)
{
	PixelsColor.Init(FColor::White, 65535);
	ResetMap();
	Pass.Empty();
	CurrentIndex = 0;
	Pass = {
		MakeShared<FString>("R"),
		MakeShared<FString>("G"),
		MakeShared<FString>("B"),
		MakeShared<FString>("Gray"),
		MakeShared<FString>("RGB"),
		MakeShared<FString>("RGB And Gray")
	};

	ChildSlot
	[

		SNew(SBox)
		  .WidthOverride(500)
		  .HeightOverride(200)
		  .HAlign(HAlign_Left)
		  .VAlign(VAlign_Bottom)
		  .Padding(FMargin(0, -200, 0, 0))
		[
			SNew(SHorizontalBox)
			+ SHorizontalBox::Slot()
			  .AutoWidth()
			  .VAlign(VAlign_Top)
			[
				SNew(STextComboBox)
				.InitiallySelectedItem(Pass[CurrentIndex])
				.OptionsSource(&Pass)
				.OnSelectionChanged(this, &SPixHistogramWidget::SelectionChanged)
			]
			+ SHorizontalBox::Slot()
			  .AutoWidth()
			  .VAlign(VAlign_Center)
			  .Padding(20, 0, 0, 0)
			[
				SNew(STextBlock)
				.Text(FText::FromString(TEXT("scale speed:")))
			]
			+ SHorizontalBox::Slot()
			  .AutoWidth()
			  .VAlign(VAlign_Center)
			[
				SNew(SSpinBox<float>)
				.Value(ScalingFactor)
				.MinValue(0.0f)
				.MaxValue(100.0f)
				.OnValueChanged(this, &SPixHistogramWidget::OnScalingFactorChanged)
			]
		]
	];
	bCanSupportFocus = true;
}

void SPixHistogramWidget::SelectionChanged(TSharedPtr<FString> NewSelection, ESelectInfo::Type SelectInfo)
{
	CurrentIndex = Pass.Find(NewSelection);
}

void SPixHistogramWidget::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
	SCompoundWidget::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
	RefreshData();
}

int32 SPixHistogramWidget::OnPaint(const FPaintArgs& Args, const FGeometry& AllottedGeometry,
                                   const FSlateRect& MyCullingRect,
                                   FSlateWindowElementList& OutDrawElements, int32 LayerId,
                                   const FWidgetStyle& InWidgetStyle,
                                   bool bParentEnabled) const
{
	const int32 NewLayerId = SCompoundWidget::OnPaint(Args, AllottedGeometry, MyCullingRect,
	                                                  OutDrawElements, LayerId, InWidgetStyle,
	                                                  bParentEnabled);

	const float BarWidth = 1.f * LinearScale.X;
	const float BarGap = 0.f * LinearScale.X;

	const FVector2D EdgeSize = FVector2D(0, 0);
	const FVector2D BackGroundSize = FVector2D((256 * LinearScale.X + EdgeSize.X * 2),
	                                           (100 * LinearScale.Y + EdgeSize.Y * 2));
	if (CurrentIndex == 0)
	{
		DrawPixelOnScreen(RData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Red);
	}
	else if (CurrentIndex == 1)
	{
		DrawPixelOnScreen(GData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Green);
	}
	else if (CurrentIndex == 2)
	{
		DrawPixelOnScreen(BData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Blue);
	}
	else if (CurrentIndex == 3)
	{
		DrawPixelOnScreen(GData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Gray);
	}
	else if (CurrentIndex == 4)
	{
		DrawPixelOnScreen(RData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Red);
		DrawPixelOnScreen(GData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Green);
		DrawPixelOnScreen(BData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Blue);
	}
	else if (CurrentIndex == 5)
	{
		DrawPixelOnScreen(RData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Red);
		DrawPixelOnScreen(GData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Green);
		DrawPixelOnScreen(BData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Blue);
		DrawPixelOnScreen(GrayData, BarWidth, BarGap,
		                  AllottedGeometry, OutDrawElements,
		                  LayerId, EdgeSize, FLinearColor::Gray);
	}
	//Background frame drawing
	FSlateDrawElement::MakeBox(
		OutDrawElements,
		LayerId + 10,
		AllottedGeometry.ToPaintGeometry(
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y), BackGroundSize),
		new FSlateBrush(),
		ESlateDrawEffect::None,
		FLinearColor(0, 0, 0, 0.3)
	);
	//X Axis ruler
	FLinearColor XColor = FLinearColor::White;
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BottomSize.Y),
			FVector2D(BottomSize.X + BackGroundSize.X + 20, AllottedGeometry.Size.Y - BottomSize.Y)
		},
		ESlateDrawEffect::None,
		XColor
	);
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X + BackGroundSize.X + 20, AllottedGeometry.Size.Y - BottomSize.Y),
			FVector2D(BottomSize.X + BackGroundSize.X + 10, AllottedGeometry.Size.Y - BottomSize.Y + 5)
		},
		ESlateDrawEffect::None,
		XColor
	);
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X + BackGroundSize.X + 20, AllottedGeometry.Size.Y - BottomSize.Y),
			FVector2D(BottomSize.X + BackGroundSize.X + 10, AllottedGeometry.Size.Y - BottomSize.Y - 5)
		},
		ESlateDrawEffect::None,
		XColor
	);
	//X Axis ruler
	int XDefaultSectionNum = FMath::Clamp<int>(8 * LinearScale.X, 2, 256);
	const FSlateFontInfo XCoordinateFont = FCoreStyle::GetDefaultFontStyle("Regular", 8);
	for (int i = 1; i <= XDefaultSectionNum; ++i)
	{
		FSlateDrawElement::MakeLines(
			OutDrawElements,
			LayerId + 12,
			AllottedGeometry.ToPaintGeometry(),
			TArray<FVector2D>{
				FVector2D(BottomSize.X + BackGroundSize.X / XDefaultSectionNum * i,
				          AllottedGeometry.Size.Y - BottomSize.Y),
				FVector2D(BottomSize.X + BackGroundSize.X / XDefaultSectionNum * i,
				          AllottedGeometry.Size.Y - BottomSize.Y - 3)
			},
			ESlateDrawEffect::None,
			XColor
		);
		FSlateDrawElement::MakeText(
			OutDrawElements,
			LayerId + 12,
			AllottedGeometry.ToPaintGeometry(
				FVector2D(BottomSize.X + BackGroundSize.X / XDefaultSectionNum * i,
				          AllottedGeometry.Size.Y - BottomSize.Y + 5),
				FVector2D(30, 30)),
			FString::FromInt(256 / XDefaultSectionNum * i - 1),
			XCoordinateFont,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
	}
	//Y Axis
	FLinearColor YColor = FLinearColor::White;
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BottomSize.Y),
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y - 20)
		},
		ESlateDrawEffect::None,
		YColor
	);
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y - 20),
			FVector2D(BottomSize.X - 5, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y - 10)
		},
		ESlateDrawEffect::None,
		YColor
	);
	FSlateDrawElement::MakeLines(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(),
		TArray<FVector2D>{
			FVector2D(BottomSize.X, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y - 20),
			FVector2D(BottomSize.X + 5, AllottedGeometry.Size.Y - BackGroundSize.Y - BottomSize.Y - 10)
		},
		ESlateDrawEffect::None,
		YColor
	);
	//Y Axis ruler
	int YDefaultSectionNum = FMath::Clamp<int>(5 * LinearScale.Y, 2, static_cast<int>(100 / HeightScale * HeightScalingFactor) - 1);
	
	const FSlateFontInfo YCoordinateFont = FCoreStyle::GetDefaultFontStyle("Regular", 8);
	for (int i = 1; i <= YDefaultSectionNum; ++i)
	{
		FSlateDrawElement::MakeLines(
			OutDrawElements,
			LayerId + 12,
			AllottedGeometry.ToPaintGeometry(),
			TArray<FVector2D>{
				FVector2D(BottomSize.X,
				          AllottedGeometry.Size.Y - BackGroundSize.Y / YDefaultSectionNum * i - BottomSize.Y),
				FVector2D(BottomSize.X + 3,
				          AllottedGeometry.Size.Y - BackGroundSize.Y / YDefaultSectionNum * i - BottomSize.Y)
			},
			ESlateDrawEffect::None,
			YColor
		);
		FSlateDrawElement::MakeText(
			OutDrawElements,
			LayerId + 12,
			AllottedGeometry.ToPaintGeometry(
				FVector2D(BottomSize.X + 5,
				          AllottedGeometry.Size.Y - BackGroundSize.Y / YDefaultSectionNum * i - BottomSize.Y),
				FVector2D(30, 30)),
			FString::FromInt(100 / HeightScale * HeightScalingFactor / YDefaultSectionNum * i),
			YCoordinateFont,
			ESlateDrawEffect::None,
			FLinearColor::White
		);
	}
	//Origin of coordinate
	const FSlateFontInfo CoordinateFont = FCoreStyle::GetDefaultFontStyle("Regular", 10);
	FSlateDrawElement::MakeText(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(FVector2D(BottomSize.X - 15, AllottedGeometry.Size.Y - BottomSize.Y),
		                                 FVector2D(30, 30)),
		FString(TEXT("O")),
		CoordinateFont,
		ESlateDrawEffect::None,
		FLinearColor::White
	);
	//X Axis labeling
	FSlateDrawElement::MakeText(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(
			FVector2D(BottomSize.X + BackGroundSize.X + 20, AllottedGeometry.Size.Y - BottomSize.Y - 15),
			FVector2D(30, 30)),
		FString(TEXT("Color Pass(0 ~ 255)")),
		CoordinateFont,
		ESlateDrawEffect::None,
		XColor
	);
	//Y Axis labeling
	FSlateDrawElement::MakeText(
		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(
			FVector2D(BottomSize.X + 5, AllottedGeometry.Size.Y - BottomSize.Y - BackGroundSize.Y - 20),
			FVector2D(30, 30)),
		FString(TEXT("Pixel Num")),
		CoordinateFont,
		ESlateDrawEffect::None,
		YColor
	);
	//Operation reminder
	const FSlateFontInfo TooltipsFontInfo = FCoreStyle::GetDefaultFontStyle("Regular", 15);
	FSlateDrawElement::MakeText(

		OutDrawElements,
		LayerId + 12,
		AllottedGeometry.ToPaintGeometry(
			FVector2D(AllottedGeometry.Size.X / 2 - 425, 0), FVector2D(30, 30)),
		FString(TEXT("Adjust the zoom with the mouse wheel. Press and hold Ctrl + mouse wheel to adjust the height.")),
		TooltipsFontInfo,
		ESlateDrawEffect::None,
		FLinearColor::White
	);

	return NewLayerId;
}

FReply SPixHistogramWidget::OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	const float ScrollDelta = MouseEvent.GetWheelDelta();
	const float TempScalingFactor = 1.f + ScalingFactor * 0.01f;
	if (IsCtrlDown)
	{
		if (ScrollDelta > 0)
		{
			HeightScale = HeightScale * TempScalingFactor;
		}
		else if (ScrollDelta < 0)
		{
			HeightScale = HeightScale / TempScalingFactor;
		}
	}
	else
	{
		if (ScrollDelta > 0)
		{
			LinearScale = LinearScale * TempScalingFactor;
		}
		else if (ScrollDelta < 0)
		{
			LinearScale = LinearScale / TempScalingFactor;
		}
	}
	return FReply::Handled();
}

FReply SPixHistogramWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
{
	IsCtrlDown = InKeyEvent.IsControlDown();
	return SCompoundWidget::OnKeyDown(MyGeometry, InKeyEvent);
}

FReply SPixHistogramWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent)
{
	IsCtrlDown = false;
	return SCompoundWidget::OnKeyUp(MyGeometry, InKeyEvent);
}

void SPixHistogramWidget::OnMouseEnter(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent)
{
	SCompoundWidget::OnMouseEnter(MyGeometry, MouseEvent);
	FSlateApplication::Get().SetKeyboardFocus(SharedThis(this), EFocusCause::OtherWidgetLostFocus);
}

void SPixHistogramWidget::DrawPixelOnScreen(const TMap<int, float>& InData, const float InBarWidth,
                                            const float InBarGap,
                                            const FGeometry& InAllottedGeometry,
                                            FSlateWindowElementList& InOutDrawElements,
                                            const int32 InLayerId, const FVector2D InEdgeSize,
                                            const FLinearColor InColor) const
{
	for (int i = 0; i < InData.Num(); ++i)
	{
		const float BarHeight = InData[i] * LinearScale.Y * HeightScale / HeightScalingFactor;
		FVector2D BarPosition(i * (InBarWidth + InBarGap) + InEdgeSize.X,
		                      InAllottedGeometry.Size.Y - BarHeight - InEdgeSize.Y);
		FVector2D BarSize(InBarWidth, BarHeight);

		FSlateDrawElement::MakeBox(
			InOutDrawElements,
			InLayerId,
			InAllottedGeometry.ToPaintGeometry(BarPosition + FVector2D(BottomSize.X, -BottomSize.Y), BarSize),
			new FSlateBrush(),
			ESlateDrawEffect::None,
			InColor
		);
	}
}

bool SPixHistogramWidget::SupportsKeyboardFocus() const
{
	return true;
}

void SPixHistogramWidget::GetScreenPixelValue()
{
	PixelsColor.Empty();
	FViewport* Viewport = GEditor->GetActiveViewport();
	Viewport->ReadPixels(PixelsColor);
}

void SPixHistogramWidget::RefreshData()
{
	GetScreenPixelValue();
	ResetMap();
	//float Gray = 0.299 * Color.R + 0.587 * Color.G + 0.114 * Color.B;
	for (const FColor Color : PixelsColor)
	{
		RData[Color.R] += 1;
		GData[Color.G] += 1;
		BData[Color.B] += 1;
		const int Index = FMath::Clamp<int>((0.299 * Color.R + 0.587 * Color.G + 0.114 * Color.B), 0, 255);
		GrayData[Index] += 1;
	}
}

void SPixHistogramWidget::ResetMap()
{
	GrayData.Empty();
	RData.Empty();
	GData.Empty();
	BData.Empty();
	for (int i = 0; i <= 255; ++i)
	{
		GrayData.Add(i, 0);
		RData.Add(i, 0);
		GData.Add(i, 0);
		BData.Add(i, 0);
	}
}

void SPixHistogramWidget::OnScalingFactorChanged(float InScalingFactor)
{
	ScalingFactor = InScalingFactor;
}

END_SLATE_FUNCTION_BUILD_OPTIMIZATION

Module添加内容:
.h

#pragma once

#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"

class FSlashEditorModule : public IModuleInterface
{
public:
    virtual void StartupModule() override;
    virtual void ShutdownModule() override;
    void AddProjectToolsMenu(FMenuBarBuilder& MenuBuilder);
    void FillProjectToolsMenu(FMenuBuilder& MenuBuilder);

private:
    TSharedRef<SDockTab> SpawnPixHistogramTab(const FSpawnTabArgs& Args);
    static TSharedRef<FWorkspaceItem> ProjectMenuRoot;

};

.cpp

#include "SlashEditor.h"

#include "LevelEditor.h"
#include "SlashEditorStyle.h"
#include "PixHistogram/PixHistogramWidget.h"

#define LOCTEXT_NAMESPACE "FSlashEditorModule"

TSharedRef<FWorkspaceItem> FSlashEditorModule::ProjectMenuRoot = FWorkspaceItem::NewGroup(
    FText::FromString("ProjectToolsRoot"));
void FSlashEditorModule::StartupModule()
{
    FSlashEditorStyle::Register();

    FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
    const TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
    MenuExtender->AddMenuBarExtension(
        "Help",
        EExtensionHook::Before,
        nullptr,
        FMenuBarExtensionDelegate::CreateRaw(this, &FSlashEditorModule::AddProjectToolsMenu));
    LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
    
	
    FGlobalTabmanager::Get()->RegisterNomadTabSpawner(FName("PixHistogramTab"),
                                                      FOnSpawnTab::CreateRaw(
                                                          this,
                                                          &FSlashEditorModule::SpawnPixHistogramTab))
                            .SetGroup(ProjectMenuRoot)
                            .SetDisplayName(FText::FromString(TEXT("PixHistogram")));
}

void FSlashEditorModule::ShutdownModule()
{
    FSlashEditorStyle::Unregister();
}

void FSlashEditorModule::AddProjectToolsMenu(FMenuBarBuilder& MenuBuilder)
{
    MenuBuilder.AddPullDownMenu(
        LOCTEXT("Menu", "Project Menu"),
        LOCTEXT("ToolTip", "Open project menu"),
        FNewMenuDelegate::CreateRaw(this, &FSlashEditorModule::FillProjectToolsMenu),
        FName(TEXT("Project Menu")),
        FName(TEXT("ProjectMenu")));
}

void FSlashEditorModule::FillProjectToolsMenu(FMenuBuilder& MenuBuilder)
{
    MenuBuilder.BeginSection("ProjectMenu", TAttribute<FText>(LOCTEXT("PixHistogramSectionName", "PixHistogram")));
    {
        FGlobalTabmanager::Get()->PopulateTabSpawnerMenu(MenuBuilder, FName("PixHistogramTab"));
    }
    MenuBuilder.EndSection();
}

TSharedRef<SDockTab> FSlashEditorModule::SpawnPixHistogramTab(const FSpawnTabArgs& Args)
{
    TSharedRef<SDockTab> SpawnedTab = SNew(SDockTab)
        .TabRole(ETabRole::NomadTab)
        [
            SNew(SPixHistogramWidget)
        ];
    return SpawnedTab;
}

#undef LOCTEXT_NAMESPACE
    
IMPLEMENT_MODULE(FSlashEditorModule, SlashEditor)

.Build.cs

            {
                "CoreUObject",
                "Engine",
                "Slate",
                "SlateCore", 
                "UMG",
                "InputCore"
            }

最后成功添加按钮,点击即可得到开头结果:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/194653.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【100个Cocos实例】编码不规范,接手泪两行...

点击上方亿元程序员关注和★星标。 引言 规范编码&#xff0c;从文件头部注释规范做起。 头部注释规范是一种在代码文件开头添加注释信息的做法&#xff0c;通常用于描述文件的基本信息、作者、创建日期、修改历史等。 这有助于团队成员更好地理解和维护代码。 本文将介绍一…

JVM执行引擎

目录 &#xff08;一&#xff09;执行引擎概述 &#xff08;二&#xff09;Java代码编译和执行过程 &#xff08;三&#xff09;机器码&#xff0c;指令&#xff0c;汇编语言&#xff0c;字节码 1、机器码 2、指令 3、指令集 4、汇编 5、字节码 &#xff08;四&#x…

一、Oceanbase基础

一、集群相关概念 集群&#xff1a;整个分布式数据库。Region&#xff1a;表示区域&#xff0c;是地域的逻辑概念&#xff0c;如1个城市&#xff0c;1个集群可以有多个Region&#xff0c;用于跨城市远 距离容灾。Zone&#xff1a;表示分区&#xff0c;是机房或机架的逻辑概念…

深度学习【二】

1.运行时错误 1.1 ModuleNotFoundError: No module named ‘torch_scatter’ 参考 https://blog.csdn.net/weixin_42421914/article/details/132875571 pip install --no-index torch-scatter -f https://pytorch-geometric.com/whl/torch-1.13.1%2Bcpu.html

某思路等考通一级MSOffice的分析

看到有朋友寻求2021版的等级考试一级软件&#xff0c;秉承授人以鱼不如授人以渔的理念&#xff0c;特写这个帖子。 某思路等考通一级MSOffice&#xff0c;版本6.5。 用到的软件&#xff0c;ScanId&#xff0c;de4dot,dnSpy。 第一步&#xff1a;分析 软件启动后有在线激活提示&…

华为云CDN刷新与查询余量的Go实现及在Jenkins中的部署

引言 在华为云上&#xff0c;对CDN缓存内容进行刷新是一个常见的需求&#xff0c;以确保最新的内容能尽快被用户访问到。通过使用Go语言&#xff0c;我们可以开发一个自动化的工具来实现这一需求&#xff0c;并将其集成到Jenkins中以实现持续部署。下面我们将分步骤讲解如何实…

MySQL递归查询:洞悉数据的层层关联

在处理关系型数据库时&#xff0c;我们经常会遇到这样的情况&#xff1a;某些数据之间存在层级关系&#xff0c;例如目录、组织结构、评论等。在这些场景下&#xff0c;我们需要一种灵活的查询技术来处理这种层级关系。今天我们就来探讨MySQL中的递归查询&#xff0c;体验其独特…

ThinkPHP6学生选课管理系统

有需要请加文章底部Q哦 可远程调试 ThinkPHP6学生选课管理系统 一 介绍 此学生选课管理系统基于ThinkPHP6框架开发&#xff0c;数据库mysql8&#xff0c;前端bootstrap。系统角色分为学生&#xff0c;教师和管理员。学生登录后可进行选课&#xff0c;教师登录后可查看选课情况…

Android : 获取、添加、手机联系人-ContentResolver简单应用

示例图&#xff1a; MainActivity.java package com.example.mygetdata;import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat;import android.Mani…

图书管理系统源码,图书管理系统开发,图书借阅系统源码四TuShuManager应用程序MVC视图View

Asp.net web应用程序MVC之View视图 .ASP.NET MVC页面也就是要说的视图基本被放在Views文件夹下&#xff1b; 2.利用APS.NET MVC模板生成框架&#xff0c;Views文件夹下的默认页面为.cshtml页面&#xff1b; 3.ASP.NET MVC默认页面为Razor格式的页面&#xff0c;因此默认页面为.…

三、Lua变量

文章目录 一、变量分类二、变量赋值三、索引 一、变量分类 lua变量分为全局变量&#xff0c;局部变量。 全局变量&#xff1a;默认&#xff0c;全局有效。 局部变量&#xff1a;从作用范围开始到作用范围结束&#xff0c;需加local 修饰。 a1function ff()local b1 endprint(a…

spring boot的redis连接数过多导致redis服务器压力过大的一次问题排查

一、背景 在今天上午的时候&#xff0c;突然收到大量的sentry报错&#xff0c;都是关于redis连接超时的警告。 首先想到的是去查看redis的监控&#xff0c;发现那个时间段&#xff0c;redis的请求数剧增&#xff0c;cpu使用率和带宽都陡增双倍。 下面的是redis监控的cpu情况 …

Module build failed: Error: ENOENT: no such file or directory

前言 这个错误通常发生在Node.js 和 vue,js项目中&#xff0c;当你试图访问一个不存在的文件或目录时。在大多数情况下&#xff0c;这是因为你的代码试图打开一个不存在的文件&#xff0c;或者你的构建系统&#xff08;例如Webpack&#xff09;需要一个配置文件&#xff0c;但找…

程序员为什么要一直坚持写博客

shigen日更文章的博客写手&#xff0c;擅长Java、python、vue、shell等编程语言和各种应用程序、脚本的开发。记录成长&#xff0c;分享认知&#xff0c;留住感动。 今天的文章其实说和技术有关系也没有什么问题&#xff0c;算起来我日更文章已经快四个月了&#xff0c;从最初的…

四、Lua循环

文章目录 一、while(循环条件)二、for&#xff08;一&#xff09;数值for&#xff08;二&#xff09;泛型for&#xff08;三&#xff09;repeat util 既然同为编程语言&#xff0c;那么控制逻辑里的循环就不能缺少&#xff0c;它可以帮助我们实现有规律的重复操作&#xff0c;而…

洗地机应该怎么选?希亦、必胜、米博、添可、小米洗地机实测推荐

作为一个常年测评智能家居的博主&#xff0c;关于洗地机的测评使用这些年也积累了不少的体验感受。以至于常被周边的朋友问到&#xff0c;洗地机到底是不是真的好用&#xff1f;洗地机有什么优点吗&#xff1f;选购的时候应该怎么选呢&#xff1f;洗地机什么牌子比较好呢&#…

.NET6实现破解Modbus poll点表配置文件

📢欢迎点赞 :👍 收藏 ⭐留言 📝 如有错误敬请指正,赐人玫瑰,手留余香!📢本文作者:由webmote 原创📢作者格言:新的征程,我们面对的不仅仅是技术还有人心,人心不可测,海水不可量,唯有技术,才是深沉黑夜中的一座闪烁的灯塔 !序言 Modbus 协议是工控领域常见…

Elasticsearch:什么是非结构化数据?

非结构化数据定义 非结构化数据是指未按照设计的模型或结构组织的数据。 非结构化数据通常被归类为定性数据&#xff0c;可以是人类或机器生成的。 非结构化数据是最丰富的可用数据类型&#xff0c;经过分析后&#xff0c;可用于指导业务决策并在许多其他用例中实现业务目标。…

2015年五一杯数学建模B题空气污染问题研究解题全过程文档及程序

2015年五一杯数学建模 B题 空气污染问题研究 原题再现 近十年来&#xff0c;我国 GDP 持续快速增长&#xff0c;但经济增长模式相对传统落后&#xff0c;对生态平衡和自然环境造成一定的破坏&#xff0c;空气污染的弊病日益突出&#xff0c;特别是日益加重的雾霾天气已经干扰…