Working direct Profile to ImageListView

Manged to get the ImageListView working directly
from the Bitmap stored in the Profile. This makes
the refresh of the ILV much faster, and makes it way
easier to use it in other UI forms.
This commit is contained in:
temacdonald 2020-05-16 15:58:59 +12:00
parent 470cba0a1d
commit 423b3fb656
6 changed files with 216 additions and 150 deletions

View File

@ -1,9 +0,0 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ATI/@EntryIndexedValue">ATI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=DPI/@EntryIndexedValue">DPI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EDID/@EntryIndexedValue">EDID</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=EX/@EntryIndexedValue">EX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=GDI/@EntryIndexedValue">GDI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IPC/@EntryIndexedValue">IPC</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NVIDIA/@EntryIndexedValue">NVIDIA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SLI/@EntryIndexedValue">SLI</s:String></wpf:ResourceDictionary>

View File

@ -441,7 +441,7 @@ namespace HeliosPlus.Shared
public override string ToString()
{
return (Name ?? Language.UN_TITLED_PROFILE) + (IsActive ? " " + Language._Active_ : "");
return (Name ?? Language.UN_TITLED_PROFILE);
}
private static string GetValidFilename(string uncheckedFilename)

View File

@ -75,7 +75,7 @@
<Compile Include="GameLibraries\SteamAppInfoParser\Package.cs" />
<Compile Include="GameLibraries\SteamAppInfoParser\PackageInfo.cs" />
<Compile Include="GameLibraries\SteamAppInfoParser\App.cs" />
<Compile Include="ProfileAdaptor.cs" />
<Compile Include="UIForms\ProfileAdaptor.cs" />
<Compile Include="UIForms\MainForm.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -1,133 +0,0 @@
/*using Manina.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Manina.Windows.Forms
{
class ProfileAdaptor : ImageListView.ImageListViewItemAdaptor
{
private bool disposed;
/// <summary>
/// Initializes a new instance of the <see cref="ProfileAdaptor"/> class.
/// </summary>
public ProfileAdaptor()
{
disposed = false;
}
/// <summary>
/// Returns the thumbnail image for the given item.
/// </summary>
/// <param name="key">Item key.</param>
/// <param name="size">Requested image size.</param>
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
/// <returns>The thumbnail image from the given item or null if an error occurs.</returns>
public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
{
if (disposed)
return null;
string filename = (string)key;
if (File.Exists(filename))
return Extractor.Instance.GetThumbnail(filename, size, useEmbeddedThumbnails, useExifOrientation);
else
return null;
}
/// <summary>
/// Returns a unique identifier for this thumbnail to be used in persistent
/// caching.
/// </summary>
/// <param name="key">Item key.</param>
/// <param name="size">Requested image size.</param>
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
/// <returns>A unique identifier string for the thumnail.</returns>
public override string GetUniqueIdentifier(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
{
StringBuilder sb = new StringBuilder();
sb.Append((string)key);// Filename
sb.Append(':');
sb.Append(size.Width); // Thumbnail size
sb.Append(',');
sb.Append(size.Height);
sb.Append(':');
sb.Append(useEmbeddedThumbnails);
sb.Append(':');
sb.Append(useExifOrientation);
return sb.ToString();
}
/// <summary>
/// Returns the path to the source image for use in drag operations.
/// </summary>
/// <param name="key">Item key.</param>
/// <returns>The path to the source image.</returns>
public override string GetSourceImage(object key)
{
if (disposed)
return null;
string filename = (string)key;
return filename;
}
/// <summary>
/// Returns the details for the given item.
/// </summary>
/// <param name="key">Item key.</param>
/// <returns>An array of tuples containing item details or null if an error occurs.</returns>
public override Utility.Tuple<ColumnType, string, object>[] GetDetails(object key)
{
if (disposed)
return null;
string filename = (string)key;
List<Utility.Tuple<ColumnType, string, object>> details = new List<Utility.Tuple<ColumnType, string, object>>();
// Get file info
if (File.Exists(filename))
{
FileInfo info = new FileInfo(filename);
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateCreated, string.Empty, info.CreationTime));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateAccessed, string.Empty, info.LastAccessTime));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateModified, string.Empty, info.LastWriteTime));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FileSize, string.Empty, info.Length));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FilePath, string.Empty, info.DirectoryName ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FolderName, string.Empty, info.Directory.Name ?? ""));
// Get metadata
Metadata metadata = Extractor.Instance.GetMetadata(filename);
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, new Size(metadata.Width, metadata.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, new SizeF((float)metadata.DPIX, (float)metadata.DPIY)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, metadata.ImageDescription ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, metadata.EquipmentModel ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, metadata.DateTaken));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, metadata.Artist ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Copyright, string.Empty, metadata.Copyright ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ExposureTime, string.Empty, (float)metadata.ExposureTime));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FNumber, string.Empty, (float)metadata.FNumber));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ISOSpeed, string.Empty, (ushort)metadata.ISOSpeed));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.UserComment, string.Empty, metadata.Comment ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Rating, string.Empty, (ushort)metadata.Rating));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Software, string.Empty, metadata.Software ?? ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FocalLength, string.Empty, (float)metadata.FocalLength));
}
return details.ToArray();
}
/// <summary>
/// Performs application-defined tasks associated with freeing,
/// releasing, or resetting unmanaged resources.
/// </summary>
public override void Dispose()
{
disposed = true;
}
}
}
*/

View File

