[WIP] Mostly working NVIDIAProfileItem

NVIDIA Profiles can be created, JSON file saved ok, and the bitmaps and icons are drawn correctly and showin in the Display Profile window. The problem comes when the DisplayProfiles_2.0.json file is loaded. JsonConvert causes an exception trying to populate ProfileBitmap, and I can't figure out why!
This commit is contained in:
Terry MacDonald 2021-08-22 21:45:51 +12:00
parent 508f3751b9
commit ddbd6431c5
6 changed files with 34 additions and 44 deletions

View File

@ -260,7 +260,15 @@ namespace DisplayMagician.UIForms
lbl_profile_shown.Text = _selectedProfile.Name; lbl_profile_shown.Text = _selectedProfile.Name;
// And show the logo for the driver // And show the logo for the driver
if (_selectedProfile.VideoMode == VIDEO_MODE.AMD) if (_selectedProfile.VideoMode == VIDEO_MODE.NVIDIA)
{
pbLogo.Image = PickBitmapBasedOnBgColour(BackColor, Properties.Resources.amdblack, Properties.Resources.amdwhite);
}
else if (_selectedProfile.VideoMode == VIDEO_MODE.AMD)
{
pbLogo.Image = PickBitmapBasedOnBgColour(BackColor, Properties.Resources.amdblack, Properties.Resources.amdwhite);
}
else
{ {
pbLogo.Image = PickBitmapBasedOnBgColour(BackColor, Properties.Resources.amdblack, Properties.Resources.amdwhite); pbLogo.Image = PickBitmapBasedOnBgColour(BackColor, Properties.Resources.amdblack, Properties.Resources.amdwhite);
} }

View File

