Skip to content

Commit

Permalink
Plugin updated for Noesis SDK 3.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
s-fernandez-v committed Oct 29, 2024
1 parent e17f5a2 commit 6515320
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void FNoesisBlueprintCompilerContext::CopyTermDefaultsToDefaultObject(UObject* D
DefaultInstance->EnableKeyboard = NoesisBlueprint->EnableKeyboard;
DefaultInstance->EnableMouse = NoesisBlueprint->EnableMouse;
DefaultInstance->EmulateTouch = NoesisBlueprint->EmulateTouch;
DefaultInstance->SetUserFocusToViewport = NoesisBlueprint->SetUserFocusToViewport;
DefaultInstance->EnableTouch = NoesisBlueprint->EnableTouch;
DefaultInstance->EnableActions = NoesisBlueprint->EnableActions;
DefaultInstance->PixelDepthBias = NoesisBlueprint->PixelDepthBias;
Expand Down
4 changes: 4 additions & 0 deletions Source/NoesisRuntime/Classes/NoesisBlueprint.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class NOESISRUNTIME_API UNoesisBlueprint : public UBlueprint
UPROPERTY(EditAnywhere, Category = "Noesis View", meta = (EditCondition = "EnableMouse"))
bool EmulateTouch;

/** Handled mouse events set user focus to the game viewport. */
UPROPERTY(EditAnywhere, Category = "Noesis View", meta = (EditCondition = "EnableMouse"))
bool SetUserFocusToViewport;

UPROPERTY(EditAnywhere, Category = "Noesis View")
bool EnableTouch;

Expand Down
6 changes: 6 additions & 0 deletions Source/NoesisRuntime/Classes/NoesisInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class NOESISRUNTIME_API UNoesisInstance : public UUserWidget
UPROPERTY(BlueprintReadWrite, Category = "NoesisGUI")
bool EmulateTouch;

UPROPERTY(BlueprintReadWrite, Category = "NoesisGUI")
bool SetUserFocusToViewport;

UPROPERTY(BlueprintReadWrite, Category = "NoesisGUI")
bool EnableTouch;

Expand Down Expand Up @@ -216,6 +219,7 @@ class NOESISRUNTIME_API UNoesisInstance : public UUserWidget
void OnPreviewLostKeyboardFocus(Noesis::BaseComponent* Component, const Noesis::KeyboardFocusChangedEventArgs& Args);

bool HitTest(FVector2D Position) const;
bool HasMouseCapture() const;

void TermInstance();

Expand Down Expand Up @@ -264,6 +268,8 @@ class NOESISRUNTIME_API UNoesisInstance : public UUserWidget
virtual FReply NativeOnTouchEnded(const FGeometry& MyGeometry, const FPointerEvent& InTouchEvent) override;
virtual FCursorReply NativeOnCursorQuery(const FGeometry& MyGeometry, const FPointerEvent& CursorEvent) override;
virtual FReply NativeOnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override;
virtual void NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;
virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override;
virtual bool NativeSupportsKeyboardFocus() const override;
virtual void NativeConstruct() override;
virtual void NativeDestruct() override;
Expand Down
1 change: 1 addition & 0 deletions Source/NoesisRuntime/Private/NoesisBlueprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ UNoesisBlueprint::UNoesisBlueprint(const FObjectInitializer& ObjectInitializer)
EnableKeyboard = true;
EnableMouse = true;
EmulateTouch = false;
SetUserFocusToViewport = false;
EnableTouch = true;
EnableActions = false;
PixelDepthBias = -1.0f;
Expand Down
184 changes: 150 additions & 34 deletions Source/NoesisRuntime/Private/NoesisInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,11 @@ void FNoesisSlateElement::RenderView(FRHICommandList& RHICmdList, const FViewInf
}

// We shouldn't use the versions of Render that use ViewProj if it's invalid, but we still need to call Render
#if UE_VERSION_OLDER_THAN(5, 1, 0)
bool IsViewProjectionMatrixValid = FMath::Abs(ViewProjectionMatrix.Determinant()) >= KINDA_SMALL_NUMBER;
#else
bool IsViewProjectionMatrixValid = FMath::Abs(ViewProjectionMatrix.Determinant()) >= UE_KINDA_SMALL_NUMBER;
#endif
RenderOnscreen(RHICmdList, IsViewProjectionMatrixValid);
}

Expand Down Expand Up @@ -526,6 +530,7 @@ UNoesisInstance::UNoesisInstance(const FObjectInitializer& ObjectInitializer)
EnableKeyboard = true;
EnableMouse = true;
EmulateTouch = false;
SetUserFocusToViewport = false;
EnableTouch = true;
EnableActions = false;
PixelDepthBias = -1.0f;
Expand Down Expand Up @@ -1162,6 +1167,18 @@ bool UNoesisInstance::HitTest(FVector2D Position) const
return HitTester.Hit != nullptr;
}

bool UNoesisInstance::HasMouseCapture() const
{
if (XamlView && !Is3DWidget)
{
auto Root = XamlView->GetContent();
auto Mouse = Root != nullptr ? Root->GetMouse() : nullptr;
return Mouse != nullptr && Mouse->GetCaptured() != nullptr;
}

return false;
}

void UNoesisInstance::TermInstance()
{
if (XamlView)
Expand Down Expand Up @@ -1465,10 +1482,15 @@ FReply UNoesisInstance::NativeOnKeyChar(const FGeometry& MyGeometry, const FChar
{
TCHAR Character = CharacterEvent.GetCharacter();

XamlView->Char(CharCast<char>(Character));
bool Handled = XamlView->Char(CharCast<char>(Character));

if (Handled)
{
return FReply::Handled();
}
}

return Super::NativeOnKeyChar(MyGeometry, CharacterEvent);
return FReply::Unhandled();
}

static TMap<FKey, Noesis::Key> InitKeyMap()
Expand Down Expand Up @@ -1595,11 +1617,16 @@ FReply UNoesisInstance::NativeOnKeyDown(const FGeometry& MyGeometry, const FKeyE
Noesis::Key* NoesisKey = KeyToNoesisKey(Key);
if (NoesisKey != nullptr)
{
XamlView->KeyDown(*NoesisKey);
bool Handled = XamlView->KeyDown(*NoesisKey);

if (Handled)
{
return FReply::Handled();
}
}
}

return Super::NativeOnKeyDown(MyGeometry, KeyEvent);
return FReply::Unhandled();
}

FReply UNoesisInstance::NativeOnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent)
Expand All @@ -1611,31 +1638,20 @@ FReply UNoesisInstance::NativeOnKeyUp(const FGeometry& MyGeometry, const FKeyEve
Noesis::Key* NoesisKey = KeyToNoesisKey(Key);
if (NoesisKey != nullptr)
{
XamlView->KeyUp(*NoesisKey);
bool Handled = XamlView->KeyUp(*NoesisKey);

if (Handled)
{
return FReply::Handled();
}
}
}

return Super::NativeOnKeyUp(MyGeometry, KeyEvent);
return FReply::Unhandled();
}

FReply UNoesisInstance::NativeOnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& InAnalogEvent)
{
SCOPE_CYCLE_COUNTER(STAT_NoesisInstance_OnAnalogValueChanged);
if (XamlView)
{
if (FMath::Abs(InAnalogEvent.GetAnalogValue()) > 0.25f)
{
if (InAnalogEvent.GetKey() == EKeys::Gamepad_RightX)
{
XamlView->HScroll(InAnalogEvent.GetAnalogValue());
}
else if (InAnalogEvent.GetKey() == EKeys::Gamepad_RightY)
{
XamlView->Scroll(InAnalogEvent.GetAnalogValue());
}
}
}

return Super::NativeOnAnalogValueChanged(MyGeometry, InAnalogEvent);
}

Expand Down Expand Up @@ -1670,7 +1686,7 @@ FReply UNoesisInstance::NativeOnMouseButtonDown(const FGeometry& MyGeometry, con

if (Handled)
{
return FReply::Handled().PreventThrottling().CaptureMouse(MyWidget.Pin().ToSharedRef());
return FReply::Handled().PreventThrottling().CaptureMouse(TakeWidget());
}
}
else
Expand All @@ -1679,11 +1695,24 @@ FReply UNoesisInstance::NativeOnMouseButtonDown(const FGeometry& MyGeometry, con
bool Hit = HitTest(Position);

Noesis::MouseButton MouseButton = GetNoesisMouseButton(MouseEvent.GetEffectingButton());
bool Handled = XamlView->MouseButtonDown(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y), MouseButton);
bool Handled = XamlView->MouseButtonDown(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y), MouseButton) || HasMouseCapture();

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (SetUserFocusToViewport)
{
Reply.SetUserFocus(FSlateApplication::Get().GetGameViewport().ToSharedRef());
}
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}
}
Expand Down Expand Up @@ -1712,11 +1741,24 @@ FReply UNoesisInstance::NativeOnMouseButtonUp(const FGeometry& MyGeometry, const
bool Hit = HitTest(Position);

Noesis::MouseButton MouseButton = GetNoesisMouseButton(MouseEvent.GetEffectingButton());
bool Handled = XamlView->MouseButtonUp(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y), MouseButton);
bool Handled = XamlView->MouseButtonUp(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y), MouseButton) || HasMouseCapture();

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (SetUserFocusToViewport)
{
Reply.SetUserFocus(FSlateApplication::Get().GetGameViewport().ToSharedRef());
}
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}
}
Expand All @@ -1732,11 +1774,24 @@ FReply UNoesisInstance::NativeOnMouseMove(const FGeometry& MyGeometry, const FPo
FVector2D Position = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()) * MyGeometry.Scale;
bool Hit = HitTest(Position);

bool Handled = XamlView->MouseMove(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y));
bool Handled = XamlView->MouseMove(FPlatformMath::RoundToInt(Position.X), FPlatformMath::RoundToInt(Position.Y)) || HasMouseCapture();

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (SetUserFocusToViewport)
{
Reply.SetUserFocus(FSlateApplication::Get().GetGameViewport().ToSharedRef());
}
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

Expand All @@ -1756,7 +1811,16 @@ FReply UNoesisInstance::NativeOnMouseWheel(const FGeometry& MyGeometry, const FP

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

Expand All @@ -1776,7 +1840,16 @@ FReply UNoesisInstance::NativeOnTouchStarted(const FGeometry& MyGeometry, const

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

Expand All @@ -1796,7 +1869,16 @@ FReply UNoesisInstance::NativeOnTouchMoved(const FGeometry& MyGeometry, const FP

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

Expand All @@ -1816,7 +1898,16 @@ FReply UNoesisInstance::NativeOnTouchEnded(const FGeometry& MyGeometry, const FP

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

Expand All @@ -1841,13 +1932,38 @@ FReply UNoesisInstance::NativeOnMouseButtonDoubleClick(const FGeometry& MyGeomet

if (Handled && Hit)
{
return FReply::Handled().PreventThrottling();
auto Reply = FReply::Handled().PreventThrottling();
if (HasMouseCapture())
{
Reply.CaptureMouse(TakeWidget());
}
else
{
Reply.ReleaseMouseCapture();
}
return Reply;
}
}

return FReply::Unhandled();
}

void UNoesisInstance::NativeOnMouseEnter(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent)
{
if (XamlView)
{
XamlView->Activate();
}
}

void UNoesisInstance::NativeOnMouseLeave(const FPointerEvent& InMouseEvent)
{
if (XamlView && !HasMouseCapture())
{
XamlView->Deactivate();
}
}

bool UNoesisInstance::NativeSupportsKeyboardFocus() const
{
// SObjectWidget::OnKeyDown calls UNoesisInstance::NativeOnKeyDown. There we set SupportsKeyboardFocus = !EnableActions.
Expand Down
5 changes: 5 additions & 0 deletions Source/NoesisRuntime/Private/NoesisRuntimeModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ class FNoesisRuntimeModule : public INoesisRuntimeModuleInterface
Noesis::GUI::DisableHotReload();
Noesis::GUI::DisableInspector();
#endif

#if !WITH_CASE_PRESERVING_NAME
Noesis::SymbolManager::SetCaseSensitive(false);
#endif

Noesis::GUI::DisableSocketInit();

Noesis::GUI::Init();
Expand Down
Loading

0 comments on commit 6515320

Please sign in to comment.