@ -18,11 +18,13 @@ namespace HeliosPlus.UIForms
private string _saveOrRenameMode = "save";
private static bool _inDialog = false;
private static Profile _profileToLoad = null;
private ProfileAdaptor _profileAdaptor;
public DisplayProfileForm()
{
InitializeComponent();
this.AcceptButton = this.btn_save_or_rename;
_profileAdaptor = new ProfileAdaptor();
}
public DisplayProfileForm(Profile profileToLoad)
@ -157,9 +159,12 @@ namespace HeliosPlus.UIForms
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere)
{
loadedProfile.SaveProfileImageToCache();
newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
ilv_saved_profiles.Items.Add(newItem);
//loadedProfile.SaveProfileImageToCache();
//newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
//newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
newItem = new ImageListViewItem(loadedProfile, loadedProfile.Name);
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
}
if (Profile.CurrentProfile.Equals(loadedProfile))
@ -347,12 +352,14 @@ namespace HeliosPlus.UIForms
_savedProfiles.Add(_selectedProfile);
// Also update the imagelistview so that we can see the new profile we just saved
_selectedProfile.SaveProfileImageToCache();
//_selectedProfile.SaveProfileImageToCache();
// Load the currentProfile image into the imagelistview
ImageListViewItem newItem = new ImageListViewItem(_selectedProfile.SavedProfileCacheFilename, _selectedProfile.Name);
//ImageListViewItem newItem = new ImageListViewItem(_selectedProfile.SavedProfileCacheFilename, _selectedProfile.Name);
ImageListViewItem newItem = new ImageListViewItem(_selectedProfile, _selectedProfile.Name);
newItem.Selected = true;
ilv_saved_profiles.Items.Add(newItem);
//ilv_saved_profiles.Items.Add(newItem);
ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
}
else
{

View File

@ -0,0 +1,201 @@
using HeliosPlus.Shared;
using Manina.Windows.Forms;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HeliosPlus.UIForms
{
#region Profile Adaptor
/// <summary>
/// A custom item adaptor for ImageListView that reads from a Profile.
/// </summary>
class ProfileAdaptor : ImageListView.ImageListViewItemAdaptor
{
private bool disposed;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemAdaptor"/> class.
/// </summary>
public ProfileAdaptor()
{
disposed = false;
}
/// <summary>
/// Returns the thumbnail image for the given item.
/// </summary>
/// <param name="key">Item key.</param>
/// <param name="size">Requested image size.</param>
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
/// <returns>The thumbnail image from the given item or null if an error occurs.</returns>
public override Image GetThumbnail(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
{
if (disposed)
return null;
try
{
string profileName = key.ToString();
Profile profileToUse = null;
foreach (Profile profileToTest in Profile.AllSavedProfiles)
{
if (profileToTest.Name == profileName)
{
profileToUse = profileToTest;
}
}
if (profileToUse == null)
{
profileToUse = Profile.CurrentProfile;
}
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(() => { return false; });
return profileToUse.ProfileBitmap.GetThumbnailImage(size.Width, size.Height, myCallback, IntPtr.Zero);
}
catch {
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
}
return null;
}
/// <summary>
/// Returns a unique identifier for this thumbnail to be used in persistent
/// caching.
/// </summary>
/// <param name="key">Item key.</param>
/// <param name="size">Requested image size.</param>
/// <param name="useEmbeddedThumbnails">Embedded thumbnail usage.</param>
/// <param name="useExifOrientation">true to automatically rotate images based on Exif orientation; otherwise false.</param>
/// <returns>A unique identifier string for the thumnail.</returns>
public override string GetUniqueIdentifier(object key, Size size, UseEmbeddedThumbnails useEmbeddedThumbnails, bool useExifOrientation)
{
if (disposed)
return null;
try
{
string profileName = (string)key;
return profileName;
}
catch
{
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
}
}
/// <summary>
/// Returns the path to the source image for use in drag operations.
/// </summary>
/// <param name="key">Item key.</param>
/// <returns>The path to the source image.</returns>
public override string GetSourceImage(object key)
{
if (disposed)
return null;
try
{
string profileName = (string)key;
return profileName;
}
catch
{
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
}
}
/// <summary>
/// Returns the details for the given item.
/// </summary>
/// <param name="key">Item key.</param>
/// <returns>An array of tuples containing item details or null if an error occurs.</returns>
public override Utility.Tuple<ColumnType, string, object>[] GetDetails(object key)
{
if (disposed)
return null;
List<Utility.Tuple<ColumnType, string, object>> details = new List<Utility.Tuple<ColumnType, string, object>>();
try
{
string profileName = (string)key;
Profile profileToUse = null;
foreach (Profile profileToTest in Profile.AllSavedProfiles)
{
if (profileToTest.Name == profileName)
{
profileToUse = profileToTest;
}
}
if (profileToUse == null)
{
profileToUse = Profile.CurrentProfile;
}
// Get file info
if (profileToUse.ProfileBitmap is Bitmap)
{
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FileName, string.Empty, profileToUse.Name));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateCreated, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateAccessed, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateModified, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FileSize, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FilePath, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FolderName, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Dimensions, string.Empty, new Size(profileToUse.ProfileBitmap.Width, profileToUse.ProfileBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Resolution, string.Empty, new SizeF((float)profileToUse.ProfileBitmap.Width, (float)profileToUse.ProfileBitmap.Height)));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ImageDescription, string.Empty, profileToUse.Name));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.EquipmentModel, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.DateTaken, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Artist, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Copyright, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ExposureTime, string.Empty, (float)0));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FNumber, string.Empty, (float)0));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.ISOSpeed, string.Empty, (ushort)0));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.UserComment, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Rating, string.Empty, (ushort)0));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.Software, string.Empty, ""));
details.Add(new Utility.Tuple<ColumnType, string, object>(ColumnType.FocalLength, string.Empty, (float)0));
}
return details.ToArray();
}
catch
{
// If we have a problem with converting the submitted key to a profile
// Then we return null
return null;
}
}
public override void Dispose()
{
disposed = true;
}
}
#endregion
}