Day 4

2018-04-09  本文已影响0人  蛋求疼

SlateCore\Public\Styling模块中定义了 窗口风格,描述了widget如何的绘制样式。

  1. ISlateStyle.h
/**
*  Slate Style 接口类
*/
class SLATECORE_API ISlateStyle
  1. SlateStyle.h
/**
 * A slate style chunk that contains a collection of named properties that guide the appearance of Slate.
 * At the moment, basically FEditorStyle.
 */
class SLATECORE_API FSlateStyleSet : public ISlateStyle
  1. SlateStyleRegister.h
    管理和注册 各种 Style Set.
/**
* A central repository that can be used to track and manage chunks of slate style data.
*/
class SLATECORE_API FSlateStyleRegistry
{
public:

    /**
     * Add a slate style to the repository.
     *
     * @param ISlateStyle interface to a user-definable style to add.
     */
    static void RegisterSlateStyle( const ISlateStyle& InSlateStyle );

    /**
     * Remove a slate style from the repository.
     *
     * @param ISlateStyle Interface to the style to remove.
     */
    static void UnRegisterSlateStyle( const ISlateStyle& InSlateStyle );

    /**
     * Removes a slate style from the repository (by name).
     *
     * @param StyleSetName The name of the style set to remove.
     */
    static void UnRegisterSlateStyle( const FName StyleSetName );

    /**
     * Find a slate style in the repository.
     *
     * @param InSlateStyleName The name of the slate style to find.
     * @return The slate style, or null if it couldn't be found
     */
    static const ISlateStyle* FindSlateStyle( const FName& InSlateStyleName );

    /**
     * Iterate all the slate style known to this registry
     *
     * @param Iter A predicate to call for each known style that returns true to continue iteration, and false to terminate iteration
     * @return true where to loop completed, of false if it was terminated by the predicate
     */
    static bool IterateAllStyles(const TFunctionRef<bool(const ISlateStyle&)>& Iter);

    /**
     * Populate an array of slate brushes with all of the resources used by the registered styles.
     *
     * @param OutResources Array of slate brushes to populate.
     */
    static void GetAllResources( TArray<const FSlateBrush*>& OutResources );

private:

    /** Repository is just a collection of shared style pointers. */
    static TMap<FName, const ISlateStyle*> SlateStyleRepository;
};
  1. SlateTypes.h
    定了几种基本空间的风格。
/**
 * Represents the appearance of an SCheckBox
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FCheckBoxStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an STextBlock
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FTextBlockStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SButton
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FButtonStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SComboButton
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FComboButtonStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SComboBox
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FComboBoxStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SHyperlink
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FHyperlinkStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SEditableText
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FEditableTextStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SScrollBar
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FScrollBarStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SEditableTextBox
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FEditableTextBoxStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SInlineEditableTextBlock
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FInlineEditableTextBlockStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SProgressBar
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FProgressBarStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SExpandableArea
 */
USTRUCT()
struct SLATECORE_API FExpandableAreaStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SSearchBox
 */
USTRUCT()
struct SLATECORE_API FSearchBoxStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SSlider
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FSliderStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SVolumeControl
 */
USTRUCT()
struct SLATECORE_API FVolumeControlStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an inline image used by rich text
 */
USTRUCT()
struct SLATECORE_API FInlineTextImageStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SSpinBox
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FSpinBoxStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SSplitter
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FSplitterStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an STableRow
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FTableRowStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an STableColumnHeader
 */
USTRUCT()
struct SLATECORE_API FTableColumnHeaderStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SHeaderRow
 */
USTRUCT()
struct SLATECORE_API FHeaderRowStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SDockTab
 */
USTRUCT()
struct SLATECORE_API FDockTabStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SScrollBox
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FScrollBoxStyle : public FSlateWidgetStyle;

/**
* Represents the appearance of an FScrollBorderStyle
*/
USTRUCT(BlueprintType)
struct SLATECORE_API FScrollBorderStyle : public FSlateWidgetStyle;

