diff --git a/ShareX.HelpersLib/Native/NativeEnums.cs b/ShareX.HelpersLib/Native/NativeEnums.cs index 174004be8..ff32c91b4 100644 --- a/ShareX.HelpersLib/Native/NativeEnums.cs +++ b/ShareX.HelpersLib/Native/NativeEnums.cs @@ -3224,7 +3224,7 @@ public enum EndSessionReasons : uint } [Flags] - enum SHGFI : uint + public enum SHGFI : uint { /// get icon Icon = 0x000000100, @@ -3263,4 +3263,169 @@ enum SHGFI : uint /// Get the index of the overlay in the upper 8 bits of the iIcon OverlayIndex = 0x000000040 } + + public enum DeviceCap + { + /// + /// Device driver version + /// + DRIVERVERSION = 0, + /// + /// Device classification + /// + TECHNOLOGY = 2, + /// + /// Horizontal size in millimeters + /// + HORZSIZE = 4, + /// + /// Vertical size in millimeters + /// + VERTSIZE = 6, + /// + /// Horizontal width in pixels + /// + HORZRES = 8, + /// + /// Vertical height in pixels + /// + VERTRES = 10, + /// + /// Number of bits per pixel + /// + BITSPIXEL = 12, + /// + /// Number of planes + /// + PLANES = 14, + /// + /// Number of brushes the device has + /// + NUMBRUSHES = 16, + /// + /// Number of pens the device has + /// + NUMPENS = 18, + /// + /// Number of markers the device has + /// + NUMMARKERS = 20, + /// + /// Number of fonts the device has + /// + NUMFONTS = 22, + /// + /// Number of colors the device supports + /// + NUMCOLORS = 24, + /// + /// Size required for device descriptor + /// + PDEVICESIZE = 26, + /// + /// Curve capabilities + /// + CURVECAPS = 28, + /// + /// Line capabilities + /// + LINECAPS = 30, + /// + /// Polygonal capabilities + /// + POLYGONALCAPS = 32, + /// + /// Text capabilities + /// + TEXTCAPS = 34, + /// + /// Clipping capabilities + /// + CLIPCAPS = 36, + /// + /// Bitblt capabilities + /// + RASTERCAPS = 38, + /// + /// Length of the X leg + /// + ASPECTX = 40, + /// + /// Length of the Y leg + /// + ASPECTY = 42, + /// + /// Length of the hypotenuse + /// + ASPECTXY = 44, + /// + /// Shading and Blending caps + /// + SHADEBLENDCAPS = 45, + + /// + /// Logical pixels inch in X + /// + LOGPIXELSX = 88, + /// + /// Logical pixels inch in Y + /// + LOGPIXELSY = 90, + + /// + /// Number of entries in physical palette + /// + SIZEPALETTE = 104, + /// + /// Number of reserved entries in palette + /// + NUMRESERVED = 106, + /// + /// Actual color resolution + /// + COLORRES = 108, + + // Printing related DeviceCaps. These replace the appropriate Escapes + /// + /// Physical Width in device units + /// + PHYSICALWIDTH = 110, + /// + /// Physical Height in device units + /// + PHYSICALHEIGHT = 111, + /// + /// Physical Printable Area x margin + /// + PHYSICALOFFSETX = 112, + /// + /// Physical Printable Area y margin + /// + PHYSICALOFFSETY = 113, + /// + /// Scaling factor x + /// + SCALINGFACTORX = 114, + /// + /// Scaling factor y + /// + SCALINGFACTORY = 115, + + /// + /// Current vertical refresh rate of the display device (for displays only) in Hz + /// + VREFRESH = 116, + /// + /// Vertical height of entire desktop in pixels + /// + DESKTOPVERTRES = 117, + /// + /// Horizontal width of entire desktop in pixels + /// + DESKTOPHORZRES = 118, + /// + /// Preferred blt alignment + /// + BLTALIGNMENT = 119 + } } \ No newline at end of file diff --git a/ShareX.HelpersLib/Native/NativeMethods.cs b/ShareX.HelpersLib/Native/NativeMethods.cs index 5a4040881..f1c231ebf 100644 --- a/ShareX.HelpersLib/Native/NativeMethods.cs +++ b/ShareX.HelpersLib/Native/NativeMethods.cs @@ -353,6 +353,9 @@ public static extern bool CreateProcess(string lpApplicationName, string lpComma [DllImport("gdi32.dll")] public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref BITMAPINFOHEADER pbmi, uint pila, out IntPtr ppvBits, IntPtr hSection, uint dwOffset); + [DllImport("gdi32.dll")] + public static extern int GetDeviceCaps(IntPtr hdc, int nIndex); + [DllImport("gdi32.dll")] public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos); diff --git a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs index 9af6f6c61..8295172fc 100644 --- a/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs +++ b/ShareX.HelpersLib/Native/NativeMethods_Helpers.cs @@ -568,5 +568,24 @@ public static Icon GetJumboFileIcon(string filePath, bool jumboSize = true) DestroyIcon(hIcon); return icon; } + + public static float GetScreenScalingFactor() + { + float scalingFactor; + + using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) + { + IntPtr desktop = g.GetHdc(); + int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES); + int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES); + int logpixelsy = GetDeviceCaps(desktop, (int)DeviceCap.LOGPIXELSY); + float screenScalingFactor = (float)PhysicalScreenHeight / LogicalScreenHeight; + float dpiScalingFactor = logpixelsy / 96f; + scalingFactor = Math.Max(screenScalingFactor, dpiScalingFactor); + g.ReleaseHdc(desktop); + } + + return scalingFactor; + } } } \ No newline at end of file diff --git a/ShareX.ScreenCaptureLib/RegionCaptureOptions.cs b/ShareX.ScreenCaptureLib/RegionCaptureOptions.cs index 88ff7b763..ade24fc79 100644 --- a/ShareX.ScreenCaptureLib/RegionCaptureOptions.cs +++ b/ShareX.ScreenCaptureLib/RegionCaptureOptions.cs @@ -71,6 +71,7 @@ public class RegionCaptureOptions public bool IsFixedSize = false; public Size FixedSize = new Size(250, 250); public bool ShowFPS = false; + public int MenuIconSize = 0; public bool RememberMenuState = false; public bool MenuCollapsed = false; public Point MenuPosition = Point.Empty; diff --git a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs index afe895a7e..c74103e82 100644 --- a/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs +++ b/ShareX.ScreenCaptureLib/Shapes/ShapeManagerMenu.cs @@ -81,6 +81,13 @@ internal void CreateToolbar() menuForm.SuspendLayout(); + if (Options.MenuIconSize == 0) + { + Options.MenuIconSize = (int)(16 * NativeMethods.GetScreenScalingFactor()); + } + + int imageScalingSize = Options.MenuIconSize.Clamp(16, 64); + tsMain = new ToolStripEx() { AutoSize = true, @@ -88,6 +95,7 @@ internal void CreateToolbar() ClickThrough = true, Dock = DockStyle.None, GripStyle = ToolStripGripStyle.Hidden, + ImageScalingSize = new Size(imageScalingSize, imageScalingSize), Location = new Point(0, 0), MinimumSize = new Size(10, 30), Padding = Form.IsEditorMode ? new Padding(5, 1, 3, 0) : new Padding(0, 1, 0, 0), @@ -976,6 +984,24 @@ internal void CreateToolbar() }; tsddbOptions.DropDownItems.Add(tsmiSwitchToSelectionToolAfterDrawing); + // TODO: Translate + ToolStripLabeledNumericUpDown tslnudMenuIconSize = new ToolStripLabeledNumericUpDown("Menu icon size:"); + tslnudMenuIconSize.Content.Minimum = 16; + tslnudMenuIconSize.Content.Maximum = 64; + tslnudMenuIconSize.Content.Increment = 16; + tslnudMenuIconSize.Content.Value = Options.MenuIconSize; + tslnudMenuIconSize.Content.ValueChanged = (sender, e) => + { + Options.MenuIconSize = (int)tslnudMenuIconSize.Content.Value; + tsMain.SuspendLayout(); + tsMain.AutoSize = false; + tsMain.ImageScalingSize = new Size(Options.MenuIconSize, Options.MenuIconSize); + tsMain.AutoSize = true; + tsMain.ResumeLayout(); + UpdateMenuPosition(); + }; + tsddbOptions.DropDownItems.Add(tslnudMenuIconSize); + if (!Form.IsEditorMode) { ToolStripMenuItem tsmiRememberMenuState = new ToolStripMenuItem(Resources.ShapeManager_CreateContextMenu_RememberMenuState);