KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UDrawingBoardWidget 클래스 참조

#include <DrawingBoardWidget.h>

+ UDrawingBoardWidget에 대한 상속 다이어그램 :
+ UDrawingBoardWidget에 대한 협력 다이어그램:

Public 멤버 함수

 UDrawingBoardWidget (const FObjectInitializer &ObjectInitializer)
 
virtual void NativeConstruct () override
 

Protected 멤버 함수

virtual FReply NativeOnMouseButtonDown (const FGeometry &InGeometry, const FPointerEvent &InMouseEvent) override
 
virtual FReply NativeOnMouseButtonUp (const FGeometry &InGeometry, const FPointerEvent &InMouseEvent) override
 
virtual FReply NativeOnMouseMove (const FGeometry &InGeometry, const FPointerEvent &InMouseEvent) override
 

Protected 속성

bool bIsDrawing
 
TObjectPtr< class UImageButtonButton_Clear
 
TObjectPtr< class UImageButtonButton_Save
 
TObjectPtr< class UImage > Image_Canvas
 
TObjectPtr< class UOverlay > Overlay_DrawWindow
 
FVector2D prevMousePos
 
TObjectPtr< class UTextureRenderTarget2D > RT_Canvas
 

Private 멤버 함수

void ClearCanvas ()
 
void CloseDrawWindow ()
 
void DrawLines (FVector2D mousePos, FLinearColor drawColor)
 
void DrawPoint (FVector2D mousePos, FLinearColor drawColor)
 
FVector2D GetLocalMousePos (FVector2D mousePos)
 
void SaveCanvas ()
 
bool SaveRenderTargetToPNG (UTextureRenderTarget2D *RenderTarget, const FString &FullFilePath)
 

상세한 설명

DrawingBoardWidget.h 파일의 13 번째 라인에서 정의되었습니다.

생성자 & 소멸자 문서화

◆ UDrawingBoardWidget()

UDrawingBoardWidget::UDrawingBoardWidget ( const FObjectInitializer &  ObjectInitializer)

DrawingBoardWidget.cpp 파일의 17 번째 라인에서 정의되었습니다.

17 : Super(ObjectInitializer)
18{
19 // ConstructorHelpers::FObjectFinder<UTextureRenderTarget2D> rtCanvasRef(TEXT("/Script/Engine.TextureRenderTarget2D'/Game/CustomContents/UI/DrawingBoard/RT_Canvas.RT_Canvas'"));
20 // if (rtCanvasRef.Succeeded())
21 // {
22 // RT_Canvas = rtCanvasRef.Object;
23 // }
24}

멤버 함수 문서화

◆ ClearCanvas()

void UDrawingBoardWidget::ClearCanvas ( )
private

DrawingBoardWidget.cpp 파일의 148 번째 라인에서 정의되었습니다.

149{
150 UKismetRenderingLibrary::ClearRenderTarget2D(this, RT_Canvas, RT_Canvas->ClearColor);
151}
TObjectPtr< class UTextureRenderTarget2D > RT_Canvas

다음을 참조함 : RT_Canvas.

다음에 의해서 참조됨 : NativeConstruct().

+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ CloseDrawWindow()

void UDrawingBoardWidget::CloseDrawWindow ( )
private

◆ DrawLines()

void UDrawingBoardWidget::DrawLines ( FVector2D  mousePos,
FLinearColor  drawColor 
)
private

DrawingBoardWidget.cpp 파일의 106 번째 라인에서 정의되었습니다.

107{
108 // Begin Draw Canvas To Render Target
109 UCanvas* canvas = nullptr;
110 FVector2D size;
111 FDrawToRenderTargetContext context;
112 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(this, RT_Canvas, canvas, size, context);
113
114 // Calculate Draw Positions
115 FVector2D currPos = prevMousePos;
116 int32 div = 64;
117 FVector2D drawOffset = (mousePos - currPos) / div;
118
119 // Draw
120 for (int32 i = 1; i < div; ++i)
121 {
122 currPos = prevMousePos + drawOffset * i;
123
124 // Set thickness Whether now in Draw or Erase
125 float thickness = (drawColor == FLinearColor::Black) ? 10 : 30;
126 // Draw Line
127 canvas->K2_DrawLine(prevMousePos, currPos, thickness, drawColor);
128 }
129 prevMousePos = mousePos;
130
131 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(this, context);
132}

