HAxis sos
This commit is contained in:
14
Source/UnrealProject/GUI/ToolTip/ToolTipText.cpp
Normal file
14
Source/UnrealProject/GUI/ToolTip/ToolTipText.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "ToolTipText.h"
|
||||
|
||||
|
||||
void UToolTipText::SetTitle_Implementation(const FString& title)
|
||||
{
|
||||
|
||||
}
|
||||
void UToolTipText::SetText_Implementation(const FString& text)
|
||||
{
|
||||
|
||||
}
|
||||
27
Source/UnrealProject/GUI/ToolTip/ToolTipText.h
Normal file
27
Source/UnrealProject/GUI/ToolTip/ToolTipText.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "ToolTipText.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UToolTipText : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
public:
|
||||
UPROPERTY(BlueprintReadWrite, Category = "ToolTip")
|
||||
class USizeBox* sizeBox;
|
||||
|
||||
UFUNCTION(BlueprintNativeEvent, Category = "ToolTip")
|
||||
void SetTitle(const FString& title);
|
||||
|
||||
UFUNCTION(BlueprintNativeEvent, Category = "ToolTip")
|
||||
void SetText(const FString& text);
|
||||
|
||||
};
|
||||
108
Source/UnrealProject/GUI/ToolTip/ToolTipWidget.cpp
Normal file
108
Source/UnrealProject/GUI/ToolTip/ToolTipWidget.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#include "UnrealProject.h"
|
||||
#include "ToolTipWidget.h"
|
||||
#include "ToolTipText.h"
|
||||
#include "WidgetLayoutLibrary.h"
|
||||
|
||||
|
||||
void UToolTipWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
m_toolTip = CreateWidget<UToolTipText>(GetWorld(), textWidget);
|
||||
canvas->AddChild(m_toolTip);
|
||||
m_toolTip->SetVisibility(ESlateVisibility::Hidden);
|
||||
|
||||
showTooltip = false;
|
||||
}
|
||||
void UToolTipWidget::NativeDestruct()
|
||||
{
|
||||
Super::NativeDestruct();
|
||||
}
|
||||
|
||||
void UToolTipWidget::NativeTick(const FGeometry& geometry, float deltaTime)
|
||||
{
|
||||
Super::NativeTick(geometry, deltaTime);
|
||||
|
||||
if (!showTooltip)
|
||||
{
|
||||
m_toolTip->SetVisibility(ESlateVisibility::Hidden);
|
||||
}
|
||||
else
|
||||
{
|
||||
UWorld* const world = GetWorld();
|
||||
if (!IsValid(world)) return;
|
||||
|
||||
const FVector2D screenSize = FVector2D(world->GetGameViewport()->Viewport->GetSizeXY().X, world->GetGameViewport()->Viewport->GetSizeXY().Y);
|
||||
const float viewportScale = UWidgetLayoutLibrary::GetViewportScale(this);
|
||||
|
||||
m_toolTip->SetVisibility(ESlateVisibility::Visible);
|
||||
|
||||
FVector2D currentPos = position + size + FVector2D(5, 5);
|
||||
|
||||
if ((currentPos.X + m_toolTip->GetDesiredSize().X) * viewportScale >= screenSize.X)
|
||||
currentPos.X = position.X - 5 - m_toolTip->GetDesiredSize().X;
|
||||
if ((currentPos.Y + m_toolTip->GetDesiredSize().Y) * viewportScale >= screenSize.Y)
|
||||
currentPos.Y = position.Y - 5 - m_toolTip->GetDesiredSize().Y;
|
||||
|
||||
UCanvasPanelSlot* const slot = Cast<UCanvasPanelSlot>(m_toolTip->Slot);
|
||||
slot->SetPosition(currentPos);
|
||||
slot->SetSize(m_toolTip->GetDesiredSize());
|
||||
}
|
||||
|
||||
//UWorld* const world = GetWorld();
|
||||
//if (!IsValid(world)) return;
|
||||
//
|
||||
//FVector2D mousePos;
|
||||
//const FVector2D screenSize = FVector2D(world->GetGameViewport()->Viewport->GetSizeXY().X, world->GetGameViewport()->Viewport->GetSizeXY().Y);
|
||||
//const float viewportScale = UWidgetLayoutLibrary::GetViewportScale(this);
|
||||
//if (UWidgetLayoutLibrary::GetMousePositionScaledByDPI(GetOwningPlayer(), mousePos.X, mousePos.Y))
|
||||
//{
|
||||
// for (int32 i = 0; i < m_handles.Num(); i++)
|
||||
// {
|
||||
// FToolTipHandle& handle = *m_handles[i];
|
||||
// UToolTipText& toolTip = *handle.m_toolTip;
|
||||
//
|
||||
// FVector2D triggerTopLeft;
|
||||
// FVector2D triggerSize;
|
||||
// const FVector2D scaledMouse = mousePos * viewportScale;
|
||||
// const FVector2D scaledSize = handle.size * viewportScale;
|
||||
// const FVector2D scaledPosition = handle.position * viewportScale;
|
||||
//
|
||||
// triggerTopLeft = handle.position;
|
||||
// triggerSize = handle.size;
|
||||
//
|
||||
// mousePos = (scaledMouse - scaledPosition) / scaledSize;
|
||||
//
|
||||
// if (!(mousePos.X >= 0 && mousePos.X <= 1 && mousePos.Y >= 0 && mousePos.Y <= 1))
|
||||
// {
|
||||
// toolTip.SetVisibility(ESlateVisibility::Hidden);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// UCanvasPanelSlot* const slot = Cast<UCanvasPanelSlot>(toolTip.Slot);
|
||||
//
|
||||
// toolTip.SetVisibility(ESlateVisibility::Visible);
|
||||
//
|
||||
// FVector2D currentPos = triggerTopLeft + triggerSize + FVector2D(5, 5);
|
||||
//
|
||||
// if ((currentPos.X + toolTip.GetDesiredSize().X) * viewportScale >= screenSize.X)
|
||||
// currentPos.X = triggerTopLeft.X - 5 - toolTip.GetDesiredSize().X;
|
||||
// if ((currentPos.Y + toolTip.GetDesiredSize().Y) * viewportScale >= screenSize.Y)
|
||||
// currentPos.Y = triggerTopLeft.Y - 5 - toolTip.GetDesiredSize().Y;
|
||||
//
|
||||
// slot->SetPosition(currentPos);
|
||||
// slot->SetSize(toolTip.GetDesiredSize());
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
void UToolTipWidget::SetTitle(const FString& title)
|
||||
{
|
||||
m_toolTip->SetTitle(title);
|
||||
}
|
||||
void UToolTipWidget::SetText(const FString& text)
|
||||
{
|
||||
m_toolTip->SetText(text);
|
||||
}
|
||||
37
Source/UnrealProject/GUI/ToolTip/ToolTipWidget.h
Normal file
37
Source/UnrealProject/GUI/ToolTip/ToolTipWidget.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// Project Lab - NHTV Igad
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "ToolTipWidget.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
UCLASS()
|
||||
class UNREALPROJECT_API UToolTipWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
virtual void NativeConstruct();
|
||||
virtual void NativeDestruct();
|
||||
virtual void NativeTick(const FGeometry& geometry, float deltaTime) override;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category = "ToolTip")
|
||||
TSubclassOf<class UToolTipText> textWidget;
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, Category = "ToolTip")
|
||||
class UCanvasPanel* canvas;
|
||||
|
||||
bool showTooltip;
|
||||
FVector2D position;
|
||||
FVector2D size;
|
||||
|
||||
void SetTitle(const FString& title);
|
||||
void SetText(const FString& text);
|
||||
|
||||
private:
|
||||
class UToolTipText* m_toolTip;
|
||||
};
|
||||
Reference in New Issue
Block a user