mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-24 19:11:09 +00:00
MacOS: Add proper icon support for the dock.
This commit is contained in:
parent
63b314c4a8
commit
d695bb599c
|
@ -416,6 +416,7 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
enum HICoordinateSpace
|
enum HICoordinateSpace
|
||||||
{
|
{
|
||||||
_72DPIGlobal = 1,
|
_72DPIGlobal = 1,
|
||||||
|
@ -855,6 +856,20 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
internal static extern int SetFrontProcess(ref Carbon.ProcessSerialNumber psn);
|
internal static extern int SetFrontProcess(ref Carbon.ProcessSerialNumber psn);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
#region --- Setting Dock Tile ---
|
||||||
|
|
||||||
|
[DllImport(carbon)]
|
||||||
|
internal extern static IntPtr CGColorSpaceCreateDeviceRGB();
|
||||||
|
[DllImport(carbon)]
|
||||||
|
internal extern static IntPtr CGDataProviderCreateWithData(IntPtr info, IntPtr[] data, int size, IntPtr releasefunc);
|
||||||
|
[DllImport(carbon)]
|
||||||
|
internal extern static IntPtr CGImageCreate(int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace, uint bitmapInfo, IntPtr provider, IntPtr decode, int shouldInterpolate, int intent);
|
||||||
|
[DllImport(carbon)]
|
||||||
|
internal extern static void SetApplicationDockTileImage(IntPtr imageRef);
|
||||||
|
[DllImport(carbon)]
|
||||||
|
internal extern static void RestoreApplicationDockTileImage();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
[DllImport(carbon)]
|
[DllImport(carbon)]
|
||||||
|
|
|
@ -69,6 +69,8 @@ namespace OpenTK.Platform.MacOS
|
||||||
bool mMouseIn = false;
|
bool mMouseIn = false;
|
||||||
bool mIsActive = false;
|
bool mIsActive = false;
|
||||||
|
|
||||||
|
Icon mIcon;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region AGL Device Hack
|
#region AGL Device Hack
|
||||||
|
@ -752,10 +754,63 @@ namespace OpenTK.Platform.MacOS
|
||||||
|
|
||||||
public Icon Icon
|
public Icon Icon
|
||||||
{
|
{
|
||||||
get { return null; }
|
get { return mIcon; }
|
||||||
set { }
|
set {
|
||||||
|
SetIcon(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetIcon(Icon icon)
|
||||||
|
{
|
||||||
|
// The code for this function was adapted from Mono's XplatUICarbon implementation,
|
||||||
|
// written by Geoff Norton
|
||||||
|
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
|
||||||
|
if (icon == null)
|
||||||
|
{
|
||||||
|
API.RestoreApplicationDockTileImage();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Bitmap bitmap;
|
||||||
|
int size;
|
||||||
|
IntPtr[] data;
|
||||||
|
int index;
|
||||||
|
|
||||||
|
bitmap = new Bitmap(128, 128);
|
||||||
|
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
|
||||||
|
{
|
||||||
|
g.DrawImage(icon.ToBitmap(), 0, 0, 128, 128);
|
||||||
|
}
|
||||||
|
index = 0;
|
||||||
|
size = bitmap.Width * bitmap.Height;
|
||||||
|
data = new IntPtr[size];
|
||||||
|
|
||||||
|
for (int y = 0; y < bitmap.Height; y++)
|
||||||
|
{
|
||||||
|
for (int x = 0; x < bitmap.Width; x++)
|
||||||
|
{
|
||||||
|
int pixel = bitmap.GetPixel(x, y).ToArgb();
|
||||||
|
if (BitConverter.IsLittleEndian)
|
||||||
|
{
|
||||||
|
byte a = (byte)((pixel >> 24) & 0xFF);
|
||||||
|
byte r = (byte)((pixel >> 16) & 0xFF);
|
||||||
|
byte g = (byte)((pixel >> 8) & 0xFF);
|
||||||
|
byte b = (byte)(pixel & 0xFF);
|
||||||
|
data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data[index++] = (IntPtr)pixel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IntPtr provider = API.CGDataProviderCreateWithData(IntPtr.Zero, data, size * 4, IntPtr.Zero);
|
||||||
|
IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128, API.CGColorSpaceCreateDeviceRGB(), 4, provider, IntPtr.Zero, 0, 0);
|
||||||
|
API.SetApplicationDockTileImage(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string Title
|
public string Title
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
Loading…
Reference in a new issue