public static ShapeDescription DrawFullRectangle(Vector3 position, Size size, IGradientShader linearShader, Color4 fillColor, Thickness borderSize, BorderStyle borderStyle, Color4 borderColor) { Color4[] shadedColors = linearShader.Method(linearShader, 4,Shape.Rectangle); Color4[] borderColors; switch (borderStyle) { case BorderStyle.None: borderColors = LinearShader.FillColorArray(new Color4(0), 4); break; case BorderStyle.Flat: borderColors = LinearShader.FillColorArray(borderColor, 4); break; case BorderStyle.Raised: borderColors = LinearShader.BorderRaised(borderColor, 4); break; case BorderStyle.Sunken: borderColors = LinearShader.BorderSunken(borderColor, 4); break; default: throw new ArgumentOutOfRangeException("borderStyle"); } ShapeDescription inside = DrawRectangle(position, size, shadedColors); ShapeDescription outline = DrawRectangularOutline(position, size, borderSize.All, borderColors, borderStyle, Borders.All); ShapeDescription result = ShapeDescription.Join(inside, outline); result.Shape = Shape.RectangleWithOutline; return result; }
public void Render(RenderContext context, IGradientShader shader) { context.Paint.Shader = shader.Create(context); if (context.RenderRect != context.CanvasRect) { RenderTiled(context); } else { context.Canvas.DrawRect(context.RenderRect, context.Paint); } }
private void Render(RenderContext context, IGradientShader shader) { context.Paint.Shader = shader.Create(context); if (context.RenderRect != context.CanvasRect) { RenderTiled(context); } else { RenderSingle(context); } }
public static Color4[] Radial(IGradientShader shader, int numVertex, Shape shape) { RadialShader rs = (RadialShader)shader; Color4[] colors = new Color4[numVertex]; switch (shape) { default: //case Shape.RectangleMesh: colors[0] = shader.Gradient[0].Color; int k = 1; for (int i = 1; i < colors.Length; i++ ) { if (i > 1 && (i - 1) % rs.Slices == 0) k++; colors[i] = shader.Gradient[k].Color; } break; } return colors; }
static IGradientShader[] ConvertShaders(XmlGradientShader[] shaderArray) { IGradientShader[] convertedShaders = new IGradientShader[shaderArray.Length]; for (int i = 0; i < shaderArray.Length; i++ ) { switch (shaderArray[i].GradientType) { default: convertedShaders[i] = shaderArray[i].ToColorShader(); break; } } return convertedShaders; }
public XmlBorderShader(IGradientShader cs) : base(cs) { }
public XmlGradientShader(IGradientShader cs) { Name = cs.Name; GradientType = cs.GradientType; if (cs.Gradient == null) return; if (cs.Gradient[0] == cs.Gradient[1] || cs.Gradient.Length ==1) { ColorValue = cs.Gradient[0].Color.ToArgb().ToString("X8"); } else { XmlGradient = new XmlGradientStop[cs.Gradient.Length]; for (int i = 0; i < cs.Gradient.Length; i++) { XmlGradient[i] = new XmlGradientStop(cs.Gradient[i]); } } }
private float[] DetailOffsets(float minDelta, int innerSegments, IGradientShader rs, out GradientStop[] gradient) { Dictionary<float, GradientStop> gradientStops = new Dictionary<float, GradientStop> {{rs.Gradient[0].Offset, rs.Gradient[0]}}; float prevOffset = rs.Gradient[0].Offset; //foreach (float offset in offsets.Skip(1)) for (int i = 1; i < rs.Gradient.Length; i++) { GradientStop gs = rs.Gradient[i]; float offset = gs.Offset; float range = offset - prevOffset; if (range <= minDelta) { gradientStops.Add(gs.Offset, gs); continue; } if (i > innerSegments) break; int numOffsets = (int) Math.Truncate(range/minDelta); for (int j = 1; j <= numOffsets; j++) { float newOffset = prevOffset + j*minDelta; //(float)Math.Pow(j*minDelta,2); float weight = (float) MathHelper.ConvertRange(prevOffset, offset, 0, 1.0, newOffset); Color4 newColor = Color4.Lerp(rs.Gradient[i - 1].Color, rs.Gradient[i].Color, weight); if (!gradientStops.Keys.Contains(newOffset)) gradientStops.Add(newOffset, new GradientStop(newColor, newOffset)); } //if (!gradientStops.Keys.Contains(offset)) // gradientStops.Add(offset,gs); prevOffset = offset; } List<GradientStop> gList = gradientStops.Values.ToList(); gradient = gList.ToArray(); return (from g in gList select g.Offset).ToArray(); }