using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharpDX.Mathematics.Interop;
using System.Runtime.InteropServices;
namespace SharpDX.Direct2D1
{
public partial class SvgElement
{
///
/// Gets all children of this element.
///
public SvgElement[] Children
{
get
{
if (!HasChildren())
return new SvgElement[0];
//We do not know the amount of children, and nothing in api does help us, count pass
SvgElement current = FirstChild;
int childCount = 0;
SvgElement next;
do
{
GetNextChild(current, out next);
current = next;
childCount++;
}
while (next != null);
SvgElement[] result = new SvgElement[childCount];
current = FirstChild;
for (int i = 0; i < childCount; i++)
{
result[i] = current;
GetNextChild(current, out current);
}
return result;
}
}
///
/// Gets tag name for this element
///
public unsafe string TagName
{
get
{
int nameLength = GetTagNameLength();
sbyte* name = stackalloc sbyte[nameLength];
GetTagName(new IntPtr(name), nameLength + 1);
return Marshal.PtrToStringUni((IntPtr)name, nameLength);
}
}
///
/// Sets float attribute
///
/// Attribute name
/// New valuee
public unsafe void SetAttributeValue(string name, float value)
{
SetAttributeValue(name, SvgAttributePodType.Float, new IntPtr(&value), sizeof(float));
}
///
/// Gets a float attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out float value)
{
fixed (float* ptr = &value)
{
GetAttributeValue(name, SvgAttributePodType.Float, new IntPtr(ptr), sizeof(float));
}
}
///
/// Sets color attribute
///
/// Attribute name
/// New color
public unsafe void SetAttributeValue(string name, RawColor4 color)
{
SetAttributeValue(name, SvgAttributePodType.Color, new IntPtr(&color), sizeof(RawColor4));
}
///
/// Gets a color attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out RawColor4 color)
{
fixed (RawColor4* ptr = &color)
{
GetAttributeValue(name, SvgAttributePodType.Color, new IntPtr(ptr), sizeof(RawColor4));
}
}
///
/// Sets fill mode attribute
///
/// Attribute name
/// New fill mode
public unsafe void SetAttributeValue(string name, FillMode fillMode)
{
SetAttributeValue(name, SvgAttributePodType.FillMode, new IntPtr(&fillMode), sizeof(FillMode));
}
///
/// Gets a fill mode attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out FillMode fillMode)
{
fixed (FillMode* ptr = &fillMode)
{
GetAttributeValue(name, SvgAttributePodType.FillMode, new IntPtr(ptr), sizeof(FillMode));
}
}
///
/// Sets display mode attribute
///
/// Attribute name
/// New svg display
public unsafe void SetAttributeValue(string name, SvgDisplay display)
{
SetAttributeValue(name, SvgAttributePodType.Display, new IntPtr(&display), sizeof(SvgDisplay));
}
///
/// Gets a display attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgDisplay display)
{
fixed (SvgDisplay* ptr = &display)
{
GetAttributeValue(name, SvgAttributePodType.Display, new IntPtr(ptr), sizeof(SvgDisplay));
}
}
///
/// Sets overflow mode attribute
///
/// Attribute name
/// New svg overfloe
public unsafe void SetAttributeValue(string name, SvgOverflow overflow)
{
SetAttributeValue(name, SvgAttributePodType.Overflow, new IntPtr(&overflow), sizeof(SvgOverflow));
}
///
/// Gets an overflow attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgOverflow overflow)
{
fixed (SvgOverflow* ptr = &overflow)
{
GetAttributeValue(name, SvgAttributePodType.Overflow, new IntPtr(ptr), sizeof(SvgOverflow));
}
}
///
/// Sets line join attribute
///
/// Attribute name
/// New svg line join
public unsafe void SetAttributeValue(string name, SvgLineJoin lineJoin)
{
SetAttributeValue(name, SvgAttributePodType.LineJoin, new IntPtr(&lineJoin), sizeof(SvgLineJoin));
}
///
/// Gets a line join attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgLineJoin lineJoin)
{
fixed (SvgLineJoin* ptr = &lineJoin)
{
GetAttributeValue(name, SvgAttributePodType.LineJoin, new IntPtr(ptr), sizeof(SvgLineJoin));
}
}
///
/// Sets line cap attribute
///
/// Attribute name
/// New svg line cap
public unsafe void SetAttributeValue(string name, SvgLineCap lineCap)
{
SetAttributeValue(name, SvgAttributePodType.LineCap, new IntPtr(&lineCap), sizeof(SvgLineCap));
}
///
/// Gets a line cap attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgLineCap lineCap)
{
fixed (SvgLineCap* ptr = &lineCap)
{
GetAttributeValue(name, SvgAttributePodType.LineCap, new IntPtr(ptr), sizeof(SvgLineCap));
}
}
///
/// Sets visibility attribute
///
/// Attribute name
/// New svg visibility
public unsafe void SetAttributeValue(string name, SvgVisibility visibility)
{
SetAttributeValue(name, SvgAttributePodType.Visibility, new IntPtr(&visibility), sizeof(SvgVisibility));
}
///
/// Gets a visibility attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgVisibility visibility)
{
fixed (SvgVisibility* ptr = &visibility)
{
GetAttributeValue(name, SvgAttributePodType.Visibility, new IntPtr(ptr), sizeof(SvgVisibility));
}
}
///
/// Sets transform attribute
///
/// Attribute name
/// New transform
public unsafe void SetAttributeValue(string name, RawMatrix3x2 matrix)
{
SetAttributeValue(name, SvgAttributePodType.Matrix, new IntPtr(&matrix), sizeof(RawMatrix3x2));
}
///
/// Gets a transform attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out RawMatrix3x2 matrix)
{
fixed (RawMatrix3x2* ptr = &matrix)
{
GetAttributeValue(name, SvgAttributePodType.Matrix, new IntPtr(ptr), sizeof(RawMatrix3x2));
}
}
///
/// Sets unit type attribute
///
/// Attribute name
/// New unit type
public unsafe void SetAttributeValue(string name, SvgUnitType unitType)
{
SetAttributeValue(name, SvgAttributePodType.UnitType, new IntPtr(&unitType), sizeof(SvgUnitType));
}
///
/// Gets a unit type attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgUnitType unitType)
{
fixed (SvgUnitType* ptr = &unitType)
{
GetAttributeValue(name, SvgAttributePodType.UnitType, new IntPtr(ptr), sizeof(SvgUnitType));
}
}
///
/// Sets extend mode attribute
///
/// Attribute name
/// New extend mode
public unsafe void SetAttributeValue(string name, ExtendMode extendMode)
{
SetAttributeValue(name, SvgAttributePodType.ExtendMode, new IntPtr(&extendMode), sizeof(ExtendMode));
}
///
/// Gets an extend mode attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out ExtendMode extendMode)
{
fixed (ExtendMode* ptr = &extendMode)
{
GetAttributeValue(name, SvgAttributePodType.ExtendMode, new IntPtr(ptr), sizeof(ExtendMode));
}
}
///
/// Sets preserve Aspect Ratio attribute
///
/// Attribute name
/// preserve Aspect Ratio/param>
public unsafe void SetAttributeValue(string name, SvgPreserveAspectRatio preserveAspectRatio)
{
SetAttributeValue(name, SvgAttributePodType.PreserveAspectRatio, new IntPtr(&preserveAspectRatio), sizeof(SvgPreserveAspectRatio));
}
///
/// Gets a preserve aspect ratio attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgPreserveAspectRatio preserveAspectRatio)
{
fixed (SvgPreserveAspectRatio* ptr = &preserveAspectRatio)
{
GetAttributeValue(name, SvgAttributePodType.PreserveAspectRatio, new IntPtr(ptr), sizeof(SvgPreserveAspectRatio));
}
}
///
/// Sets length attribute
///
/// Attribute name
/// New length
public unsafe void SetAttributeValue(string name, SvgLength length)
{
SetAttributeValue(name, SvgAttributePodType.Length, new IntPtr(&length), sizeof(SvgLength));
}
///
/// Gets an svg length attribute
///
/// Attribute name
/// When this returns , contains the attribute value
public unsafe void GetAttributeValue(string name, out SvgLength length)
{
fixed (SvgLength* ptr = &length)
{
GetAttributeValue(name, SvgAttributePodType.Length, new IntPtr(ptr), sizeof(SvgLength));
}
}
///
/// Gets an attribute from a type id
///
/// Attribute type, must inherit from
/// Attribute name
/// Attribute instance
public T GetAttributeValue(string name) where T : SvgAttribute
{
IntPtr nativePointer;
GetAttributeValue(name, SharpDX.Utilities.GetGuidFromType(typeof(T)), out nativePointer);
return ComObject.FromPointer(nativePointer);
}
}
}