chore: use file-scoped namespace

This commit is contained in:
NaBian committed 2022-03-13 20:28:58 +08:00
1 parent 99d2fafb72
commit bbf1b7d4c6
748 files changed
+57929 -58678

No files matched your search

@@ -1,21 +1,20 @@
using HandyControl.Controls;
namespace HandyControl.Data
namespace HandyControl.Data;
internal class ChangeScope : DisposableObject
{
internal class ChangeScope : DisposableObject
private readonly GlowWindow _window;
public ChangeScope(GlowWindow window)
{
private readonly GlowWindow _window;
public ChangeScope(GlowWindow window)
{
_window = window;
_window.DeferGlowChangesCount++;
}
protected override void DisposeManagedResources()
{
_window.DeferGlowChangesCount--;
if (_window.DeferGlowChangesCount == 0) _window.EndDeferGlowChanges();
}
_window = window;
_window.DeferGlowChangesCount++;
}
}
protected override void DisposeManagedResources()
{
_window.DeferGlowChangesCount--;
if (_window.DeferGlowChangesCount == 0) _window.EndDeferGlowChanges();
}
}
@@ -4,111 +4,110 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using HandyControl.Tools.Interop;
namespace HandyControl.Data
namespace HandyControl.Data;
internal class GlowBitmap : DisposableObject
{
internal class GlowBitmap : DisposableObject
internal const int GlowBitmapPartCount = 16;
private const int BytesPerPixelBgra32 = 4;
private static readonly CachedBitmapInfo[] _transparencyMasks = new CachedBitmapInfo[GlowBitmapPartCount];
private readonly InteropValues.BITMAPINFO _bitmapInfo;
private readonly IntPtr _pbits;
internal GlowBitmap(IntPtr hdcScreen, int width, int height)
{
internal const int GlowBitmapPartCount = 16;
_bitmapInfo.biSize = Marshal.SizeOf(typeof(InteropValues.BITMAPINFOHEADER));
_bitmapInfo.biPlanes = 1;
_bitmapInfo.biBitCount = 32;
_bitmapInfo.biCompression = 0;
_bitmapInfo.biXPelsPerMeter = 0;
_bitmapInfo.biYPelsPerMeter = 0;
_bitmapInfo.biWidth = width;
_bitmapInfo.biHeight = -height;
private const int BytesPerPixelBgra32 = 4;
Handle = InteropMethods.CreateDIBSection(
hdcScreen,
ref _bitmapInfo,
0u,
out _pbits,
IntPtr.Zero,
0u);
}
private static readonly CachedBitmapInfo[] _transparencyMasks = new CachedBitmapInfo[GlowBitmapPartCount];
internal IntPtr Handle { get; }
private readonly InteropValues.BITMAPINFO _bitmapInfo;
internal IntPtr DIBits => _pbits;
private readonly IntPtr _pbits;
internal int Width => _bitmapInfo.biWidth;
internal GlowBitmap(IntPtr hdcScreen, int width, int height)
internal int Height => -_bitmapInfo.biHeight;
protected override void DisposeNativeResources() => InteropMethods.DeleteObject(Handle);
private static byte PremultiplyAlpha(byte channel, byte alpha) => (byte) (channel * alpha / 255.0);
internal static GlowBitmap Create(GlowDrawingContext drawingContext, GlowBitmapPart bitmapPart, Color color)
{
var orCreateAlphaMask =
GetOrCreateAlphaMask(bitmapPart);
var glowBitmap =
new GlowBitmap(
drawingContext.ScreenDC,
orCreateAlphaMask.Width,
orCreateAlphaMask.Height);
for (var i = 0; i < orCreateAlphaMask.DIBits.Length; i += BytesPerPixelBgra32)
{
_bitmapInfo.biSize = Marshal.SizeOf(typeof(InteropValues.BITMAPINFOHEADER));
_bitmapInfo.biPlanes = 1;
_bitmapInfo.biBitCount = 32;
_bitmapInfo.biCompression = 0;
_bitmapInfo.biXPelsPerMeter = 0;
_bitmapInfo.biYPelsPerMeter = 0;
_bitmapInfo.biWidth = width;
_bitmapInfo.biHeight = -height;
Handle = InteropMethods.CreateDIBSection(
hdcScreen,
ref _bitmapInfo,
0u,
out _pbits,
IntPtr.Zero,
0u);
var b = orCreateAlphaMask.DIBits[i + 3];
var val = PremultiplyAlpha(color.R, b);
var val2 = PremultiplyAlpha(color.G, b);
var val3 = PremultiplyAlpha(color.B, b);
Marshal.WriteByte(glowBitmap.DIBits, i, val3);
Marshal.WriteByte(glowBitmap.DIBits, i + 1, val2);
Marshal.WriteByte(glowBitmap.DIBits, i + 2, val);
Marshal.WriteByte(glowBitmap.DIBits, i + 3, b);
}
internal IntPtr Handle { get; }
return glowBitmap;
}
internal IntPtr DIBits => _pbits;
internal int Width => _bitmapInfo.biWidth;
internal int Height => -_bitmapInfo.biHeight;
protected override void DisposeNativeResources() => InteropMethods.DeleteObject(Handle);
private static byte PremultiplyAlpha(byte channel, byte alpha) => (byte) (channel * alpha / 255.0);
internal static GlowBitmap Create(GlowDrawingContext drawingContext, GlowBitmapPart bitmapPart, Color color)
private static CachedBitmapInfo GetOrCreateAlphaMask(GlowBitmapPart bitmapPart)
{
if (_transparencyMasks[(int) bitmapPart] == null)
{
var orCreateAlphaMask =
GetOrCreateAlphaMask(bitmapPart);
var bitmapImage = new BitmapImage(new Uri($"pack://application:,,,/HandyControl;Component/Resources/Images/GlowWindow/{bitmapPart}.png"));
var glowBitmap =
new GlowBitmap(
drawingContext.ScreenDC,
orCreateAlphaMask.Width,
orCreateAlphaMask.Height);
var array = new byte[BytesPerPixelBgra32 * bitmapImage.PixelWidth * bitmapImage.PixelHeight];
var stride = BytesPerPixelBgra32 * bitmapImage.PixelWidth;
bitmapImage.CopyPixels(array, stride, 0);
bitmapImage.Freeze();
for (var i = 0; i < orCreateAlphaMask.DIBits.Length; i += BytesPerPixelBgra32)
{
var b = orCreateAlphaMask.DIBits[i + 3];
var val = PremultiplyAlpha(color.R, b);
var val2 = PremultiplyAlpha(color.G, b);
var val3 = PremultiplyAlpha(color.B, b);
Marshal.WriteByte(glowBitmap.DIBits, i, val3);
Marshal.WriteByte(glowBitmap.DIBits, i + 1, val2);
Marshal.WriteByte(glowBitmap.DIBits, i + 2, val);
Marshal.WriteByte(glowBitmap.DIBits, i + 3, b);
}
return glowBitmap;
_transparencyMasks[(int) bitmapPart] =
new CachedBitmapInfo(
array,
bitmapImage.PixelWidth,
bitmapImage.PixelHeight);
}
private static CachedBitmapInfo GetOrCreateAlphaMask(GlowBitmapPart bitmapPart)
return _transparencyMasks[(int) bitmapPart];
}
private sealed class CachedBitmapInfo
{
internal readonly byte[] DIBits;
internal readonly int Height;
internal readonly int Width;
internal CachedBitmapInfo(byte[] diBits, int width, int height)
{
if (_transparencyMasks[(int) bitmapPart] == null)
{
var bitmapImage = new BitmapImage(new Uri($"pack://application:,,,/HandyControl;Component/Resources/Images/GlowWindow/{bitmapPart}.png"));
var array = new byte[BytesPerPixelBgra32 * bitmapImage.PixelWidth * bitmapImage.PixelHeight];
var stride = BytesPerPixelBgra32 * bitmapImage.PixelWidth;
bitmapImage.CopyPixels(array, stride, 0);
bitmapImage.Freeze();
_transparencyMasks[(int) bitmapPart] =
new CachedBitmapInfo(
array,
bitmapImage.PixelWidth,
bitmapImage.PixelHeight);
}
return _transparencyMasks[(int) bitmapPart];
}
private sealed class CachedBitmapInfo
{
internal readonly byte[] DIBits;
internal readonly int Height;
internal readonly int Width;
internal CachedBitmapInfo(byte[] diBits, int width, int height)
{
Width = width;
Height = height;
DIBits = diBits;
}
Width = width;
Height = height;
DIBits = diBits;
}
}
}
}
@@ -1,22 +1,21 @@
namespace HandyControl.Data
namespace HandyControl.Data;
internal enum GlowBitmapPart
{
internal enum GlowBitmapPart
{
CornerTopLeft,
CornerTopRight,
CornerBottomLeft,
CornerBottomRight,
TopLeft,
Top,
TopRight,
LeftTop,
Left,
LeftBottom,
BottomLeft,
Bottom,
BottomRight,
RightTop,
Right,
RightBottom
}
}
CornerTopLeft,
CornerTopRight,
CornerBottomLeft,
CornerBottomRight,
TopLeft,
Top,
TopRight,
LeftTop,
Left,
LeftBottom,
BottomLeft,
Bottom,
BottomRight,
RightTop,
Right,
RightBottom
}
@@ -1,51 +1,50 @@
using System;
using HandyControl.Tools.Interop;
namespace HandyControl.Data
namespace HandyControl.Data;
internal class GlowDrawingContext : DisposableObject
{
internal class GlowDrawingContext : DisposableObject
private readonly GlowBitmap _windowBitmap;
internal InteropValues.BLENDFUNCTION Blend;
internal GlowDrawingContext(int width, int height)
{
private readonly GlowBitmap _windowBitmap;
internal InteropValues.BLENDFUNCTION Blend;
internal GlowDrawingContext(int width, int height)
{
ScreenDC = InteropMethods.GetDC(IntPtr.Zero);
if (ScreenDC == IntPtr.Zero) return;
WindowDC = InteropMethods.CreateCompatibleDC(ScreenDC);
if (WindowDC == IntPtr.Zero) return;
BackgroundDC = InteropMethods.CreateCompatibleDC(ScreenDC);
if (BackgroundDC == IntPtr.Zero) return;
Blend.BlendOp = 0;
Blend.BlendFlags = 0;
Blend.SourceConstantAlpha = 255;
Blend.AlphaFormat = 1;
_windowBitmap = new GlowBitmap(ScreenDC, width, height);
InteropMethods.SelectObject(WindowDC, _windowBitmap.Handle);
}
internal bool IsInitialized =>
ScreenDC != IntPtr.Zero && WindowDC != IntPtr.Zero &&
BackgroundDC != IntPtr.Zero && _windowBitmap != null;
internal IntPtr ScreenDC { get; }
internal IntPtr WindowDC { get; }
internal IntPtr BackgroundDC { get; }
internal int Width => _windowBitmap.Width;
internal int Height => _windowBitmap.Height;
protected override void DisposeManagedResources() => _windowBitmap.Dispose();
protected override void DisposeNativeResources()
{
if (ScreenDC != IntPtr.Zero) InteropMethods.ReleaseDC(IntPtr.Zero, ScreenDC);
if (WindowDC != IntPtr.Zero) InteropMethods.DeleteDC(WindowDC);
if (BackgroundDC != IntPtr.Zero) InteropMethods.DeleteDC(BackgroundDC);
}
ScreenDC = InteropMethods.GetDC(IntPtr.Zero);
if (ScreenDC == IntPtr.Zero) return;
WindowDC = InteropMethods.CreateCompatibleDC(ScreenDC);
if (WindowDC == IntPtr.Zero) return;
BackgroundDC = InteropMethods.CreateCompatibleDC(ScreenDC);
if (BackgroundDC == IntPtr.Zero) return;
Blend.BlendOp = 0;
Blend.BlendFlags = 0;
Blend.SourceConstantAlpha = 255;
Blend.AlphaFormat = 1;
_windowBitmap = new GlowBitmap(ScreenDC, width, height);
InteropMethods.SelectObject(WindowDC, _windowBitmap.Handle);
}
}
internal bool IsInitialized =>
ScreenDC != IntPtr.Zero && WindowDC != IntPtr.Zero &&
BackgroundDC != IntPtr.Zero && _windowBitmap != null;
internal IntPtr ScreenDC { get; }
internal IntPtr WindowDC { get; }
internal IntPtr BackgroundDC { get; }
internal int Width => _windowBitmap.Width;
internal int Height => _windowBitmap.Height;
protected override void DisposeManagedResources() => _windowBitmap.Dispose();
protected override void DisposeNativeResources()
{
if (ScreenDC != IntPtr.Zero) InteropMethods.ReleaseDC(IntPtr.Zero, ScreenDC);
if (WindowDC != IntPtr.Zero) InteropMethods.DeleteDC(WindowDC);
if (BackgroundDC != IntPtr.Zero) InteropMethods.DeleteDC(BackgroundDC);
}
}
File diff suppressed because it is too large. Load diff