diff --git a/DisplayMagicianShared/AMD/AMDProfileItem.cs b/DisplayMagicianShared/AMD/AMDProfileItem.cs index 039d483..e64f57f 100644 --- a/DisplayMagicianShared/AMD/AMDProfileItem.cs +++ b/DisplayMagicianShared/AMD/AMDProfileItem.cs @@ -19,6 +19,7 @@ namespace DisplayMagicianShared.AMD private ProfileIcon _profileIcon; private Bitmap _profileBitmap, _profileShortcutBitmap; private List _profileDisplayIdentifiers = new List(); + private List _screens; private static readonly string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$"; @@ -88,6 +89,20 @@ namespace DisplayMagicianShared.AMD } } + [JsonIgnore] + public override List Screens + { + get + { + if (_screens.Count == 0) + { + _screens = GetScreenPositions(); + } + return _screens; + } + } + + [JsonConverter(typeof(CustomBitmapConverter))] public new Bitmap ProfileBitmap { @@ -161,6 +176,12 @@ namespace DisplayMagicianShared.AMD return IsValid(); } + public override List GetScreenPositions() + { + + return new List(); + } + // The public override for the Object.Equals public override bool Equals(object obj) diff --git a/DisplayMagicianShared/ProfileIcon.cs b/DisplayMagicianShared/ProfileIcon.cs index ef8a015..9e25be8 100644 --- a/DisplayMagicianShared/ProfileIcon.cs +++ b/DisplayMagicianShared/ProfileIcon.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.IconLib; @@ -6,6 +7,7 @@ using System.Drawing.Imaging; using System.Linq; using System.Windows.Forms; using DisplayMagicianShared.Topology; +//using static DisplayMagicianShared.ProfileItem; namespace DisplayMagicianShared { @@ -28,7 +30,7 @@ namespace DisplayMagicianShared // ReSharper disable once TooManyArguments public static RectangleF CalculateViewSize( - Path[] paths, + List screens, bool withPadding = false, int paddingX = 0, int paddingY = 0) @@ -38,13 +40,13 @@ namespace DisplayMagicianShared var minY = 0; var maxY = 0; - foreach (var path in paths) + foreach (var screen in screens) { - var res = NormalizeResolution(path); - minX = Math.Min(minX, path.Position.X); - maxX = Math.Max(maxX, res.Width + path.Position.X); - minY = Math.Min(minY, path.Position.Y); - maxY = Math.Max(maxY, res.Height + path.Position.Y); + var res = NormalizeResolution(screens); + minX = Math.Min(minX, screen.ScreenX); + maxX = Math.Max(maxX, res.Width + screen.ScreenX); + minY = Math.Min(minY, screen.ScreenY); + maxY = Math.Max(maxY, res.Height + screen.ScreenY); } if (withPadding) @@ -61,7 +63,7 @@ namespace DisplayMagicianShared return rect; } - public static Size NormalizeResolution(Size resolution, Rotation rotation) + /*public static Size NormalizeResolution(Size resolution, Rotation rotation) { if (rotation == Rotation.Rotate90 || rotation == Rotation.Rotate270) { @@ -69,23 +71,35 @@ namespace DisplayMagicianShared } return resolution; - } + }*/ - public static Size NormalizeResolution(Path path) + public static Size NormalizeResolution(List screens) { - var biggest = Size.Empty; + Size biggest = Size.Empty; - foreach (var target in path.TargetDisplays) + foreach (ScreenPosition screen in screens) { - var res = NormalizeResolution(path.Resolution, target.Rotation); - - if ((ulong) res.Width * (ulong) res.Height > (ulong) biggest.Width * (ulong) biggest.Height) + //var res = NormalizeResolution(screen.ScreenWidth, screen.ScreenHeight, screen.ScreenRotation); + int width = 0; + int height = 0; + if (screen.ScreenOrientation == Orientation.Vertical) { - biggest = res; + width = screen.ScreenHeight; + height = screen.ScreenWidth; + } + else + { + width = screen.ScreenWidth; + height = screen.ScreenHeight; + } + + if ((ulong) width * (ulong) height > (ulong) biggest.Width * (ulong) biggest.Height) + { + biggest = new Size(width,height); } } - return biggest.IsEmpty ? path.Resolution : biggest; + return biggest; } @@ -144,7 +158,7 @@ namespace DisplayMagicianShared public Bitmap ToTightestBitmap(int width = 256, int height = 0, PixelFormat format = PixelFormat.Format32bppArgb) { - var viewSize = CalculateViewSize(_profile.Paths, true, PaddingX, PaddingY); + var viewSize = CalculateViewSize(_profile.Screens, true, PaddingX, PaddingY); int viewSizeRatio = Convert.ToInt32(viewSize.Width / viewSize.Height); if (height == 0) @@ -200,7 +214,7 @@ namespace DisplayMagicianShared return bitmap;*/ - var viewSize = CalculateViewSize(_profile.Paths, true, PaddingX, PaddingY); + var viewSize = CalculateViewSize(_profile.Screens, true, PaddingX, PaddingY); var width = bitmap.Width * 0.7f; var height = width / viewSize.Width * viewSize.Height; @@ -303,10 +317,10 @@ namespace DisplayMagicianShared return multiIcon; } - private void DrawPath(Graphics g, Path path) + private void DrawScreen(Graphics g, ScreenPosition screen) { - var res = NormalizeResolution(path); - var rect = new Rectangle(path.Position, res); + //var res = NormalizeResolution(screen); + var rect = new Rectangle(screen.ScreenX, screen.ScreenY, screen.ScreenWidth, screen.ScreenHeight); var rows = rect.Width < rect.Height ? path.TargetDisplays.Length : 1; var cols = rect.Width >= rect.Height ? path.TargetDisplays.Length : 1; @@ -361,7 +375,7 @@ namespace DisplayMagicianShared private void DrawView(Graphics g, float width, float height) { - var viewSize = CalculateViewSize(_profile.Paths, true, PaddingX, PaddingY); + var viewSize = CalculateViewSize(_profile.Screens, true, PaddingX, PaddingY); var standPadding = height * 0.005f; height -= standPadding * 8; var factor = Math.Min((width - 2 * standPadding - 1) / viewSize.Width, @@ -398,9 +412,9 @@ namespace DisplayMagicianShared viewSize.Width, viewSize.Height); } - foreach (var path in _profile.Paths) + foreach (ScreenPosition screen in _profile.Screens) { - DrawPath(g, path); + DrawScreen(g, screen); } } } diff --git a/DisplayMagicianShared/ProfileItem.cs b/DisplayMagicianShared/ProfileItem.cs index 5e0cbe9..3a0bc86 100644 --- a/DisplayMagicianShared/ProfileItem.cs +++ b/DisplayMagicianShared/ProfileItem.cs @@ -13,12 +13,27 @@ using IWshRuntimeLibrary; namespace DisplayMagicianShared { + + public struct ScreenPosition + { + public int ScreenX; + public int ScreenY; + public int ScreenWidth; + public int ScreenHeight; + public Orientation ScreenOrientation; + public Rotation ScreenRotation; + public string Name; + public bool IsPrimary; + public bool Colour; + } + public class ProfileItem : IComparable { private static List _allSavedProfiles = new List(); private ProfileIcon _profileIcon; private Bitmap _profileBitmap, _profileShortcutBitmap; private List _profileDisplayIdentifiers = new List(); + private List _screens; internal static string AppDataPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "DisplayMagician"); private static readonly string uuidV4Regex = @"(?im)^[{(]?[0-9A-F]{8}[-]?(?:[0-9A-F]{4}[-]?){3}[0-9A-F]{12}[)}]?$"; @@ -26,7 +41,7 @@ namespace DisplayMagicianShared private string _uuid = ""; private bool _isPossible = false; private Keys _hotkey = Keys.None; - + #region JsonConverterBitmap internal class CustomBitmapConverter : JsonConverter @@ -180,6 +195,20 @@ namespace DisplayMagicianShared } + + [JsonIgnore] + public virtual List Screens + { + get + { + if (_screens.Count == 0) + { + _screens = GetScreenPositions(); + } + return _screens; + } + } + public string SavedProfileIconCacheFilename { get; set; } public virtual List ProfileDisplayIdentifiers @@ -546,6 +575,11 @@ namespace DisplayMagicianShared } } + + public virtual List GetScreenPositions() + { + return new List(); + } } // Custom Equality comparer for the Profile class diff --git a/DisplayMagicianShared/UserControls/DisplayView.cs b/DisplayMagicianShared/UserControls/DisplayView.cs index 52fc5b2..d8d1c5a 100644 --- a/DisplayMagicianShared/UserControls/DisplayView.cs +++ b/DisplayMagicianShared/UserControls/DisplayView.cs @@ -42,10 +42,10 @@ namespace DisplayMagicianShared.UserControls } } - private void DrawPath(Graphics g, Path path) + private virtual void DrawScreen(Graphics g, ScreenPosition screen) { - var res = ProfileIcon.NormalizeResolution(path); - var rect = new Rectangle(path.Position, res); + //var res = ProfileIcon.NormalizeResolution(screens); + var rect = new Rectangle(screen.ScreenX, screen.ScreenY, screen.ScreenWidth, screen.ScreenHeight); g.FillRectangle(new SolidBrush(Color.FromArgb(15, Color.White)), rect); g.DrawRectangle(Pens.Black, rect); @@ -93,7 +93,7 @@ namespace DisplayMagicianShared.UserControls return new Size((int) stringSize.Width, (int) stringSize.Height); } - private void DrawSurroundTopology(Graphics g, PathTarget target, Rectangle rect) + private virtual void DrawSurroundTopology(Graphics g, PathTarget target, Rectangle rect) { g.DrawRectangle(Pens.Black, rect); @@ -146,7 +146,7 @@ namespace DisplayMagicianShared.UserControls } } - private void DrawTarget( + private virtual void DrawTarget( Graphics g, Path path, PathTarget target, @@ -224,7 +224,7 @@ namespace DisplayMagicianShared.UserControls private void DrawView(Graphics g) { - var viewSize = ProfileIcon.CalculateViewSize(_profile.Paths, true, PaddingX, PaddingY); + var viewSize = ProfileIcon.CalculateViewSize(_profile.Screens, true, PaddingX, PaddingY); var factor = Math.Min(Width / viewSize.Width, Height / viewSize.Height); g.ScaleTransform(factor, factor); @@ -232,9 +232,9 @@ namespace DisplayMagicianShared.UserControls var yOffset = (Height / factor - viewSize.Height) / 2f; g.TranslateTransform(-viewSize.X + xOffset, -viewSize.Y + yOffset); - foreach (var path in _profile.Paths) + foreach (ScreenPosition screen in _profile.Screens) { - DrawPath(g, path); + DrawScreen(g, screen); } }