Skip to content

Commit b5923a0

Browse files
committed
Add files
1 parent 0cea45d commit b5923a0

File tree

12 files changed

+848
-0
lines changed

12 files changed

+848
-0
lines changed

ColorWheelPlugin.uplugin

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"FileVersion": 3,
3+
"Version": 1,
4+
"VersionName": "2020.1.4",
5+
"FriendlyName": "Color Wheel",
6+
"Description": "Lets you add a color wheel to your widget, comes with helper nodes like Hexadecimal conversion.",
7+
"Category": "Widget",
8+
"CreatedBy": "W2.Wizard",
9+
"CreatedByURL": "https://w2wizard.myportfolio.com/",
10+
"DocsURL": "",
11+
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/ce01648a2cde41338991bb855a624ffa",
12+
"SupportURL": "https://w2wizard.myportfolio.com/contact",
13+
"EngineVersion": "4.27.0",
14+
"CanContainContent": false,
15+
"Installed": false,
16+
"Modules": [
17+
{
18+
"Name": "ColorWheelPlugin",
19+
"Type": "Runtime",
20+
"LoadingPhase": "PreDefault",
21+
"BlacklistPlatforms": [
22+
"IOS",
23+
"Android",
24+
"Linux"
25+
]
26+
}
27+
]
28+
}