@ -7,6 +7,7 @@ using DisplayMagicianShared.Resources;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Drawing; using System.Drawing;
using DisplayMagicianShared.Windows; using DisplayMagicianShared.Windows;
using System.Drawing.Imaging;
namespace DisplayMagicianShared.AMD namespace DisplayMagicianShared.AMD
{ {
@ -26,7 +27,6 @@ namespace DisplayMagicianShared.AMD
private bool _isPossible = false; private bool _isPossible = false;
private Keys _hotkey = Keys.None; private Keys _hotkey = Keys.None;
public AMDProfileItem() public AMDProfileItem()
{ {
} }
@ -67,8 +67,6 @@ namespace DisplayMagicianShared.AMD
public override string Name { get; set; } public override string Name { get; set; }
//public Topology.Path[] Paths { get; set; } = new Topology.Path[0];
[JsonRequired] [JsonRequired]
public AMD_DISPLAY_CONFIG AMDDisplayConfig public AMD_DISPLAY_CONFIG AMDDisplayConfig
{ {
@ -132,8 +130,7 @@ namespace DisplayMagicianShared.AMD
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public override Bitmap ProfileBitmap public override Bitmap ProfileBitmap
{ {
get get
@ -158,8 +155,8 @@ namespace DisplayMagicianShared.AMD
//[JsonConverter(typeof(CustomBitmapConverter))] //[JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public override Bitmap ProfileTightestBitmap /*public override Bitmap ProfileTightestBitmap
{ {
get get
{ {
@ -176,7 +173,7 @@ namespace DisplayMagicianShared.AMD
_profileShortcutBitmap = value; _profileShortcutBitmap = value;
} }
} } */
#endregion #endregion

View File

@ -27,7 +27,7 @@ namespace DisplayMagicianShared.NVIDIA
private string _uuid = ""; private string _uuid = "";
private bool _isPossible = false; private bool _isPossible = false;
private Keys _hotkey = Keys.None; private Keys _hotkey = Keys.None;
public NVIDIAProfileItem() public NVIDIAProfileItem()
{ {
} }
@ -151,7 +151,7 @@ namespace DisplayMagicianShared.NVIDIA
[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
public new Bitmap ProfileBitmap public override Bitmap ProfileBitmap
{ {
get get
{ {
@ -288,12 +288,13 @@ namespace DisplayMagicianShared.NVIDIA
ScreenPosition screen = new ScreenPosition(); ScreenPosition screen = new ScreenPosition();
screen.Library = "NVIDIA"; screen.Library = "NVIDIA";
UInt32 sourceId = path.SourceInfo.Id;
UInt32 targetId = path.TargetInfo.Id; UInt32 targetId = path.TargetInfo.Id;
foreach (DISPLAYCONFIG_MODE_INFO displayMode in _windowsDisplayConfig.DisplayConfigModes) foreach (DISPLAYCONFIG_MODE_INFO displayMode in _windowsDisplayConfig.DisplayConfigModes)
{ {
// Find the matching Display Config Source Mode // Find the matching Display Config Source Mode
if (displayMode.InfoType != DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE && displayMode.Id == targetId) if (displayMode.InfoType == DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE && displayMode.Id == sourceId)
{ {
screen.Name = targetId.ToString(); screen.Name = targetId.ToString();
//screen.DisplayConnector = displayMode.DisplayConnector; //screen.DisplayConnector = displayMode.DisplayConnector;
@ -307,6 +308,8 @@ namespace DisplayMagicianShared.NVIDIA
{ {
screen.IsPrimary = true; screen.IsPrimary = true;
} }
break;
} }
} }
@ -334,7 +337,7 @@ namespace DisplayMagicianShared.NVIDIA
screen.HDRSupported = false; screen.HDRSupported = false;
screen.HDREnabled = false; screen.HDREnabled = false;
} }
break;
} }
} }

View File

@ -220,7 +220,7 @@ namespace DisplayMagicianShared
} }
[JsonIgnore] [JsonRequired]
public virtual List<ScreenPosition> Screens public virtual List<ScreenPosition> Screens
{ {
get get
@ -256,8 +256,7 @@ namespace DisplayMagicianShared
} }
} }
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public virtual Bitmap ProfileBitmap public virtual Bitmap ProfileBitmap
{ {
get get
@ -277,8 +276,8 @@ namespace DisplayMagicianShared
} }
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore] //[JsonIgnore]
public virtual Bitmap ProfileTightestBitmap public virtual Bitmap ProfileTightestBitmap
{ {
get get

View File

@ -147,7 +147,7 @@ namespace DisplayMagicianShared.UserControls
} }
} }
private void DrawTarget( /* private void DrawTarget(
Graphics g, Graphics g,
ScreenPosition screen, ScreenPosition screen,
Rectangle rect, Rectangle rect,
@ -181,7 +181,7 @@ namespace DisplayMagicianShared.UserControls
g.DrawRectangle(Pens.Black, targetRect); g.DrawRectangle(Pens.Black, targetRect);
var str = $"{screen.Name}{Environment.NewLine}{screen.ScreenWidth}×{screen.ScreenHeight}"; var str = $"{screen.Name}{Environment.NewLine}{screen.ScreenWidth}×{screen.ScreenHeight}";
*/
/* switch (target.Rotation) /* switch (target.Rotation)
{ {
case Rotation.Rotate90: case Rotation.Rotate90:
@ -220,23 +220,8 @@ namespace DisplayMagicianShared.UserControls
{ {
DrawString(g, str, targetRect.Size, targetRect.Location); DrawString(g, str, targetRect.Size, targetRect.Location);
}*/ }*/
} //}
/*private void DrawView(Graphics g)
{
var viewSize = ProfileIcon.CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
var factor = Math.Min(Width / viewSize.Width, Height / viewSize.Height);
g.ScaleTransform(factor, factor);
var xOffset = (Width / factor - viewSize.Width) / 2f;
var yOffset = (Height / factor - viewSize.Height) / 2f;
g.TranslateTransform(-viewSize.X + xOffset, -viewSize.Y + yOffset);
foreach (ScreenPosition screen in _profile.Screens)
{
DrawScreen(g, screen);
}
}*/
private void DrawView(Graphics g) private void DrawView(Graphics g)
{ {
@ -287,7 +272,7 @@ namespace DisplayMagicianShared.UserControls
} }
else else
{ {
screenBgColour = Color.FromArgb(255, 155, 155, 155); screenBgColour = Color.FromArgb(255, 195, 195, 195);
} }
} }

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using DisplayMagicianShared.Resources; using DisplayMagicianShared.Resources;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging;
namespace DisplayMagicianShared.Windows namespace DisplayMagicianShared.Windows
{ {
@ -24,7 +25,6 @@ namespace DisplayMagicianShared.Windows
private bool _isPossible = false; private bool _isPossible = false;
private Keys _hotkey = Keys.None; private Keys _hotkey = Keys.None;
public WinProfileItem() public WinProfileItem()
{ {
} }
@ -96,7 +96,7 @@ namespace DisplayMagicianShared.Windows
} }
} }
[JsonIgnore] [JsonRequired]
public override List<ScreenPosition> Screens public override List<ScreenPosition> Screens
{ {
get get
@ -115,8 +115,7 @@ namespace DisplayMagicianShared.Windows
//[JsonConverter(typeof(CustomBitmapConverter))] [JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public override Bitmap ProfileBitmap public override Bitmap ProfileBitmap
{ {
get get
@ -140,8 +139,7 @@ namespace DisplayMagicianShared.Windows
} }
//[JsonConverter(typeof(CustomBitmapConverter))] /*[JsonConverter(typeof(CustomBitmapConverter))]
[JsonIgnore]
public override Bitmap ProfileTightestBitmap public override Bitmap ProfileTightestBitmap
{ {
get get
@ -159,7 +157,7 @@ namespace DisplayMagicianShared.Windows
_profileShortcutBitmap = value; _profileShortcutBitmap = value;
} }
} } */
#endregion #endregion