From ddbd6431c51bbbc63382ca5d272f4b820e2cbc2b Mon Sep 17 00:00:00 2001 From: Terry MacDonald Date: Sun, 22 Aug 2021 21:45:51 +1200 Subject: [PATCH] [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! --- DisplayMagician/UIForms/DisplayProfileForm.cs | 10 +++++++- DisplayMagicianShared/AMD/AMDProfileItem.cs | 13 ++++------- .../NVIDIA/NVIDIAProfileItem.cs | 11 +++++---- DisplayMagicianShared/ProfileItem.cs | 9 ++++---- .../UserControls/DisplayView.cs | 23 ++++--------------- .../Windows/WinProfileItem.cs | 12 ++++------ 6 files changed, 34 insertions(+), 44 deletions(-) diff --git a/DisplayMagician/UIForms/DisplayProfileForm.cs b/DisplayMagician/UIForms/DisplayProfileForm.cs index 33e604c..3dc16b9 100644 --- a/DisplayMagician/UIForms/DisplayProfileForm.cs +++ b/DisplayMagician/UIForms/DisplayProfileForm.cs @@ -260,7 +260,15 @@ namespace DisplayMagician.UIForms lbl_profile_shown.Text = _selectedProfile.Name; // 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); } diff --git a/DisplayMagicianShared/AMD/AMDProfileItem.cs b/DisplayMagicianShared/AMD/AMDProfileItem.cs index 6513347..bf99d3c 100644 --- a/DisplayMagicianShared/AMD/AMDProfileItem.cs +++ b/DisplayMagicianShared/AMD/AMDProfileItem.cs @@ -7,6 +7,7 @@ using DisplayMagicianShared.Resources; using Newtonsoft.Json; using System.Drawing; using DisplayMagicianShared.Windows; +using System.Drawing.Imaging; namespace DisplayMagicianShared.AMD { @@ -26,7 +27,6 @@ namespace DisplayMagicianShared.AMD private bool _isPossible = false; private Keys _hotkey = Keys.None; - public AMDProfileItem() { } @@ -67,8 +67,6 @@ namespace DisplayMagicianShared.AMD public override string Name { get; set; } - //public Topology.Path[] Paths { get; set; } = new Topology.Path[0]; - [JsonRequired] public AMD_DISPLAY_CONFIG AMDDisplayConfig { @@ -132,8 +130,7 @@ namespace DisplayMagicianShared.AMD - //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] + [JsonConverter(typeof(CustomBitmapConverter))] public override Bitmap ProfileBitmap { get @@ -158,8 +155,8 @@ namespace DisplayMagicianShared.AMD //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] - public override Bitmap ProfileTightestBitmap + + /*public override Bitmap ProfileTightestBitmap { get { @@ -176,7 +173,7 @@ namespace DisplayMagicianShared.AMD _profileShortcutBitmap = value; } - } + } */ #endregion diff --git a/DisplayMagicianShared/NVIDIA/NVIDIAProfileItem.cs b/DisplayMagicianShared/NVIDIA/NVIDIAProfileItem.cs index b332a1c..4bd82ad 100644 --- a/DisplayMagicianShared/NVIDIA/NVIDIAProfileItem.cs +++ b/DisplayMagicianShared/NVIDIA/NVIDIAProfileItem.cs @@ -27,7 +27,7 @@ namespace DisplayMagicianShared.NVIDIA private string _uuid = ""; private bool _isPossible = false; private Keys _hotkey = Keys.None; - + public NVIDIAProfileItem() { } @@ -151,7 +151,7 @@ namespace DisplayMagicianShared.NVIDIA [JsonConverter(typeof(CustomBitmapConverter))] - public new Bitmap ProfileBitmap + public override Bitmap ProfileBitmap { get { @@ -288,12 +288,13 @@ namespace DisplayMagicianShared.NVIDIA ScreenPosition screen = new ScreenPosition(); screen.Library = "NVIDIA"; + UInt32 sourceId = path.SourceInfo.Id; UInt32 targetId = path.TargetInfo.Id; foreach (DISPLAYCONFIG_MODE_INFO displayMode in _windowsDisplayConfig.DisplayConfigModes) { // 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.DisplayConnector = displayMode.DisplayConnector; @@ -307,6 +308,8 @@ namespace DisplayMagicianShared.NVIDIA { screen.IsPrimary = true; } + + break; } } @@ -334,7 +337,7 @@ namespace DisplayMagicianShared.NVIDIA screen.HDRSupported = false; screen.HDREnabled = false; } - + break; } } diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index efea8e6..f568721 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -220,7 +220,7 @@ namespace DisplayMagicianShared } - [JsonIgnore] + [JsonRequired] public virtual List Screens { get @@ -256,8 +256,7 @@ namespace DisplayMagicianShared } } - //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] + [JsonConverter(typeof(CustomBitmapConverter))] public virtual Bitmap ProfileBitmap { get @@ -277,8 +276,8 @@ namespace DisplayMagicianShared } - //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] + [JsonConverter(typeof(CustomBitmapConverter))] + //[JsonIgnore] public virtual Bitmap ProfileTightestBitmap { get diff --git a/DisplayMagicianShared/UserControls/DisplayView.cs b/DisplayMagicianShared/UserControls/DisplayView.cs index 7deb8d5..a8013c1 100644 --- a/DisplayMagicianShared/UserControls/DisplayView.cs +++ b/DisplayMagicianShared/UserControls/DisplayView.cs @@ -147,7 +147,7 @@ namespace DisplayMagicianShared.UserControls } } - private void DrawTarget( + /* private void DrawTarget( Graphics g, ScreenPosition screen, Rectangle rect, @@ -181,7 +181,7 @@ namespace DisplayMagicianShared.UserControls g.DrawRectangle(Pens.Black, targetRect); var str = $"{screen.Name}{Environment.NewLine}{screen.ScreenWidth}×{screen.ScreenHeight}"; - +*/ /* switch (target.Rotation) { case Rotation.Rotate90: @@ -220,23 +220,8 @@ namespace DisplayMagicianShared.UserControls { 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) { @@ -287,7 +272,7 @@ namespace DisplayMagicianShared.UserControls } else { - screenBgColour = Color.FromArgb(255, 155, 155, 155); + screenBgColour = Color.FromArgb(255, 195, 195, 195); } } diff --git a/DisplayMagicianShared/Windows/WinProfileItem.cs b/DisplayMagicianShared/Windows/WinProfileItem.cs index 4b6334e..8a40ed3 100644 --- a/DisplayMagicianShared/Windows/WinProfileItem.cs +++ b/DisplayMagicianShared/Windows/WinProfileItem.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using DisplayMagicianShared.Resources; using Newtonsoft.Json; using System.Drawing; +using System.Drawing.Imaging; namespace DisplayMagicianShared.Windows { @@ -24,7 +25,6 @@ namespace DisplayMagicianShared.Windows private bool _isPossible = false; private Keys _hotkey = Keys.None; - public WinProfileItem() { } @@ -96,7 +96,7 @@ namespace DisplayMagicianShared.Windows } } - [JsonIgnore] + [JsonRequired] public override List Screens { get @@ -115,8 +115,7 @@ namespace DisplayMagicianShared.Windows - //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] + [JsonConverter(typeof(CustomBitmapConverter))] public override Bitmap ProfileBitmap { get @@ -140,8 +139,7 @@ namespace DisplayMagicianShared.Windows } - //[JsonConverter(typeof(CustomBitmapConverter))] - [JsonIgnore] + /*[JsonConverter(typeof(CustomBitmapConverter))] public override Bitmap ProfileTightestBitmap { get @@ -159,7 +157,7 @@ namespace DisplayMagicianShared.Windows _profileShortcutBitmap = value; } - } + } */ #endregion