mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 16:55:28 +00:00
Use different implementations for accessing GDI+ internals on .Net and Mono.
This commit is contained in:
parent
f4700cb676
commit
f218071fa7
|
@ -18,6 +18,8 @@ namespace OpenTK.Platform
|
||||||
{
|
{
|
||||||
internal static class GdiPlus
|
internal static class GdiPlus
|
||||||
{
|
{
|
||||||
|
static IGdiPlusInternals internals;
|
||||||
|
|
||||||
const string gdi_plus_library = "gdiplus.dll";
|
const string gdi_plus_library = "gdiplus.dll";
|
||||||
static readonly PropertyInfo native_graphics_property, native_font_property;
|
static readonly PropertyInfo native_graphics_property, native_font_property;
|
||||||
static readonly FieldInfo native_string_format_field;
|
static readonly FieldInfo native_string_format_field;
|
||||||
|
@ -26,33 +28,29 @@ namespace OpenTK.Platform
|
||||||
|
|
||||||
static GdiPlus()
|
static GdiPlus()
|
||||||
{
|
{
|
||||||
native_graphics_property =
|
if (Configuration.RunningOnWindows)
|
||||||
typeof(System.Drawing.Graphics).GetProperty("NativeGraphics", BindingFlags.Instance | BindingFlags.NonPublic);
|
internals = new Windows.WinGdiPlusInternals();
|
||||||
|
else
|
||||||
native_font_property =
|
internals = new X11.X11GdiPlusInternals();
|
||||||
typeof(System.Drawing.Font).GetProperty("NativeFont", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
|
|
||||||
native_string_format_field =
|
|
||||||
typeof(System.Drawing.StringFormat).GetField("nativeFormat", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region --- Reflection ---
|
#region --- Public Methods ---
|
||||||
|
|
||||||
public static IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
public static IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
||||||
{
|
{
|
||||||
return (IntPtr)native_graphics_property.GetValue(graphics, null);
|
return internals.GetNativeGraphics(graphics);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntPtr GetNativeFont(Font font)
|
public static IntPtr GetNativeFont(Font font)
|
||||||
{
|
{
|
||||||
return (IntPtr)native_font_property.GetValue(font, null);
|
return internals.GetNativeFont(font);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IntPtr GetNativeStringFormat(StringFormat format)
|
public static IntPtr GetNativeStringFormat(StringFormat format)
|
||||||
{
|
{
|
||||||
return (IntPtr)native_string_format_field.GetValue(format);
|
return internals.GetNativeStringFormat(format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int MaxMeasurableCharacterRanges
|
public static int MaxMeasurableCharacterRanges
|
||||||
|
@ -63,11 +61,7 @@ namespace OpenTK.Platform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipSetStringFormatMeasurableCharacterRanges")]
|
||||||
|
|
||||||
#region --- Methods ---
|
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint="GdipSetStringFormatMeasurableCharacterRanges")]
|
|
||||||
public static extern int SetStringFormatMeasurableCharacterRanges(HandleRef format, int rangeCount, [In, Out] CharacterRange[] range);
|
public static extern int SetStringFormatMeasurableCharacterRanges(HandleRef format, int rangeCount, [In, Out] CharacterRange[] range);
|
||||||
|
|
||||||
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipGetStringFormatMeasurableCharacterRangeCount")]
|
[DllImport(gdi_plus_library, CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true, EntryPoint = "GdipGetStringFormatMeasurableCharacterRangeCount")]
|
||||||
|
@ -87,6 +81,7 @@ namespace OpenTK.Platform
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#if false
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
internal struct GPRECTF
|
internal struct GPRECTF
|
||||||
{
|
{
|
||||||
|
@ -122,9 +117,6 @@ namespace OpenTK.Platform
|
||||||
return new RectangleF(this.X, this.Y, this.Width, this.Height);
|
return new RectangleF(this.X, this.Y, this.Width, this.Height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
21
Source/OpenTK/Platform/IGdiPlusInternals.cs
Normal file
21
Source/OpenTK/Platform/IGdiPlusInternals.cs
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform
|
||||||
|
{
|
||||||
|
// Provides methods to access internal GdiPlus fields. This is necessary for
|
||||||
|
// managed <-> native GdiPlus interoperability.
|
||||||
|
// Note that the fields are named differently between .Net and Mono.
|
||||||
|
// GdiPlus is considered deprecated by Microsoft - it is highly unlikely that
|
||||||
|
// future framework upgrades will break this code, but it is something to
|
||||||
|
// keep in mind.
|
||||||
|
interface IGdiPlusInternals
|
||||||
|
{
|
||||||
|
IntPtr GetNativeGraphics(System.Drawing.Graphics graphics);
|
||||||
|
|
||||||
|
IntPtr GetNativeFont(System.Drawing.Font font);
|
||||||
|
|
||||||
|
IntPtr GetNativeStringFormat(System.Drawing.StringFormat format);
|
||||||
|
}
|
||||||
|
}
|
46
Source/OpenTK/Platform/Windows/WinGdiPlusInternals.cs
Normal file
46
Source/OpenTK/Platform/Windows/WinGdiPlusInternals.cs
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform.Windows
|
||||||
|
{
|
||||||
|
class WinGdiPlusInternals : IGdiPlusInternals
|
||||||
|
{
|
||||||
|
const string gdi_plus_library = "gdiplus.dll";
|
||||||
|
static readonly PropertyInfo native_graphics_property, native_font_property;
|
||||||
|
static readonly FieldInfo native_string_format_field;
|
||||||
|
|
||||||
|
static WinGdiPlusInternals()
|
||||||
|
{
|
||||||
|
native_graphics_property =
|
||||||
|
typeof(System.Drawing.Graphics).GetProperty("NativeGraphics", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
native_font_property =
|
||||||
|
typeof(System.Drawing.Font).GetProperty("NativeFont", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
|
||||||
|
native_string_format_field =
|
||||||
|
typeof(System.Drawing.StringFormat).GetField("nativeFormat", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region --- IGdiPlusInternals Members ---
|
||||||
|
|
||||||
|
public IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
||||||
|
{
|
||||||
|
return (IntPtr)native_graphics_property.GetValue(graphics, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetNativeFont(Font font)
|
||||||
|
{
|
||||||
|
return (IntPtr)native_font_property.GetValue(font, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetNativeStringFormat(StringFormat format)
|
||||||
|
{
|
||||||
|
return (IntPtr)native_string_format_field.GetValue(format);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
28
Source/OpenTK/Platform/X11/X11GdiPlusInternals.cs
Normal file
28
Source/OpenTK/Platform/X11/X11GdiPlusInternals.cs
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace OpenTK.Platform.X11
|
||||||
|
{
|
||||||
|
class X11GdiPlusInternals : IGdiPlusInternals
|
||||||
|
{
|
||||||
|
#region IGdiPlusInternals Members
|
||||||
|
|
||||||
|
public IntPtr GetNativeGraphics(System.Drawing.Graphics graphics)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetNativeFont(System.Drawing.Font font)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntPtr GetNativeStringFormat(System.Drawing.StringFormat format)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue