Progress on radial menus
This commit is contained in:
@@ -13,6 +13,49 @@ class SRadialMenu;
|
||||
class UTexture2D;
|
||||
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FRadialMenuConfig
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
int32 NumItems = 8;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float ItemHeight = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float InnerRadius = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float MinSpoke = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float Spread = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float LineThickness = 4.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
FLinearColor LineColor = FLinearColor::White;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
TObjectPtr<UTexture2D> DotTexture;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float DotRadius = 3.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
int32 SelectedItem = -1;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
FLinearColor SelectedColor = FLinearColor::Yellow;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="RadialMenu")
|
||||
float SelectedThickness = 2.0f;
|
||||
};
|
||||
|
||||
|
||||
USTRUCT(BlueprintType)
|
||||
struct FRadialMenuItem
|
||||
{
|
||||
@@ -29,26 +72,8 @@ struct FRadialMenuItem
|
||||
|
||||
UPROPERTY(BlueprintReadOnly)
|
||||
bool RightSide = false;
|
||||
};
|
||||
|
||||
UCLASS(BlueprintType)
|
||||
class URadialMenuLayout : public UObject
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void Configure(int32 NItems, float ItemHeight, float InnerRadius, float MinSpoke, float Spread);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
int32 LeftNum() const { return NumLeft; }
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
int32 RightNum() const { return NumRight; }
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const TArray<FRadialMenuItem> &GetItems() const { return Items; }
|
||||
|
||||
static TArray<FRadialMenuItem> Calculate(const FRadialMenuConfig &Config);
|
||||
|
||||
private:
|
||||
using View = TArrayView<FRadialMenuItem>;
|
||||
@@ -59,31 +84,24 @@ private:
|
||||
// spokes on both sides. The spokes on a given side are
|
||||
// organized top-to-bottom, and the angle between the
|
||||
// spokes is always equal to (1/NTotal) of the circle.
|
||||
FVector2D SpokeVector(int32 I, int32 NSide, int32 NTotal);
|
||||
static FVector2D SpokeVector(int32 I, int32 NSide, int32 NTotal);
|
||||
|
||||
// Populate Point1 and Point2, these are the
|
||||
// endpoints of the spoke segment. Spokes are
|
||||
// designed to always be long enough to make room
|
||||
// for MinSpoke, but also to make enough room to
|
||||
// keep the menu items from overlapping.
|
||||
void CalculateSpokes(View V, float ItemHeight, float InnerRadius, float MinSpoke);
|
||||
static void CalculateSpokes(View V, int32 TotalItems, float ItemHeight, float InnerRadius, float MinSpoke);
|
||||
|
||||
// Search for the widest spoke, and return its X coordinate.
|
||||
double WidestSpoke(View V);
|
||||
static double WidestSpoke(View V);
|
||||
|
||||
// Populate Point3, this is the endpoint of the spread
|
||||
// line that goes horizontal.
|
||||
void CalculateSpread(View V, double Offset);
|
||||
static void CalculateSpread(View V, double Offset);
|
||||
|
||||
// Flip everything in the specified view horizontally.
|
||||
void FlipHorizontal(View V);
|
||||
|
||||
// The array of items.
|
||||
TArray<FRadialMenuItem> Items;
|
||||
|
||||
// Number of items on the left, and on the right.
|
||||
int32 NumLeft = 0;
|
||||
int32 NumRight = 0;
|
||||
static void FlipHorizontal(View V);
|
||||
};
|
||||
|
||||
|
||||
@@ -121,43 +139,38 @@ public:
|
||||
void SetDotRadius(float NewDotRadius);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
URadialMenuLayout* GetLayout() const { return Layout; }
|
||||
bool SetSelectedItem(int32 NewSelectedItem);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SetSelectedColor(FLinearColor NewSelectedColor);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SetSelectedThickness(float NewSelectedThickness);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
const TArray<FRadialMenuItem> &GetItems() const { return Items; }
|
||||
|
||||
// Returns true if the selected item changed.
|
||||
UFUNCTION(BlueprintCallable)
|
||||
bool AddPointer(FVector2D Direction, float Scale);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FVector2D GetPointer() const { return PointerVector; }
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
FLinearColor GetItemColor(int N) const;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere)
|
||||
FRadialMenuConfig Config;
|
||||
|
||||
TArray<FRadialMenuItem> Items;
|
||||
|
||||
FVector2D PointerVector = {0,0};
|
||||
|
||||
virtual TSharedRef<SWidget> RebuildWidget() override;
|
||||
virtual void ReleaseSlateResources(bool bReleaseChildren) override;
|
||||
virtual void SynchronizeProperties() override;
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(ClampMin="0", AllowPrivateAccess="true"))
|
||||
int32 NumItems = 8;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float ItemHeight = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float InnerRadius = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float MinSpoke = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float Spread = 20.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float LineThickness = 2.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
FLinearColor LineColor = FLinearColor::White;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
TObjectPtr<UTexture2D> DotTexture;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Setter, Category="RadialMenu", meta=(AllowPrivateAccess="true"))
|
||||
float DotRadius = 0.0f;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<URadialMenuLayout> Layout;
|
||||
|
||||
TSharedPtr<SRadialMenu> MySlateWidget;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user