Day 4

SlateCore\Public\Styling模塊中定義了 窗口風(fēng)格垮兑,描述了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
    定了幾種基本空間的風(fēng)格砚尽。
/**
 * 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對象等扰路。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市倔叼,隨后出現(xiàn)的幾起案子汗唱,更是在濱河造成了極大的恐慌,老刑警劉巖丈攒,帶你破解...
    沈念sama閱讀 219,270評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件哩罪,死亡現(xiàn)場離奇詭異,居然都是意外死亡巡验,警方通過查閱死者的電腦和手機(jī)际插,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,489評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來深碱,“玉大人腹鹉,你說我怎么就攤上這事藏畅》蠊瑁” “怎么了?”我有些...
    開封第一講書人閱讀 165,630評論 0 356
  • 文/不壞的土叔 我叫張陵愉阎,是天一觀的道長绞蹦。 經(jīng)常有香客問我,道長榜旦,這世上最難降的妖魔是什么幽七? 我笑而不...
    開封第一講書人閱讀 58,906評論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮溅呢,結(jié)果婚禮上澡屡,老公的妹妹穿的比我還像新娘。我一直安慰自己咐旧,他們只是感情好驶鹉,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,928評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著铣墨,像睡著了一般室埋。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上伊约,一...
    開封第一講書人閱讀 51,718評論 1 305
  • 那天姚淆,我揣著相機(jī)與錄音,去河邊找鬼屡律。 笑死腌逢,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的超埋。 我是一名探鬼主播上忍,決...
    沈念sama閱讀 40,442評論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼骤肛,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了窍蓝?” 一聲冷哼從身側(cè)響起腋颠,我...
    開封第一講書人閱讀 39,345評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎吓笙,沒想到半個月后淑玫,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,802評論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡面睛,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,984評論 3 337
  • 正文 我和宋清朗相戀三年絮蒿,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片叁鉴。...
    茶點(diǎn)故事閱讀 40,117評論 1 351
  • 序言:一個原本活蹦亂跳的男人離奇死亡土涝,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出幌墓,到底是詐尸還是另有隱情但壮,我是刑警寧澤,帶...
    沈念sama閱讀 35,810評論 5 346
  • 正文 年R本政府宣布常侣,位于F島的核電站蜡饵,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏胳施。R本人自食惡果不足惜溯祸,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,462評論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望舞肆。 院中可真熱鬧焦辅,春花似錦、人聲如沸椿胯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,011評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽压状。三九已至仆抵,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間种冬,已是汗流浹背镣丑。 一陣腳步聲響...
    開封第一講書人閱讀 33,139評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留娱两,地道東北人莺匠。 一個月前我還...
    沈念sama閱讀 48,377評論 3 373
  • 正文 我出身青樓,卻偏偏與公主長得像十兢,于是被迫代替她去往敵國和親趣竣。 傳聞我的和親對象是個殘疾皇子摇庙,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,060評論 2 355

推薦閱讀更多精彩內(nèi)容