KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
UHoverButton.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 "UHoverButton.h"
4#include "Components/Button.h"
5#include "Components/Border.h"
6#include "Components/TextBlock.h"
7
9{
10 Super::NativePreConstruct();
11 ApplyStyle();
12}
13
15{
16 Super::NativeConstruct();
17
18 if (Button_Main)
19 {
20 Button_Main->OnHovered.AddDynamic(this, &UHoverButton::HandleHovered);
21 Button_Main->OnUnhovered.AddDynamic(this, &UHoverButton::HandleUnhovered);
22 Button_Main->OnPressed.AddDynamic(this, &UHoverButton::HandlePressed);
23 Button_Main->OnReleased.AddDynamic(this, &UHoverButton::HandleReleased);
24 Button_Main->OnClicked.AddDynamic(this, &UHoverButton::HandleClicked);
25 }
26}
27
29{
30 if (!Text_Label)
31 return;
32
33 // 텍스트 반영
34 Text_Label->SetText(LabelText);
35
36 // 폰트 크기 반영
37 FSlateFontInfo NewFont = Text_Label->GetFont();
38 NewFont.OutlineSettings.OutlineSize = FontOutlineSize; // 원하는 외곽선 두께
39 NewFont.Size = FontSize;
40 Text_Label->SetFont(NewFont);
41
42 // Normal 상태 기본 세팅
43 Text_Label->SetColorAndOpacity(NormalTextColor);
44 Border_BG->SetBrushColor(NormalButtonColor);
45}
46
47void UHoverButton::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
48{
49 Super::NativeTick(MyGeometry, InDeltaTime);
50
51 // 스케일 보간
52 CurrentScale = FMath::Vector2DInterpTo(CurrentScale, TargetScale, InDeltaTime, LerpSpeed);
53 SetRenderScale(CurrentScale);
54}
55
57{
58 if (!bEnabled)
59 return;
60
61 TargetScale = FVector2D(1.06f, 1.06f); // Hover 확대
62 TargetBrightness = 1.15f;
63 Text_Label->SetColorAndOpacity(HoverTextColor);
64 Border_BG->SetBrushColor(HoverButtonColor);
65}
66
68{
69 if (!bEnabled)
70 return;
71
72 TargetScale = FVector2D(1.0f, 1.0f);
73 TargetBrightness = 1.0f;
74 Text_Label->SetColorAndOpacity(NormalTextColor);
75 Border_BG->SetBrushColor(NormalButtonColor);
76}
77
79{
80 if (!bEnabled)
81 return;
82
83 TargetScale = FVector2D(0.97f, 0.97f); // 눌리는 효과
84 Text_Label->SetColorAndOpacity(PressTextColor);
85 Border_BG->SetBrushColor(PressButtonColor);
86}
87
89{
90 if (!bEnabled)
91 return;
92
93 if (Button_Main->IsHovered())
95 else
97}
98
100{
101 if (!bEnabled)
102 return;
103
104 OnButtonClickedEvent.Broadcast();
105}
106
108{
109 bEnabled = bInEnabled;
110
111 Button_Main->SetIsEnabled(bInEnabled);
112
113 if (bInEnabled)
114 {
115 TargetScale = FVector2D(1.f, 1.f);
116 TargetBrightness = 1.f;
117
118 // 상태가 다시 Normal이므로 색 복구
119 Border_BG->SetBrushColor(NormalButtonColor);
120 Text_Label->SetColorAndOpacity(NormalTextColor);
121 }
122 else
123 {
124 TargetScale = FVector2D(1.f, 1.f);
125 TargetBrightness = 0.4f; // Disable 톤 다운
126
127 // 비활성화 시 조금 어둡게
128 Border_BG->SetBrushColor(NormalButtonColor * 0.5f);
129 Text_Label->SetColorAndOpacity(NormalTextColor * 0.5f);
130 }
131}
FLinearColor PressButtonColor
virtual void NativeTick(const FGeometry &MyGeometry, float InDeltaTime) override
void HandleReleased()
FLinearColor HoverTextColor
FVector2D TargetScale
int32 FontOutlineSize
void SetButtonEnabled(bool bInEnabled)
class UBorder * Border_BG
float TargetBrightness
class UTextBlock * Text_Label
void HandlePressed()
virtual void NativeConstruct() override
void HandleClicked()
FLinearColor PressTextColor
FLinearColor NormalTextColor
FOnHoverButtonClickedEvent OnButtonClickedEvent
FLinearColor HoverButtonColor
void HandleUnhovered()
FLinearColor NormalButtonColor
virtual void NativePreConstruct() override
FVector2D CurrentScale
class UButton * Button_Main
void HandleHovered()