CustomLineCap
Encapsulates a custom user-defined line cap.
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Graphics.GdiPlus;
namespace System.Drawing.Drawing2D
{
public class CustomLineCap : MarshalByRefObject, ICloneable, IDisposable
{
internal unsafe GpCustomLineCap* _nativeCap;
private bool _disposed;
public unsafe LineJoin StrokeJoin {
get {
LineJoin result = default(LineJoin);
PInvoke.GdipGetCustomLineCapStrokeJoin(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineJoin*)(&result)).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
set {
PInvoke.GdipSetCustomLineCapStrokeJoin(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineJoin)value).ThrowIfFailed();
GC.KeepAlive(this);
}
}
public unsafe LineCap BaseCap {
get {
LineCap result = default(LineCap);
PInvoke.GdipGetCustomLineCapBaseCap(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineCap*)(&result)).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
set {
PInvoke.GdipSetCustomLineCapBaseCap(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineCap)value).ThrowIfFailed();
GC.KeepAlive(this);
}
}
public unsafe float BaseInset {
get {
float result = default(float);
PInvoke.GdipGetCustomLineCapBaseInset(_nativeCap, &result).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
set {
PInvoke.GdipSetCustomLineCapBaseInset(_nativeCap, value).ThrowIfFailed();
GC.KeepAlive(this);
}
}
public unsafe float WidthScale {
get {
float result = default(float);
PInvoke.GdipGetCustomLineCapWidthScale(_nativeCap, &result).ThrowIfFailed();
GC.KeepAlive(this);
return result;
}
set {
PInvoke.GdipSetCustomLineCapWidthScale(_nativeCap, value).ThrowIfFailed();
GC.KeepAlive(this);
}
}
internal CustomLineCap()
{
}
[NullableContext(2)]
public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath)
: this(fillPath, strokePath, LineCap.Flat)
{
}
[NullableContext(2)]
public CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap)
: this(fillPath, strokePath, baseCap, 0)
{
}
[NullableContext(2)]
public unsafe CustomLineCap(GraphicsPath fillPath, GraphicsPath strokePath, LineCap baseCap, float baseInset)
{
GpCustomLineCap* nativeLineCap = default(GpCustomLineCap*);
PInvoke.GdipCreateCustomLineCap(fillPath.Pointer(), strokePath.Pointer(), (global::Windows.Win32.Graphics.GdiPlus.LineCap)baseCap, baseInset, &nativeLineCap).ThrowIfFailed();
SetNativeLineCap(nativeLineCap);
}
internal unsafe CustomLineCap(GpCustomLineCap* lineCap)
{
SetNativeLineCap(lineCap);
}
[return: Nullable(1)]
internal unsafe static CustomLineCap CreateCustomLineCapObject(GpCustomLineCap* cap)
{
global::Windows.Win32.Graphics.GdiPlus.CustomLineCapType customLineCapType = default(global::Windows.Win32.Graphics.GdiPlus.CustomLineCapType);
Status status = PInvoke.GdipGetCustomLineCapType(cap, &customLineCapType);
if (status == Status.Ok) {
switch (customLineCapType) {
case global::Windows.Win32.Graphics.GdiPlus.CustomLineCapType.CustomLineCapTypeDefault:
return new CustomLineCap(cap);
case global::Windows.Win32.Graphics.GdiPlus.CustomLineCapType.CustomLineCapTypeAdjustableArrow:
return new AdjustableArrowCap(cap);
default:
PInvoke.GdipDeleteCustomLineCap(cap);
throw Status.NotImplemented.GetException();
}
}
PInvoke.GdipDeleteCustomLineCap(cap);
throw status.GetException();
}
internal unsafe void SetNativeLineCap(GpCustomLineCap* handle)
{
if (handle == null)
throw new ArgumentNullException("handle");
_nativeCap = handle;
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected unsafe virtual void Dispose(bool disposing)
{
if (!_disposed) {
if (_nativeCap != null && Gdip.Initialized) {
PInvoke.GdipDeleteCustomLineCap(_nativeCap);
_nativeCap = null;
}
_disposed = true;
}
}
~CustomLineCap()
{
Dispose(false);
}
[NullableContext(1)]
public object Clone()
{
return CoreClone();
}
[NullableContext(1)]
internal unsafe virtual object CoreClone()
{
GpCustomLineCap* cap = default(GpCustomLineCap*);
PInvoke.GdipCloneCustomLineCap(_nativeCap, &cap).ThrowIfFailed();
GC.KeepAlive(this);
return CreateCustomLineCapObject(cap);
}
public unsafe void SetStrokeCaps(LineCap startCap, LineCap endCap)
{
PInvoke.GdipSetCustomLineCapStrokeCaps(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineCap)startCap, (global::Windows.Win32.Graphics.GdiPlus.LineCap)endCap).ThrowIfFailed();
GC.KeepAlive(this);
}
public unsafe void GetStrokeCaps(out LineCap startCap, out LineCap endCap)
{
fixed (LineCap* startCap2 = &startCap) {
fixed (LineCap* endCap2 = &endCap) {
PInvoke.GdipGetCustomLineCapStrokeCaps(_nativeCap, (global::Windows.Win32.Graphics.GdiPlus.LineCap*)startCap2, (global::Windows.Win32.Graphics.GdiPlus.LineCap*)endCap2).ThrowIfFailed();
GC.KeepAlive(this);
}
}
}
}
}