mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Renamed app to HeliosPlus namespace so that the updated changes don't interfere with HeliosDisplayManagement if that is also installed. The fact that I've changed so much of the app means that my changes would be unlikely to be accepted by Soroush, so I'm best to release this work in a similar way to other projects like Notepad++, by keeping the same root name, and adding a plus. I've also changed the Shortcut form to put all the games in a single list to reduce the number of clicks a user has to do in order for them to create a shortcut. I have begun to prepare the form so that it will support multiple game libraries, but now I am at a point that I need to fix the Steam and Uplay game detection mechanisms so that they report the correct information for the lv_games list view.
140 lines
4.4 KiB
C#
140 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using WindowsDisplayAPI;
|
|
using WindowsDisplayAPI.DisplayConfig;
|
|
using HeliosPlus.Shared;
|
|
using HeliosPlus.Shared.Topology;
|
|
|
|
namespace HeliosPlus
|
|
{
|
|
internal class DisplayRepresentation
|
|
{
|
|
public DisplayRepresentation(Display display)
|
|
{
|
|
Name = display.DeviceName;
|
|
Path = display.DevicePath;
|
|
var index = Path.IndexOf("{", StringComparison.InvariantCultureIgnoreCase);
|
|
|
|
if (index > 0)
|
|
{
|
|
Path = Path.Substring(0, index).TrimEnd('#');
|
|
}
|
|
|
|
IsAvailable = display.IsAvailable;
|
|
|
|
if (IsAvailable)
|
|
{
|
|
PossibleSettings = GetDisplay()?.GetPossibleSettings()?.ToArray() ?? new DisplayPossibleSetting[0];
|
|
}
|
|
}
|
|
|
|
public DisplayRepresentation(PathTarget display)
|
|
{
|
|
Name = display.DisplayName;
|
|
Path = display.DevicePath;
|
|
IsAvailable = GetDisplay()?.IsAvailable ?? false;
|
|
|
|
if (IsAvailable)
|
|
{
|
|
PossibleSettings = GetDisplay()?.GetPossibleSettings()?.ToArray() ?? new DisplayPossibleSetting[0];
|
|
}
|
|
}
|
|
|
|
public bool IsAvailable { get; }
|
|
public string Name { get; }
|
|
public string Path { get; }
|
|
|
|
public DisplayPossibleSetting[] PossibleSettings { get; }
|
|
|
|
public static IEnumerable<DisplayRepresentation> GetDisplays(Profile profile = null)
|
|
{
|
|
//var displays =
|
|
// Display.GetDisplays()
|
|
// .Select(display => new DisplayRepresentation(display))
|
|
// .OrderByDescending(representation => representation.IsAvailable)
|
|
// .GroupBy(representation => representation.Path)
|
|
// .Select(grouping => grouping.First()).ToList();
|
|
var displays = new List<DisplayRepresentation>();
|
|
|
|
if (profile != null)
|
|
{
|
|
foreach (var target in profile.Paths.SelectMany(path => path.Targets))
|
|
{
|
|
if (displays.All(display => display.Path != target.DevicePath))
|
|
{
|
|
displays.Add(new DisplayRepresentation(target));
|
|
}
|
|
}
|
|
}
|
|
|
|
return displays;
|
|
}
|
|
|
|
public Display GetDisplay()
|
|
{
|
|
return Display.GetDisplays().FirstOrDefault(display => display.DevicePath.StartsWith(Path));
|
|
}
|
|
|
|
public Path GetPathSource(Profile profile)
|
|
{
|
|
return profile.Paths.FirstOrDefault(path => path.Targets.Any(target => target.DevicePath == Path));
|
|
}
|
|
|
|
public PathTarget GetPathTarget(Profile profile)
|
|
{
|
|
return profile.Paths.SelectMany(path => path.Targets).FirstOrDefault(target => target.DevicePath == Path);
|
|
}
|
|
|
|
public PathDisplayTarget GetTargetInfo()
|
|
{
|
|
return
|
|
PathDisplayTarget.GetDisplayTargets()
|
|
.Where(target => target.DevicePath.StartsWith(Path))
|
|
.OrderByDescending(target => target.IsAvailable)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public Bitmap ToBitmap(Size size, Profile profile = null)
|
|
{
|
|
var targetInfo = GetTargetInfo();
|
|
var resolution = Size.Empty;
|
|
|
|
if (targetInfo != null && targetInfo.IsAvailable)
|
|
{
|
|
resolution = targetInfo.PreferredResolution;
|
|
}
|
|
else if (profile != null)
|
|
{
|
|
var targetPath = GetPathSource(profile);
|
|
|
|
if (targetPath != null)
|
|
{
|
|
resolution = targetPath.Resolution;
|
|
}
|
|
}
|
|
|
|
var p = new Profile {Paths = new Path[1]};
|
|
p.Paths[0] = new Path
|
|
{
|
|
Resolution = resolution,
|
|
Position = new Point(),
|
|
Targets = new PathTarget[1]
|
|
};
|
|
p.Paths[0].Targets[0] = new PathTarget {DevicePath = Path};
|
|
|
|
if (profile != null)
|
|
{
|
|
var targetPath = GetPathTarget(profile);
|
|
|
|
if (targetPath != null)
|
|
{
|
|
p.Paths[0].Targets[0].SurroundTopology = targetPath.SurroundTopology;
|
|
}
|
|
}
|
|
|
|
return new ProfileIcon(p).ToBitmap(size.Width, size.Height);
|
|
}
|
|
}
|
|
} |