KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UImageButton.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 "UImageButton.h"
4#include "Components/Button.h"
5#include "Components/Border.h"
6#include "Components/TextBlock.h"
7#include "Components/SizeBox.h"
8#include "Engine/Texture2D.h"
9
11{
12 Super::NativePreConstruct();
13 ApplyStyle();
14}
15
17{
18 Super::NativeConstruct();
19
20 if (Button_Main)
21 {
22 // 중복 등록 방지를 위해 기존 바인딩 제거
23 Button_Main->OnHovered.RemoveDynamic(this, &UImageButton::HandleHovered);
24 Button_Main->OnUnhovered.RemoveDynamic(this, &UImageButton::HandleUnhovered);
25 Button_Main->OnPressed.RemoveDynamic(this, &UImageButton::HandlePressed);
26 Button_Main->OnReleased.RemoveDynamic(this, &UImageButton::HandleReleased);
27 Button_Main->OnClicked.RemoveDynamic(this, &UImageButton::HandleClicked);
28
29 Button_Main->OnHovered.AddDynamic(this, &UImageButton::HandleHovered);
30 Button_Main->OnUnhovered.AddDynamic(this, &UImageButton::HandleUnhovered);
31 Button_Main->OnPressed.AddDynamic(this, &UImageButton::HandlePressed);
32 Button_Main->OnReleased.AddDynamic(this, &UImageButton::HandleReleased);
33 Button_Main->OnClicked.AddDynamic(this, &UImageButton::HandleClicked);
34 }
35}
36
38{
39 // ========== 텍스트 스타일 적용 ==========
40 if (Text_Label)
41 {
42 Text_Label->SetText(LabelText);
43
44 FSlateFontInfo NewFont = Text_Label->GetFont();
45 NewFont.OutlineSettings.OutlineSize = FontOutlineSize;
46 NewFont.Size = FontSize;
47 Text_Label->SetFont(NewFont);
48
49 Text_Label->SetColorAndOpacity(NormalTextColor);
50 }
51
52 // ========== Border 배경 및 이미지 적용 ==========
53 if (Border_BG)
54 {
55 // Border 이미지가 설정되어 있으면 이미지 사용
56 if (BorderImage)
57 {
58 CachedBorderBrush.SetResourceObject(BorderImage);
61 CachedBorderBrush.TintColor = FSlateColor(NormalButtonColor);
64 }
65 else
66 {
67 // 이미지가 없으면 색상만 사용
68 Border_BG->SetBrushColor(NormalButtonColor);
70 }
71 }
72
73 // ========== 고정 크기 적용 ==========
74 if (SizeBox_Root)
75 {
76 if (bUseFixedSize)
77 {
78 SizeBox_Root->SetWidthOverride(FixedWidth);
79 SizeBox_Root->SetHeightOverride(FixedHeight);
80 }
81 else
82 {
83 // 고정 크기를 사용하지 않으면 자동 크기 조정
84 SizeBox_Root->ClearWidthOverride();
85 SizeBox_Root->ClearHeightOverride();
86 }
87 }
88}
89
90void UImageButton::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
91{
92 Super::NativeTick(MyGeometry, InDeltaTime);
93
94 // 스케일 보간
95 CurrentScale = FMath::Vector2DInterpTo(CurrentScale, TargetScale, InDeltaTime, LerpSpeed);
96 SetRenderScale(CurrentScale);
97}
98
100{
101 if (!bEnabled)
102 return;
103
104 TargetScale = FVector2D(1.06f, 1.06f);
105 TargetBrightness = 1.15f;
106
107 if (Text_Label)
108 {
109 Text_Label->SetColorAndOpacity(HoverTextColor);
110 }
111
112 if (Border_BG)
113 {
115 {
116 // 이미지가 있으면 Tint 색상 변경
117 CachedBorderBrush.TintColor = FSlateColor(HoverButtonColor);
118 Border_BG->SetBrush(CachedBorderBrush);
119 }
120 else
121 {
122 Border_BG->SetBrushColor(HoverButtonColor);
123 }
124 }
125}
126
128{
129 if (!bEnabled)
130 return;
131
132 TargetScale = FVector2D(1.0f, 1.0f);
133 TargetBrightness = 1.0f;
134
135 if (Text_Label)
136 {
137 Text_Label->SetColorAndOpacity(NormalTextColor);
138 }
139
140 if (Border_BG)
141 {
143 {
144 CachedBorderBrush.TintColor = FSlateColor(NormalButtonColor);
145 Border_BG->SetBrush(CachedBorderBrush);
146 }
147 else
148 {
149 Border_BG->SetBrushColor(NormalButtonColor);
150 }
151 }
152}
153
155{
156 if (!bEnabled)
157 return;
158
159 TargetScale = FVector2D(0.97f, 0.97f);
160
161 if (Text_Label)
162 {
163 Text_Label->SetColorAndOpacity(PressTextColor);
164 }
165
166 if (Border_BG)
167 {
169 {
170 CachedBorderBrush.TintColor = FSlateColor(PressButtonColor);
171 Border_BG->SetBrush(CachedBorderBrush);
172 }
173 else
174 {
175 Border_BG->SetBrushColor(PressButtonColor);
176 }
177 }
178}
179
181{
182 if (!bEnabled)
183 return;
184
185 if (Button_Main && Button_Main->IsHovered())
187 else
189}
190
192{
193 if (!bEnabled)
194 return;
195
196 OnButtonClickedEvent.Broadcast();
197}
198
200{
201 bEnabled = bInEnabled;
202
203 if (Button_Main)
204 {
205 Button_Main->SetIsEnabled(bInEnabled);
206 }
207
208 if (bInEnabled)
209 {
210 TargetScale = FVector2D(1.f, 1.f);
211 TargetBrightness = 1.f;
212
213 if (Border_BG)
214 {
216 {
217 CachedBorderBrush.TintColor = FSlateColor(NormalButtonColor);
218 Border_BG->SetBrush(CachedBorderBrush);
219 }
220 else
221 {
222 Border_BG->SetBrushColor(NormalButtonColor);
223 }
224 }
225
226 if (Text_Label)
227 {
228 Text_Label->SetColorAndOpacity(NormalTextColor);
229 }
230 }
231 else
232 {
233 TargetScale = FVector2D(1.f, 1.f);
234 TargetBrightness = 0.4f;
235
236 if (Border_BG)
237 {
239 {
240 CachedBorderBrush.TintColor = FSlateColor(NormalButtonColor * 0.5f);
241 Border_BG->SetBrush(CachedBorderBrush);
242 }
243 else
244 {
245 Border_BG->SetBrushColor(NormalButtonColor * 0.5f);
246 }
247 }
248
249 if (Text_Label)
250 {
251 Text_Label->SetColorAndOpacity(NormalTextColor * 0.5f);
252 }
253 }
254}
int32 FontOutlineSize
FOnImageButtonClickedEvent OnButtonClickedEvent
버튼 클릭 시 발생하는 이벤트
class USizeBox * SizeBox_Root
float FixedHeight
고정 높이 (bUseFixedSize가 true일 때 적용)
FLinearColor NormalTextColor
FSlateBrush CachedBorderBrush
FVector2D CurrentScale
FLinearColor PressButtonColor
class UTextBlock * Text_Label
FLinearColor NormalButtonColor
FMargin BorderMargin
Border 이미지의 여백 (9-slice 방식으로 그릴 때 사용)
float TargetBrightness
FLinearColor HoverButtonColor
void HandleUnhovered()
void SetButtonEnabled(bool bInEnabled)
버튼의 활성화/비활성화 상태를 설정합니다.
bool bUseFixedSize
고정 크기 사용 여부
void ApplyStyle()
설정된 스타일 속성을 위젯에 적용합니다.
class UBorder * Border_BG
virtual void NativeTick(const FGeometry &MyGeometry, float InDeltaTime) override
virtual void NativeConstruct() override
float FixedWidth
고정 너비 (bUseFixedSize가 true일 때 적용)
void HandleReleased()
void HandleHovered()
TEnumAsByte< ESlateBrushDrawType::Type > BorderDrawAs
Border 이미지의 그리기 방식 (Image, Box, Border, RoundedBox 등)
virtual void NativePreConstruct() override
class UButton * Button_Main
FLinearColor HoverTextColor
UTexture2D * BorderImage
Border에 적용할 이미지 (null이면 색상만 사용)
bool bBorderBrushInitialized
FLinearColor PressTextColor
FVector2D TargetScale