Use cached transforms for images in widgets

This commit is contained in:
Ivaylo Draganov
2020-11-21 21:33:57 +02:00
committed by Paul Chote
parent c8ab409d38
commit ad4425d11e
4 changed files with 35 additions and 15 deletions

View File

@@ -31,6 +31,16 @@ namespace OpenRA.Mods.Common.Widgets
return baseName + suffix;
}
public static CachedTransform<(bool Disabled, bool Pressed, bool Hover, bool Focused), Sprite> GetCachedStatefulImage(string collection, string baseName)
{
return new CachedTransform<(bool, bool, bool, bool), Sprite>(
((bool Disabled, bool Pressed, bool Hover, bool Focused) args) =>
{
var imageName = GetStatefulImageName(baseName, args.Disabled, args.Pressed, args.Hover, args.Focused);
return ChromeProvider.GetImage(collection, imageName) ?? ChromeProvider.GetImage(collection, baseName);
});
}
public static void DrawRGBA(Sprite s, float2 pos)
{
Game.Renderer.RgbaSpriteRenderer.DrawSprite(s, pos);