Config/FilterPlugin.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[FilterPlugin]
2+
; This section lists additional files which will be packaged along with your plugin. Paths should be listed relative to the root plugin directory, and
3+
; may include "...", "*", and "?" wildcards to match directories, files, and individual characters respectively.
4+
;
5+
; Examples:
6+
; /README.txt
7+
; /Extras/...
8+
; /Binaries/ThirdParty/*.dll

Resources/Icon128.png

14.2 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) W2.Wizard 2020-2021. All Rights Reserved.
2+
3+
using System.IO;
4+
using UnrealBuildTool;
5+
6+
public class ColorWheelPlugin : ModuleRules
7+
{
8+
public ColorWheelPlugin(ReadOnlyTargetRules Target) : base(Target)
9+
{
10+
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
11+
12+
PublicIncludePaths.Add(Path.Combine(ModuleDirectory, "Public"));
13+
PrivateIncludePaths.Add(Path.Combine(ModuleDirectory, "Private"));
14+
15+
PrivateDependencyModuleNames.AddRange(
16+
new string[]
17+
{
18+
"Core",
19+
"ApplicationCore",
20+
"CoreUObject",
21+
"InputCore",
22+
"Engine",
23+
"UMG",
24+
"Slate",
25+
"SlateCore"
26+
}
27+
);
28+
}
29+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) W2.Wizard 2020-2021. All Rights Reserved.
2+
3+
#include "ColorWheelHelper.h"
4+
5+
uint8 UColorWheelHelper::HexToByte(FString Hex)
6+
{
7+
uint8 OutDec;
8+
9+
Hex.StartsWith("#") ? Hex = Hex.Mid(1,Hex.Len()-1) : Hex;
10+
11+
HexToBytes(Hex.ToUpper(), &OutDec);
12+
return OutDec;
13+
14+
// Old Method, if you're looking for a way without using functions.
15+
// const int len = Hex.Len();
16+
// uint8 Out = 0;
17+
//
18+
// for (int i = 0; i < len; i++)
19+
// {
20+
// char digit = Hex[len - 1 - i];
21+
// if (digit >= '0' && digit <= '9')
22+
// {
23+
// Out += (digit - '0') * FMath::Pow(16,i);
24+
// }
25+
// else
26+
// {
27+
// Out += (digit - 'A' + 10) * FMath::Pow(16,i);
28+
// }
29+
// }
30+
//
31+
// return Out;
32+
}
33+
34+
FLinearColor UColorWheelHelper::RandomLinearColor(bool RandomAlpha, bool TrueRandom)
35+
{
36+
FLinearColor OutColor;
37+
38+
// True random color
39+
if (TrueRandom)
40+
{
41+
OutColor = FLinearColor
42+
(
43+
FMath::FRand(),
44+
FMath::FRand(),
45+
FMath::FRand(),
46+
RandomAlpha ? FMath::FRand() : 1
47+
);
48+
49+
return OutColor;
50+
}
51+
52+
// Simple random color
53+
OutColor = FLinearColor::MakeRandomColor();
54+
if (RandomAlpha) OutColor.A = FMath::FRand();
55+
56+
return OutColor;
57+
}
58+
59+
FColor UColorWheelHelper::RandomColor(bool RandomAlpha, bool TrueRandom)
60+
{
61+
FColor OutColor;
62+
63+
// True random color
64+
if (TrueRandom)
65+
{
66+
OutColor = FColor
67+
(
68+
FMath::RandRange(0,255),
69+
FMath::RandRange(0,255),
70+
FMath::RandRange(0,255),
71+
RandomAlpha ? FMath::Rand() : 1
72+
);
73+
74+
return OutColor;
75+
}
76+
77+
// Simple random color
78+
OutColor = FColor::MakeRandomColor();
79+
if (RandomAlpha) OutColor.A = FMath::Rand();
80+
81+
return OutColor;
82+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) W2.Wizard 2020-2021. All Rights Reserved.
2+
3+
#include "ColorWheelPlugin.h"
4+
5+
#define LOCTEXT_NAMESPACE "FColorWheelPluginModule"
6+
7+
void FColorWheelPluginModule::StartupModule()
8+
{
9+
10+
}
11+
12+
void FColorWheelPluginModule::ShutdownModule()
13+
{
14+
15+
}
16+
17+
#undef LOCTEXT_NAMESPACE
18+
19+
IMPLEMENT_MODULE(FColorWheelPluginModule, ColorWheelPlugin)
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Copyright (c) W2.Wizard 2020-2021. All Rights Reserved.
2+
3+
#include "ColorWidget.h"
4+
5+
/// Slate Overrides ///
6+
7+
TSharedRef<SWidget> UColorWidget::RebuildWidget()
8+
{
9+
ColorWheel = SNew(SWColorWheel)
10+
.SelectedColor_UObject(this, &UColorWidget::GetColor)
11+
.SelectorPin(&SelectorPin)
12+
.HueCircle(&HueCircle)
13+
.OnMouseCaptureBegin_UObject(this, &UColorWidget::MouseDown)
14+
.OnMouseCaptureEnd_UObject(this, &UColorWidget::MouseUp)
15+
.OnValueChanged(FOnLinearColorValueChanged::CreateUObject(this, &UColorWidget::OnValueChanged));
16+
17+
return ColorWheel.ToSharedRef();
18+
}
19+
20+
void UColorWidget::ReleaseSlateResources(bool bReleaseChildren)
21+
{
22+
Super::ReleaseSlateResources(bReleaseChildren);
23+
24+
ColorWheel.Reset();
25+
}
26+
27+
void UColorWidget::OnValueChanged(FLinearColor NewValue)
28+
{
29+
Color = NewValue.HSVToLinearRGB();
30+
OnColorChanged.Broadcast(Color);
31+
}
32+
33+
/// Main Functions ///
34+
35+
void UColorWidget::SetColor(const FLinearColor NewColor)
36+
{
37+
// Incase of Black, the wheel gets fucked ヽ(`Д´)ノ︵ ┻━┻.
38+
if (NewColor.IsAlmostBlack())
39+
{
40+
// We pass in a false value
41+
Color = FLinearColor::White;
42+
43+
// Preserve alpha.
44+
Color.A = NewColor.A;
45+
IsNull = true;
46+
47+
return;
48+
}
49+
50+
Color = NewColor;
51+
IsNull = false;
52+
}
53+
54+
FLinearColor UColorWidget::GetCurrentColor()
55+
{
56+
// Was input black?
57+
if (IsNull)
58+
{
59+
// Return black color
60+
auto FallbackVal = FLinearColor::Black;
61+
FallbackVal.A = Color.A;
62+
63+
return FallbackVal;
64+
}
65+
66+
return Color;
67+
}
68+
69+
/// Generics ///
70+
71+
void UColorWidget::SetColorAndOpacity(FLinearColor InColorAndOpacity, TEnumAsByte<EWheelBrushTarget> Target)
72+
{
73+
// Update the values themselves, again this doesnt look good so change it later perhaps.
74+
auto ColorVal = FSlateColor(InColorAndOpacity);
75+
switch (Target)
76+
{
77+
case EWheelBrushTarget::All:
78+
SelectorPin.TintColor = ColorVal;
79+
HueCircle.TintColor = ColorVal;
80+
break;
81+
82+
case EWheelBrushTarget::SelectorPin:
83+
SelectorPin.TintColor = ColorVal;
84+
break;
85+
86+
case EWheelBrushTarget::HueCircle:
87+
HueCircle.TintColor = ColorVal;
88+
break;
89+
}
90+
91+
// Update the visual widget itself
92+
if (ColorWheel.IsValid())
93+
{
94+
ColorWheel->SetColorAndOpacity(InColorAndOpacity, Target);
95+
}
96+
}
97+
98+
99+

0 commit comments

Comments
 (0)