diff --git a/Source/DasherVR/Private/SDasherWidget.cpp b/Source/DasherVR/Private/SDasherWidget.cpp index 4da819d5901ec6461c61acd52c49a90be4159705..a378e0008b777ee9b4f4027162ca55c4a21add86 100644 --- a/Source/DasherVR/Private/SDasherWidget.cpp +++ b/Source/DasherVR/Private/SDasherWidget.cpp @@ -45,18 +45,10 @@ FReply SDasherWidget::HandleMouseMoveEvent(const FGeometry& Geometry, const FPoi { if (CurrentlyUsingVectorInput) return FReply::Unhandled(); //The mouse event only contains the Screen Space Position - CursorPosition = Geometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()); + const FVector2D newMousePosition = Geometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()); - if(URWTHVRUtilities::IsRoomMountedMode()) - { - FDisplayClusterClusterEventBinary ClusterEvent; - ClusterEvent.EventId = DasherEventID; - ClusterEvent.EventData.SetNumUninitialized(sizeof(CursorPosition.X) + sizeof(CursorPosition.Y) + 1); - ClusterEvent.EventData[0] = static_cast<uint8>(DasherEventType::Input_MouseMove); - FMemory::Memcpy(&ClusterEvent.EventData[1], &CursorPosition.X, sizeof(CursorPosition.X)); - FMemory::Memcpy(&ClusterEvent.EventData[1] + sizeof(CursorPosition.X), &CursorPosition.Y, sizeof(CursorPosition.Y)); - IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventBinary(ClusterEvent, false); - } + NewMousePosition.x = newMousePosition.X; + NewMousePosition.y = newMousePosition.Y; } return FReply::Handled(); } @@ -137,9 +129,9 @@ FReply SDasherWidget::HandleMouseDoubleClickEvent(const FGeometry& Geometry, con //Set in the HandleMouseMoveEvent or via Set InputVector //See tick for geometry things that could be use to modify this. -FVector2D SDasherWidget::GetCursorPosition() +FVector2D SDasherWidget::GetCursorPosition() const { - return CursorPosition; + return FVector2D(CursorPosition.x, CursorPosition.y); } bool SDasherWidget::GetScreenCoords(screenint& iX, screenint& iY, Dasher::CDasherView* pView) @@ -166,13 +158,13 @@ void SDasherWidget::HandleClusterEvent(const FDisplayClusterClusterEventBinary& DasherMainInterface->KeyUp(FDateTime::Now().GetSecond() + FDateTime::Now().GetMillisecond(), Dasher::Keys::Primary_Input); MouseUpListeners.ExecuteIfBound(); break; - case DasherEventType::Input_MouseMove: - FMemory::Memcpy(&CursorPosition.X, &Event.EventData[1], sizeof(CursorPosition.X)); - FMemory::Memcpy(&CursorPosition.Y, &Event.EventData[1] + sizeof(CursorPosition.X), sizeof(CursorPosition.Y)); - break; case DasherEventType::Tick: double currentTime = 0; + FMemory::Memcpy(¤tTime, &Event.EventData[1], sizeof(currentTime)); + FMemory::Memcpy(&CursorPosition.x, &Event.EventData[1] + sizeof(currentTime), sizeof(CursorPosition.x)); + FMemory::Memcpy(&CursorPosition.y, &Event.EventData[1] + sizeof(currentTime) + sizeof(CursorPosition.x), sizeof(CursorPosition.y)); + DasherMainInterface->Tick(static_cast<unsigned long>(currentTime * 1000.0)); break; } @@ -182,8 +174,10 @@ void SDasherWidget::InputVector(const FVector2D InputVector) { if (!InputPaused) { if (!CurrentlyUsingVectorInput) return; - CursorPosition = DasherMainInterface->ConvertDasher2Screen(Dasher::CDasherModel::ORIGIN_X, Dasher::CDasherModel::ORIGIN_Y) + const FVector2D pos = DasherMainInterface->ConvertDasher2Screen(Dasher::CDasherModel::ORIGIN_X, Dasher::CDasherModel::ORIGIN_Y) + InputVector * FVector2D(1.0f, -1.0f) * (GetHeight() / 2); + CursorPosition.x = pos.X; + CursorPosition.y = pos.Y; } } @@ -302,17 +296,26 @@ void SDasherWidget::Tick(const FGeometry& AllottedGeometry, const double InCurre //don't tick in the editor if (IsEditor || InputPaused) return; + //Needs to be updated in Tick due to event order in cluster mode + CursorPosition = NewMousePosition; + if(!URWTHVRUtilities::IsRoomMountedMode()){ DasherMainInterface->Tick(static_cast<unsigned long>(InCurrentTime * 1000.0)); //we need to provide ticks in milliseconds } else if(URWTHVRUtilities::IsPrimaryNode()) { + UE_LOG(LogTemp, Log, TEXT("EventSend: %d, %d"), CursorPosition.x, CursorPosition.y); + FDisplayClusterClusterEventBinary ClusterEvent; ClusterEvent.EventId = DasherEventID; - ClusterEvent.EventData.SetNumUninitialized(sizeof(InCurrentTime) + 1); + ClusterEvent.EventData.SetNumUninitialized(sizeof(InCurrentTime) + sizeof(CursorPosition.x) + sizeof(CursorPosition.y) + 1); + ClusterEvent.EventData[0] = static_cast<uint8>(DasherEventType::Tick); FMemory::Memcpy(&ClusterEvent.EventData[1], &InCurrentTime, sizeof(InCurrentTime)); + FMemory::Memcpy(&ClusterEvent.EventData[1] + sizeof(InCurrentTime), &CursorPosition.x, sizeof(CursorPosition.x)); + FMemory::Memcpy(&ClusterEvent.EventData[1] + sizeof(InCurrentTime) + sizeof(CursorPosition.x), &CursorPosition.y, sizeof(CursorPosition.y)); + IDisplayCluster::Get().GetClusterMgr()->EmitClusterEventBinary(ClusterEvent, false); } @@ -328,7 +331,7 @@ void SDasherWidget::Tick(const FGeometry& AllottedGeometry, const double InCurre } } -std::pair<SDasherWidget::screenint, SDasherWidget::screenint> SDasherWidget::TextSize(CDasherScreen::Label* Label, unsigned Size) +std::pair<Dasher::screenint, Dasher::screenint> SDasherWidget::TextSize(Label* Label, unsigned Size) { const FSlateFontInfo Font = FCoreStyle::GetDefaultFontStyle("Roboto", Size, FFontOutlineSettings::NoOutline); //get the font const FVector2D TextSize = FontMeasureService->Measure(FString(UTF8_TO_TCHAR(Label->m_strText.c_str())), Font, 1); //get the real size of the text, using the fontmeasuring service diff --git a/Source/DasherVR/Public/SDasherWidget.h b/Source/DasherVR/Public/SDasherWidget.h index f1d52165acc1bd1db405079e0ddb6929212f2b7b..563f607d7a5d2ee7ca2ebc33b234c83f149c4e7c 100644 --- a/Source/DasherVR/Public/SDasherWidget.h +++ b/Source/DasherVR/Public/SDasherWidget.h @@ -25,8 +25,7 @@ enum class DasherEventType : uint8 { Input_MouseDown = 1, Input_MouseUp = 2, - Input_MouseMove = 3, - Tick + Tick = 3 }; struct DasherDrawGeometry @@ -136,7 +135,7 @@ public: void InputVector(FVector2D InputVector); void InputButton(bool Pressed); - FVector2D GetCursorPosition(); + FVector2D GetCursorPosition() const; //Allows to Pause Input void PauseInput(); @@ -160,7 +159,8 @@ private: int Width = 0; bool HasBeenPainted = false; bool CurrentlyUsingVectorInput = false; - FVector2D CursorPosition; + point CursorPosition = {0,0}; + point NewMousePosition = {0,0}; bool CharacterEnteredFlag = false; bool CharacterDeletedFlag = false; FString AlteredChar = ""; @@ -175,7 +175,7 @@ private: //CAVE Sync FOnClusterEventBinaryListener ClusterEventListener; - inline static int32 DasherEventID = -424242; + inline static int32 DasherEventID = 424242; protected: // stores color information