void SProfilerThreadView::DrawText( const FString& Text, const FSlateFontInfo& FontInfo, FVector2D Position, const FColor& TextColor, const FColor& ShadowColor, FVector2D ShadowOffset, const FSlateRect* ClippingRect /*= nullptr*/ ) const { check( PaintState ); if( ShadowOffset.Size() > 0.0f ) { FSlateDrawElement::MakeText ( PaintState->OutDrawElements, PaintState->LayerId, PaintState->AllottedGeometry.ToOffsetPaintGeometry( Position + ShadowOffset ), Text, FontInfo, ClippingRect ? *ClippingRect : PaintState->AbsoluteClippingRect, PaintState->DrawEffects, ShadowColor ); } FSlateDrawElement::MakeText ( PaintState->OutDrawElements, ++PaintState->LayerId, PaintState->AllottedGeometry.ToOffsetPaintGeometry( Position ), Text, FontInfo, ClippingRect ? *ClippingRect : PaintState->AbsoluteClippingRect, PaintState->DrawEffects, TextColor ); }
void UReporterBase::DrawLine(UCanvas* Canvas,const FVector2D& StartPos,const FVector2D& EndPos,const FLinearColor& Color, EReporterLineStyle::Type LineStyle) { FCanvasLineItem LineItem; LineItem.SetColor( Color ); switch(LineStyle) { case EReporterLineStyle::Line: { LineItem.Draw( Canvas->Canvas, ToScreenSpace(StartPos, Canvas), ToScreenSpace(EndPos, Canvas) ); } break; case EReporterLineStyle::Dash: { float NormalizedDashSize = DASH_LINE_SIZE / Canvas->SizeX; FVector2D Dir = EndPos - StartPos; float LineLength = Dir.Size(); Dir.Normalize(); FVector2D CurrentLinePos = StartPos; while(FVector2D::DotProduct(EndPos - CurrentLinePos, Dir) > 0) { LineItem.Draw( Canvas->Canvas, ToScreenSpace(CurrentLinePos, Canvas), ToScreenSpace(CurrentLinePos + Dir * NormalizedDashSize, Canvas) ); CurrentLinePos += Dir * NormalizedDashSize * 2.0f; } } break; } }
void AMinimapActor::ReceiveCharacterVisibilityUpdate(const TArray<AGameCharacter*>& visibleCharacters) { TArray<FMinimapEntry> entries; for (int32 i = 0; i < visibleCharacters.Num(); i++) { if (!IsValid(visibleCharacters[i])) continue; FMinimapEntry entry; entry.character = visibleCharacters[i]; FVector2D relPos; relPos.X = (visibleCharacters[i]->GetActorLocation().Y - GetActorLocation().Y) / mapSize.X; relPos.Y = (GetActorLocation().X - visibleCharacters[i]->GetActorLocation().X) / mapSize.X; entry.relativePosition.X = relPos.Size() * FMath::Cos(FMath::Atan2(relPos.Y, relPos.X)); entry.relativePosition.Y = relPos.Size() * FMath::Sin(FMath::Atan2(relPos.Y, relPos.X)); entries.Add(entry); } if (IsValid(hud)) hud->OnMinimapVisibleCharactersUpdate(entries); }
FReply SPaperEditorViewport::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { const bool bIsRightMouseButtonDown = MouseEvent.IsMouseButtonDown(EKeys::RightMouseButton); const bool bIsLeftMouseButtonDown = MouseEvent.IsMouseButtonDown(EKeys::LeftMouseButton); if (HasMouseCapture()) { // Track how much the mouse moved since the mouse down. const FVector2D CursorDelta = MouseEvent.GetCursorDelta(); TotalMouseDelta += CursorDelta.Size(); if (bIsRightMouseButtonDown) { FReply ReplyState = FReply::Handled(); if (!CursorDelta.IsZero()) { bShowSoftwareCursor = true; } bIsPanning = true; ViewOffset -= CursorDelta / GetZoomAmount(); return ReplyState; } else if (bIsLeftMouseButtonDown) { // TSharedPtr<SNode> NodeBeingDragged = NodeUnderMousePtr.Pin(); // Update the amount to pan panel UpdateViewOffset(MyGeometry, MouseEvent.GetScreenSpacePosition()); const bool bCursorInDeadZone = TotalMouseDelta <= FSlateApplication::Get().GetDragTriggerDistance(); { // We are marquee selecting const FVector2D GraphMousePos = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ); Marquee.Rect.UpdateEndPoint(GraphMousePos); return FReply::Handled(); } } } return FReply::Unhandled(); }
bool SVirtualJoystick::HandleTouch(int32 ControlIndex, const FVector2D& LocalCoord, const FVector2D& ScreenSize) { FControlInfo& Control = Controls[ControlIndex]; // figure out position around center FVector2D Offset = LocalCoord - Controls[ControlIndex].VisualCenter; // only do work if we aren't at the center if (Offset == FVector2D(0, 0)) { Control.ThumbPosition = Offset; } else { // clamp to the ellipse of the stick (snaps to the visual size, so, the art should go all the way to the edge of the texture) float DistanceToTouch = Offset.Size(); float Angle = FMath::Atan2(Offset.Y, Offset.X); // length along line to ellipse: L = 1.0 / sqrt(((sin(T)/Rx)^2 + (cos(T)/Ry)^2)) float CosAngle = FMath::Cos(Angle); float SinAngle = FMath::Sin(Angle); float XTerm = CosAngle / (Control.VisualSize.X * 0.5f); float YTerm = SinAngle / (Control.VisualSize.Y * 0.5f); float DistanceToEdge = FMath::InvSqrt(XTerm * XTerm + YTerm * YTerm); // only clamp if (DistanceToTouch > DistanceToEdge) { Control.ThumbPosition = FVector2D(DistanceToEdge * CosAngle, DistanceToEdge * SinAngle); } else { Control.ThumbPosition = Offset; } } FVector2D AbsoluteThumbPos = Control.ThumbPosition + Controls[ControlIndex].VisualCenter; AlignBoxIntoScreen(AbsoluteThumbPos, Control.ThumbSize, ScreenSize); Control.ThumbPosition = AbsoluteThumbPos - Controls[ControlIndex].VisualCenter; return true; }
bool SColorWheel::ProcessMouseAction(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent, bool bProcessWhenOutsideColorWheel) { const FVector2D LocalMouseCoordinate = MyGeometry.AbsoluteToLocal(MouseEvent.GetScreenSpacePosition()); const FVector2D Location = LocalMouseCoordinate / (MyGeometry.Size * 0.5f) - FVector2D(1.0f, 1.0f); const float Radius = Location.Size(); if (Radius <= 1.0f || bProcessWhenOutsideColorWheel) { float Angle = FMath::Atan2(Location.Y, Location.X); if (Angle < 0.0f) { Angle += 2.0f * PI; } FLinearColor NewColor = SelectedColor.Get(); NewColor.R = Angle * 180.0f * INV_PI; NewColor.G = FMath::Min(Radius, 1.0f); OnValueChanged.ExecuteIfBound(NewColor); } return (Radius <= 1.0f); }
float UKismetMathLibrary::VSize2D(FVector2D A) { return A.Size(); }
/** SWidget interface */ virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override { const bool bIsRightMouseButtonDown = MouseEvent.IsMouseButtonDown( EKeys::RightMouseButton ); const bool bIsLeftMouseButtonDown = MouseEvent.IsMouseButtonDown( EKeys::LeftMouseButton ); PastePosition = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ); if ( this->HasMouseCapture() ) { const FVector2D CursorDelta = MouseEvent.GetCursorDelta(); // Track how much the mouse moved since the mouse down. TotalMouseDelta += CursorDelta.Size(); if (bIsRightMouseButtonDown) { FReply ReplyState = FReply::Handled(); if( !CursorDelta.IsZero() ) { bShowSoftwareCursor = true; } // Panning and mouse is outside of panel? Pasting should just go to the screen center. PastePosition = PanelCoordToGraphCoord( 0.5 * MyGeometry.Size ); this->bIsPanning = true; ViewOffset -= CursorDelta / GetZoomAmount(); return ReplyState; } else if (bIsLeftMouseButtonDown) { TSharedPtr<SNode> NodeBeingDragged = NodeUnderMousePtr.Pin(); if ( IsEditable.Get() ) { // Update the amount to pan panel UpdateViewOffset(MyGeometry, MouseEvent.GetScreenSpacePosition()); const bool bCursorInDeadZone = TotalMouseDelta <= FSlateApplication::Get().GetDragTriggerDistance(); if ( NodeBeingDragged.IsValid() ) { if ( !bCursorInDeadZone ) { // Note, NodeGrabOffset() comes from the node itself, so it's already scaled correctly. FVector2D AnchorNodeNewPos = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ) - NodeGrabOffset; // Dragging an unselected node automatically selects it. SelectionManager.StartDraggingNode(NodeBeingDragged->GetObjectBeingDisplayed(), MouseEvent); // Move all the selected nodes. { const FVector2D AnchorNodeOldPos = NodeBeingDragged->GetPosition(); const FVector2D DeltaPos = AnchorNodeNewPos - AnchorNodeOldPos; if (DeltaPos.Size() > KINDA_SMALL_NUMBER) { MoveSelectedNodes(NodeBeingDragged, AnchorNodeNewPos); } } } return FReply::Handled(); } } if ( !NodeBeingDragged.IsValid() ) { // We are marquee selecting const FVector2D GraphMousePos = PanelCoordToGraphCoord( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ) ); Marquee.Rect.UpdateEndPoint(GraphMousePos); FindNodesAffectedByMarquee( /*out*/ Marquee.AffectedNodes ); return FReply::Handled(); } } } return FReply::Unhandled(); }
bool UPhysicsMovementComponent::ServerSetDesiredDirection_Validate(FVector2D direction, float clientTimestamp) { return direction.Size() <= 1; }