/**
 * Represents the appearance of an SWindow
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FWindowStyle : public FSlateWidgetStyle;

  1. SlateBrush.h
/**
 * An brush which contains information about how to draw a Slate element
 */
USTRUCT(BlueprintType)
struct SLATECORE_API FSlateBrush
{
    GENERATED_USTRUCT_BODY()

    /** Size of the resource in Slate Units */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush)
    FVector2D ImageSize;

    /** The margin to use in Box and Border modes */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush, meta=( UVSpace="true" ))
    FMargin Margin;

#if WITH_EDITORONLY_DATA
    /** Tinting applied to the image. */
    UPROPERTY()
    FLinearColor Tint_DEPRECATED;
#endif

    /** Tinting applied to the image. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush, meta=( DisplayName="Tint", sRGB="true" ))
    FSlateColor TintColor;

public:

    /**
     * Default constructor.
     */
    FSlateBrush()
        : ImageSize(SlateBrushDefs::DefaultImageSize, SlateBrushDefs::DefaultImageSize)
        , Margin(0.0f)
#if WITH_EDITORONLY_DATA
        , Tint_DEPRECATED(FLinearColor::White)
#endif
        , TintColor(FLinearColor::White)
        , ResourceObject(nullptr)
        , ResourceName(NAME_None)
        , UVRegion(ForceInit)
        , DrawAs(ESlateBrushDrawType::Image)
        , Tiling(ESlateBrushTileType::NoTile)
        , Mirroring(ESlateBrushMirrorType::NoMirror)
        , ImageType(ESlateBrushImageType::NoImage)
        , bIsDynamicallyLoaded(false)
        , bHasUObject_DEPRECATED(false)
    { }

    virtual ~FSlateBrush(){}

public:

    /**
     * Gets the name of the resource object, if any.
     *
     * @return Resource name, or NAME_None if the resource object is not set.
     */
    const FName GetResourceName() const
    {
        return ( ( ResourceName != NAME_None ) || ( ResourceObject == nullptr ) )
            ? ResourceName
            : ResourceObject->GetFName();
    }

    /**
     * Gets the UObject that represents the brush resource, if any.
     *
     * The object may be a UMaterialInterface or a UTexture.
     *
     * @return The resource object, or nullptr if it is not set.
     */
    class UObject* GetResourceObject( ) const
    {
        return ResourceObject;
    }

    /**
     * Sets the UObject that represents the brush resource.
     */
    void SetResourceObject(class UObject* InResourceObject)
    {
        ResourceObject = InResourceObject;
    }

    /**
     * Gets the brush's tint color.
     *
     * @param InWidgetStyle The widget style to get the tint for.
     * @return Tint color.
     */
    FLinearColor GetTint( const FWidgetStyle& InWidgetStyle ) const
    {
        return TintColor.GetColor(InWidgetStyle);
    }

    /**
     * Checks whether this brush has a UTexture object
     *
     * @return true if it has a UTexture object, false otherwise.
     */
    bool HasUObject( ) const
    {
        return (ResourceObject != nullptr) || (bHasUObject_DEPRECATED);
    }

    /**
     * Checks whether the brush resource is loaded dynamically.
     *
     * @return true if loaded dynamically, false otherwise.
     */
    bool IsDynamicallyLoaded( ) const
    {
        return bIsDynamicallyLoaded;
    }

    /**
     * Get brush UV region, should check if region is valid before using it
     *
     * @return UV region
     */
    FBox2D GetUVRegion() const
    {
        return UVRegion;
    }

    /**
     * Set brush UV region
     *
     * @param InUVRegion When valid - overrides UV region specified in resource proxy
     */
    void SetUVRegion(const FBox2D& InUVRegion)
    {
        UVRegion = InUVRegion;
    }

    /**
     * Compares this brush with another for equality.
     *
     * @param Other The other brush.
     *
     * @return true if the two brushes are equal, false otherwise.
     */
    bool operator==( const FSlateBrush& Other ) const 
    {
        return ImageSize == Other.ImageSize
            && DrawAs == Other.DrawAs
            && Margin == Other.Margin
            && TintColor == Other.TintColor
            && Tiling == Other.Tiling
            && Mirroring == Other.Mirroring
            && ResourceObject == Other.ResourceObject
            && ResourceName == Other.ResourceName
            && bIsDynamicallyLoaded == Other.bIsDynamicallyLoaded
            && UVRegion == Other.UVRegion;
    }

    /**
     * Compares this brush with another for inequality.
     *
     * @param Other The other brush.
     *
     * @return false if the two brushes are equal, true otherwise.
     */
    bool operator!=( const FSlateBrush& Other ) const 
    {
        return !(*this == Other);
    }

    void PostSerialize(const FArchive& Ar);

    void AddReferencedObjects(FReferenceCollector& Collector);

    /**
     * Gets the identifier for UObject based texture paths.
     *
     * @return Texture identifier string.
     */
    static const FString UTextureIdentifier( );

