KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UTextureButton.cpp
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
2
3#include "UTextureButton.h"
4#include "Components/Button.h"
5#include "Components/Image.h"
6#include "Components/SizeBox.h"
7
9{
10 Super::NativePreConstruct();
12}
13
15{
16 Super::NativeConstruct();
17
18 if (Button_Main)
19 {
20 // 중복 등록 방지를 위해 기존 바인딩 제거
21 Button_Main->OnClicked.RemoveDynamic(this, &UTextureButton::HandleClicked);
22 Button_Main->OnHovered.RemoveDynamic(this, &UTextureButton::HandleHovered);
23 Button_Main->OnUnhovered.RemoveDynamic(this, &UTextureButton::HandleUnhovered);
24 Button_Main->OnPressed.RemoveDynamic(this, &UTextureButton::HandlePressed);
25 Button_Main->OnReleased.RemoveDynamic(this, &UTextureButton::HandleReleased);
26
27 Button_Main->OnClicked.AddDynamic(this, &UTextureButton::HandleClicked);
28 Button_Main->OnHovered.AddDynamic(this, &UTextureButton::HandleHovered);
29 Button_Main->OnUnhovered.AddDynamic(this, &UTextureButton::HandleUnhovered);
30 Button_Main->OnPressed.AddDynamic(this, &UTextureButton::HandlePressed);
31 Button_Main->OnReleased.AddDynamic(this, &UTextureButton::HandleReleased);
32 }
33
34 // 초기 상태는 Normal
36}
37
39{
40 // 버튼 배경 텍스쳐 설정
42 {
43 FSlateBrush Brush;
44 Brush.SetResourceObject(ButtonTexture);
45
46 FButtonStyle Style = Button_Main->GetStyle();
47 Style.Normal = Brush;
48 Style.Hovered = Brush;
49 Style.Pressed = Brush;
50 Button_Main->SetStyle(Style);
51 }
52
53 // 심볼 이미지 텍스쳐 설정
55 {
56 Image_Symbol->SetBrushFromTexture(SymbolTexture);
58 }
59
60 // 버튼 크기 설정
62}
63
64void UTextureButton::SetButtonTexture(UTexture2D* InTexture)
65{
66 ButtonTexture = InTexture;
67
69 {
70 FSlateBrush Brush;
71 Brush.SetResourceObject(ButtonTexture);
72
73 FButtonStyle Style = Button_Main->GetStyle();
74 Style.Normal = Brush;
75 Style.Hovered = Brush;
76 Style.Pressed = Brush;
77 Button_Main->SetStyle(Style);
78 }
79}
80
81void UTextureButton::SetSymbolTexture(UTexture2D* InTexture)
82{
83 SymbolTexture = InTexture;
84
86 {
87 Image_Symbol->SetBrushFromTexture(SymbolTexture);
88 }
89}
90
91void UTextureButton::SetButtonSize(float InWidth, float InHeight)
92{
93 ButtonWidth = InWidth;
94 ButtonHeight = InHeight;
95
96 if (Button_Main)
97 {
98 // Button을 SizeBox로 감싸서 크기 조정
99 // 또는 RenderTransform 사용
100 // UMG 구조에 따라 SizeBox가 있다면 해당 SizeBox의 크기를 설정
101 // 여기서는 SetRenderTransformPivot와 SetRenderScale을 사용하지 않고
102 // 위젯 블루프린트에서 SizeBox를 사용하는 것을 권장
103 }
104}
105
107{
108 bEnabled = bInEnabled;
109
110 if (Button_Main)
111 {
112 Button_Main->SetIsEnabled(bInEnabled);
113 }
114
115 // Disabled 상태 색상 적용
116 if (!bEnabled)
117 {
119 }
120 else
121 {
123 }
124}
125
127{
128 if (Image_Symbol)
129 {
130 Image_Symbol->SetColorAndOpacity(Color);
131 }
132}
133
135{
136 if (!bEnabled)
137 return;
138
139 OnButtonClickedEvent.Broadcast();
140}
141
143{
144 if (!bEnabled)
145 return;
146
148}
149
151{
152 if (!bEnabled)
153 return;
154
156}
157
159{
160 if (!bEnabled)
161 return;
162
164}
165
167{
168 if (!bEnabled)
169 return;
170
171 // Released 후 마우스가 여전히 버튼 위에 있는지 확인
172 if (Button_Main->IsHovered())
173 {
175 }
176 else
177 {
179 }
180}
class UButton * Button_Main
void SetButtonTexture(UTexture2D *InTexture)
버튼 배경 텍스쳐 설정
void SetSymbolTexture(UTexture2D *InTexture)
심볼 이미지 텍스쳐 설정
void ApplySymbolColor(const FLinearColor &Color)
FOnTextureButtonClickedEvent OnButtonClickedEvent
버튼 클릭 이벤트
float ButtonHeight
버튼 높이
class UImage * Image_Symbol
FLinearColor HoverSymbolColor
Hover 상태 심볼 색상
FLinearColor NormalSymbolColor
Normal 상태 심볼 색상
virtual void NativePreConstruct() override
void SetButtonSize(float InWidth, float InHeight)
버튼 크기 설정
virtual void NativeConstruct() override
void SetButtonEnabled(bool bInEnabled)
버튼 활성화 상태 설정
UTexture2D * SymbolTexture
심볼 이미지 텍스쳐
FLinearColor PressSymbolColor
Press 상태 심볼 색상
FLinearColor DisabledSymbolColor
Disabled 상태 심볼 색상
UTexture2D * ButtonTexture
버튼 배경 텍스쳐
float ButtonWidth
버튼 너비