Files
UnrealEngine/Engine/Source/Editor/GraphEditor/Public/SGraphNodeComment.h
2025-05-18 13:04:45 +08:00

141 lines
4.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Containers/Array.h"
#include "Containers/UnrealString.h"
#include "CoreMinimal.h"
#include "HAL/Platform.h"
#include "Input/Reply.h"
#include "Layout/SlateRect.h"
#include "Math/Vector2D.h"
#include "SGraphNodeResizable.h"
#include "SNodePanel.h"
#include "Styling/SlateColor.h"
#include "Styling/SlateTypes.h"
#include "Templates/SharedPointer.h"
#include "Widgets/DeclarativeSyntaxSupport.h"
class FDragDropEvent;
class SBorder;
class SCommentBubble;
class SGraphNode;
class UEdGraphNode_Comment;
struct FGeometry;
struct FPointerEvent;
struct FSlateBrush;
class GRAPHEDITOR_API SGraphNodeComment : public SGraphNodeResizable
{
public:
SLATE_BEGIN_ARGS(SGraphNodeComment){}
SLATE_END_ARGS()
//~ Begin SWidget Interface
virtual FReply OnMouseButtonDoubleClick( const FGeometry& InMyGeometry, const FPointerEvent& InMouseEvent ) override;
virtual FReply OnMouseButtonUp( const FGeometry& MyGeometry, const FPointerEvent& MouseEvent ) override;
virtual void Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime) override;
virtual FReply OnDrop( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
virtual void OnDragEnter( const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent ) override;
//~ End SWidget Interface
//~ Begin SNodePanel::SNode Interface
virtual const FSlateBrush* GetShadowBrush(bool bSelected) const override;
virtual void GetOverlayBrushes(bool bSelected, const FVector2f& WidgetSize, TArray<FOverlayBrushInfo>& Brushes) const override;
virtual bool ShouldAllowCulling() const override { return true; }
virtual int32 GetSortDepth() const override;
virtual void EndUserInteraction() const override;
virtual FString GetNodeComment() const override;
//~ End SNodePanel::SNode Interface
//~ Begin SPanel Interface
virtual FVector2D ComputeDesiredSize(float) const override;
//~ End SPanel Interface
//~ Begin SGraphNode Interface
virtual bool IsNameReadOnly() const override;
virtual FSlateColor GetCommentColor() const override { return GetCommentBodyColor(); }
/** Requests a rename when the node was initially spawned */
virtual void RequestRenameOnSpawn()
{
RequestRename();
ApplyRename();
}
//~ End SGraphNode Interface
void Construct( const FArguments& InArgs, UEdGraphNode_Comment* InNode );
/** return if the node can be selected, by pointing given location */
virtual bool CanBeSelected( const FVector2f& MousePositionInNode ) const override;
/** return size of the title bar */
virtual FVector2f GetDesiredSizeForMarquee2f() const override;
/** return rect of the title bar */
virtual FSlateRect GetTitleRect() const override;
protected:
//~ Begin SGraphNode Interface
virtual void UpdateGraphNode() override;
virtual void PopulateMetaTag(class FGraphNodeMetaData* TagMeta) const override;
/**
* Helper method to update selection state of comment and any nodes 'contained' within it
* @param bSelected If true comment is being selected, false otherwise
* @param bUpdateNodesUnderComment If true then force the rebuild of the list of nodes under the comment
*/
void HandleSelection(bool bIsSelected, bool bUpdateNodesUnderComment = false) const;
/** Helper function to determine if a node is under this comment widget or not */
virtual bool IsNodeUnderComment(UEdGraphNode_Comment* InCommentNode, const TSharedRef<SGraphNode> InNodeWidget) const;
/** called when user is moving the comment node */
virtual void MoveTo(const FVector2f& NewPosition, FNodeSet& NodeFilter, bool bMarkDirty = true) override;
//~ Begin SGraphNodeResizable Interface
virtual float GetTitleBarHeight() const override;
virtual FSlateRect GetHitTestingBorder() const override;
virtual FVector2f GetNodeMaximumSize2f() const override;
//~ Begin SGraphNodeResizable Interface
/** @return the color to tint the comment body */
FSlateColor GetCommentBodyColor() const;
/** @return the color to tint the title bar */
FSlateColor GetCommentTitleBarColor() const;
/** @return the color to tint the comment bubble */
FSlateColor GetCommentBubbleColor() const;
private:
/** Returns the width to wrap the text of the comment at */
float GetWrapAt() const;
/** The comment bubble widget (used when zoomed out) */
TSharedPtr<SCommentBubble> CommentBubble;
/** The current selection state of the comment */
mutable bool bIsSelected;
/** the title bar, needed to obtain it's height */
TSharedPtr<SBorder> TitleBar;
protected:
/** cached comment title */
FString CachedCommentTitle;
/** cached font size */
int32 CachedFontSize;
/** Was the bubble desired to be visible last frame? */
mutable bool bCachedBubbleVisibility;
private:
/** cached comment title */
int32 CachedWidth;
/** Local copy of the comment style */
FInlineEditableTextBlockStyle CommentStyle;
};