mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
FIxed invalid shortcut detection
Made the shortcuts that were invalid visually different to the others. This is now working properly!
This commit is contained in:
parent
3a180d8813
commit
7d411b0aff
@ -308,6 +308,7 @@
|
|||||||
<None Include="Resources\Epic.ico" />
|
<None Include="Resources\Epic.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Include="Resources\warning.png" />
|
||||||
<None Include="Resources\DisplayMagician.ico" />
|
<None Include="Resources\DisplayMagician.ico" />
|
||||||
<Content Include="Resources\redarrows.png" />
|
<Content Include="Resources\redarrows.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
20
DisplayMagician/Properties/Resources.Designer.cs
generated
20
DisplayMagician/Properties/Resources.Designer.cs
generated
@ -90,6 +90,16 @@ namespace DisplayMagician.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Drawing.Bitmap RedArrows {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("RedArrows", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -109,5 +119,15 @@ namespace DisplayMagician.Properties {
|
|||||||
return ((System.Drawing.Icon)(obj));
|
return ((System.Drawing.Icon)(obj));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||||
|
/// </summary>
|
||||||
|
public static System.Drawing.Bitmap Warning {
|
||||||
|
get {
|
||||||
|
object obj = ResourceManager.GetObject("Warning", resourceCulture);
|
||||||
|
return ((System.Drawing.Bitmap)(obj));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,4 +133,10 @@
|
|||||||
<data name="Uplay" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
<data name="Uplay" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
<value>..\Resources\Uplay.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
<value>..\Resources\Uplay.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="RedArrows" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\resources\redarrows.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
|
<data name="Warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||||
|
<value>..\Resources\warning.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
BIN
DisplayMagician/Resources/warning.png
Normal file
BIN
DisplayMagician/Resources/warning.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Drawing2D;
|
using System.Drawing.Drawing2D;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -9,10 +10,14 @@ using Manina.Windows.Forms;
|
|||||||
|
|
||||||
namespace DisplayMagician.UIForms
|
namespace DisplayMagician.UIForms
|
||||||
{
|
{
|
||||||
|
#pragma warning disable CS3009 // Base type is not CLS-compliant
|
||||||
public class ShortcutILVRenderer : ImageListView.ImageListViewRenderer
|
public class ShortcutILVRenderer : ImageListView.ImageListViewRenderer
|
||||||
|
#pragma warning restore CS3009 // Base type is not CLS-compliant
|
||||||
{
|
{
|
||||||
// Returns item size for the given view mode.
|
// Returns item size for the given view mode.
|
||||||
|
#pragma warning disable CS3001 // Argument type is not CLS-compliant
|
||||||
public override Size MeasureItem(View view)
|
public override Size MeasureItem(View view)
|
||||||
|
#pragma warning restore CS3001 // Argument type is not CLS-compliant
|
||||||
{
|
{
|
||||||
Size itemPadding = new Size(4, 4);
|
Size itemPadding = new Size(4, 4);
|
||||||
Size sz = ImageListView.ThumbnailSize +
|
Size sz = ImageListView.ThumbnailSize +
|
||||||
@ -39,9 +44,20 @@ namespace DisplayMagician.UIForms
|
|||||||
base.DrawBackground(g, bounds);
|
base.DrawBackground(g, bounds);
|
||||||
}
|
}
|
||||||
// Draws the specified item on the given graphics.
|
// Draws the specified item on the given graphics.
|
||||||
public override void DrawItem(Graphics g, ImageListViewItem item,
|
#pragma warning disable CS3001 // Argument type is not CLS-compliant
|
||||||
ItemState state, Rectangle bounds)
|
public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
|
||||||
|
#pragma warning restore CS3001 // Argument type is not CLS-compliant
|
||||||
{
|
{
|
||||||
|
if (g is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(g));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item is null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(item));
|
||||||
|
}
|
||||||
|
|
||||||
Size itemPadding = new Size(4, 4);
|
Size itemPadding = new Size(4, 4);
|
||||||
bool alternate = (item.Index % 2 == 1);
|
bool alternate = (item.Index % 2 == 1);
|
||||||
|
|
||||||
@ -106,7 +122,24 @@ namespace DisplayMagician.UIForms
|
|||||||
if (img != null)
|
if (img != null)
|
||||||
{
|
{
|
||||||
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
||||||
|
|
||||||
|
if (ShortcutLibraryForm.shortcutValidity[item.Text])
|
||||||
|
{
|
||||||
|
// Draw the full color image as the shortcuts is not invalid
|
||||||
g.DrawImage(img, pos);
|
g.DrawImage(img, pos);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// THe shortcut is invalid
|
||||||
|
// so we make the image grayscale
|
||||||
|
Image grayImg = MakeGrayscale(img);
|
||||||
|
g.DrawImage(grayImg, pos);
|
||||||
|
|
||||||
|
// Draw a warning triangle over it
|
||||||
|
// right in the centre
|
||||||
|
g.DrawImage(Properties.Resources.Warning, pos.X + 30, pos.Y + 30, 40, 40);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw image border
|
// Draw image border
|
||||||
if (Math.Min(pos.Width, pos.Height) > 32)
|
if (Math.Min(pos.Width, pos.Height) > 32)
|
||||||
{
|
{
|
||||||
@ -298,5 +331,41 @@ namespace DisplayMagician.UIForms
|
|||||||
path.CloseFigure();
|
path.CloseFigure();
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Image MakeGrayscale(Image original)
|
||||||
|
{
|
||||||
|
//create a blank bitmap the same size as original
|
||||||
|
Image newBitmap = new Bitmap(original.Width, original.Height);
|
||||||
|
|
||||||
|
//get a graphics object from the new image
|
||||||
|
using (Graphics g = Graphics.FromImage(newBitmap))
|
||||||
|
{
|
||||||
|
|
||||||
|
//create the grayscale ColorMatrix
|
||||||
|
ColorMatrix colorMatrix = new ColorMatrix(
|
||||||
|
new float[][]
|
||||||
|
{
|
||||||
|
new float[] {.3f, .3f, .3f, 0, 0},
|
||||||
|
new float[] {.59f, .59f, .59f, 0, 0},
|
||||||
|
new float[] {.11f, .11f, .11f, 0, 0},
|
||||||
|
new float[] {0, 0, 0, 1, 0},
|
||||||
|
new float[] {0, 0, 0, 0, 1}
|
||||||
|
});
|
||||||
|
|
||||||
|
//create some image attributes
|
||||||
|
using (ImageAttributes attributes = new ImageAttributes())
|
||||||
|
{
|
||||||
|
|
||||||
|
//set the color matrix attribute
|
||||||
|
attributes.SetColorMatrix(colorMatrix);
|
||||||
|
|
||||||
|
//draw the original image on the new image
|
||||||
|
//using the grayscale color matrix
|
||||||
|
g.DrawImage(original, new Rectangle(0, 0, original.Width, original.Height),
|
||||||
|
0, 0, original.Width, original.Height, GraphicsUnit.Pixel, attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newBitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor();
|
private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor();
|
||||||
private ShortcutItem _selectedShortcut = null;
|
private ShortcutItem _selectedShortcut = null;
|
||||||
|
public static Dictionary<string, bool> shortcutValidity = new Dictionary<string, bool>();
|
||||||
|
|
||||||
public ShortcutLibraryForm()
|
public ShortcutLibraryForm()
|
||||||
{
|
{
|
||||||
@ -55,7 +56,7 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
ImageListViewItem newItem = null;
|
ImageListViewItem newItem = null;
|
||||||
ilv_saved_shortcuts.Items.Clear();
|
ilv_saved_shortcuts.Items.Clear();
|
||||||
|
shortcutValidity.Clear();
|
||||||
|
|
||||||
foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name))
|
foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name))
|
||||||
{
|
{
|
||||||
@ -65,6 +66,9 @@ namespace DisplayMagician.UIForms
|
|||||||
if (_selectedShortcut is ShortcutItem && _selectedShortcut.Equals(loadedShortcut))
|
if (_selectedShortcut is ShortcutItem && _selectedShortcut.Equals(loadedShortcut))
|
||||||
newItem.Selected = true;
|
newItem.Selected = true;
|
||||||
|
|
||||||
|
(bool result, string thing) = loadedShortcut.IsValid();
|
||||||
|
shortcutValidity[loadedShortcut.Name] = result;
|
||||||
|
|
||||||
//ilv_saved_profiles.Items.Add(newItem);
|
//ilv_saved_profiles.Items.Add(newItem);
|
||||||
ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor);
|
ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor);
|
||||||
}
|
}
|
||||||
@ -240,10 +244,7 @@ namespace DisplayMagician.UIForms
|
|||||||
|
|
||||||
// Only run the if shortcut is valid
|
// Only run the if shortcut is valid
|
||||||
(bool result, string validityMessage) = _selectedShortcut.IsValid();
|
(bool result, string validityMessage) = _selectedShortcut.IsValid();
|
||||||
if (result)
|
if (!result)
|
||||||
// Run the selected shortcut
|
|
||||||
btn_run.PerformClick();
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// We tell the user the reason that we couldnt run the shortcut
|
// We tell the user the reason that we couldnt run the shortcut
|
||||||
if (MessageBox.Show($"The shortcut '{_selectedShortcut.Name}' isn't valid for some reason so we cannot run the application or game. Has your hardware or screen layout changed from when the shortcut was made? We recommend that you edit the shortcut to make it valid again, or reverse the hardware changes you made. Do you want to do that now?", $"Edit the '{_selectedShortcut.Name}' Shortcut?", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
|
if (MessageBox.Show($"The shortcut '{_selectedShortcut.Name}' isn't valid for some reason so we cannot run the application or game. Has your hardware or screen layout changed from when the shortcut was made? We recommend that you edit the shortcut to make it valid again, or reverse the hardware changes you made. Do you want to do that now?", $"Edit the '{_selectedShortcut.Name}' Shortcut?", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
|
||||||
|
Loading…
Reference in New Issue
Block a user