다음을 참조함 : prevMousePos, RT_Canvas.

다음에 의해서 참조됨 : NativeOnMouseMove().

+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ DrawPoint()

void UDrawingBoardWidget::DrawPoint ( FVector2D  mousePos,
FLinearColor  drawColor 
)
private

DrawingBoardWidget.cpp 파일의 90 번째 라인에서 정의되었습니다.

91{
92 // Begin Draw Canvas To Render Target
93 UCanvas* canvas = nullptr;
94 FVector2D size;
95 FDrawToRenderTargetContext context;
96 UKismetRenderingLibrary::BeginDrawCanvasToRenderTarget(this, RT_Canvas, canvas, size, context);
97
98 // Set thickness Whether now in Draw or Erase
99 float thickness = (drawColor == FLinearColor::Black) ? 10 : 30;
100 // Draw Box
101 canvas->K2_DrawBox(mousePos, FVector2D(1, 1), thickness, drawColor);
102
103 UKismetRenderingLibrary::EndDrawCanvasToRenderTarget(this, context);
104}

다음을 참조함 : RT_Canvas.

다음에 의해서 참조됨 : NativeOnMouseButtonDown().

+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ GetLocalMousePos()

FVector2D UDrawingBoardWidget::GetLocalMousePos ( FVector2D  mousePos)
private

DrawingBoardWidget.cpp 파일의 134 번째 라인에서 정의되었습니다.

135{
136 // Get Absolute Local Pos
137 const FGeometry& geometry = Image_Canvas->GetCachedGeometry();
138 FVector2D localPos = geometry.AbsoluteToLocal(mousePos);
139
140 // Get Canvas Size
141 const FVector2D canvasSize = geometry.GetLocalSize();
142 // Transform localPos(in Image_Canvas Coord) to RT_Canvas Coord && Clamp upto RT_Canvas' Border
143 localPos.X = FMath::Clamp((localPos.X / canvasSize.X * RT_Canvas->SizeX), 0.f, RT_Canvas->SizeX);
144 localPos.Y = FMath::Clamp((localPos.Y / canvasSize.Y * RT_Canvas->SizeY), 0.f, RT_Canvas->SizeY);
145 return localPos;
146}
TObjectPtr< class UImage > Image_Canvas

다음을 참조함 : Image_Canvas, RT_Canvas.

다음에 의해서 참조됨 : NativeOnMouseButtonDown(), NativeOnMouseButtonUp(), NativeOnMouseMove().

+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ NativeConstruct()

void UDrawingBoardWidget::NativeConstruct ( )
overridevirtual

DrawingBoardWidget.cpp 파일의 26 번째 라인에서 정의되었습니다.

27{
28 Super::NativeConstruct();
29
30 // Button Event
31 Button_Clear->OnButtonClickedEvent.AddDynamic(this, &UDrawingBoardWidget::ClearCanvas);
32 Button_Save->OnButtonClickedEvent.AddDynamic(this, &UDrawingBoardWidget::SaveCanvas);
33}
TObjectPtr< class UImageButton > Button_Clear
TObjectPtr< class UImageButton > Button_Save

다음을 참조함 : Button_Clear, Button_Save, ClearCanvas(), SaveCanvas().

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ NativeOnMouseButtonDown()

FReply UDrawingBoardWidget::NativeOnMouseButtonDown ( const FGeometry &  InGeometry,
const FPointerEvent &  InMouseEvent 
)
overrideprotectedvirtual

DrawingBoardWidget.cpp 파일의 35 번째 라인에서 정의되었습니다.

