/// <inheritdoc/> protected override bool OnDraw(CanvasDevice device, CanvasDrawingSession session, Vector2 size) { // Create our Brush if (GradientStops != null && GradientStops.Count > 0) { var gradientBrush = new CanvasRadialGradientBrush( device, GradientStops.ToWin2DGradientStops(), SpreadMethod.ToEdgeBehavior(), (CanvasAlphaMode)(int)AlphaMode, ColorInterpolationMode.ToCanvasColorSpace(), CanvasColorSpace.Srgb, CanvasBufferPrecision.Precision8UIntNormalized) { // Calculate Surface coordinates from 0.0-1.0 range given in WPF brush RadiusX = size.X * (float)RadiusX, RadiusY = size.Y * (float)RadiusY, Center = size * Center.ToVector2(), // Calculate Win2D Offset from origin/center used in WPF brush OriginOffset = size * (GradientOrigin.ToVector2() - Center.ToVector2()), }; // Use brush to draw on our canvas session.FillRectangle(size.ToRect(), gradientBrush); gradientBrush.Dispose(); return(true); } return(false); }
internal override void CopyPropertiesFrom(LW_Element element) { LW_PaintStyle style = element as LW_PaintStyle; if (style != null) { m_Material = style.m_Material; m_MainTexture = style.m_MainTexture; m_PaintMode = style.m_PaintMode; m_UvMode = style.m_UvMode; m_UvTiling = style.m_UvTiling; m_UvOffset = style.m_UvOffset; if (style.m_GradientColors != null) { m_GradientColors = new List <LW_ColorStop>(style.m_GradientColors); } else { m_GradientColors = null; } m_GradientPosition = style.m_GradientPosition; m_GradientRotation = style.m_GradientRotation; m_GradientScale = style.m_GradientScale; m_GradientSpreadMethod = style.m_GradientSpreadMethod; m_GradientUnits = style.m_GradientUnits; m_GradientStart = style.m_GradientStart; m_GradientEnd = style.m_GradientEnd; m_Opacity = style.m_Opacity; } base.CopyPropertiesFrom(element); }
public void ResolveBrush(RadialGradientBrush radialGrBrush) { //for gradient : PointF p1 = radialGrBrush.StartPoint; PointF p2 = radialGrBrush.EndPoint; if (radialGrBrush.CoordTransformer != null) { _invertCoordTx = radialGrBrush.CoordTransformer.CreateInvert(); } _center_x = (int)Math.Round(p1.X); _center_y = (int)Math.Round(p1.Y); float r = (float)Math.Sqrt((p2.X - _center_x) * (p2.X - _center_x) + (p2.Y - _center_y) * (p2.Y - _center_y)); ColorStop[] colorStops = radialGrBrush.ColorStops; int pairCount = colorStops.Length - 1; _orgList = new LinearGradientPair[pairCount]; _pairList = new LinearGradientPair[_orgList.Length]; ColorStop c1 = ColorStop.Empty; for (int i = 0; i < pairCount; ++i) { ColorStop c0 = colorStops[i]; c1 = colorStops[i + 1]; var pairN = new LinearGradientPair( c0.Offset * r, //to actual pixel c1.Offset * r, //to actual pixel c0.Color, c1.Color); _orgList[i] = pairN; } _endColor = c1.Color; this.SpreadMethod = radialGrBrush.SpreadMethod; Opactiy = 1; }
public LinearGradientBrush( string tag, GradientUnits gradientUnits, ITransform gradientTransform, SpreadMethod spreadMethod, Measure x1, Measure y1, Measure x2, Measure y2, Stop[] stops) { Tag = "LGB:" + tag; GradientUnits = gradientUnits; GradientTransform = gradientTransform; SpreadMethod = spreadMethod; X1 = x1; Y1 = y1; X2 = x2; Y2 = y2; Stops = stops; }
internal override void Reset() { base.Reset(); m_Material = null; m_MainTexture = null; m_PaintMode = PaintMode.Solid; m_UvMode = UvMode.Scaled; m_UvTiling = Vector2.one; m_UvOffset = Vector2.zero; m_GradientColors = new List <LW_ColorStop>() { new LW_ColorStop(Color.white, 0f), new LW_ColorStop(Color.black, 1f) }; m_GradientPosition = Vector3.zero; m_GradientRotation = Vector3.zero; m_GradientScale = Vector3.one; m_GradientSpreadMethod = SpreadMethod.pad; m_GradientUnits = GradientUnits.objectBoundingBox; m_GradientStart = new Vector2(0, 0); m_GradientEnd = new Vector2(1, 0); m_Opacity = 1; }
public RadialGradientBrush( string tag, GradientUnits gradientUnits, ITransform gradientTransform, SpreadMethod spreadMethod, Measure cx, Measure cy, Measure r, Measure fx, Measure fy, Stop[] stops) { Tag = "LGB:" + tag; GradientUnits = gradientUnits; GradientTransform = gradientTransform; SpreadMethod = spreadMethod; Stops = stops; Cx = cx; Cy = cy; Fx = fx; Fy = fy; R = r; }
/// <summary> /// Specifies a gradient fill used by subsequent calls to other Graphics methods (such as lineTo() or drawCircle()) for the object. /// </summary> public void beginGradientFill(string type, uint[] colors, float[] alphas, int[] ratios, Matrix matrix, SpreadMethod spreadMethod) { return; }
/// <summary> /// Specifies a gradient fill used by subsequent calls to other Graphics methods (such as <see cref="lineTo"/>() or <see cref="drawCircle"/>()) for the object. /// </summary> public void beginGradientFill(string type, uint[] colors, float[] alphas, int[] ratios, Matrix matrix, SpreadMethod spreadMethod, InterpolationMethod interpolationMethod, float focalPointRatio) { return; }
public void ResolveBrush(LinearGradientBrush linearGrBrush) { PointF p1 = linearGrBrush.StartPoint; PointF p2 = linearGrBrush.EndPoint; //assume horizontal line _beginX = p1.X; _beginY = p1.Y; _endX = p2.X; _endY = p2.Y; //-------------- //find transformation matrix double angle = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X); ICoordTransformer rotateTx = Affine.NewRotation(angle); if (linearGrBrush.CoordTransformer != null) { //*** IMPORTANT : matrix transform order !** rotateTx = linearGrBrush.CoordTransformer.MultiplyWith(rotateTx); } _transformBackToHorizontal = rotateTx.CreateInvert(); _totalLen = (float)Math.Sqrt((_endX - _beginX) * (_endX - _beginX) + (_endY - _beginY) * (_endY - _beginY)); double tmpX = _beginX; double tmpY = _beginY; _transformBackToHorizontal.Transform(ref tmpX, ref tmpY); _beginX = (float)tmpX; _beginY = (float)tmpY; //-------------- tmpX = _endX; tmpY = _endY; _transformBackToHorizontal.Transform(ref tmpX, ref tmpY); _endX = (float)tmpX; _endY = (float)tmpY; //-------------- ColorStop[] colorStops = linearGrBrush.ColorStops; int pairCount = colorStops.Length - 1; _pairList = new LinearGradientPair[pairCount]; ColorStop c0 = ColorStop.Empty; ColorStop c1 = ColorStop.Empty; for (int i = 0; i < pairCount; ++i) { c0 = colorStops[i]; c1 = colorStops[i + 1]; if (i == 0) { _beginColor = c0.Color; } var pairN = new LinearGradientPair( _beginX + c0.Offset * _totalLen, //to actual pixel _beginX + c1.Offset * _totalLen, //to actual pixel c0.Color, c1.Color); _pairList[i] = pairN; } this.SpreadMethod = linearGrBrush.SpreadMethod; _endColor = c1.Color; }