Improve updating the image list

This commit is contained in:
KillzXGaming 2019-06-09 12:19:23 -04:00
parent 80f0c765aa
commit e36173ce1e
8 changed files with 30 additions and 15 deletions

Binary file not shown.

View file

@ -20,6 +20,8 @@ namespace Switch_Toolbox.Library.Forms
ImageList ImageList = new ImageList();
List<STGenericTexture> Textures = new List<STGenericTexture>();
private ListViewItem ActiveItem;
public void LoadArchive(IArchiveFile ArchiveFile)
{
ImageList.ColorDepth = ColorDepth.Depth32Bit;
@ -87,6 +89,13 @@ namespace Switch_Toolbox.Library.Forms
Thread.Start();
}
private void ReloadTexture(Bitmap Image, ListViewItem listItem)
{
Image = BitmapExtension.Resize(Image, ImageList.ImageSize);
ImageList.Images[listItem.ImageIndex] = Image;
Image.Dispose();
}
private void ReloadTexture(STGenericTexture tex, ListViewItem listItem)
{
Thread Thread = new Thread((ThreadStart)(() =>
@ -213,10 +222,10 @@ namespace Switch_Toolbox.Library.Forms
imageEditorForm.OnTextureReplaced += new ImageEditorBase.StatusUpdateHandler(UpdateTextureEdit);
}
private void UpdateTextureEdit(object sender, ImageEditorBase.ProgressEventArgs e)
private void UpdateTextureEdit(object sender, ImageEditorBase.ImageReplaceEventArgs e)
{
var item = listViewCustom1.SelectedItems[0];
ReloadTexture(GetActiveTexture(), item);
ReloadTexture(e.ReplacedTexture, ActiveItem);
listViewCustom1.Refresh();
}
private void listViewCustom1_DoubleClick(object sender, EventArgs e)
@ -233,10 +242,10 @@ namespace Switch_Toolbox.Library.Forms
{
if (listViewCustom1.SelectedItems.Count > 0)
{
var item = listViewCustom1.SelectedItems[0];
if (item.Tag is STGenericTexture)
ActiveItem = listViewCustom1.SelectedItems[0];
if (ActiveItem.Tag is STGenericTexture)
{
LoadImageEditor((STGenericTexture)item.Tag, ((STGenericTexture)item.Tag).GenericProperties);
LoadImageEditor((STGenericTexture)ActiveItem.Tag, ((STGenericTexture)ActiveItem.Tag).GenericProperties);
}
}
}

View file

@ -15,22 +15,24 @@ namespace Switch_Toolbox.Library.Forms
{
public partial class ImageEditorBase : UserControl
{
public class ProgressEventArgs : EventArgs
public class ImageReplaceEventArgs : EventArgs
{
public ProgressEventArgs()
{
public Bitmap ReplacedTexture { get; private set; }
public ImageReplaceEventArgs(Bitmap texture) {
ReplacedTexture = texture;
}
}
public delegate void StatusUpdateHandler(object sender, ProgressEventArgs e);
public delegate void StatusUpdateHandler(object sender, ImageReplaceEventArgs e);
public event StatusUpdateHandler OnTextureReplaced;
private void UpdateTextureReplace()
private void UpdateTextureReplace(Bitmap texture)
{
// Make sure someone is listening to event
if (OnTextureReplaced == null) return;
ProgressEventArgs args = new ProgressEventArgs();
ImageReplaceEventArgs args = new ImageReplaceEventArgs(texture);
OnTextureReplaced(this, args);
}
@ -752,7 +754,7 @@ namespace Switch_Toolbox.Library.Forms
progressBar.Value = 100;
UpdateTextureReplace();
UpdateTextureReplace(new Bitmap(Image));
}
private void saveBtn_Click(object sender, EventArgs e)

View file

@ -41,11 +41,15 @@ namespace Switch_Toolbox.Library
}
return datas;
}
public static Bitmap Resize(Image original, Size size)
{
return ResizeImage(original, size.Width, size.Height);
}
public static Bitmap Resize(Image original, int width, int height)
{
return ResizeImage(original, width, height);
// return new Bitmap(original, new Size(width, height));
}
public static Bitmap ReplaceChannel(Image OriginalImage, Image ChannelImage, STChannelType ChannelType)