36{
37 // Check Mouse is in Canvas
38 const FGeometry CanvasGeometry = Image_Canvas->GetCachedGeometry();
39 if (!CanvasGeometry.IsUnderLocation(InMouseEvent.GetScreenSpacePosition()))
40 {
41 return FReply::Unhandled();
42 }
43
44 // Get Mouse Position in Local Image Coordinate System
45 // Save Current MousePos to prevMousePos
46 prevMousePos = GetLocalMousePos(InMouseEvent.GetScreenSpacePosition());
47 bIsDrawing = true;
48
49 // Draw Point Once
50 // PRINT_STRING(TEXT("%s"), *InMouseEvent.GetEffectingButton().GetFName().ToString());
51 if (InMouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton)) // Draw
52 {
53 DrawPoint(GetLocalMousePos(InMouseEvent.GetScreenSpacePosition()), FLinearColor::Black);
54 }
55 else if (InMouseEvent.IsMouseButtonDown(EKeys::RightMouseButton)) // Erase
56 {
57 DrawPoint(GetLocalMousePos(InMouseEvent.GetScreenSpacePosition()), FLinearColor::White);
58 }
59
60 return FReply::Handled();
61}
FVector2D GetLocalMousePos(FVector2D mousePos)
void DrawPoint(FVector2D mousePos, FLinearColor drawColor)

다음을 참조함 : bIsDrawing, DrawPoint(), GetLocalMousePos(), Image_Canvas, prevMousePos.

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ NativeOnMouseButtonUp()

FReply UDrawingBoardWidget::NativeOnMouseButtonUp ( const FGeometry &  InGeometry,
const FPointerEvent &  InMouseEvent 
)
overrideprotectedvirtual

DrawingBoardWidget.cpp 파일의 63 번째 라인에서 정의되었습니다.

64{
65 // Get Mouse Position in Local Image Coordinate System
66 // Save ZeroVector to prevMousePos
67 prevMousePos = GetLocalMousePos(FVector2D::ZeroVector);
68 bIsDrawing = false;
69
70 return FReply::Handled();
71}

다음을 참조함 : bIsDrawing, GetLocalMousePos(), prevMousePos.

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ NativeOnMouseMove()

FReply UDrawingBoardWidget::NativeOnMouseMove ( const FGeometry &  InGeometry,
const FPointerEvent &  InMouseEvent 
)
overrideprotectedvirtual

DrawingBoardWidget.cpp 파일의 73 번째 라인에서 정의되었습니다.

74{
75 // return When Mouse Not Pressed
76 if (!bIsDrawing) return Super::NativeOnMouseMove(InGeometry, InMouseEvent);
77
78 if (InMouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton)) // Draw
79 {
80 DrawLines(GetLocalMousePos(InMouseEvent.GetScreenSpacePosition()), FLinearColor::Black);
81 }
82 else if (InMouseEvent.IsMouseButtonDown(EKeys::RightMouseButton)) // Erase
83 {
84 DrawLines(GetLocalMousePos(InMouseEvent.GetScreenSpacePosition()), FLinearColor::White);
85 }
86
87 return FReply::Handled();
88}
void DrawLines(FVector2D mousePos, FLinearColor drawColor)

다음을 참조함 : bIsDrawing, DrawLines(), GetLocalMousePos().

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:

◆ SaveCanvas()

void UDrawingBoardWidget::SaveCanvas ( )
private

DrawingBoardWidget.cpp 파일의 153 번째 라인에서 정의되었습니다.

154{
155 // File Path
156 const FString filePath = FPaths::ProjectSavedDir() / TEXT("WriteImage/");
157 IFileManager::Get().MakeDirectory(*filePath, true);
158 // File Name
159 FString fileName = FDateTime::Now().ToString(TEXT("%Y_%m_%d_%H_%M_%S.png"));
160
161 // Export Render Target to png
162 UKismetRenderingLibrary::ExportRenderTarget(this, RT_Canvas, filePath, fileName);
163 // UE_LOG(LogTemp, Warning, TEXT("%s | %s"), *filePath, *fileName);
164
165 SaveRenderTargetToPNG(RT_Canvas, filePath / fileName);
166}
bool SaveRenderTargetToPNG(UTextureRenderTarget2D *RenderTarget, const FString &FullFilePath)

