[WIP] Partial profile image restructure

Trying to make the DisplayView and ProfileIcon
image drawing logic more generic so that it will
work with NVIDIA, AMD , Intel and Windows video
card drivers. Having to reverse engineer the amazing
wok that Soroush did with this stuff. I just know that
I'm going to break this before I fix it, but I really think
this is needed in order for this new video card
separation refactoring to work. This is going to take a
while I feel!
This commit is contained in:
Terry MacDonald 2021-06-24 22:14:39 +12:00
parent ac5d51bb12
commit 5cb0984637
4 changed files with 103 additions and 34 deletions

View File

@ -19,6 +19,7 @@ namespace DisplayMagicianShared.AMD
private ProfileIcon _profileIcon;
private Bitmap _profileBitmap, _profileShortcutBitmap;
private List<string> _profileDisplayIdentifiers = new List<string>();
private List<ScreenPosition> _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<ScreenPosition> 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<ScreenPosition> GetScreenPositions()
{
return new List<ScreenPosition>();
}
// The public override for the Object.Equals
public override bool Equals(object obj)

View File

@ -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<ScreenPosition> 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<ScreenPosition> 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);
}
}
}

View File

@ -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<ProfileItem> _allSavedProfiles = new List<ProfileItem>();
private ProfileIcon _profileIcon;
private Bitmap _profileBitmap, _profileShortcutBitmap;
private List<string> _profileDisplayIdentifiers = new List<string>();
private List<ScreenPosition> _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}[)}]?$";
@ -180,6 +195,20 @@ namespace DisplayMagicianShared
}
[JsonIgnore]
public virtual List<ScreenPosition> Screens
{
get
{
if (_screens.Count == 0)
{
_screens = GetScreenPositions();
}
return _screens;
}
}
public string SavedProfileIconCacheFilename { get; set; }
public virtual List<string> ProfileDisplayIdentifiers
@ -546,6 +575,11 @@ namespace DisplayMagicianShared
}
}
public virtual List<ScreenPosition> GetScreenPositions()
{
return new List<ScreenPosition>();
}
}
// Custom Equality comparer for the Profile class

View File

@ -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);
}
}