protected:

    /**
     * The image to render for this brush, can be a UTexture or UMaterialInterface or an object implementing 
     * the AtlasedTextureInterface. 
     */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush, meta=( DisplayThumbnail="true", DisplayName="Image", AllowedClasses="Texture,MaterialInterface,SlateTextureAtlasInterface" ))
    UObject* ResourceObject;

    /** The name of the rendering resource to use */
    UPROPERTY()
    FName ResourceName;

    /** 
     *  Optional UV region for an image
     *  When valid - overrides UV region specified in resource proxy
     */
    UPROPERTY()
    FBox2D UVRegion;

public:
    /** How to draw the image */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush)
    TEnumAsByte<enum ESlateBrushDrawType::Type > DrawAs;

    /** How to tile the image in Image mode */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush)
    TEnumAsByte<enum ESlateBrushTileType::Type> Tiling;

    /** How to mirror the image in Image mode.  This is normally only used for dynamic image brushes where the source texture
        comes from a hardware device such as a web camera. */
    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Brush)
    TEnumAsByte<enum ESlateBrushMirrorType::Type> Mirroring;

    /** The type of image */
    UPROPERTY()
    TEnumAsByte<enum ESlateBrushImageType::Type> ImageType;

protected:

    /** Whether or not the brush path is a path to a UObject */
    UPROPERTY()
    uint8 bIsDynamicallyLoaded:1;

    /** Whether or not the brush has a UTexture resource */
    UPROPERTY()
    uint8 bHasUObject_DEPRECATED:1;

    /** 
     * This constructor is protected; use one of the deriving classes instead.
     *
     * @param InDrawType      How to draw the texture
     * @param InResourceName  The name of the resource
     * @param InMargin        Margin to use in border and box modes
     * @param InTiling        Tile horizontally/vertically or both? (only in image mode)
     * @param InImageType     The type of image
     * @param InTint          Tint to apply to the element.
     */
     FORCENOINLINE FSlateBrush( ESlateBrushDrawType::Type InDrawType, const FName InResourceName, const FMargin& InMargin, ESlateBrushTileType::Type InTiling, ESlateBrushImageType::Type InImageType, const FVector2D& InImageSize, const FLinearColor& InTint = FLinearColor::White, UObject* InObjectResource = nullptr, bool bInDynamicallyLoaded = false );

     FORCENOINLINE FSlateBrush( ESlateBrushDrawType::Type InDrawType, const FName InResourceName, const FMargin& InMargin, ESlateBrushTileType::Type InTiling, ESlateBrushImageType::Type InImageType, const FVector2D& InImageSize, const TSharedRef< FLinearColor >& InTint, UObject* InObjectResource = nullptr, bool bInDynamicallyLoaded = false );

     FORCENOINLINE FSlateBrush( ESlateBrushDrawType::Type InDrawType, const FName InResourceName, const FMargin& InMargin, ESlateBrushTileType::Type InTiling, ESlateBrushImageType::Type InImageType, const FVector2D& InImageSize, const FSlateColor& InTint, UObject* InObjectResource = nullptr, bool bInDynamicallyLoaded = false );
};

FSlateBrush定义了如何绘制一个slate元素,它拥有 画刷类型、UV、Image对象等。

上一篇下一篇

猜你喜欢

热点阅读