다음을 참조함 : RT_Canvas, SaveRenderTargetToPNG().

다음에 의해서 참조됨 : NativeConstruct().

+ 이 함수 내부에서 호출하는 함수들에 대한 그래프입니다.:
+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

◆ SaveRenderTargetToPNG()

bool UDrawingBoardWidget::SaveRenderTargetToPNG ( UTextureRenderTarget2D *  RenderTarget,
const FString &  FullFilePath 
)
private

DrawingBoardWidget.cpp 파일의 168 번째 라인에서 정의되었습니다.

169{
170 FTextureRenderTargetResource* RTResource = RenderTarget->GameThread_GetRenderTargetResource();
171 if (!RTResource)
172 {
173 return false;
174 }
175
176 // Get Width & Height
177 const int32 Width = RenderTarget->SizeX;
178 const int32 Height = RenderTarget->SizeY;
179
180 // Set Bitmap array
181 TArray<FColor> Bitmap;
182 Bitmap.AddUninitialized(Width * Height);
183
184 // Read BGRA8 pixels in RenderTarget
185 RTResource->ReadPixels(Bitmap);
186
187 // PNG Encoder
188 IImageWrapperModule& ImageWrapperModule =
189 FModuleManager::LoadModuleChecked<IImageWrapperModule>("ImageWrapper");
190
191 TSharedPtr<IImageWrapper> ImageWrapper =
192 ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
193
194 if (!ImageWrapper.IsValid())
195 {
196 return false;
197 }
198
199 ImageWrapper->SetRaw(
200 Bitmap.GetData(),
201 Bitmap.GetAllocatedSize(),
202 Width,
203 Height,
204 ERGBFormat::BGRA,
205 8
206 );
207
208 // Compress to PNG
209 const TArray64<uint8>& PNGData = ImageWrapper->GetCompressed(100);
210
211 // Make Directory
212 const FString Directory = FPaths::GetPath(FullFilePath);
213 IFileManager::Get().MakeDirectory(*Directory, true);
214
215 return FFileHelper::SaveArrayToFile(PNGData, *FullFilePath);
216}

다음에 의해서 참조됨 : SaveCanvas().

+ 이 함수를 호출하는 함수들에 대한 그래프입니다.:

멤버 데이터 문서화

◆ bIsDrawing

bool UDrawingBoardWidget::bIsDrawing
protected

DrawingBoardWidget.h 파일의 40 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : NativeOnMouseButtonDown(), NativeOnMouseButtonUp(), NativeOnMouseMove().

◆ Button_Clear

TObjectPtr<class UImageButton> UDrawingBoardWidget::Button_Clear
protected

DrawingBoardWidget.h 파일의 32 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : NativeConstruct().

◆ Button_Save

TObjectPtr<class UImageButton> UDrawingBoardWidget::Button_Save
protected

DrawingBoardWidget.h 파일의 34 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : NativeConstruct().

◆ Image_Canvas

TObjectPtr<class UImage> UDrawingBoardWidget::Image_Canvas
protected

DrawingBoardWidget.h 파일의 30 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : GetLocalMousePos(), NativeOnMouseButtonDown().

◆ Overlay_DrawWindow

TObjectPtr<class UOverlay> UDrawingBoardWidget::Overlay_DrawWindow
protected

DrawingBoardWidget.h 파일의 28 번째 라인에서 정의되었습니다.

◆ prevMousePos

FVector2D UDrawingBoardWidget::prevMousePos
protected

DrawingBoardWidget.h 파일의 38 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : DrawLines(), NativeOnMouseButtonDown(), NativeOnMouseButtonUp().

◆ RT_Canvas

TObjectPtr<class UTextureRenderTarget2D> UDrawingBoardWidget::RT_Canvas
protected

DrawingBoardWidget.h 파일의 24 번째 라인에서 정의되었습니다.

다음에 의해서 참조됨 : ClearCanvas(), DrawLines(), DrawPoint(), GetLocalMousePos(), SaveCanvas().


이 클래스에 대한 문서화 페이지는 다음의 파일들로부터 생성되었습니다.: