mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-30 12:11:07 +12:00
Code refactor
This commit is contained in:
parent
ce35af243c
commit
a19439ef33
|
@ -3224,7 +3224,7 @@ public enum EndSessionReasons : uint
|
|||
}
|
||||
|
||||
[Flags]
|
||||
enum SHGFI : uint
|
||||
public enum SHGFI : uint
|
||||
{
|
||||
/// <summary>get icon</summary>
|
||||
Icon = 0x000000100,
|
||||
|
@ -3263,4 +3263,169 @@ enum SHGFI : uint
|
|||
/// <summary>Get the index of the overlay in the upper 8 bits of the iIcon</summary>
|
||||
OverlayIndex = 0x000000040
|
||||
}
|
||||
|
||||
public enum DeviceCap
|
||||
{
|
||||
/// <summary>
|
||||
/// Device driver version
|
||||
/// </summary>
|
||||
DRIVERVERSION = 0,
|
||||
/// <summary>
|
||||
/// Device classification
|
||||
/// </summary>
|
||||
TECHNOLOGY = 2,
|
||||
/// <summary>
|
||||
/// Horizontal size in millimeters
|
||||
/// </summary>
|
||||
HORZSIZE = 4,
|
||||
/// <summary>
|
||||
/// Vertical size in millimeters
|
||||
/// </summary>
|
||||
VERTSIZE = 6,
|
||||
/// <summary>
|
||||
/// Horizontal width in pixels
|
||||
/// </summary>
|
||||
HORZRES = 8,
|
||||
/// <summary>
|
||||
/// Vertical height in pixels
|
||||
/// </summary>
|
||||
VERTRES = 10,
|
||||
/// <summary>
|
||||
/// Number of bits per pixel
|
||||
/// </summary>
|
||||
BITSPIXEL = 12,
|
||||
/// <summary>
|
||||
/// Number of planes
|
||||
/// </summary>
|
||||
PLANES = 14,
|
||||
/// <summary>
|
||||
/// Number of brushes the device has
|
||||
/// </summary>
|
||||
NUMBRUSHES = 16,
|
||||
/// <summary>
|
||||
/// Number of pens the device has
|
||||
/// </summary>
|
||||
NUMPENS = 18,
|
||||
/// <summary>
|
||||
/// Number of markers the device has
|
||||
/// </summary>
|
||||
NUMMARKERS = 20,
|
||||
/// <summary>
|
||||
/// Number of fonts the device has
|
||||
/// </summary>
|
||||
NUMFONTS = 22,
|
||||
/// <summary>
|
||||
/// Number of colors the device supports
|
||||
/// </summary>
|
||||
NUMCOLORS = 24,
|
||||
/// <summary>
|
||||
/// Size required for device descriptor
|
||||
/// </summary>
|
||||
PDEVICESIZE = 26,
|
||||
/// <summary>
|
||||
/// Curve capabilities
|
||||
/// </summary>
|
||||
CURVECAPS = 28,
|
||||
/// <summary>
|
||||
/// Line capabilities
|
||||
/// </summary>
|
||||
LINECAPS = 30,
|
||||
/// <summary>
|
||||
/// Polygonal capabilities
|
||||
/// </summary>
|
||||
POLYGONALCAPS = 32,
|
||||
/// <summary>
|
||||
/// Text capabilities
|
||||
/// </summary>
|
||||
TEXTCAPS = 34,
|
||||
/// <summary>
|
||||
/// Clipping capabilities
|
||||
/// </summary>
|
||||
CLIPCAPS = 36,
|
||||
/// <summary>
|
||||
/// Bitblt capabilities
|
||||
/// </summary>
|
||||
RASTERCAPS = 38,
|
||||
/// <summary>
|
||||
/// Length of the X leg
|
||||
/// </summary>
|
||||
ASPECTX = 40,
|
||||
/// <summary>
|
||||
/// Length of the Y leg
|
||||
/// </summary>
|
||||
ASPECTY = 42,
|
||||
/// <summary>
|
||||
/// Length of the hypotenuse
|
||||
/// </summary>
|
||||
ASPECTXY = 44,
|
||||
/// <summary>
|
||||
/// Shading and Blending caps
|
||||
/// </summary>
|
||||
SHADEBLENDCAPS = 45,
|
||||
|
||||
/// <summary>
|
||||
/// Logical pixels inch in X
|
||||
/// </summary>
|
||||
LOGPIXELSX = 88,
|
||||
/// <summary>
|
||||
/// Logical pixels inch in Y
|
||||
/// </summary>
|
||||
LOGPIXELSY = 90,
|
||||
|
||||
/// <summary>
|
||||
/// Number of entries in physical palette
|
||||
/// </summary>
|
||||
SIZEPALETTE = 104,
|
||||
/// <summary>
|
||||
/// Number of reserved entries in palette
|
||||
/// </summary>
|
||||
NUMRESERVED = 106,
|
||||
/// <summary>
|
||||
/// Actual color resolution
|
||||
/// </summary>
|
||||
COLORRES = 108,
|
||||
|
||||
// Printing related DeviceCaps. These replace the appropriate Escapes
|
||||
/// <summary>
|
||||
/// Physical Width in device units
|
||||
/// </summary>
|
||||
PHYSICALWIDTH = 110,
|
||||
/// <summary>
|
||||
/// Physical Height in device units
|
||||
/// </summary>
|
||||
PHYSICALHEIGHT = 111,
|
||||
/// <summary>
|
||||
/// Physical Printable Area x margin
|
||||
/// </summary>
|
||||
PHYSICALOFFSETX = 112,
|
||||
/// <summary>
|
||||
/// Physical Printable Area y margin
|
||||
/// </summary>
|
||||
PHYSICALOFFSETY = 113,
|
||||
/// <summary>
|
||||
/// Scaling factor x
|
||||
/// </summary>
|
||||
SCALINGFACTORX = 114,
|
||||
/// <summary>
|
||||
/// Scaling factor y
|
||||
/// </summary>
|
||||
SCALINGFACTORY = 115,
|
||||
|
||||
/// <summary>
|
||||
/// Current vertical refresh rate of the display device (for displays only) in Hz
|
||||
/// </summary>
|
||||
VREFRESH = 116,
|
||||
/// <summary>
|
||||
/// Vertical height of entire desktop in pixels
|
||||
/// </summary>
|
||||
DESKTOPVERTRES = 117,
|
||||
/// <summary>
|
||||
/// Horizontal width of entire desktop in pixels
|
||||
/// </summary>
|
||||
DESKTOPHORZRES = 118,
|
||||
/// <summary>
|
||||
/// Preferred blt alignment
|
||||
/// </summary>
|
||||
BLTALIGNMENT = 119
|
||||
}
|
||||
}
|
|
@ -354,16 +354,10 @@ public static partial class NativeMethods
|
|||
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 uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
|
||||
public static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
|
||||
[DllImport("gdi32.dll")]
|
||||
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
|
||||
public enum DeviceCap
|
||||
{
|
||||
VERTRES = 10,
|
||||
DESKTOPVERTRES = 117,
|
||||
LOGPIXELSY = 90
|
||||
}
|
||||
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);
|
||||
|
||||
#endregion gdi32.dll
|
||||
|
||||
|
|
|
@ -568,16 +568,24 @@ public static Icon GetJumboFileIcon(string filePath, bool jumboSize = true)
|
|||
DestroyIcon(hIcon);
|
||||
return icon;
|
||||
}
|
||||
|
||||
public static float GetScreenScalingFactor()
|
||||
{
|
||||
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 / (float)LogicalScreenHeight;
|
||||
float dpiScalingFactor = (float)logpixelsy / (float)96;
|
||||
return Math.Max(screenScalingFactor, dpiScalingFactor);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -71,7 +71,7 @@ public class RegionCaptureOptions
|
|||
public bool IsFixedSize = false;
|
||||
public Size FixedSize = new Size(250, 250);
|
||||
public bool ShowFPS = false;
|
||||
public int MenuIconSize = (int)(16 * NativeMethods.GetScreenScalingFactor());
|
||||
public int MenuIconSize = 0;
|
||||
public bool RememberMenuState = false;
|
||||
public bool MenuCollapsed = false;
|
||||
public Point MenuPosition = Point.Empty;
|
||||
|
|
|
@ -81,6 +81,11 @@ 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()
|
||||
|
|
Loading…
Reference in a new issue