Fixed screen drawing for icons and forms

Fixed the NVIDIA screen drawing so that it works fine now.
This commit is contained in:
Terry MacDonald 2021-09-01 22:13:22 +12:00
parent b6bd89bed2
commit ee1d2e4717
6 changed files with 93 additions and 340 deletions

View File

@ -2074,8 +2074,8 @@ namespace DisplayMagicianShared.NVIDIA
GetDelegate(NvId_DISP_GetGDIPrimaryDisplayId, out DISP_GetGDIPrimaryDisplayIdInternal);
GetDelegate(NvId_Disp_GetHdrCapabilities, out Disp_GetHdrCapabilitiesInternal);
GetDelegate(NvId_Disp_HdrColorControl, out Disp_HdrColorControlInternal);
GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternal);
GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternalNull); // null version of the submission
/*GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternal);
GetDelegate(NvId_DISP_GetDisplayConfig, out DISP_GetDisplayConfigInternalNull); // null version of the submission*/
GetDelegate(NvId_DISP_GetDisplayIdByDisplayName, out DISP_GetDisplayIdByDisplayNameInternal);
// GPUs

View File

@ -94,7 +94,7 @@ namespace DisplayMagicianShared.NVIDIA
{
public NVIDIA_MOSAIC_CONFIG MosaicConfig;
public NVIDIA_HDR_CONFIG HdrConfig;
public Dictionary<string, UInt32> DisplayNames;
public Dictionary<UInt32, string> DisplayNames;
public List<string> DisplayIdentifiers;
public override bool Equals(object obj) => obj is NVIDIA_DISPLAY_CONFIG other && this.Equals(other);
@ -102,7 +102,7 @@ namespace DisplayMagicianShared.NVIDIA
=> MosaicConfig.Equals(other.MosaicConfig) &&
HdrConfig.Equals(other.HdrConfig) &&
DisplayIdentifiers.SequenceEqual(other.DisplayIdentifiers) &&
DisplayNames.Equals(other.DisplayNames);
DisplayNames.SequenceEqual(other.DisplayNames);
public override int GetHashCode()
{
@ -873,17 +873,17 @@ namespace DisplayMagicianShared.NVIDIA
// Now we need to loop through each of the windows paths so we can record the Windows DisplayName to DisplayID mapping
// This is needed for us to piece together the Screen layout for when we draw the NVIDIA screens!
myDisplayConfig.DisplayNames = new Dictionary<string, uint>();
foreach (KeyValuePair<uint, string> displaySource in WinLibrary.GetDisplaySourceNames())
myDisplayConfig.DisplayNames = new Dictionary<uint, string>();
foreach (KeyValuePair<string, uint> displaySource in WinLibrary.GetDisplaySourceNames())
{
// Now we try to get the information about the displayIDs and map them to windows \\DISPLAY names e.g. \\DISPLAY1
string displayName = displaySource.Value;
string displayName = displaySource.Key;
UInt32 displayId = 0;
NVStatus = NVImport.NvAPI_DISP_GetDisplayIdByDisplayName(displayName, out displayId);
if (NVStatus == NVAPI_STATUS.NVAPI_OK)
{
SharedLogger.logger.Trace($"NVIDIALibrary/GetNVIDIADisplayConfig: NvAPI_DISP_GetDisplayIdByDisplayName returned OK. The display {displayName} has NVIDIA DisplayID {displayId}");
myDisplayConfig.DisplayNames.Add(displayName, displayId);
myDisplayConfig.DisplayNames.Add(displayId, displayName);
}
else if (NVStatus == NVAPI_STATUS.NVAPI_NVIDIA_DEVICE_NOT_FOUND)
{

View File

@ -262,9 +262,9 @@ namespace DisplayMagicianShared.NVIDIA
public override List<ScreenPosition> GetScreenPositions()
{
// Set up some colours
Color primaryScreenColor = Color.FromArgb(150, 255, 97, 27); // represents Primary screen blue
Color primaryScreenColor = Color.FromArgb(0, 174, 241); // represents Primary screen blue
Color spannedScreenColor = Color.FromArgb(118, 185, 0); // represents NVIDIA Green
Color normalScreenColor = Color.FromArgb(195, 195, 195); // represents normal screen colour (gray)
Color normalScreenColor = Color.FromArgb(155, 155, 155); // represents normal screen colour (gray)
// Now we create the screens structure from the AMD profile information
_screens = new List<ScreenPosition>();
@ -280,12 +280,16 @@ namespace DisplayMagicianShared.NVIDIA
if (_nvidiaDisplayConfig.MosaicConfig.IsMosaicEnabled)
{
// TODO: Make the NVIDIA displays show the individual screens and overlap!
// Create a dictionary of all the screen sizes we want
//Dictionary<string,SpannedScreenPosition> MosaicScreens = new Dictionary<string,SpannedScreenPosition>();
for (int i = 0; i < _nvidiaDisplayConfig.MosaicConfig.MosaicGridCount; i++)
{
ScreenPosition screen = new ScreenPosition();
screen.Library = "NVIDIA";
screen.Colour = normalScreenColor;
if (_nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].DisplayCount > 1)
{
// Set some basics about the screen
@ -380,12 +384,31 @@ namespace DisplayMagicianShared.NVIDIA
else if (_nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].DisplayCount == 1)
{
// This is a single screen
// Set some basics about the screen
NV_MOSAIC_DISPLAY_SETTING_V1 viewDisplaySettings = _nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].DisplaySettings;
screen.ScreenX = (int)viewDisplaySettings.;
screen.ScreenY = (int)viewDisplaySettings.Top;
screen.ScreenWidth = (int)viewDisplaySettings.Width;
screen.ScreenHeight = (int)viewDisplaySettings.Height;
// Set some basics about the screen
uint displayId = _nvidiaDisplayConfig.MosaicConfig.MosaicGridTopos[i].Displays[0].DisplayId;
string windowsDisplayName = _nvidiaDisplayConfig.DisplayNames[displayId];
uint sourceIndex = _windowsDisplayConfig.DisplaySources[windowsDisplayName];
for (int x = 0; x < _windowsDisplayConfig.DisplayConfigModes.Length; x++)
{
// Skip this if its not a source info config type
if (_windowsDisplayConfig.DisplayConfigModes[x].InfoType != DISPLAYCONFIG_MODE_INFO_TYPE.DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE)
{
continue;
}
// If the source index matches the index of the source info object we're looking at, then process it!
if (_windowsDisplayConfig.DisplayConfigModes[x].Id == sourceIndex)
{
screen.Name = displayId.ToString();
screen.ScreenX = (int)_windowsDisplayConfig.DisplayConfigModes[x].SourceMode.Position.X;
screen.ScreenY = (int)_windowsDisplayConfig.DisplayConfigModes[x].SourceMode.Position.Y;
screen.ScreenWidth = (int)_windowsDisplayConfig.DisplayConfigModes[x].SourceMode.Width;
screen.ScreenHeight = (int)_windowsDisplayConfig.DisplayConfigModes[x].SourceMode.Height;
break;
}
}
// If we're at the 0,0 coordinate then we're the primary monitor
if (screen.ScreenX == 0 && screen.ScreenY == 0)

View File

@ -135,42 +135,6 @@ namespace DisplayMagicianShared
public Bitmap ToBitmapOverlay(Bitmap bitmap)
{
/* if (width == 0)
width = bitmap.Width;
if (height == 0)
height = bitmap.Height;
var viewSize = CalculateViewSize(_profile.Viewports, true, PaddingX, PaddingY);
int viewSizeRatio = (int) Math.Round(viewSize.Width / viewSize.Height);
int overlayWidth = (int) Math.Round(width * 0.7f,0);
int overlayHeight = overlayWidth / viewSizeRatio;
int overlayX = width - overlayWidth;
int overlayY = height - overlayHeight;
Point overlayPosition = new Point(overlayX, overlayY);
Size overlaySize = new Size(overlayWidth, overlayHeight);
Rectangle overlayRect = new Rectangle(overlayPosition, overlaySize);
//var width = bitmap.Width * 0.7f;
//var height = width / viewSize.Width * viewSize.Height;
var combinedBitmap = new Bitmap(width, height, format);
combinedBitmap.MakeTransparent();
using (var g = Graphics.FromImage(combinedBitmap))
{
g.SmoothingMode = SmoothingMode.HighQuality;
//g.DrawImage(bitmap, 0, 0, width, height);
g.TranslateTransform(overlayX, overlayY);
//Rectangle compressionRectangle = new Rectangle(300, 10,
//myBitmap.Width / 2, myBitmap.Height / 2);
g.DrawRectangle(new Pen(Color.FromArgb(125, 50, 50, 50), 2f), overlayRect);
DrawView(g, overlayWidth, overlayHeight);
}
return bitmap;*/
var viewSize = CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
var width = bitmap.Width * 0.7f;
var height = width / viewSize.Width * viewSize.Height;
@ -274,122 +238,6 @@ namespace DisplayMagicianShared
return multiIcon;
}
/*private void DrawSingleScreen(Graphics g, ScreenPosition screen)
{
//var res = NormalizeResolution(screen);
Rectangle rect = new Rectangle(screen.ScreenX, screen.ScreenY, screen.ScreenWidth, screen.ScreenHeight);
int rows = rect.Width < rect.Height ? path.TargetDisplays.Length : 1;
int cols = rect.Width >= rect.Height ? path.TargetDisplays.Length : 1;
for (var i = 0; i < path.TargetDisplays.Length; i++)
{
DrawTarget(g, screen, path.TargetDisplays[i],
new Rectangle(
rect.X + PaddingX,
rect.Y + PaddingY,
rect.Width - 2 * PaddingX,
rect.Height - 2 * PaddingY),
rows > 1 ? i : 0, cols > 1 ? i : 0, rows, cols);
}
}*/
/*private void DrawScreen(Graphics g, ScreenPosition screen)
{
//var res = NormalizeResolution(screen);
Rectangle rect = new Rectangle(screen.ScreenX, screen.ScreenY, screen.ScreenWidth, screen.ScreenHeight);
int rows = rect.Width < rect.Height ? screen.SpannedScreens.Count : 1;
int cols = rect.Width >= rect.Height ? screen.SpannedScreens.Count : 1;
for(var i = 0; i < screen.SpannedScreens.Count ; i++)
{
DrawTarget(g, screen,
new Rectangle(
rect.X + PaddingX,
rect.Y + PaddingY,
rect.Width - 2 * PaddingX,
rect.Height - 2 * PaddingY),
rows > 1 ? i : 0, cols > 1 ? i : 0, rows, cols);
}
}
// ReSharper disable once TooManyArguments
private void DrawTarget(
Graphics g,
ScreenPosition screen,
Rectangle rect,
int row,
int col,
int rows,
int cols)
{
var targetSize = new Size(rect.Width / cols, rect.Height / rows);
var targetPosition = new Point(targetSize.Width * col + rect.X, targetSize.Height * row + rect.Y);
var targetRect = new Rectangle(targetPosition, targetSize);
if (screen.IsSpanned)
{
g.FillRectangle(new SolidBrush(screen.Colour), targetRect);
}
else if (screen.SpannedScreens.Count > 1)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 255, 97, 27)), targetRect);
}
else if (!screen.IsSpanned)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 0, 174, 241)), targetRect);
}
else
{
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 155, 155, 155)), targetRect);
}
g.DrawRectangle(new Pen(Color.FromArgb(125, 50, 50, 50), 2f), targetRect);
}
private void DrawView(Graphics g, float width, float height)
{
var viewSize = CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
var standPadding = height * 0.005f;
height -= standPadding * 8;
var factor = Math.Min((width - 2 * standPadding - 1) / viewSize.Width,
(height - 2 * standPadding - 1) / viewSize.Height);
g.ScaleTransform(factor, factor);
var xOffset = ((width - 1) / factor - viewSize.Width) / 2f;
var yOffset = ((height - 1) / factor - viewSize.Height) / 2f;
g.TranslateTransform(-viewSize.X + xOffset, -viewSize.Y + yOffset);
if (standPadding * 6 >= 1)
{
using (var boundRect = RoundedRect(viewSize, 2 * standPadding / factor))
{
g.FillPath(new SolidBrush(Color.FromArgb(200, 255, 255, 255)), boundRect);
g.DrawPath(new Pen(Color.FromArgb(170, 50, 50, 50), standPadding / factor), boundRect);
}
using (
var boundRect =
RoundedRect(
new RectangleF(viewSize.Width * 0.375f + viewSize.X,
viewSize.Height + standPadding / factor,
viewSize.Width / 4, standPadding * 7 / factor), 2 * standPadding / factor))
{
g.FillPath(new SolidBrush(Color.FromArgb(250, 50, 50, 50)), boundRect);
g.DrawPath(new Pen(Color.FromArgb(50, 255, 255, 255), 2 / factor), boundRect);
}
}
else
{
g.FillRectangle(new SolidBrush(Color.FromArgb(200, 255, 255, 255)), viewSize);
g.DrawRectangle(new Pen(Color.FromArgb(170, 50, 50, 50), standPadding / factor), viewSize.X, viewSize.Y,
viewSize.Width, viewSize.Height);
}
foreach (ScreenPosition screen in _profile.Screens)
{
DrawScreen(g, screen);
}
}*/
private void DrawView(Graphics g, float width, float height)
{
@ -408,17 +256,11 @@ namespace DisplayMagicianShared
// How wide the Bezel is on the screen graphics
int screenBezel = 60;
int screenWordBuffer = 30;
//int screenWordBuffer = 30;
// Draw the stand
if (standPadding * 6 >= 1)
{
using (var boundRect = RoundedRect(viewSize, 2 * standPadding / factor))
{
g.FillPath(new SolidBrush(Color.FromArgb(200, 255, 255, 255)), boundRect);
g.DrawPath(new Pen(Color.FromArgb(170, 50, 50, 50), standPadding / factor), boundRect);
}
using (
var boundRect =
RoundedRect(
@ -441,10 +283,6 @@ namespace DisplayMagicianShared
foreach (ScreenPosition screen in _profile.Screens)
{
Color screenBgColour;
Color lightTextColour = Color.White;
Color darkTextColour = Color.Black;
// draw the screen
if (screen.IsSpanned)
{
@ -456,9 +294,8 @@ namespace DisplayMagicianShared
// Draw the screen of the monitor
Rectangle screenRect = new Rectangle(screen.ScreenX + screenBezel, screen.ScreenY + screenBezel, screen.ScreenWidth - (screenBezel * 2), screen.ScreenHeight - (screenBezel * 2));
screenBgColour = screen.Colour;
g.FillRectangle(new SolidBrush(screenBgColour), screenRect);
g.FillRectangle(new SolidBrush(screen.Colour), screenRect);
g.DrawRectangle(Pens.Black, screenRect);
}
else
@ -471,23 +308,8 @@ namespace DisplayMagicianShared
// Draw the screen of the monitor
Rectangle screenRect = new Rectangle(screen.ScreenX + screenBezel, screen.ScreenY + screenBezel, screen.ScreenWidth - (screenBezel * 2), screen.ScreenHeight - (screenBezel * 2));
if (screen.IsPrimary)
{
//screenBgColour = Color.FromArgb(255, 66, 173, 245);
screenBgColour = Color.FromArgb(240, 116, 215, 255);
}
else
{
if (screen.Colour != null)
{
screenBgColour = screen.Colour;
}
else
{
screenBgColour = Color.FromArgb(255, 155, 155, 155);
}
}
g.FillRectangle(new SolidBrush(screenBgColour), screenRect);
g.FillRectangle(new SolidBrush(screen.Colour), screenRect);
g.DrawRectangle(Pens.Black, screenRect);
}

View File

@ -41,37 +41,11 @@ namespace DisplayMagicianShared.UserControls
}
}
/*private void DrawScreen(Graphics g, ScreenPosition screen)
{
//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);
*//*DrawString(g, path.Position.IsEmpty ? "[Primary]" : $"[{path.Position.X}, {path.Position.Y}]", rect.Size,
new PointF(rect.X + PaddingY / 2, rect.Y + PaddingY / 2), StringAlignment.Near, StringAlignment.Near);*//*
var str = $"DISPLAY {screen.Name}{Environment.NewLine}{rect.Width}×{rect.Height}";
var strSize = DrawString(g, str, rect.Size, new PointF(rect.X - PaddingX / 2, rect.Y + PaddingY / 2),
StringAlignment.Near, StringAlignment.Far);
var rows = rect.Width < rect.Height ? screen.Count : 1;
var cols = rect.Width >= rect.Height ? screen.Count : 1;
for (var i = 0; i < screen.Count; i++)
{
DrawTarget(g, screen,
new Rectangle(rect.X + PaddingX, rect.Y + strSize.Height + PaddingY, rect.Width - 2 * PaddingX,
rect.Height - strSize.Height - 2 * PaddingY),
rows > 1 ? i : 0, cols > 1 ? i : 0, rows, cols);
}
}*/
private Size DrawString(
Graphics g,
string str,
Color colour,
Font font,
SizeF drawingSize = default(SizeF),
PointF? drawingPoint = null,
StringAlignment vertical = StringAlignment.Center,
@ -87,7 +61,7 @@ namespace DisplayMagicianShared.UserControls
if (drawingPoint != null)
{
g.DrawString(str, Font, new SolidBrush(colour), new RectangleF(drawingPoint.Value, drawingSize),
g.DrawString(str, font, new SolidBrush(colour), new RectangleF(drawingPoint.Value, drawingSize),
format);
}
@ -147,82 +121,6 @@ namespace DisplayMagicianShared.UserControls
}
}
/* private void DrawTarget(
Graphics g,
ScreenPosition screen,
Rectangle rect,
int row,
int col,
int rows,
int cols)
{
var targetSize = new Size(rect.Width / cols, rect.Height / rows);
var targetPosition = new Point(targetSize.Width * col + rect.X, targetSize.Height * row + rect.Y);
var targetRect = new Rectangle(targetPosition, targetSize);
if (screen.IsSpanned)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(150, 106, 185, 0)), targetRect);
}
//else if (target.EyefinityTopology != null)
// g.FillRectangle(new SolidBrush(Color.FromArgb(150, 99, 0, 0)), targetRect);
else if (screen.SpannedScreens.Count > 1)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(150, 255, 97, 27)), targetRect);
}
else if (!screen.IsSpanned)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(150, 0, 174, 241)), targetRect);
}
else
{
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 155, 155, 155)), targetRect);
}
g.DrawRectangle(Pens.Black, targetRect);
var str = $"{screen.Name}{Environment.NewLine}{screen.ScreenWidth}×{screen.ScreenHeight}";
*/
/* switch (target.Rotation)
{
case Rotation.Rotate90:
DrawString(g, "90°", targetRect.Size,
new PointF(targetRect.X - PaddingX / 2, targetRect.Y + PaddingY / 2), StringAlignment.Near,
StringAlignment.Far);
break;
case Rotation.Rotate180:
DrawString(g, "180°", targetRect.Size,
new PointF(targetRect.X - PaddingX / 2, targetRect.Y + PaddingY / 2), StringAlignment.Near,
StringAlignment.Far);
break;
case Rotation.Rotate270:
DrawString(g, "270°", targetRect.Size,
new PointF(targetRect.X - PaddingX / 2, targetRect.Y + PaddingY / 2), StringAlignment.Near,
StringAlignment.Far);
break;
}
*//*
if (screen.IsSpanned)
{
var strSize = DrawString(g, str, targetRect.Size,
new PointF(targetRect.X + PaddingX / 2, targetRect.Y + PaddingY / 2),
StringAlignment.Near, StringAlignment.Near);
DrawSpannedTopology(g, screen,
new Rectangle(
targetRect.X + PaddingX,
targetRect.Y + strSize.Height + PaddingY,
targetRect.Width - 2 * PaddingX,
targetRect.Height - strSize.Height - 2 * PaddingY));
}
else
{
DrawString(g, str, targetRect.Size, targetRect.Location);
}*/
//}
private void DrawView(Graphics g)
{
var viewSize = ProfileIcon.CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
@ -237,28 +135,55 @@ namespace DisplayMagicianShared.UserControls
int screenBezel = 60;
int screenWordBuffer = 30;
Color lightTextColour = Color.White;
Color darkTextColour = Color.Black;
Font selectedWordFont;
Font normalWordFont = new Font(Font.FontFamily, 55);
Font bigWordFont = new Font(Font.FontFamily, 80);
Font hugeWordFont = new Font(Font.FontFamily, 110);
// Figure out the sized font we need
if (g.VisibleClipBounds.Width > 10000 || g.VisibleClipBounds.Height > 4000)
{
selectedWordFont = hugeWordFont;
}
else if (g.VisibleClipBounds.Width > 6000 || g.VisibleClipBounds.Height > 3500)
{
selectedWordFont = bigWordFont;
}
else
{
selectedWordFont = normalWordFont;
}
foreach (ScreenPosition screen in _profile.Screens)
{
Color screenBgColour;
Color lightTextColour = Color.White;
Color darkTextColour = Color.Black;
// draw the screen
if (screen.IsSpanned)
{
// We do these things only if the screen IS spanned!
// We do these things only if the screen IS spanned!
// Draw the outline of the spanned monitor
Rectangle outlineRect = new Rectangle(screen.ScreenX, screen.ScreenY, screen.ScreenWidth, screen.ScreenHeight);
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 33, 33, 33)), outlineRect);
g.DrawRectangle(Pens.Black, outlineRect);
// Draw the screen of the monitor
Rectangle screenRect = new Rectangle(screen.ScreenX + screenBezel, screen.ScreenY + screenBezel, screen.ScreenWidth - (screenBezel * 2), screen.ScreenHeight - (screenBezel * 2));
screenBgColour = screen.Colour;
g.FillRectangle(new SolidBrush(screenBgColour), screenRect);
Rectangle screenRect = new Rectangle(screen.ScreenX + screenBezel, screen.ScreenY + screenBezel, screen.ScreenWidth - (screenBezel * 2), screen.ScreenHeight - (screenBezel * 2));
g.FillRectangle(new SolidBrush(screen.Colour), screenRect);
g.DrawRectangle(Pens.Black, screenRect);
// Temporarily disabling this dotted line as it really isn't great visually.
/*foreach (SpannedScreenPosition subScreen in screen.SpannedScreens)
{
Rectangle spannedScreenRect = new Rectangle(subScreen.ScreenX, subScreen.ScreenY, subScreen.ScreenWidth, subScreen.ScreenHeight);
Pen dashedLine = new Pen(Color.Black);
dashedLine.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDotDot;
g.DrawRectangle(dashedLine, spannedScreenRect);
}*/
}
else
{
@ -268,43 +193,26 @@ namespace DisplayMagicianShared.UserControls
g.FillRectangle(new SolidBrush(Color.FromArgb(255, 33, 33, 33)), outlineRect);
g.DrawRectangle(Pens.Black, outlineRect);
if (screen.IsPrimary)
{
//screenBgColour = Color.FromArgb(255, 66, 173, 245);
screenBgColour = Color.FromArgb(240, 116, 215, 255);
}
else
{
if (screen.Colour != null)
{
screenBgColour = screen.Colour;
}
else
{
screenBgColour = Color.FromArgb(255, 195, 195, 195);
}
}
// Draw the screen of the monitor
Rectangle screenRect = new Rectangle(screen.ScreenX + screenBezel, screen.ScreenY + screenBezel, screen.ScreenWidth - (screenBezel * 2), screen.ScreenHeight - (screenBezel * 2));
g.FillRectangle(new SolidBrush(screenBgColour), screenRect);
g.FillRectangle(new SolidBrush(screen.Colour), screenRect);
g.DrawRectangle(Pens.Black, screenRect);
}
Rectangle wordRect = new Rectangle(screen.ScreenX + screenBezel + screenWordBuffer, screen.ScreenY + screenBezel + screenWordBuffer, screen.ScreenWidth - (screenBezel * 2) - (screenWordBuffer * 2), screen.ScreenHeight - (screenBezel * 2) - (screenWordBuffer * 2));
Color wordTextColour = pickTextColorBasedOnBgColour(screenBgColour, lightTextColour, darkTextColour);
Color wordTextColour = pickTextColorBasedOnBgColour(screen.Colour, lightTextColour, darkTextColour);
// Draw the name of the screen and the size of it
string str = $"{screen.Name}{Environment.NewLine}{screen.ScreenWidth}×{screen.ScreenHeight}{Environment.NewLine}{screen.DisplayConnector}";
if (screen.IsPrimary)
{
str = $"Primary Display{Environment.NewLine}" + str;
}
DrawString(g, str, wordTextColour, wordRect.Size, wordRect.Location);
DrawString(g, str, wordTextColour, selectedWordFont, wordRect.Size, wordRect.Location);
// Draw the position of the screen
str = $"[{screen.ScreenX},{screen.ScreenY}]";
DrawString(g, str, wordTextColour, wordRect.Size, wordRect.Location, StringAlignment.Near, StringAlignment.Near);
DrawString(g, str, wordTextColour, selectedWordFont, wordRect.Size, wordRect.Location, StringAlignment.Near, StringAlignment.Near);
}
}

View File

@ -41,7 +41,7 @@ namespace DisplayMagicianShared.Windows
public DISPLAYCONFIG_PATH_INFO[] DisplayConfigPaths;
public DISPLAYCONFIG_MODE_INFO[] DisplayConfigModes;
public ADVANCED_HDR_INFO_PER_PATH[] DisplayHDRStates;
public Dictionary<uint, string> DisplaySources;
public Dictionary<string, uint> DisplaySources;
public List<string> DisplayIdentifiers;
public override bool Equals(object obj) => obj is WINDOWS_DISPLAY_CONFIG other && this.Equals(other);
@ -279,7 +279,7 @@ namespace DisplayMagicianShared.Windows
WINDOWS_DISPLAY_CONFIG windowsDisplayConfig = new WINDOWS_DISPLAY_CONFIG();
windowsDisplayConfig.DisplayAdapters = new Dictionary<ulong, string>();
windowsDisplayConfig.DisplayHDRStates = new ADVANCED_HDR_INFO_PER_PATH[pathCount];
windowsDisplayConfig.DisplaySources = new Dictionary<uint, string>();
windowsDisplayConfig.DisplaySources = new Dictionary<string, uint>();
// Now cycle through the paths and grab the HDR state information
// and map the adapter name to adapter id
@ -297,7 +297,7 @@ namespace DisplayMagicianShared.Windows
if (err == WIN32STATUS.ERROR_SUCCESS)
{
// Store it for later
windowsDisplayConfig.DisplaySources.Add(path.SourceInfo.Id, sourceInfo.ViewGdiDeviceName);
windowsDisplayConfig.DisplaySources.Add(sourceInfo.ViewGdiDeviceName, path.SourceInfo.Id);
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Found Display Source {sourceInfo.ViewGdiDeviceName} for source {path.SourceInfo.Id}.");
}
else
@ -394,7 +394,7 @@ namespace DisplayMagicianShared.Windows
return windowsDisplayConfig;
}
public static Dictionary<uint, string> GetDisplaySourceNames()
public static Dictionary<string, uint> GetDisplaySourceNames()
{
// Get the size of the largest Active Paths and Modes arrays
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Getting the size of the largest Active Paths and Modes arrays");
@ -445,7 +445,7 @@ namespace DisplayMagicianShared.Windows
}
// Prepare the empty DisplaySources dictionary
Dictionary<uint, string> DisplaySources = new Dictionary<uint, string>();
Dictionary<string, uint> DisplaySources = new Dictionary<string, uint>();
// Now cycle through the paths and grab the HDR state information
// and map the adapter name to adapter id
@ -463,7 +463,7 @@ namespace DisplayMagicianShared.Windows
if (err == WIN32STATUS.ERROR_SUCCESS)
{
// Store it for later
DisplaySources.Add(path.SourceInfo.Id, sourceInfo.ViewGdiDeviceName);
DisplaySources.Add(sourceInfo.ViewGdiDeviceName, path.SourceInfo.Id);
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Found Display Source {sourceInfo.ViewGdiDeviceName} for source {path.SourceInfo.Id}.");
}
else