Files
UnrealEngineUWP/Engine/Source/Runtime/Online/ImageDownload/Public/WebImageCache.h
ryan durand 0f0464a30e Updating copyright for Engine Runtime.
#rnx
#rb none


#ROBOMERGE-OWNER: ryan.durand
#ROBOMERGE-AUTHOR: ryan.durand
#ROBOMERGE-SOURCE: CL 10869210 via CL 10869511 via CL 10869900
#ROBOMERGE-BOT: (v613-10869866)

[CL 10870549 by ryan durand in Main branch]
2019-12-26 14:45:42 -05:00

50 lines
1.8 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Containers/UnrealString.h"
#include "WebImage.h"
struct FSlateBrush;
/**
* This class is designed to facilitate caching of web images and setting a global stand-in so we don't
* re-download the same image every time the UI shows it again.
*
* See WebImage.h for example usage.
*/
class IMAGEDOWNLOAD_API FWebImageCache
{
public:
FWebImageCache();
/** Signifies the module is being unloaded and to perform any actions that depend on other modules which may be unloaded as well */
void PreUnload();
/** Removes all cached images */
void Empty();
/** Find or create a WebImage object for this URL (you probably just want to call ->Attr() on this) */
TSharedRef<const FWebImage> Download(const FString& Url, const TOptional<FString>& DefaultImageUrl = TOptional<FString>());
/** Set the brush that will be returned until the download completes (only affects future downloads). */
FORCEINLINE void SetDefaultStandInBrush(TAttribute<const FSlateBrush*> StandInBrushIn) { DefaultStandInBrush = StandInBrushIn; }
/* This function causes the web image cache to stop holding on to strong references to images. Normally
* once downloaded, an image is cached forever. This allows us to release images that are not currently
* being displayed (those would have Strong pointers existing external to this class) to be released.
*/
void RelinquishUnusedImages();
private:
/** Map of canonical URL to web images (weak pointer so we don't affect lifetime) */
TMap<FString, TWeakPtr<FWebImage> > UrlToImageMap;
/** Strong references to keep images cached when not in use. Can be flushed manually */
TArray< TSharedRef<FWebImage> > StrongRefCache;
/** The image resource to show */
TAttribute< const FSlateBrush* > DefaultStandInBrush;
};