FReply STrack::OnMouseButtonUp( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) { bool bLeftMouseButton = MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton; bool bRightMouseButton = MouseEvent.GetEffectingButton() == EKeys::RightMouseButton; if ( bRightMouseButton ) { TSharedPtr<SWidget> WidgetToFocus; WidgetToFocus = SummonContextMenu(MyGeometry, MouseEvent); return (WidgetToFocus.IsValid()) ? FReply::Handled().ReleaseMouseCapture().SetUserFocus( WidgetToFocus.ToSharedRef(), EFocusCause::SetDirectly ) : FReply::Handled().ReleaseMouseCapture(); } else if ( bLeftMouseButton ) { float SnapPos = 0.f; if ( GetDraggableBarSnapPosition(MyGeometry, SnapPos) ) { // Final update on draggable bar to snap position OnBarDrag.Execute(DraggableBarIndex, SnapPos); } if(bDraggingBar) { OnBarDrop.Execute(DraggableBarIndex); OnBarClicked.ExecuteIfBound(DraggableBarIndex); } /** Bar dragging */ DraggableBarIndex = INDEX_NONE; bDraggingBar = false; } return FReply::Unhandled(); }
int32 STrack::OnPaint( const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const { int32 CustomLayerId = LayerId + 1; FPaintGeometry MyGeometry = AllottedGeometry.ToPaintGeometry(); // Background FSlateDrawElement::MakeBox( OutDrawElements, CustomLayerId++, MyGeometry, FEditorStyle::GetBrush(TEXT( "Persona.NotifyEditor.NotifyTrackBackground" )), MyClippingRect, ESlateDrawEffect::None, TrackColor.Get() ); // Draw Scrub Position if ( ScrubPosition.Get() >= 0.f ) { float XPos = DataToLocalX(ScrubPosition.Get(), AllottedGeometry); TArray<FVector2D> LinePoints; LinePoints.Add(FVector2D(XPos, 0.f)); LinePoints.Add(FVector2D(XPos, AllottedGeometry.Size.Y)); FSlateDrawElement::MakeLines( OutDrawElements, CustomLayerId++, MyGeometry, LinePoints, MyClippingRect, ESlateDrawEffect::None, FLinearColor(1, 0, 0) ); } // Draggable Bars for ( int32 I=0; DraggableBars.IsBound() && I < DraggableBars.Get().Num(); I++ ) { // Draw lines float XPos = DataToLocalX(DraggableBars.Get()[I], AllottedGeometry); TArray<FVector2D> LinePoints; LinePoints.Add(FVector2D(XPos, 0.f)); LinePoints.Add(FVector2D(XPos, AllottedGeometry.Size.Y)); FSlateDrawElement::MakeLines( OutDrawElements, CustomLayerId, MyGeometry, LinePoints, MyClippingRect, ESlateDrawEffect::None, FLinearColor(0.0f, 1.0f, 0.0f, 1.0f) ); // Draw Labels if (DraggableBarLabels.IsBound() && DraggableBarLabels.Get().IsValidIndex(I)) { //float EndPos = (DraggableBarIndex.Get().IsValidIndex(I+1) ? DraggableBarIndex.Get()(I+1) FPaintGeometry TextGeometry = AllottedGeometry.ToPaintGeometry( FVector2D(XPos + 5.f, 5.f), AllottedGeometry.GetDrawSize() ); FSlateDrawElement::MakeText( OutDrawElements, CustomLayerId, TextGeometry, DraggableBarLabels.Get()[I], Font, MyClippingRect, ESlateDrawEffect::None, FLinearColor::Black ); } } // Ghost snap position float SnapPos = 0.f; if ( GetDraggableBarSnapPosition(AllottedGeometry, SnapPos) ) { SnapPos = DataToLocalX(SnapPos, AllottedGeometry); TArray<FVector2D> LinePoints; LinePoints.Add(FVector2D(SnapPos, 0.f)); LinePoints.Add(FVector2D(SnapPos, AllottedGeometry.Size.Y)); FSlateDrawElement::MakeLines( OutDrawElements, CustomLayerId, MyGeometry, LinePoints, MyClippingRect, ESlateDrawEffect::None, FLinearColor(0.5f, 0.0f, 0.0f, 0.5f) ); } CustomLayerId++; // draw line for every 1/4 length if ( TrackMaxValue.Get() > 0.f && TrackNumDiscreteValues.Get() > 0 ) { int32 Divider = SScrubWidget::GetDivider( ViewInputMin.Get(), ViewInputMax.Get(), AllottedGeometry.Size, TrackMaxValue.Get(), TrackNumDiscreteValues.Get()); const float TimePerValue = TrackMaxValue.Get()/static_cast<float>(TrackNumDiscreteValues.Get()); for (int I=1; I<TrackNumDiscreteValues.Get(); ++I) { if ( I % Divider == 0 ) { float XPos = DataToLocalX(TimePerValue*I, AllottedGeometry); TArray<FVector2D> LinePoints; LinePoints.Add(FVector2D(XPos, 0.f)); LinePoints.Add(FVector2D(XPos, AllottedGeometry.Size.Y)); FSlateDrawElement::MakeLines( OutDrawElements, CustomLayerId, MyGeometry, LinePoints, MyClippingRect, ESlateDrawEffect::None, FLinearColor::Black ); } } ++CustomLayerId; } return SPanel::OnPaint( AllottedGeometry, MyClippingRect, OutDrawElements, CustomLayerId, InWidgetStyle, bParentEnabled ); }