// ***********************************************************************
// Assembly : Construction
// Author : flythink
// Created : 07-01-2020
//
// Last Modified By : flythink
// Last Modified On : 09-01-2020
// ***********************************************************************
//
// Copyright (c) jindongfang. All rights reserved.
//
//
// ***********************************************************************
namespace WellWorkDataUI
{
using System;
using System.Drawing;
///
/// 高分辨率处理类
///
public static class HightDpiHelper
{
///
/// Gets the dpi scale factor.
///
/// The dpi scale factor.
public static float DpiScaleFactor => DevExpress.Skins.DpiProvider.Default.DpiScaleFactor;
///
/// Scales the center rectangle.
///
/// The rectangle.
/// Rectangle.
public static Rectangle ScaleCenterRectangle(Rectangle rectangle)
{
double centerX = rectangle.Left + (rectangle.Width / 2.0);
double centerY = rectangle.Top + (rectangle.Height / 2.0);
Size newSize = ScaleSize(rectangle.Size);
return new Rectangle(
Convert.ToInt32(centerX - (newSize.Width / 2)),
Convert.ToInt32(centerY - (newSize.Height / 2)),
newSize.Width,
newSize.Height);
}
///
/// Scales the font.
///
/// The font.
/// Font.
public static Font ScaleFont(Font font)
{
if (DpiScaleFactor != 1f)
{
return new Font(font.FontFamily, ScaleHeight(font.SizeInPoints - 0.25f));
}
return font;
}
///
/// Scales the height.
///
/// The h.
/// System.Int32.
public static int ScaleHeight(int h) => Convert.ToInt32(h * DpiScaleFactor);
///
/// Scales the height.
///
/// The h.
/// System.Single.
public static float ScaleHeight(float h) => Convert.ToSingle(h * DpiScaleFactor);
///
/// Scales the rectangle.
///
/// The rectangle.
/// Rectangle.
public static Rectangle ScaleRectangle(Rectangle rectangle)
{
return new Rectangle(rectangle.Location, ScaleSize(rectangle.Size));
}
///
/// Scales the size.
///
/// The size.
/// Size.
public static Size ScaleSize(Size size)
{
return new Size(ScaleWidth(size.Width), ScaleHeight(size.Height));
}
///
/// Scales the size.
///
/// The size.
/// SizeF.
public static SizeF ScaleSize(SizeF size)
{
return new SizeF(ScaleWidth(size.Width), ScaleHeight(size.Height));
}
///
/// Scales the width.
///
/// The w.
/// System.Int32.
public static int ScaleWidth(int w) => Convert.ToInt32(w * DpiScaleFactor);
///
/// Scales the width.
///
/// The w.
/// System.Single.
public static float ScaleWidth(float w) => Convert.ToSingle(w * DpiScaleFactor);
///
/// Uns the height of the scale.
///
/// The h.
/// System.Single.
public static float UnScaleHeight(float h) => Convert.ToSingle(h / DpiScaleFactor);
///
/// Uns the width of the scale.
///
/// The w.
/// System.Single.
public static float UnScaleWidth(float w) => Convert.ToSingle(w / DpiScaleFactor);
}
}