/// <summary> /// Get gradient fill information for this hatch. If the "GradientType" for /// the fill is None, then this hatch doesn't have any gradient fill. /// </summary> /// <returns></returns> /// <since>7.0</since> public Rhino.Display.ColorGradient GetGradientFill() { IntPtr const_ptr_this = ConstPointer(); IntPtr ptrColorStopArray = UnsafeNativeMethods.ON_ColorStopArray_New(); Point3d startPoint = new Point3d(); Point3d endPoint = new Point3d(); int gradientType = 0; double repeat = 0; int stopCount = UnsafeNativeMethods.ON_Hatch_GetGradientData(const_ptr_this, ref startPoint, ref endPoint, ref gradientType, ref repeat, ptrColorStopArray); var rc = new Rhino.Display.ColorGradient(); rc.StartPoint = startPoint; rc.EndPoint = endPoint; rc.GradientType = (Display.GradientType)gradientType; rc.Repeat = repeat; Display.ColorStop[] stops = new Display.ColorStop[stopCount]; for (int i = 0; i < stopCount; i++) { int argb = 0; double t = 0; UnsafeNativeMethods.ON_ColorStopArray_Get(ptrColorStopArray, i, ref argb, ref t); var color = System.Drawing.Color.FromArgb(argb); stops[i] = new Display.ColorStop(color, t); } rc.SetColorStops(stops); UnsafeNativeMethods.ON_ColorStopArray_Delete(ptrColorStopArray); return(rc); }
/// <summary> /// </summary> /// <param name="fill"></param> /// <since>7.0</since> public void SetGradientFill(Rhino.Display.ColorGradient fill) { IntPtr ptr_this = NonConstPointer(); if (null == fill) { UnsafeNativeMethods.ON_Hatch_SetGradientData(ptr_this, Point3d.Unset, Point3d.Unset, (int)Rhino.Display.GradientType.None, 0, IntPtr.Zero); return; } var stops = fill.GetColorStops(); IntPtr ptrColorStopArray = UnsafeNativeMethods.ON_ColorStopArray_New(); foreach (var stop in stops) { int argb = stop.Color.ToArgb(); UnsafeNativeMethods.ON_ColorStopArray_Append(ptrColorStopArray, argb, stop.Position); } UnsafeNativeMethods.ON_Hatch_SetGradientData(ptr_this, fill.StartPoint, fill.EndPoint, (int)fill.GradientType, fill.Repeat, ptrColorStopArray); UnsafeNativeMethods.ON_ColorStopArray_Delete(ptrColorStopArray); }