diff --git a/Source/Swipe/Classes/SwipeViewportClient.h b/Source/Swipe/Classes/SwipeViewportClient.h index 0a53262..93f0db7 100644 --- a/Source/Swipe/Classes/SwipeViewportClient.h +++ b/Source/Swipe/Classes/SwipeViewportClient.h @@ -5,12 +5,14 @@ #pragma once -#include "UObject/Object.h" +#include "Engine/GameViewportClient.h" #include "SwipeViewportClient.generated.h" UENUM(BlueprintType) -namespace Swipe { - enum Direction { +namespace Swipe +{ + enum Direction + { None, Left, Right, @@ -20,15 +22,18 @@ namespace Swipe { } UCLASS() -class USwipeViewportClient : public UGameViewportClient { +class USwipeViewportClient : public UGameViewportClient +{ GENERATED_BODY() public: + USwipeViewportClient(); virtual bool InputTouch(FViewport* Viewport, int32 ControllerId, uint32 Handle, ETouchType::Type Type, const FVector2D& TouchLocation, + float Force, FDateTime DeviceTimestamp, uint32 TouchpadIndex) override; @@ -38,6 +43,11 @@ class USwipeViewportClient : public UGameViewportClient { FVector2D SwipeStartLocation; FVector2D SwipeTriggerLocation; int32 TapCount = 0; + const class USwipeSettings* SwipeSettings; + + void CallSwipeDelegates(const FVector2D & TouchLocation); + void DetermineTapAmount(const FVector2D & TouchLocation); + void CallSwipeEndedDelegates(const FVector2D & TouchLocation); UFUNCTION() void ResetTapHandler(); diff --git a/Source/Swipe/Private/Swipe.cpp b/Source/Swipe/Private/Swipe.cpp index 6166a6f..1ed91ef 100644 --- a/Source/Swipe/Private/Swipe.cpp +++ b/Source/Swipe/Private/Swipe.cpp @@ -3,10 +3,9 @@ // Copyright (c) 2015 Get Set Games Inc. All rights reserved. // -#include "SwipePrivatePCH.h" #include "ISettingsModule.h" - -DEFINE_LOG_CATEGORY(LogSwipe); +#include "ISwipe.h" +#include "SwipeSettings.h" #define LOCTEXT_NAMESPACE "Swipe" diff --git a/Source/Swipe/Private/SwipeComponent.cpp b/Source/Swipe/Private/SwipeComponent.cpp index 5cec58e..ad8fffc 100644 --- a/Source/Swipe/Private/SwipeComponent.cpp +++ b/Source/Swipe/Private/SwipeComponent.cpp @@ -3,8 +3,9 @@ // Copyright (c) 2015 Get Set Games Inc. All rights reserved. // +#include "ISettingsModule.h" #include "SwipeComponent.h" -#include "SwipePrivatePCH.h" +#include "SwipeDelegates.h" void USwipeComponent::OnRegister() { diff --git a/Source/Swipe/Private/SwipeDelegates.cpp b/Source/Swipe/Private/SwipeDelegates.cpp index 32ac94d..7a02c05 100644 --- a/Source/Swipe/Private/SwipeDelegates.cpp +++ b/Source/Swipe/Private/SwipeDelegates.cpp @@ -3,8 +3,8 @@ // Copyright (c) 2015 Get Set Games Inc. All rights reserved. // +#include "ISettingsModule.h" #include "SwipeDelegates.h" -#include "SwipePrivatePCH.h" USwipeDelegates::FTouchDelegate USwipeDelegates::TouchBeganDelegate; USwipeDelegates::FTouchDelegate USwipeDelegates::TouchMovedDelegate; diff --git a/Source/Swipe/Private/SwipePrivatePCH.h b/Source/Swipe/Private/SwipePrivatePCH.h deleted file mode 100644 index d53a746..0000000 --- a/Source/Swipe/Private/SwipePrivatePCH.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// Created by Derek van Vliet on 2014-12-10. -// Copyright (c) 2015 Get Set Games Inc. All rights reserved. -// - -#pragma once - -#include "ISwipe.h" - -// You should place include statements to your module's private header files here. You only need to -// add includes for headers that are used in most of your module's source files though. - -DECLARE_LOG_CATEGORY_EXTERN(LogSwipe, Log, All); - -#include "SwipeClasses.h" diff --git a/Source/Swipe/Private/SwipeSettings.cpp b/Source/Swipe/Private/SwipeSettings.cpp index 82ea0f1..f6e53e3 100644 --- a/Source/Swipe/Private/SwipeSettings.cpp +++ b/Source/Swipe/Private/SwipeSettings.cpp @@ -3,8 +3,8 @@ // Copyright (c) 2015 Get Set Games Inc. All rights reserved. // +#include "ISettingsModule.h" #include "SwipeSettings.h" -#include "SwipePrivatePCH.h" USwipeSettings::USwipeSettings(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) diff --git a/Source/Swipe/Private/SwipeViewportClient.cpp b/Source/Swipe/Private/SwipeViewportClient.cpp index 88a1017..238e094 100644 --- a/Source/Swipe/Private/SwipeViewportClient.cpp +++ b/Source/Swipe/Private/SwipeViewportClient.cpp @@ -1,17 +1,22 @@ -// -// Created by Derek van Vliet on 2014-12-10. -// Copyright (c) 2015 Get Set Games Inc. All rights reserved. -// - +#include "ISettingsModule.h" #include "SwipeViewportClient.h" -#include "SwipePrivatePCH.h" -#include "Runtime/Engine/Classes/Engine/UserInterfaceSettings.h" +#include "SwipeSettings.h" +#include "SwipeDelegates.h" + +#include "Engine/Engine.h" +#include "Engine/World.h" +#include "Engine/UserInterfaceSettings.h" + +USwipeViewportClient::USwipeViewportClient() : + SwipeSettings(GetDefault()) +{} bool USwipeViewportClient::InputTouch(FViewport* InViewport, int32 ControllerId, uint32 Handle, ETouchType::Type Type, const FVector2D& TouchLocation, + float Force, FDateTime DeviceTimestamp, uint32 TouchpadIndex) { @@ -20,8 +25,6 @@ bool USwipeViewportClient::InputTouch(FViewport* InViewport, return false; } - const USwipeSettings* SwipeSettings = GetDefault(); - switch (Type) { case ETouchType::Began: @@ -37,109 +40,126 @@ bool USwipeViewportClient::InputTouch(FViewport* InViewport, case ETouchType::Moved: { USwipeDelegates::TouchMovedDelegate.Broadcast(TouchLocation, Handle); - - float MinSwipeDistance = SwipeSettings->MinSwipeDistance; - if (SwipeSettings->EnableDPIScaling) - { - MinSwipeDistance *= GetDPIScreenScale(); - } - - if (bSwiping && SwipeDirection == Swipe::Direction::None) { - FVector2D TouchDelta = TouchLocation - SwipeStartLocation; - float AbsX = FMath::Abs(TouchDelta.X); - float AbsY = FMath::Abs(TouchDelta.Y); - bool XMeetsThreshold = (AbsX >= MinSwipeDistance); - bool YMeetsThreshold = (AbsY >= MinSwipeDistance); - - if (AbsX > AbsY && XMeetsThreshold) { - SwipeTriggerLocation = TouchLocation; - if (TouchDelta.X > 0) { - USwipeDelegates::SwipeRightDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); - SwipeDirection = Swipe::Direction::Right; - } - else { - USwipeDelegates::SwipeLeftDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); - SwipeDirection = Swipe::Direction::Left; - } - } - else if (YMeetsThreshold) { - SwipeTriggerLocation = TouchLocation; - if (TouchDelta.Y > 0) { - USwipeDelegates::SwipeDownDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); - SwipeDirection = Swipe::Direction::Down; - } - else { - USwipeDelegates::SwipeUpDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); - SwipeDirection = Swipe::Direction::Up; - } - } - } - + CallSwipeDelegates(TouchLocation); break; } case ETouchType::Ended: { USwipeDelegates::TouchEndedDelegate.Broadcast(TouchLocation, Handle); - bSwiping = false; - - switch (SwipeDirection) + if (SwipeDirection != Swipe::Direction::None) { - case Swipe::Direction::Right: - { - USwipeDelegates::SwipeRightEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); - break; - } - case Swipe::Direction::Left: - { - USwipeDelegates::SwipeLeftEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); - break; - } - case Swipe::Direction::Down: - { - USwipeDelegates::SwipeDownEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); - break; - } - case Swipe::Direction::Up: - { - USwipeDelegates::SwipeUpEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); - break; - } - default: - TapCount++; - - if (TapCount == 1) - { - USwipeDelegates::SingleTapDelegate.Broadcast(TouchLocation); - } - else if(TapCount >= 2) - { - USwipeDelegates::DoubleTapDelegate.Broadcast(TouchLocation); - } - - FTimerHandle TapHandler; - FTimerDelegate TapHandlerDelegate; - TapHandlerDelegate.BindUObject(this, &USwipeViewportClient::ResetTapHandler); - UWorld* World = GetWorld(); - if (World) - { - World->GetTimerManager().SetTimer(TapHandler, TapHandlerDelegate, SwipeSettings->MaxTimeBetweenTaps, false); - } - - break; + CallSwipeEndedDelegates(TouchLocation); + SwipeDirection = Swipe::Direction::None; + } + else + { + DetermineTapAmount(TouchLocation); } - - SwipeDirection = Swipe::Direction::None; } default: break; } - bool bResult = Super::InputTouch(InViewport, ControllerId, Handle, Type, TouchLocation, DeviceTimestamp, TouchpadIndex); + bool bResult = Super::InputTouch(InViewport, ControllerId, Handle, Type, TouchLocation, Force, DeviceTimestamp, TouchpadIndex); return bResult; } +void USwipeViewportClient::CallSwipeDelegates(const FVector2D & TouchLocation) +{ + float MinSwipeDistance = SwipeSettings->MinSwipeDistance; + if (SwipeSettings->EnableDPIScaling) + { + MinSwipeDistance *= GetDPIScreenScale(); + } + + if (bSwiping && SwipeDirection == Swipe::Direction::None) + { + const FVector2D TouchDelta = TouchLocation - SwipeStartLocation; + const float AbsX = FMath::Abs(TouchDelta.X); + const float AbsY = FMath::Abs(TouchDelta.Y); + const bool XMeetsThreshold = (AbsX >= MinSwipeDistance); + const bool YMeetsThreshold = (AbsY >= MinSwipeDistance); + if (AbsX > AbsY && XMeetsThreshold) + { + SwipeTriggerLocation = TouchLocation; + if (TouchDelta.X > 0) + { + USwipeDelegates::SwipeRightDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); + SwipeDirection = Swipe::Direction::Right; + } + else + { + USwipeDelegates::SwipeLeftDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); + SwipeDirection = Swipe::Direction::Left; + } + } + else if (YMeetsThreshold) + { + SwipeTriggerLocation = TouchLocation; + if (TouchDelta.Y > 0) + { + USwipeDelegates::SwipeDownDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); + SwipeDirection = Swipe::Direction::Down; + } + else + { + USwipeDelegates::SwipeUpDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation); + SwipeDirection = Swipe::Direction::Up; + } + } + } +} + +void USwipeViewportClient::DetermineTapAmount(const FVector2D & TouchLocation) +{ + ++TapCount; + if (TapCount == 1) + { + USwipeDelegates::SingleTapDelegate.Broadcast(TouchLocation); + } + else if (TapCount >= 2) + { + USwipeDelegates::DoubleTapDelegate.Broadcast(TouchLocation); + } + FTimerHandle TapHandler; + FTimerDelegate TapHandlerDelegate; + TapHandlerDelegate.BindUObject(this, &USwipeViewportClient::ResetTapHandler); + UWorld* World = GetWorld(); + if (World) + { + World->GetTimerManager().SetTimer(TapHandler, TapHandlerDelegate, SwipeSettings->MaxTimeBetweenTaps, false); + } +} + +void USwipeViewportClient::CallSwipeEndedDelegates(const FVector2D & TouchLocation) +{ + switch (SwipeDirection) + { + case Swipe::Direction::Right: + { + USwipeDelegates::SwipeRightEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); + break; + } + case Swipe::Direction::Left: + { + USwipeDelegates::SwipeLeftEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); + break; + } + case Swipe::Direction::Down: + { + USwipeDelegates::SwipeDownEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); + break; + } + case Swipe::Direction::Up: + { + USwipeDelegates::SwipeUpEndedDelegate.Broadcast(SwipeStartLocation, SwipeTriggerLocation, TouchLocation); + break; + } + } +} + void USwipeViewportClient::ResetTapHandler() { TapCount = 0; diff --git a/Source/Swipe/Swipe.Build.cs b/Source/Swipe/Swipe.Build.cs index f98554e..81d084a 100644 --- a/Source/Swipe/Swipe.Build.cs +++ b/Source/Swipe/Swipe.Build.cs @@ -7,7 +7,7 @@ namespace UnrealBuildTool.Rules { public class Swipe : ModuleRules { - public Swipe(TargetInfo Target) + public Swipe(ReadOnlyTargetRules Target) : base (Target) { PublicIncludePaths.AddRange( new string[] { @@ -17,7 +17,6 @@ public Swipe(TargetInfo Target) PrivateIncludePaths.AddRange( new string[] { - "Developer/Swipe/Private", // ... add other private include paths required here ... } );