Skip to content

Commit

Permalink
Add hires profile icons
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Sep 6, 2024
1 parent 700d04c commit 5182fda
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 27 deletions.
4 changes: 4 additions & 0 deletions NAPS2.Lib.Gtk/EtoForms/Gtk/GtkListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public void RegenerateImages()
{
throw new InvalidOperationException();
}
if (_entries.Count == 0)
{
return;
}
_refreshing = true;
foreach (var entry in _entries)
{
Expand Down
4 changes: 4 additions & 0 deletions NAPS2.Lib.Mac/EtoForms/Mac/MacListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public void SetItems(IEnumerable<T> items)
// TODO: Do we need this method? Clean up the name/doc at least
public void RegenerateImages()
{
if (_dataSource.Items.Count == 0)
{
return;
}
_view.ReloadData();
}

Expand Down
4 changes: 4 additions & 0 deletions NAPS2.Lib.WinForms/EtoForms/WinForms/WinFormsListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ public void RegenerateImages()
{
throw new InvalidOperationException();
}
if (Items.Count == 0)
{
return;
}
_refreshing = true;
_view.BeginUpdate();
ImageList.Clear();
Expand Down
9 changes: 9 additions & 0 deletions NAPS2.Lib/EtoForms/DefaultIconProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class DefaultIconProvider : IIconProvider
{
if (scale > 1)
{
// TODO: Maybe generalize everything with a numeric pixel size suffix?
if (name.EndsWith("_small"))
{
var norm = (byte[]?) Icons.ResourceManager.GetObject(name.Substring(0, name.Length - 6));
Expand All @@ -16,6 +17,14 @@ public class DefaultIconProvider : IIconProvider
return new Bitmap(norm).ResizeTo((int) (16 * scale));
}
}
else if (name.EndsWith("_48"))
{
var hires = (byte[]?) Icons.ResourceManager.GetObject(name.Substring(0, name.Length - 3) + "_96");
if (hires != null)
{
return new Bitmap(hires).ResizeTo((int) (48 * scale));
}
}
else
{
var hires = (byte[]?) Icons.ResourceManager.GetObject(name + "_hires");
Expand Down
6 changes: 5 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/ProfilesForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ public ProfilesForm(Naps2Config config, IScanPerformer scanPerformer, ProfileNam
profilesKsm.Assign("Mod+V", _pasteCommand);
EtoPlatform.Current.HandleKeyDown(_listView.Control, profilesKsm.Perform);

_listView.ImageSize = new Size(48, 48);
EtoPlatform.Current.AttachDpiDependency(this, scale =>
{
_listView.ImageSize = Size.Round(new SizeF(48, 48) * scale);
_listView.RegenerateImages();
});
_listView.ItemClicked += ItemClicked;
_listView.SelectionChanged += SelectionChanged;
_listView.Drop += Drop;
Expand Down
6 changes: 5 additions & 1 deletion NAPS2.Lib/EtoForms/Ui/ScannerSharingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public ScannerSharingForm(Naps2Config config, SharedDevicesListViewBehavior list
// TODO: Enable
// _shareAsService.Checked = _osServiceManager.IsRegistered;
// _shareAsService.CheckedChanged += ShareAsServiceCheckedChanged;
_listView.ImageSize = new Size(48, 48);
EtoPlatform.Current.AttachDpiDependency(this, scale =>
{
_listView.ImageSize = Size.Round(new SizeF(48, 48) * scale);
_listView.RegenerateImages();
});
_listView.SelectionChanged += SelectionChanged;

_addCommand.Enabled = true;
Expand Down
20 changes: 8 additions & 12 deletions NAPS2.Lib/EtoForms/Widgets/ProfileListViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@ public ProfileListViewBehavior(ColorScheme colorScheme) : base(colorScheme)

public override Image GetImage(ScanProfile item, Size imageSize)
{
if (item.IsDefault && item.IsLocked)
var iconName = (item.IsDefault, item.IsLocked) switch
{
return Icons.scanner_lock_default.ToEtoImage();
}
if (item.IsDefault)
{
return Icons.scanner_default.ToEtoImage();
}
if (item.IsLocked)
{
return Icons.scanner_lock.ToEtoImage();
}
return Icons.scanner_48.ToEtoImage();
(true, true) => "scanner_lock_default_48",
(true, false) => "scanner_default_48",
(false, true) => "scanner_lock_48",
(false, false) => "scanner_48"
};
var scale = imageSize.Height / 48f;
return EtoPlatform.Current.IconProvider.GetIcon(iconName, scale)!;
}

public override bool AllowDragDrop => true;
Expand Down
6 changes: 5 additions & 1 deletion NAPS2.Lib/EtoForms/Widgets/SharedDevicesListViewBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ public SharedDevicesListViewBehavior(ColorScheme colorScheme) : base(colorScheme

public override string GetLabel(SharedDevice item) => item.Name;

public override Image GetImage(SharedDevice item, Size imageSize) => Icons.scanner_wireless.ToEtoImage();
public override Image GetImage(SharedDevice item, Size imageSize)
{
var scale = imageSize.Height / 48f;
return EtoPlatform.Current.IconProvider.GetIcon("scanner_wireless_48", scale)!;
}
}
66 changes: 58 additions & 8 deletions NAPS2.Lib/Icons.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions NAPS2.Lib/Icons.resx
Original file line number Diff line number Diff line change
Expand Up @@ -238,21 +238,36 @@
<data name="scanner_64" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-64-rev2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-96.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_128" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-128.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
<data name="scanner_default_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-default-rev2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_lock_default" type="System.Resources.ResXFileRef, System.Windows.Forms">
<data name="scanner_default_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-default-hires.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_lock_default_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-lock-default-rev2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_lock" type="System.Resources.ResXFileRef, System.Windows.Forms">
<data name="scanner_lock_default_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-lock-default-hires.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_lock_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-lock-rev2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_wireless" type="System.Resources.ResXFileRef, System.Windows.Forms">
<data name="scanner_lock_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-lock-hires.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_wireless_48" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-wireless-rev2.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="scanner_wireless_96" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\scanner-wireless-hires.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="device" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Icons\device.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
Binary file added NAPS2.Lib/Icons/scanner-96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NAPS2.Lib/Icons/scanner-default-hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NAPS2.Lib/Icons/scanner-lock-default-hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NAPS2.Lib/Icons/scanner-lock-hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NAPS2.Lib/Icons/scanner-wireless-hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added NAPS2.Lib/Icons/wireless_filled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5182fda

Please sign in to comment.