Files
UnrealEngineUWP/Engine/Source/Developer/TaskGraph/Private/SGraphBar.cpp

224 lines
6.5 KiB
C++
Raw Normal View History

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
Copying //UE4/Dev-Build to //UE4/Dev-Main (Source: //UE4/Dev-Build @ 3092544) #lockdown Nick.Penwarden #rb none ========================== MAJOR FEATURES + CHANGES ========================== Change 3079316 on 2016/08/05 by Ben.Marsh Better PCH selection in ShaderFormatOpenGL and MetalShaderFormat - make sure Core is the first included header. Change 3080579 on 2016/08/08 by Ben.Marsh Slate: Move DEBUG_TAB_MANAGEMENT into SDockingTabStack.h to remove circular include dependency with DockingPrivate.h. Change 3080587 on 2016/08/08 by Ben.Marsh StandaloneRenderer: Move platform includes into a separate header so we can make individual headers self-contained, without having a circular dependency on StandaloneRendererPrivate.h. Change 3080789 on 2016/08/08 by Ben.Marsh Move BuildGraph tasks for chunking, posting builds, labeling builds, and merging manifests into the MCP project. While we do provide public interfaces for this functionality, we don't currently expect anyone outside Epic to be using them. Change 3080815 on 2016/08/08 by Ben.Marsh BuildGraph: Add a -GenerateDocs option, which writes out an HTML file constructed from C# XML documentation containing all the task information. Change 3081374 on 2016/08/08 by Ben.Marsh UBT: Invalidate the makefile if any UHT headers are deleted. Should fix issue where files are moved from one module to another, and the original module no longer contains any generated headers. Its include path needs to be removed from the compile environment. Change 3083152 on 2016/08/09 by Ben.Marsh PR #2667: Add Intel C++ Compiler support to Windows build (Contributed by JeffRous) Change 3084039 on 2016/08/10 by Ben.Marsh BuildGraph: Add additional markup for parameter attributes. Also improve some documation. Change 3084240 on 2016/08/10 by Ben.Marsh Plugins: Allow plugins in the project folder to replace plugins in the engine folder with the same name. Prohibit multiple plugins with the same name at other times. Change 3084337 on 2016/08/10 by Ben.Marsh UBT: Specify the -precompile option when generating project files for a target, so we include all valid modules for intellisense. Change 3085594 on 2016/08/11 by Ben.Marsh Change modules which reference a public header for their PCH to use a private PCH instead, even if it just includes the public header for now. Change 3085999 on 2016/08/11 by Ben.Marsh Add some missing #pragma once directives. Change 3086146 on 2016/08/11 by Ben.Marsh Core: Move prototype and linkage specifier for ConsoleCommandLibrary_* functions into header matching cpp file. Change 3086172 on 2016/08/11 by Ben.Marsh Fixup some C-style header guards to use #pragma once instead. Change 3087289 on 2016/08/12 by Ben.Marsh Split out UPackage and UMetaData into their own headers (they're already implemented in separate CPP files) Change 3087310 on 2016/08/12 by Ben.Marsh Move method stubs for FNullSlateSoundDevice into a CPP file, since they're exported from the SlateCore module. Change 3087341 on 2016/08/12 by Ben.Marsh UdpMessaging: Move PCH before #if PLATFORM_DESKTOP; it will only be defined if the definition is included. Change 3087457 on 2016/08/12 by Ben.Marsh Core: Reorganize the FTransform and FMatrix headers: Transform.h now includes TransformNonVectorized.h or TransformVectorized.h as appropriate, and UnrealMatrix.h is now Matrix.inl (and included from Matrix.h). Change 3088407 on 2016/08/13 by Ben.Marsh Replace use of Windows SIZE_T define with the regular C++ size_t. Change 3088416 on 2016/08/13 by Ben.Marsh Include a header from all .generated.cpp files (GeneratedCppIncludes.h) which includes all the basic types required to compile them, rather than assuming that the module PCH will include everything. Also include the real declarations of noexport classes in Object.h (now renamed to NoExportTypes.h for clarity) when the CPP macro is defined, so the .generated.deps.h file will automatically have the correct definitions for them at compile time rather than relying on them being in the private PCH. Finally, rename UObject.h to Object.h for consistency with the naming convention for all other UObject classes. UObject.h still exists for now, but outputs a deprecated message if included. Change 3088544 on 2016/08/14 by Ben.Marsh Core: Move the definition of the TEXT() macro into Platform.h, to avoid having to include OS headers to get it. Change 3088552 on 2016/08/14 by Ben.Marsh Fix compile errors for some modules that don't already include CoreUObject.h. Change 3088925 on 2016/08/15 by Ben.Marsh Remove circular include dependencies from VulkanRHI. Change 3088926 on 2016/08/15 by Ben.Marsh Remove duplicate definition for WITH_FIXED_AREA_ENTERING_COST from EngineDefines.h - always uses the definition from DetourNavMeshQuery.h instead. Change 3088930 on 2016/08/15 by Ben.Marsh Remove circular include dependency from PhysX. Change 3088935 on 2016/08/15 by Ben.Marsh OnlineSubsystemUtils: Move CPP files out of public header directory. Change 3088965 on 2016/08/15 by Ben.Marsh Add private PCH to Landscape, MoviePlayer, TaskGraph, XAudio2 and RealtimeProfiler modules. Change 3088966 on 2016/08/15 by Ben.Marsh Engine: Move CPP files out of public header directories. Change 3089520 on 2016/08/15 by Ben.Marsh BuildGraph: Change documentation command to output markdown. Change 3090299 on 2016/08/16 by Ben.Marsh D3D12RHI: Move around some implementations to fix circular header dependencies which are masked by delayed template instantiation. Change 3090303 on 2016/08/16 by Ben.Marsh Engine: Add a template specialization for TPointerIsConvertibleFromTo<AActor, const volatile UObject> to fix dependency on complete AActor definition for static assert in TWeakPointer<AActor>, which only appears if including Level.h without Actor.h. Delayed template instantiation usually masks this issue. Change 3091861 on 2016/08/17 by Ben.Marsh Remove circular header dependencies, and fix ambiguous include paths in OSVR. Change 3092068 on 2016/08/17 by Ben.Marsh Moving VulkanDynamicRHI into its own header. Change 3093133 on 2016/08/18 by Ben.Marsh EC: Include additional context lines for Clang errors. Change 3093147 on 2016/08/18 by Ben.Marsh UBT: Add an error message when attempting to do a single-file compile with the wrong target selected. Change 3093228 on 2016/08/18 by Ben.Marsh Remove redundant setting for remote server name from XML config, and set it to a valid machine in the engine config. [CL 3093264 by Ben Marsh in Main branch]
2016-08-18 10:28:43 -04:00
#include "TaskGraphPrivatePCH.h"
#include "SlateBasics.h"
#include "TaskGraphStyle.h"
#include "TaskGraphInterfaces.h"
#include "VisualizerEvents.h"
#include "SGraphBar.h"
FColor SGraphBar::ColorPalette[] = {
FColor( 0xff00A480 ),
FColor( 0xff62E200 ),
FColor( 0xff8F04A8 ),
FColor( 0xff1F7B67 ),
FColor( 0xff62AA2A ),
FColor( 0xff70227E ),
FColor( 0xff006B53 ),
FColor( 0xff409300 ),
FColor( 0xff5D016D ),
FColor( 0xff34D2AF ),
FColor( 0xff8BF13C ),
FColor( 0xffBC38D3 ),
FColor( 0xff5ED2B8 ),
FColor( 0xffA6F16C ),
FColor( 0xffC262D3 ),
FColor( 0xff0F4FA8 ),
FColor( 0xff00AE68 ),
FColor( 0xffDC0055 ),
FColor( 0xff284C7E ),
FColor( 0xff21825B ),
FColor( 0xffA52959 ),
FColor( 0xff05316D ),
FColor( 0xff007143 ),
FColor( 0xff8F0037 ),
FColor( 0xff4380D3 ),
FColor( 0xff36D695 ),
FColor( 0xffEE3B80 ),
FColor( 0xff6996D3 ),
FColor( 0xff60D6A7 ),
FColor( 0xffEE6B9E )
};
void SGraphBar::Construct( const FArguments& InArgs )
{
OnSelectionChanged = InArgs._OnSelectionChanged;
OnGeometryChanged = InArgs._OnGeometryChanged;
BackgroundImage = FTaskGraphStyle::Get()->GetBrush("TaskGraph.Background");
FillImage = FTaskGraphStyle::Get()->GetBrush("TaskGraph.Mono");
SelectedImage = FTaskGraphStyle::Get()->GetBrush("TaskGraph.Selected");
LastHoveredEvent = INDEX_NONE;
Zoom = 1.0f;
Offset = 0.0f;
StartTime = 0.0;
TotalTime = 1.0;
}
int32 SGraphBar::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
{
// Used to track the layer ID we will return.
int32 RetLayerId = LayerId;
bool bEnabled = ShouldBeEnabled( bParentEnabled );
const ESlateDrawEffect::Type DrawEffects = bEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect;
const FLinearColor ColorAndOpacitySRGB = InWidgetStyle.GetColorAndOpacityTint();
static const FLinearColor SelectedBarColor(FLinearColor::White);
// Paint inside the border only.
const FVector2D BorderPadding = FTaskGraphStyle::Get()->GetVector("TaskGraph.ProgressBar.BorderPadding");
Change 2122846 on 2014/07/01 00:51:24 by Wes.Hunt@WHUNT-UE4-MAIN #BUN UnrealMath updates * added RotationAboutPointMatrix * Added static Make() methods for the various derived FMatrix types. Allows single expressions that return an FMatrix so we don't have to rely on implicit conversion (which will break some generic programming). * Simplified the implementation of FQuat::MakeFromEuler. Change 2122848 on 2014/07/01 01:04:31 by Wes.Hunt@WHUNT-UE4-MAIN Added SlateLayoutTransform to store a 2D translation and uniform scale (for FGeometry). #BUN Added SlateTransformCalculus for handling arbitrary transform manipulation. See documentation in header. Change 2123889 on 2014/07/01 17:12:40 by Wes.Hunt@WHUNT-UE4-MAIN Remove unncessary use of FGeometry. Change 2221407 on 2014/07/16 17:58:20 by Wes.Hunt@WHUNT-UE4-MAIN TransformCalculus changes * Move 2D versions of functions into SlateLayoutTransform header to separate it from the base 3D stuff. * FSlateLayoutTransform is scale then translate now instead of translate then scale. * TransformPosition -> TransformPoint * Added a version of Concatenate taking 4 transforms. * Update docs. Change 2221408 on 2014/07/16 17:58:39 by Wes.Hunt@WHUNT-UE4-MAIN Adjustments to Slate headers and PCH Change 2221409 on 2014/07/16 17:59:07 by Wes.Hunt@WHUNT-UE4-MAIN Transform calculus support for SlateRects Change 2221459 on 2014/07/16 18:41:13 by Wes.Hunt@WHUNT-UE4-MAIN #BUN SWindow changes * Added GetLocalToScreenTransform. (Screen space == Desktop space) ** Basically contains the ApplicationScale and Window offset from the desktop. * Added GetLocalToWindowTransform (Window space == Desktop space without the window offset) * Added GetClientRectInScreen ** Allows code to know exactly WHERE the client rect is in the window. * Refactored GetWindowGeometryInScreen and GetWindowGeometryInWindow to use the new methods above. * SPopupLayer::OnArrangChildren refactored to clarify transformational spaces and use transformation calculus to do the work. ** This fixes PopupLayer to correctly account for the scale of the widget it is presenting a popup for. ** MenuAnchors that that create new SWindows still do no correctly account for scale. Change 2221464 on 2014/07/16 18:45:25 by Wes.Hunt@WHUNT-UE4-MAIN Render Transforms initial checkin. Lots of cleanup to do, but this is functionally working for all basic widgets and draw elements in slate. Main feature todos: * restore pixel snapping. * handle clipping in the presence of rotation. Change 2226298 on 2014/07/21 21:22:46 by Wes.Hunt@WHUNT-UE4-MAIN Use a better method to get the window's rectangle. Change 2227809 on 2014/07/22 20:41:57 by Wes.Hunt@WHUNT-UE4-MAIN Add 2D version of TransformVector to SlateTransform. Change 2232085 on 2014/07/25 16:32:15 by Wes.Hunt@WHUNT-UE4-MAIN Implement CPU pixel snapping even under render transform. This is pretty CPU intensive, but a reasonable POC. Change 2232090 on 2014/07/25 16:33:10 by Wes.Hunt@WHUNT-UE4-MAIN Font cache fixes for padding. * Add 1 pixel of padding around all fonts. * Fix font cache to properly handle padding * Fix font cache to handle texture elements of zero size with non-zero padding. Change 2232350 on 2014/07/25 19:50:11 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Updated FSlateTextureAtlas padding logic. * Added ESlateTextureAtlasPaddingStyle which lets you choose from three atlasing padding styles: * NoPadding - don't apply any padding (used to be Padding == 0). * DilateBorder - copy border edges to apply 1-pixel padding (used to be Padding == 1). * PadWithZero - expand 1-pixel border and fill it with zeros (new style). * removed notion of Padding > 1 pixel from atlasing. It wasn't useful as we don't support mips or aniso filtering. * Also the existing code didn't actually handle Padding > 1. * FontCache now uses PadWithZero padding so upon zooming text, the edges get smoother. Change 2237962 on 2014/07/31 02:17:28 by Wes.Hunt@WHUNT-UE4-MAIN TransformCalculus tweak. * Core Concatentate(T,T) no longer assumes the return type is T. Uses decltype(T.Concat(T)) instead. Change 2237964 on 2014/07/31 02:21:31 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Added a full suite of transform types for 2D transformations that are transform calculus aware: * FSlateScale2D * FSlateShear2D * FSlateQuat2D * FSlateMatrix2x2 Added appropriate overloads and ConcatenateRules for all combinations, making them compatible with FSlateTransform and FSlateLayoutTransform. FSlateTransform is now implemented in terms of a decomposed Matrix3x2. Change 2237972 on 2014/07/31 02:30:45 by Wes.Hunt@WHUNT-UE4-MAIN Remove 4x4 matrix from FSlateTransform Change 2238004 on 2014/07/31 03:11:42 by Wes.Hunt@WHUNT-UE4-MAIN FSlateTransform -> FSlateRenderTransform. Change 2238714 on 2014/07/31 15:16:18 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Moved TransformCalculus into Core/Math. * Split into TransformCalculus, 2D, and 3D support. * FSlateRenderTransform is now just a typedef. * Renamed 2D transform types to remove "Slate" from their name. Change 2240437 on 2014/08/01 19:08:59 by Wes.Hunt@WHUNT-UE4-MAIN Restore funky logic in deprecated FGeometry::MakeChild implementations. * legacy FGeometry::MakeChild functions took OffsetFromParent in the local space of the widget. This therefore CANNOT be the layout transform offset, because that needs to be in parent space for the transform of P * S + T to work correctly. * Therefore, the legacy functions now expect the ChildOffset to be in child space and re-apply the child scale to put them back into parent space. * This fixes the NodePanels to properly handle zooming around the mouse cursor point. Change 2242769 on 2014/08/04 13:44:33 by Wes.Hunt@WHUNT-UE4-MAIN remove local layout transform storage from FGeometry. Change 2242771 on 2014/08/04 13:45:59 by Wes.Hunt@WHUNT-UE4-MAIN Update Declarative syntax support to call it RenderTransform instead of Transform. Change 2245872 on 2014/08/06 14:45:44 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Add GetBottomRight function to FSlateRect. Change 2246129 on 2014/08/06 17:32:04 by Wes.Hunt@WHUNT-UE4-MAIN SThrobber now supports render transforms. Key is to not use deprecated members of FPaintGeometry, which should be treated as immutable (at least public members shouldn't be modified withotu modifying the new members as well). Change 2247782 on 2014/08/07 19:12:57 by Wes.Hunt@WHUNT-UE4-MAIN Clipping widgets now works under render transforms, FPaintGeometry legacy fixes. * Expanded FSlateVertex by 2 bytes to pass in local position. * Change clipcoords to be passed in local space. * Remove WorldPosition interpolator. Replaced by LocalPosition interpolator. FPaintGeometry fixes * FPaintGeometry now takes Size in LocalSpace unless using a legacy ctor. Avoid transform-and-back that was occurring when creating from an FGeometry, which already had it in local space, and rendering, which now wants it in local space. * FPaintGeometry again supports mutability when using legacy members (like DrawPosition). This allows legacy code to mutate an FPaintGeometry, which is committed to a render transform right before rendering.Hacky, but allows legacy code that treated FPaintGeometry as a plain-old-struct to work. * Removed a legacy ctor of FPaintGeoemtry that was not being used. Misc: * Turned off pixel snapping code in ElementBatcher because the FSlateVertex is doing it during construction. * Still texture filtering artifacts to figure out, so the last word has not been spoken on this yet! * Tweaked FGeometry::MakeRoot to use the non-render transform ctor since it doesn't need to use it. * Removed /*WindowSpace*/ Size member from SlateDrawElement. * SlateDrawElement::GetRotationPoint vastly simplified by using Local space. * Moved slate cycle counters back to the top of the function in ElementBatcher. * Uninlined FSlateVertex ctors so I can tweak their rounding rules without a full recompile. Change 2247790 on 2014/08/07 19:20:01 by Wes.Hunt@WHUNT-UE4-MAIN SSlider no longer uses MakeRotatedBox, correctly handles render transforms. * Now uses a render transform to draw a vertical slider handle instead of MakeRotatedBox. * Since we don't support layout transforms, we also have to adjust the clip rect to account for the render-only transform, and make it act like a layout transform. Change 2249106 on 2014/08/08 19:13:21 by Wes.Hunt@WHUNT-UE4-MAIN Slate clipping now done in window space again. * This addresses subpixel jittering that occured on otherwise stable clip rects because local space was moving underneath, and transforming the clip rect to local space created occasional rounding errors. * Implemented a vectorized point-in-parallelogram check in the pixel shaders to do this. Now pass clip rect in slightly differently, and moved to a float16 to allow better clip precision under rotation. But the vertex data remains the same size. * Moved some more common transform work into FSlateVertex constructor to save duplication. * Removed construction of local clip rect as it's no longer needed except for text rendering. * Hoisted construction of local clip rect out of the text drawing character loop (whoops). * Precompute InverseLayoutTransform in draw code as we use that a lot now. * Fixed OGL renderer to work. Change 2249123 on 2014/08/08 19:45:19 by Wes.Hunt@WHUNT-UE4-MAIN SProgressBar no longer uses a temporary PaintGeometry to create the inner clipping rect for drawing, it directly inflates the clipping rect now. Also tried to adjust the coords to reduce jitter in the one-pixel padding. Change 2251914 on 2014/08/11 16:26:12 by Wes.Hunt@WHUNT-UE4-MAIN Fixing HitTest 2.0 to work with latest code. * Added AppendTransform to FGeometry to preserve immutability of the struct. Change 2253023 on 2014/08/12 10:30:23 by Wes.Hunt@WHUNT-UE4-MAIN Fixing Slate RHI Renderer to use new screenspace clipping with render transforms. Change 2253090 on 2014/08/12 11:36:16 by Wes.Hunt@WHUNT-UE4-MAIN Fix SClippingHorizontalBox to use immutable FGeometry position. Also fix to properly support scale in when it needs to clip children. Change 2253701 on 2014/08/12 17:48:06 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Round viewport rect instead of trunc to match how slate does it now (fixes 1:1 pixel error on SViewports). Need to abstract slate rounding internals so clients don't have to guess. Change 2255403 on 2014/08/13 19:08:25 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Added LayoutGeometry class. Change 2255404 on 2014/08/13 19:10:40 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Made FGeometry public members const to catch all mutating uses of them. Added some hacks in the implementation to make it backward compatible. Removed the AccumulatedLayoutTransform, since it was just a copy of AbsolutePosition and Scale. Now all code creates the layout transform on the fly from those members. Still functionally the same. Added support for MakeChild using FLayoutGeometry. Change 2255405 on 2014/08/13 19:12:39 by Wes.Hunt@WHUNT-UE4-MAIN Changed SSplitter and Splitter2x2 to use FLayoutTransforms where possible. Now only calls ArrangeChildren() when rendering, avoiding accumulating the layout transforms and storing the render transforms altogether. Change 2265162 on 2014/08/20 18:24:04 by Wes.Hunt@WHUNT-UE4-MAIN Implement MakeRotatedBox in terms of a render transform. Remove all shader code associated with rotating. Change 2268034 on 2014/08/22 17:40:05 by Wes.Hunt@WHUNT-UE4-MAIN More 2D transform cleanup. * Removed a bunch of todo comments from the code, and converted them to more of a final form for main. * #BUN Removed FGeometry::CenteredPaintGeometryBelow as it was misleading, and users of the function were forced to mutate the resulting FPaintGeometry. * #BUN Removed FGeometry::GetRect() because it returned a rect in a weird space if the local scale != 1. Only one place in the code actually used it. Change 2268096 on 2014/08/22 18:12:41 by Wes.Hunt@WHUNT-UE4-MAIN Clean up more stuff in FPaintGeometry. * #BUN Removed ToSlateRect and Identity(). * Removed storage of accumulated layout transform, since DrawPosition and DrawScale implicitly stored it. * Removed a bunch of todo comments and converted them to a more final form. Change 2270989 on 2014/08/25 15:48:46 by Wes.Hunt@WHUNT-UE4-MAIN Add support for Concatenate with 5 transforms. Change 2271394 on 2014/08/25 19:12:53 by Wes.Hunt@WHUNT-UE4-MAIN #BUN Added an OffsetBy function to FSlateRect Change 2271395 on 2014/08/25 19:13:56 by Wes.Hunt@WHUNT-UE4-MAIN Added a version of FSlateRotatedRect that uses regular floats, also added IsUnderLocation ToBoundingRect function for overlap testing. Change 2271396 on 2014/08/25 19:14:38 by Wes.Hunt@WHUNT-UE4-MAIN HitTest 2.0 now works with render transforms. #codereview:matt.kuhlenschmidt,nick.atamas [CL 2276499 by Wes Hunt in Main branch]
2014-08-28 14:29:46 -04:00
const FSlateRect ForegroundClippingRect = AllottedGeometry.GetClippingRect().InsetBy(FMargin(BorderPadding.X, BorderPadding.Y)).IntersectionWith(MyClippingRect);
FSlateDrawElement::MakeBox(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(),
BackgroundImage,
MyClippingRect,
DrawEffects,
ColorAndOpacitySRGB
);
// Draw all bars
for( int32 EventIndex = 0; EventIndex < Events.Num(); ++EventIndex )
{
TSharedPtr< FVisualizerEvent > Event = Events[ EventIndex ];
float StartX, EndX;
if( CalculateEventGeometry( Event.Get(), AllottedGeometry, StartX, EndX ) )
{
// Draw Event bar
FSlateDrawElement::MakeBox(
OutDrawElements,
RetLayerId++,
AllottedGeometry.ToPaintGeometry(
FVector2D( StartX, 0.0f ),
FVector2D( EndX - StartX, AllottedGeometry.Size.Y )),
Event->IsSelected ? SelectedImage : FillImage,
ForegroundClippingRect,
DrawEffects,
Event->IsSelected ? SelectedBarColor : ColorPalette[Event->ColorIndex % (sizeof(ColorPalette) / sizeof(ColorPalette[0]))]
);
}
}
return RetLayerId - 1;
}
void SGraphBar::Tick( const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime )
{
if( OnGeometryChanged.IsBound() )
{
if( AllottedGeometry != this->LastGeometry )
{
OnGeometryChanged.ExecuteIfBound( AllottedGeometry );
LastGeometry = AllottedGeometry;
}
}
}
FReply SGraphBar::OnMouseButtonDown( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
if( MouseEvent.GetEffectingButton() == EKeys::LeftMouseButton )
{
// Translate click position from absolute to graph space
const float ClickX = MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ).X;//( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ).X / MyGeometry.Size.X ) / Zoom - Offset / Zoom;
TSharedPtr< FVisualizerEvent > SelectedEvent;
// Go through all events and check if at least one has been clicked
int32 EventIndex = INDEX_NONE;
for( EventIndex = 0; EventIndex < Events.Num(); EventIndex++ )
{
TSharedPtr< FVisualizerEvent > Event = Events[ EventIndex ];
float StartX, EndX;
if( CalculateEventGeometry( Event.Get(), MyGeometry, StartX, EndX ) )
{
if( ClickX >= StartX && ClickX < EndX )
{
// An event has been clicked, abort
SelectedEvent = Event;
Event->IsSelected = true;
break;
}
else
{
Event->IsSelected = false;
}
}
}
// Iterate over all the remaining events and mark them as not selected
for( EventIndex = EventIndex + 1; EventIndex < Events.Num(); EventIndex++ )
{
Events[ EventIndex ]->IsSelected = false;
}
// Execute OnSelectionChanged delegate
if( OnSelectionChanged.IsBound() )
{
OnSelectionChanged.ExecuteIfBound( SelectedEvent, ESelectInfo::OnMouseClick );
}
return FReply::Handled();
}
else
{
return FReply::Unhandled();
}
}
/**
* The system calls this method to notify the widget that a mouse moved within it. This event is bubbled.
*
* @param MyGeometry The Geometry of the widget receiving the event
* @param MouseEvent Information about the input event
*
* @return Whether the event was handled along with possible requests for the system to take action.
*/
FReply SGraphBar::OnMouseMove( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent )
{
const float HoverX = ( MyGeometry.AbsoluteToLocal( MouseEvent.GetScreenSpacePosition() ).X / MyGeometry.Size.X ) / Zoom - Offset / Zoom;
int32 HoveredEventIndex = INDEX_NONE;
for( int32 EventIndex = 0; EventIndex < Events.Num(); EventIndex++ )
{
TSharedPtr< FVisualizerEvent > Event = Events[ EventIndex ];
if( HoverX >= Event->Start && HoverX < ( Event->Start + Event->Duration ) )
{
HoveredEventIndex = EventIndex;
break;
}
}
if( HoveredEventIndex != LastHoveredEvent )
{
if( HoveredEventIndex != INDEX_NONE )
{
this->SetToolTipText( FText::FromString(Events[HoveredEventIndex]->EventName) );
}
else
{
this->SetToolTipText( FText::GetEmpty() );
}
LastHoveredEvent = HoveredEventIndex;
}
return SLeafWidget::OnMouseMove( MyGeometry, MouseEvent );
}
FVector2D SGraphBar::ComputeDesiredSize( float ) const
{
return FVector2D( 8.0f, 16.0f );
}
void SGraphBar::SetEvents( const FVisualizerEventsArray& InEvents, double InStartTime, double InTotalTime )
{
Events = InEvents;
StartTime = InStartTime;
TotalTime = InTotalTime;
}