public static ArrayList <VertexC4V3f> CalculateLinearGradientVxs( float x1, float y1, float x2, float y2, PixelFarm.Drawing.Color c1, PixelFarm.Drawing.Color c2) { //1. gradient distance float dx = x2 - x1; float dy = y2 - y1; float distance = (float)Math.Pow(dx * dx + dy * dy, 0.5f); //find angle double angleRad = Math.Atan2(dy, dx); if (dx < 0) { //swap float tmpx = x2; x2 = x1; x1 = tmpx; float tmpy = y2; y2 = y1; y1 = tmpy; PixelFarm.Drawing.Color tmpc = c2; c2 = c1; c1 = tmpc; } ArrayList <VertexC4V3f> vrx = new ArrayList <VertexC4V3f>(); //left solid rect pane AddRect(vrx, c1.ToABGR(), c1.ToABGR(), -600, -800, x1 + 600, 1800); //color gradient pane AddRect(vrx, c1.ToABGR(), c2.ToABGR(), x1, -800, distance, 1800); //right solid pane if (1200 - (x1 + distance) > 0) { AddRect(vrx, c2.ToABGR(), c2.ToABGR(), (x1 + distance), -800, 1200 - (x1 + distance), 1800); } //---------------------------------------------- //translate vertex around x1,y1 PixelFarm.Agg.Transform.AffinePlan[] affPlans = new PixelFarm.Agg.Transform.AffinePlan[] { PixelFarm.Agg.Transform.AffinePlan.Translate(-x1, -y1), PixelFarm.Agg.Transform.AffinePlan.Rotate(angleRad), PixelFarm.Agg.Transform.AffinePlan.Translate(x1, y1) }; var txMatrix = PixelFarm.Agg.Transform.Affine.NewMatix(affPlans); int j = vrx.Count; for (int i = j - 1; i >= 0; --i) { VertexC4V3f v = vrx[i]; double v_x = v.x; double v_y = v.y; txMatrix.Transform(ref v_x, ref v_y); vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y); } return(vrx); }
//---------------------------------------------------------------------------- public static void CalculateLinearGradientVxs2( float x1, float y1, float x2, float y2, PixelFarm.Drawing.Color c1, PixelFarm.Drawing.Color c2, out float[] v2f, out float[] colors) { //1. gradient distance float dx = x2 - x1; float dy = y2 - y1; float distance = (float)Math.Pow(dx * dx + dy * dy, 0.5f); //find angle double angleRad = Math.Atan2(dy, dx); if (dx < 0) { //swap float tmpx = x2; x2 = x1; x1 = tmpx; float tmpy = y2; y2 = y1; y1 = tmpy; PixelFarm.Drawing.Color tmpc = c2; c2 = c1; c1 = tmpc; } ArrayList <VertexC4V3f> vrx = new ArrayList <VertexC4V3f>(); //left solid rect pane AddRect(vrx, c1.ToABGR(), c1.ToABGR(), -600, -800, x1 + 600, 1800); //color gradient pane AddRect(vrx, c1.ToABGR(), c2.ToABGR(), x1, -800, distance, 1800); //right solid pane if (1200 - (x1 + distance) > 0) { AddRect(vrx, c2.ToABGR(), c2.ToABGR(), (x1 + distance), -800, 1200 - (x1 + distance), 1800); } //---------------------------------------------- //translate vertex around x1,y1 PixelFarm.Agg.Transform.AffinePlan[] affPlans = new PixelFarm.Agg.Transform.AffinePlan[] { PixelFarm.Agg.Transform.AffinePlan.Translate(-x1, -y1), PixelFarm.Agg.Transform.AffinePlan.Rotate(angleRad), PixelFarm.Agg.Transform.AffinePlan.Translate(x1, y1) }; var txMatrix = PixelFarm.Agg.Transform.Affine.NewMatix(affPlans); int j = vrx.Count; List <float> v2fList = new List <float>(); List <float> colorList = new List <float>(); for (int i = 0; i < j; ++i) { VertexC4V3f v = vrx[i]; double v_x = v.x; double v_y = v.y; txMatrix.Transform(ref v_x, ref v_y); //vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y); v2fList.Add((float)v_x); v2fList.Add((float)v_y); var color = v.color; //a,b,g,r colorList.Add((color & 0xff) / 255f); //r colorList.Add(((color >> 8) & 0xff) / 255f); //g colorList.Add(((color >> 16) & 0xff) / 255f); //b colorList.Add(((color >> 24) & 0xff) / 255f); //a } v2f = v2fList.ToArray(); colors = colorList.ToArray(); }
public static ArrayList<VertexC4V3f> CalculateLinearGradientVxs( float x1, float y1, float x2, float y2, PixelFarm.Drawing.Color c1, PixelFarm.Drawing.Color c2) { //1. gradient distance float dx = x2 - x1; float dy = y2 - y1; float distance = (float)Math.Pow(dx * dx + dy * dy, 0.5f); //find angle double angleRad = Math.Atan2(dy, dx); if (dx < 0) { //swap float tmpx = x2; x2 = x1; x1 = tmpx; float tmpy = y2; y2 = y1; y1 = tmpy; PixelFarm.Drawing.Color tmpc = c2; c2 = c1; c1 = tmpc; } ArrayList<VertexC4V3f> vrx = new ArrayList<VertexC4V3f>(); //left solid rect pane AddRect(vrx, c1.ToABGR(), c1.ToABGR(), -600, -800, x1 + 600, 1800); //color gradient pane AddRect(vrx, c1.ToABGR(), c2.ToABGR(), x1, -800, distance, 1800); //right solid pane if (1200 - (x1 + distance) > 0) { AddRect(vrx, c2.ToABGR(), c2.ToABGR(), (x1 + distance), -800, 1200 - (x1 + distance), 1800); } //---------------------------------------------- //translate vertex around x1,y1 PixelFarm.Agg.Transform.AffinePlan[] affPlans = new PixelFarm.Agg.Transform.AffinePlan[]{ PixelFarm.Agg.Transform.AffinePlan.Translate(-x1,-y1), PixelFarm.Agg.Transform.AffinePlan.Rotate(angleRad), PixelFarm.Agg.Transform.AffinePlan.Translate(x1,y1)}; var txMatrix = PixelFarm.Agg.Transform.Affine.NewMatix(affPlans); int j = vrx.Count; for (int i = j - 1; i >= 0; --i) { VertexC4V3f v = vrx[i]; double v_x = v.x; double v_y = v.y; txMatrix.Transform(ref v_x, ref v_y); vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y); } return vrx; }
/// <summary> /// we do not store input linearGradient /// </summary> /// <param name="linearGradient"></param> static void Build(Drawing.LinearGradientBrush linearGradient, out float[] v2f, out float[] colors) { ColorStop[] colorStops = linearGradient.ColorStops; s_vertices.Clear(); s_v2fList.Clear(); s_colorList.Clear(); float x_1 = linearGradient.StartPoint.X; float y_1 = linearGradient.StartPoint.Y; double angleRad = linearGradient.Angle; double totalLen = linearGradient.Length; int pairCount = colorStops.Length - 1; ColorStop c0 = ColorStop.Empty; ColorStop c1 = ColorStop.Empty; //create a simple horizontal linear gradient bar //and we will rotate and translate it to target pos for (int i = 0; i < pairCount; ++i) { c0 = colorStops[i]; c1 = colorStops[i + 1]; CalculateLinearGradientVxs(s_vertices, i == 0, i == pairCount - 1, (float)(x_1 + (c0.Offset * totalLen)), (float)((c1.Offset - c0.Offset) * totalLen), c0, c1); } var txMatrix = PixelFarm.CpuBlit.VertexProcessing.Affine.NewMatix( PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(-x_1, -y_1), PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Rotate(angleRad), PixelFarm.CpuBlit.VertexProcessing.AffinePlan.Translate(x_1, y_1) ); //---------------------------------- int j = s_vertices.Count; for (int m = 0; m < j; ++m) { VertexC4V3f v = s_vertices[m]; double v_x = v.x; double v_y = v.y; txMatrix.Transform(ref v_x, ref v_y); //vrx[i] = new VertexC4V3f(v.color, (float)v_x, (float)v_y); s_v2fList.Add((float)v_x); s_v2fList.Add((float)v_y); uint color = v.color; //a,b,g,r s_colorList.Add((color & 0xff) / 255f); //r s_colorList.Add(((color >> 8) & 0xff) / 255f); //g s_colorList.Add(((color >> 16) & 0xff) / 255f); //b s_colorList.Add(((color >> 24) & 0xff) / 255f); //a } v2f = s_v2fList.ToArray(); colors = s_colorList.ToArray(); }