mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-22 19:15:34 +00:00
Added Cairo.Path properties
New properties on Path is lazy evaluated. Only reading is supported.
This commit is contained in:
parent
ad0420b118
commit
fbe180d742
|
@ -36,7 +36,17 @@ namespace Cairo {
|
|||
|
||||
public class Path : IDisposable
|
||||
{
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct PathStruct
|
||||
{
|
||||
public Status Status;
|
||||
public IntPtr Data;
|
||||
public int NumData;
|
||||
}
|
||||
|
||||
IntPtr handle = IntPtr.Zero;
|
||||
Status status;
|
||||
PathData[] data;
|
||||
|
||||
internal Path (IntPtr handle)
|
||||
{
|
||||
|
@ -72,5 +82,57 @@ namespace Cairo {
|
|||
NativeMethods.cairo_path_destroy (handle);
|
||||
handle = IntPtr.Zero;
|
||||
}
|
||||
|
||||
void CheckDisposed ()
|
||||
{
|
||||
if (handle == IntPtr.Zero)
|
||||
throw new ObjectDisposedException ("Object has already been disposed");
|
||||
}
|
||||
|
||||
void MarshalData ()
|
||||
{
|
||||
if (data == null)
|
||||
{
|
||||
var rawStruct = Marshal.PtrToStructure<PathStruct>(handle);
|
||||
status = rawStruct.Status;
|
||||
data = new PathData[rawStruct.NumData];
|
||||
int oneDataSize = Marshal.SizeOf<PathData>();
|
||||
for (int i = 0; i < rawStruct.NumData; i++)
|
||||
{
|
||||
IntPtr iPtr = new IntPtr(rawStruct.Data.ToInt64() + i * oneDataSize);
|
||||
data[i] = Marshal.PtrToStructure<PathData>(iPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Status Status
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed ();
|
||||
MarshalData ();
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
public int NumData
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed ();
|
||||
MarshalData ();
|
||||
return data.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public PathData[] Data
|
||||
{
|
||||
get
|
||||
{
|
||||
CheckDisposed ();
|
||||
MarshalData ();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
28
Source/Libs/CairoSharp/PathData.cs
Normal file
28
Source/Libs/CairoSharp/PathData.cs
Normal file
|
@ -0,0 +1,28 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Cairo
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct PathData
|
||||
{
|
||||
[FieldOffset(0)]
|
||||
public PathDataHeader Header;
|
||||
[FieldOffset(0)]
|
||||
public PathDataPoint Point;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PathDataHeader
|
||||
{
|
||||
public PathDataType Type;
|
||||
public int Length;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct PathDataPoint
|
||||
{
|
||||
public double X;
|
||||
public double Y;
|
||||
}
|
||||
}
|
13
Source/Libs/CairoSharp/PathDataType.cs
Normal file
13
Source/Libs/CairoSharp/PathDataType.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
namespace Cairo
|
||||
{
|
||||
[Serializable]
|
||||
public enum PathDataType
|
||||
{
|
||||
MoveTo,
|
||||
LineTo,
|
||||
CurveTo,
|
||||
ClosePath
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue