mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Revamped display layout image shortcut generation
Made many changes to simplify the configuration and make the profile display layout image generation faster and more reliable.
This commit is contained in:
parent
51806494ab
commit
ae7bb095e2
@ -407,7 +407,8 @@ namespace DisplayMagician
|
|||||||
return string.Equals(image164, image264);
|
return string.Equals(image164, image264);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap ToBitmapOverlay(Bitmap originalBitmap, Bitmap overlayBitmap, int width, int height, PixelFormat format = PixelFormat.Format32bppArgb)
|
|
||||||
|
public static Bitmap MakeBitmapOverlay(Bitmap originalBitmap, Bitmap overlayBitmap, int width, int height, PixelFormat format = PixelFormat.Format32bppArgb)
|
||||||
{
|
{
|
||||||
if (originalBitmap == null)
|
if (originalBitmap == null)
|
||||||
{
|
{
|
||||||
@ -468,6 +469,8 @@ namespace DisplayMagician
|
|||||||
Size overlayBitmapNewSize = ResizeDrawing.MakeSmaller(overlayBitmapMaxSize, 70);
|
Size overlayBitmapNewSize = ResizeDrawing.MakeSmaller(overlayBitmapMaxSize, 70);
|
||||||
logger.Trace($"ShortcutItem/ToBitmapOverlay: Resize the overlay bitmap to fit in the bottom right corner of the new combined bitmap. Size is now {overlayBitmapNewSize.Width}px x {overlayBitmapNewSize.Height}px");
|
logger.Trace($"ShortcutItem/ToBitmapOverlay: Resize the overlay bitmap to fit in the bottom right corner of the new combined bitmap. Size is now {overlayBitmapNewSize.Width}px x {overlayBitmapNewSize.Height}px");
|
||||||
Point overlayBitmapNewLocation = ResizeDrawing.AlignBottomRight(overlayBitmapNewSize, targetSize);
|
Point overlayBitmapNewLocation = ResizeDrawing.AlignBottomRight(overlayBitmapNewSize, targetSize);
|
||||||
|
// Now we need to adjust that slightly up and in a bit
|
||||||
|
overlayBitmapNewLocation.Offset(0, -5);
|
||||||
logger.Trace($"ShortcutItem/ToBitmapOverlay: Drawing the overlay bitmap into the new combined bitmap at position {overlayBitmapNewLocation.X},{overlayBitmapNewLocation.Y}.");
|
logger.Trace($"ShortcutItem/ToBitmapOverlay: Drawing the overlay bitmap into the new combined bitmap at position {overlayBitmapNewLocation.X},{overlayBitmapNewLocation.Y}.");
|
||||||
g.DrawImage(overlayBitmap, overlayBitmapNewLocation.X, overlayBitmapNewLocation.Y, overlayBitmapNewSize.Width, overlayBitmapNewSize.Height);
|
g.DrawImage(overlayBitmap, overlayBitmapNewLocation.X, overlayBitmapNewLocation.Y, overlayBitmapNewSize.Width, overlayBitmapNewSize.Height);
|
||||||
|
|
||||||
@ -482,6 +485,7 @@ namespace DisplayMagician
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
#pragma warning disable CS3002 // Return type is not CLS-compliant
|
#pragma warning disable CS3002 // Return type is not CLS-compliant
|
||||||
public static MultiIcon ToIconOverlay(Bitmap originalBitmap, Bitmap overlayBitmap)
|
public static MultiIcon ToIconOverlay(Bitmap originalBitmap, Bitmap overlayBitmap)
|
||||||
#pragma warning restore CS3002 // Return type is not CLS-compliant
|
#pragma warning restore CS3002 // Return type is not CLS-compliant
|
||||||
@ -534,7 +538,7 @@ namespace DisplayMagician
|
|||||||
logger.Warn(ex, $"ShortcutItem/ToIconOverlay: Exeception occurred while trying to convert the Shortcut Bitmap to an Icon Overlay to store in the shortcut cache directory. Returning null");
|
logger.Warn(ex, $"ShortcutItem/ToIconOverlay: Exeception occurred while trying to convert the Shortcut Bitmap to an Icon Overlay to store in the shortcut cache directory. Returning null");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
[DllImport("Shell32", CharSet = CharSet.Auto)]
|
[DllImport("Shell32", CharSet = CharSet.Auto)]
|
||||||
private static extern int ExtractIconEx(string lpszFile, int nIconIndex, IntPtr[] phIconLarge, IntPtr[] phIconSmall, int nIcons);
|
private static extern int ExtractIconEx(string lpszFile, int nIconIndex, IntPtr[] phIconLarge, IntPtr[] phIconSmall, int nIcons);
|
||||||
|
@ -26,8 +26,8 @@ using System.Resources;
|
|||||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||||
|
|
||||||
// Version information
|
// Version information
|
||||||
[assembly: AssemblyVersion("2.3.1.28")]
|
[assembly: AssemblyVersion("2.3.1.40")]
|
||||||
[assembly: AssemblyFileVersion("2.3.1.28")]
|
[assembly: AssemblyFileVersion("2.3.1.40")]
|
||||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||||
[assembly: CLSCompliant(true)]
|
[assembly: CLSCompliant(true)]
|
||||||
|
|
||||||
|
@ -938,7 +938,7 @@ namespace DisplayMagician
|
|||||||
// We create the Bitmaps for the game
|
// We create the Bitmaps for the game
|
||||||
_originalBitmap = selectedImage.Image;
|
_originalBitmap = selectedImage.Image;
|
||||||
// Now we use the originalBitmap or userBitmap, and create the shortcutBitmap from it
|
// Now we use the originalBitmap or userBitmap, and create the shortcutBitmap from it
|
||||||
_shortcutBitmap = ImageUtils.ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256);
|
_shortcutBitmap = ImageUtils.MakeBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256);
|
||||||
|
|
||||||
// Empty out the unused shortcut data
|
// Empty out the unused shortcut data
|
||||||
_executableNameAndPath = "";
|
_executableNameAndPath = "";
|
||||||
@ -1017,7 +1017,7 @@ namespace DisplayMagician
|
|||||||
// We create the Bitmaps for the executable
|
// We create the Bitmaps for the executable
|
||||||
_originalBitmap = selectedImage.Image;
|
_originalBitmap = selectedImage.Image;
|
||||||
// Now we use the originalBitmap or userBitmap, and create the shortcutBitmap from it
|
// Now we use the originalBitmap or userBitmap, and create the shortcutBitmap from it
|
||||||
_shortcutBitmap = ImageUtils.ToBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256);
|
_shortcutBitmap = ImageUtils.MakeBitmapOverlay(_originalBitmap, _profileToUse.ProfileTightestBitmap, 256, 256);
|
||||||
|
|
||||||
// Empty out the unused shortcut data
|
// Empty out the unused shortcut data
|
||||||
_gameAppId = "";
|
_gameAppId = "";
|
||||||
|
@ -36,6 +36,12 @@ namespace DisplayMagicianShared
|
|||||||
var minY = 0;
|
var minY = 0;
|
||||||
var maxY = 0;
|
var maxY = 0;
|
||||||
|
|
||||||
|
// If there aren't any screens provided then return a blank rectangle
|
||||||
|
if (screens.Count == 0)
|
||||||
|
{
|
||||||
|
return new RectangleF(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var screen in screens)
|
foreach (var screen in screens)
|
||||||
{
|
{
|
||||||
//var res = GetLargestResolution(screens);
|
//var res = GetLargestResolution(screens);
|
||||||
@ -49,11 +55,18 @@ namespace DisplayMagicianShared
|
|||||||
{
|
{
|
||||||
minX -= outsidePaddingSides;
|
minX -= outsidePaddingSides;
|
||||||
maxX += outsidePaddingSides;
|
maxX += outsidePaddingSides;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (outsidePaddingTopBottom != 0)
|
||||||
|
{
|
||||||
minY -= outsidePaddingTopBottom;
|
minY -= outsidePaddingTopBottom;
|
||||||
maxY += outsidePaddingTopBottom;
|
maxY += outsidePaddingTopBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
var size = new SizeF(Math.Abs(minX) + maxX, Math.Abs(minY) + maxY);
|
var width = Math.Abs(maxX - minX);
|
||||||
|
var height = Math.Abs(maxY - minY);
|
||||||
|
|
||||||
|
var size = new SizeF(width, height);
|
||||||
var rect = new RectangleF(new PointF(minX, minY), size);
|
var rect = new RectangleF(new PointF(minX, minY), size);
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
@ -107,15 +120,39 @@ namespace DisplayMagicianShared
|
|||||||
using (var g = Graphics.FromImage(bitmap))
|
using (var g = Graphics.FromImage(bitmap))
|
||||||
{
|
{
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
DrawView(g, width, height);
|
DrawDisplayLayout(g, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap ToTightestBitmap(int width = 256, int height = 256, PixelFormat format = PixelFormat.Format32bppArgb)
|
public Bitmap ToTightestBitmap(PixelFormat format = PixelFormat.Format32bppArgb)
|
||||||
{
|
{
|
||||||
|
if (_profile.Screens.Count == 0)
|
||||||
|
{
|
||||||
|
return new Bitmap(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
var viewSize = CalculateViewSize(_profile.Screens, 0, 0);
|
var viewSize = CalculateViewSize(_profile.Screens, 0, 0);
|
||||||
|
|
||||||
|
var bitmap = new Bitmap((int)viewSize.Width, (int)viewSize.Height, format);
|
||||||
|
bitmap.MakeTransparent();
|
||||||
|
|
||||||
|
using (var g = Graphics.FromImage(bitmap))
|
||||||
|
{
|
||||||
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
|
DrawDisplayLayout(g, (int)viewSize.Width, (int)viewSize.Height, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bitmap ToTightestBitmap(int width, int height, PixelFormat format = PixelFormat.Format32bppArgb)
|
||||||
|
{
|
||||||
|
if (_profile.Screens.Count == 0)
|
||||||
|
{
|
||||||
|
return new Bitmap(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
var bitmap = new Bitmap(width, height, format);
|
var bitmap = new Bitmap(width, height, format);
|
||||||
bitmap.MakeTransparent();
|
bitmap.MakeTransparent();
|
||||||
@ -123,14 +160,19 @@ namespace DisplayMagicianShared
|
|||||||
using (var g = Graphics.FromImage(bitmap))
|
using (var g = Graphics.FromImage(bitmap))
|
||||||
{
|
{
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
DrawView(g, width, height);
|
DrawDisplayLayout(g, width, height, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap ToBitmapOverlay(Bitmap bitmap)
|
/*public Bitmap ToBitmapOverlay(Bitmap bitmap)
|
||||||
{
|
{
|
||||||
|
if (_profile.Screens.Count == 0)
|
||||||
|
{
|
||||||
|
return new Bitmap(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
var viewSize = CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
|
var viewSize = CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
|
||||||
var width = bitmap.Width * 0.7f;
|
var width = bitmap.Width * 0.7f;
|
||||||
var height = width / viewSize.Width * viewSize.Height;
|
var height = width / viewSize.Width * viewSize.Height;
|
||||||
@ -139,11 +181,11 @@ namespace DisplayMagicianShared
|
|||||||
{
|
{
|
||||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||||
g.TranslateTransform(bitmap.Width - width, bitmap.Height - height * 1.1f);
|
g.TranslateTransform(bitmap.Width - width, bitmap.Height - height * 1.1f);
|
||||||
DrawView(g, width, height);
|
DrawDisplayLayout(g, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
public MultiIcon ToIcon()
|
public MultiIcon ToIcon()
|
||||||
{
|
{
|
||||||
@ -174,7 +216,7 @@ namespace DisplayMagicianShared
|
|||||||
return multiIcon;
|
return multiIcon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiIcon ToIconOverlay(string iconAddress)
|
/*public MultiIcon ToIconOverlay(string iconAddress)
|
||||||
{
|
{
|
||||||
var multiIcon = new MultiIcon();
|
var multiIcon = new MultiIcon();
|
||||||
var icon = multiIcon.Add("Icon1");
|
var icon = multiIcon.Add("Icon1");
|
||||||
@ -232,48 +274,58 @@ namespace DisplayMagicianShared
|
|||||||
multiIcon.SelectedIndex = 0;
|
multiIcon.SelectedIndex = 0;
|
||||||
|
|
||||||
return multiIcon;
|
return multiIcon;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
private void DrawView(Graphics g, float width, float height)
|
private void DrawDisplayLayout(Graphics g, float maxWidth, float maxHeight, bool drawStand = true)
|
||||||
{
|
{
|
||||||
|
// If we don't have any screens, then we can't draw them!
|
||||||
|
if (_profile.Screens.Count == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Figure out the sizes we need based on the total size of the screens
|
// Figure out the sizes we need based on the total size of the screens
|
||||||
var viewSize = ProfileIcon.CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
|
var viewSize = ProfileIcon.CalculateViewSize(_profile.Screens, PaddingX, PaddingY);
|
||||||
var standPadding = height * 0.005f;
|
|
||||||
height -= standPadding * 8;
|
var standPadding = maxHeight * 0.005f;
|
||||||
var factor = Math.Min((width - 2 * standPadding - 1) / viewSize.Width,
|
maxHeight -= standPadding * 8;
|
||||||
(height - 2 * standPadding - 1) / viewSize.Height);
|
var factor = Math.Min((maxWidth - 2 * standPadding - 1) / viewSize.Width,
|
||||||
|
(maxHeight - 2 * standPadding - 1) / viewSize.Height);
|
||||||
g.ScaleTransform(factor, factor);
|
g.ScaleTransform(factor, factor);
|
||||||
|
|
||||||
// Make space for the stand
|
// Make space for the stand
|
||||||
var xOffset = ((width - 1) / factor - viewSize.Width) / 2f;
|
var xOffset = ((maxWidth - 1) / factor - viewSize.Width) / 2f;
|
||||||
var yOffset = ((height - 1) / factor - viewSize.Height) / 2f;
|
var yOffset = ((maxHeight - 1) / factor - viewSize.Height) / 2f;
|
||||||
g.TranslateTransform(-viewSize.X + xOffset, -viewSize.Y + yOffset);
|
g.TranslateTransform(-viewSize.X + xOffset, -viewSize.Y + yOffset);
|
||||||
|
|
||||||
// How wide the Bezel is on the screen graphics
|
// How wide the Bezel is on the screen graphics
|
||||||
int screenBezel = 60;
|
int screenBezel = 60;
|
||||||
//int screenWordBuffer = 30;
|
//int screenWordBuffer = 30;
|
||||||
|
|
||||||
// Draw the stand
|
// Draw the stand if needed
|
||||||
if (standPadding * 6 >= 1)
|
if (drawStand)
|
||||||
{
|
{
|
||||||
using (
|
if (standPadding * 6 >= 1)
|
||||||
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);
|
using (
|
||||||
g.DrawPath(new Pen(Color.FromArgb(50, 255, 255, 255), 2 / factor), boundRect);
|
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
|
||||||
else
|
{
|
||||||
{
|
g.FillRectangle(new SolidBrush(Color.FromArgb(200, 255, 255, 255)), viewSize);
|
||||||
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,
|
||||||
g.DrawRectangle(new Pen(Color.FromArgb(170, 50, 50, 50), standPadding / factor), viewSize.X, viewSize.Y,
|
viewSize.Width, viewSize.Height);
|
||||||
viewSize.Width, viewSize.Height);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now go through and draw the screens
|
// Now go through and draw the screens
|
||||||
foreach (ScreenPosition screen in _profile.Screens)
|
foreach (ScreenPosition screen in _profile.Screens)
|
||||||
|
@ -357,7 +357,8 @@ namespace DisplayMagicianShared
|
|||||||
return _profileShortcutBitmap;
|
return _profileShortcutBitmap;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_profileShortcutBitmap = this.ProfileIcon.ToTightestBitmap(256, 256);
|
//_profileShortcutBitmap = this.ProfileIcon.ToTightestBitmap();
|
||||||
|
_profileShortcutBitmap = this.ProfileIcon.ToTightestBitmap();
|
||||||
return _profileShortcutBitmap;
|
return _profileShortcutBitmap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user