ue4图表_ue4模型[通俗易懂]

ue4图表_ue4模型[通俗易懂]【代码】UE4Slate柱状图。

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


#include "ZZTWidget.h"
#include "Windows/AllowWindowsPlatformTypes.h"
#include "Windows/PreWindowsApi.h"
#include <windows.h>
#include "Windows/PostWindowsApi.h"

int32 UZZTWidget::NativePaint(const FPaintArgs& Args,
                              const FGeometry& AllottedGeometry,
                              const FSlateRect& MyCullingRect,
                              FSlateWindowElementList& OutDrawElements,
                              int32 LayerId,
                              const FWidgetStyle& InWidgetStyle,
                              bool bParentEnabled) const
{
	if(Gap <= SizeXRec)
	{
		// if(MessageBox(0, TEXT("Out Of Range!!!"), TEXT("ZZTWarning!!!"), MB_ICONWARNING) == IDOK)
		// {
		// 	
		// }
	}
	float MaxHeight = 0.f;
	for(int Index = 0; Index < SizeYRec.Num(); Index++)
	{
		MaxHeight = FMath::Max(MaxHeight, SizeYRec[Index]);
	}
	if(isDIYColor)
	{
		int32 MinLength = FMath::Min(SizeYRec.Num(), ColorsRect.Num());
		for(int Index = 0; Index < MinLength; Index++)
		{
			DrawRect(OutDrawElements,
				AllottedGeometry,
				LayerId,
				FVector2D(Gap * Index, MaxHeight),
				FVector2D(SizeXRec, SizeYRec[Index]),
				ColorsRect[Index]);
		}
	}
	else
	{
		for(int Index = 0; Index < SizeYRec.Num(); Index++)
		{
			DrawRect(OutDrawElements,
				AllottedGeometry,
				LayerId,
				FVector2D(Gap * Index, MaxHeight),
				FVector2D(SizeXRec, SizeYRec[Index]),
				ColorRec);
		}
	}
	
	//if(PositionRec.Num() > 0)	DrawRect(OutDrawElements, AllottedGeometry, LayerId, PositionRec[0], SizeRec, ColorRec);
	
	return LayerId++;
}

void UZZTWidget::DrawRect(FSlateWindowElementList& OutDrawElements,
	const FGeometry& AllocttedGeometry,
	int32 LayerId,
	FVector2D Position,
	FVector2D Size,
	FColor Color) const
{
	FSlateVertex LeftDownVertex;
	FSlateVertex RightDownVertex;
	FSlateVertex RightUpVertex;
	FSlateVertex LeftUpVertex;

	LeftDownVertex.Color = Color;
	RightDownVertex.Color = Color;
	RightUpVertex.Color = Color;
	LeftUpVertex.Color = Color;

	FVector2D LeftDownPosition = Position;
	FVector2D RightDownPosition = FVector2D(Position.X + Size.X, Position.Y);
	FVector2D RightUpPosition = FVector2D(Position.X + Size.X, Position.Y - Size.Y);
	FVector2D LeftUpPosition = FVector2D(Position.X, Position.Y - Size.Y);

	const FSlateRenderTransform& SlateRenderTransform = AllocttedGeometry.ToPaintGeometry().GetAccumulatedRenderTransform();
	LeftDownPosition = SlateRenderTransform.TransformPoint(LeftDownPosition);
	RightDownPosition = SlateRenderTransform.TransformPoint(RightDownPosition);
	RightUpPosition = SlateRenderTransform.TransformPoint(RightUpPosition);
	LeftUpPosition = SlateRenderTransform.TransformPoint(LeftUpPosition);

	LeftDownVertex.Position = LeftDownPosition;
	RightDownVertex.Position = RightDownPosition;
	RightUpVertex.Position = RightUpPosition;
	LeftUpVertex.Position = LeftUpPosition;

	TArray<FSlateVertex> SlateVertexes;
	
	int32 IndexLeftDown = SlateVertexes.Add(LeftDownVertex);
	int32 IndexRightDown = SlateVertexes.Add(RightDownVertex);
	int32 IndexRightUp = SlateVertexes.Add(RightUpVertex);
	int32 IndexLeftUp = SlateVertexes.Add(LeftUpVertex);

	TArray<SlateIndex>	Indexes;
	Indexes.Add(IndexLeftDown);
	Indexes.Add(IndexRightDown);
	Indexes.Add(IndexRightUp);
	
	Indexes.Add(IndexLeftUp);
	Indexes.Add(IndexRightUp);
	Indexes.Add(IndexLeftDown);

	for(FSlateVertex& Vertex : SlateVertexes)
	{
		Vertex.TexCoords[0] = 0.f;
		Vertex.TexCoords[1] = 0.f;
	}

	const FSlateBrush* Brush = FCoreStyle::Get().GetBrush("BrushName");
	const FSlateResourceHandle ResourceHandle = FSlateApplication::Get().GetRenderer()->GetResourceHandle(*Brush);
	FSlateDrawElement::MakeCustomVerts(
		OutDrawElements,
		LayerId,
		ResourceHandle,
		SlateVertexes,
		Indexes,
		nullptr,
		0,
		0
	);
}

void UZZTWidget::SetValues(TArray<float> Values)
{
	if(!Values.Num())	return ;

	SizeYRec = Values;
}
	
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "ZZTWidget.generated.h"

/**
 * 
 */
UCLASS()
class MYPROJECT_API UZZTWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable)
		void SetValues(TArray<float> Values);
	
protected:
	virtual int32 NativePaint(const FPaintArgs& Args,
		const FGeometry& AllottedGeometry,
		const FSlateRect& MyCullingRect,
		FSlateWindowElementList& OutDrawElements,
		int32 LayerId, 
		const FWidgetStyle& InWidgetStyle, 
		bool bParentEnabled) const override;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		bool isDIYColor;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (EditCondition = "isDIYColor"))
		TArray<FColor> ColorsRect;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float Gap;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		TArray<float> SizeYRec;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		float SizeXRec;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		FColor ColorRec;
	
private:
	void DrawRect(FSlateWindowElementList& OutDrawElements,
		const FGeometry& AllocttedGeometry,
		int32 LayerId,
		FVector2D Position,
		FVector2D Size,
		FColor Color)	const;
};

ue4图表_ue4模型[通俗易懂]

今天的文章ue4图表_ue4模型[通俗易懂]分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/59213.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注