lua - add gui.clearImageCache, also add a param to drawImage that can force it to not be cached if desired

This commit is contained in:
adelikat 2017-05-29 11:09:19 -05:00
parent 6dbf0e4822
commit 3c7707a6a0
1 changed files with 17 additions and 2 deletions

View File

@ -311,7 +311,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethodAttributes(
"drawImage", "draws an image file from the given path at the given coordinate. width and height are optional. If specified, it will resize the image accordingly")]
public void DrawImage(string path, int x, int y, int? width = null, int? height = null)
public void DrawImage(string path, int x, int y, int? width = null, int? height = null, bool cache = true)
{
if (!File.Exists(path))
{
@ -329,13 +329,28 @@ namespace BizHawk.Client.EmuHawk
else
{
img = Image.FromFile(path);
_imageCache.Add(path, img);
if (cache)
{
_imageCache.Add(path, img);
}
}
g.DrawImage(img, x, y, width ?? img.Width, height ?? img.Height);
}
}
[LuaMethodAttributes(
"clearImageCache", "clears the image cache that is built up by using gui.drawImage, also releases the file handle for cached images")]
public void ClearImageCache()
{
foreach (var image in _imageCache)
{
image.Value.Dispose();
}
_imageCache.Clear();
}
[LuaMethodAttributes(
"drawImageRegion", "draws a given region of an image file from the given path at the given coordinate, and optionally with the given size")]
public void DrawImageRegion(string path, int source_x, int source_y, int source_width, int source_height, int dest_x, int dest_y, int? dest_width = null, int? dest_height = null)