public override void OnDraw() { RasterizerScanlineAA <T> ras = new RasterizerScanlineAA <T>(); ScanlineUnpacked8 sl = new ScanlineUnpacked8(); #if SourceDepth24 FormatRGB pixf = new FormatRGB(rbuf_window(), new BlenderBGR()); #else FormatRGBA pixf = new FormatRGBA(rbuf_window(), new blender_bgra32()); #endif FormatClippingProxy clippingProxy = new FormatClippingProxy(pixf); clippingProxy.Clear(new RGBA_Doubles(0, 0, 0)); m_profile.text_size(8.0); //m_profile.Render(ras, sl, clippingProxy); //m_spline_r.Render(ras, sl, clippingProxy); //m_spline_g.Render(ras, sl, clippingProxy); //m_spline_b.Render(ras, sl, clippingProxy); //m_spline_a.Render(ras, sl, clippingProxy); //m_GradTypeRBox.Render(ras, sl, clippingProxy); //m_GradWrapRBox.Render(ras, sl, clippingProxy); // draw a background to show how the alpha is working int RectWidth = 32; int xoffset = 238; int yoffset = 171; for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect <T> rect = new VertexSource.RoundedRect <T>(i * RectWidth + xoffset, j * RectWidth + yoffset, (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2); rect.NormalizeRadius(); // Drawing as an outline ras.AddPath(rect); Renderer <T> .RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9)); } } } double ini_scale = 1.0; IAffineTransformMatrix <T> mtx1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx1.Translate(MatrixFactory <T> .CreateVector2D(center_x, center_y)); mtx1.Add(trans_affine_resizing()); VertexSource.Ellipse <T> e1 = new AGG.VertexSource.Ellipse <T>(); e1.Init(0.0, 0.0, 110.0, 110.0, 64); IAffineTransformMatrix <T> mtx_g1 = MatrixFactory <T> .NewIdentity(VectorDimension.Two); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(ini_scale, ini_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_SaveData.m_scale, m_SaveData.m_scale)); mtx_g1.Scale(MatrixFactory <T> .CreateVector2D(m_scale_x, m_scale_y)); mtx_g1.RotateAlong(MatrixFactory <T> .CreateVector2D(0, 0), m_SaveData.m_angle.ToDouble()); mtx_g1.Translate(MatrixFactory <T> .CreateVector2D(m_SaveData.m_center_x, m_SaveData.m_center_y)); mtx_g1.Add(trans_affine_resizing()); mtx_g1 = mtx_g1.Inverse; RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h for (int i = 0; i < 256; i++) { color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i].ToInt(), m_spline_g.spline()[i].ToInt(), m_spline_b.spline()[i].ToInt(), m_spline_a.spline()[i].ToInt()); } ConvTransform <T> t1 = new ConvTransform <T>(e1, mtx1); IGradient innerGradient = null; switch (m_GradTypeRBox.cur_item()) { case 0: innerGradient = new GradientRadial(); break; case 1: innerGradient = new GradientDiamond(); break; case 2: innerGradient = new GradientX(); break; case 3: innerGradient = new GradientXY(); break; case 4: innerGradient = new GradientSqrtXY(); break; case 5: innerGradient = new GradientConic(); break; } IGradient outerGradient = null; switch (m_GradWrapRBox.cur_item()) { case 0: outerGradient = new GradientReflectAdaptor(innerGradient); break; case 1: outerGradient = new GradientRepeatAdaptor(innerGradient); break; case 2: outerGradient = new GradientClampAdaptor(innerGradient); break; } SpanAllocator span_alloc = new SpanAllocator(); ColorFunctionProfile colors = new ColorFunctionProfile(color_profile, m_profile.gamma()); SpanInterpolatorLinear <T> inter = new SpanInterpolatorLinear <T>(mtx_g1); SpanGradient <T> span_gen = new SpanGradient <T>(inter, outerGradient, colors, 0, 150); ras.AddPath(t1); Renderer <T> .GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen); base.OnDraw(); }
public override void OnDraw(Graphics2D graphics2D) { ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect()); ScanlineRasterizer ras = new ScanlineRasterizer(); scanline_unpacked_8 sl = new scanline_unpacked_8(); ImageClippingProxy clippingProxy = new ImageClippingProxy(widgetsSubImage); clippingProxy.clear(new RGBA_Floats(0, 0, 0)); m_profile.text_size(8.0); // draw a background to show how the alpha is working int RectWidth = 32; int xoffset = 238; int yoffset = 171; ScanlineRenderer scanlineRenderer = new ScanlineRenderer(); for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if ((i + j) % 2 != 0) { VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth + xoffset, j * RectWidth + yoffset, (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2); rect.normalize_radius(); ras.add_path(rect); scanlineRenderer.render_scanlines_aa_solid(clippingProxy, ras, sl, new RGBA_Bytes(.9, .9, .9)); } } } double ini_scale = 1.0; Transform.Affine mtx1 = Affine.NewIdentity(); mtx1 *= Affine.NewScaling(ini_scale, ini_scale); mtx1 *= Affine.NewTranslation(center_x, center_y); VertexSource.Ellipse e1 = new MatterHackers.Agg.VertexSource.Ellipse(); e1.init(0.0, 0.0, 110.0, 110.0, 64); Transform.Affine mtx_g1 = Affine.NewIdentity(); mtx_g1 *= Affine.NewScaling(ini_scale, ini_scale); mtx_g1 *= Affine.NewScaling(m_SaveData.m_scale, m_SaveData.m_scale); mtx_g1 *= Affine.NewScaling(m_scale_x, m_scale_y); mtx_g1 *= Affine.NewRotation(m_SaveData.m_angle); mtx_g1 *= Affine.NewTranslation(m_SaveData.m_center_x, m_SaveData.m_center_y); mtx_g1.invert(); RGBA_Bytes[] color_profile = new RGBA_Bytes[256]; // color_type is defined in pixel_formats.h for (int i = 0; i < 256; i++) { color_profile[i] = new RGBA_Bytes(m_spline_r.spline()[i], m_spline_g.spline()[i], m_spline_b.spline()[i], m_spline_a.spline()[i]); } VertexSourceApplyTransform t1 = new VertexSourceApplyTransform(e1, mtx1); IGradient innerGradient = null; switch (m_GradTypeRBox.SelectedIndex) { case 0: innerGradient = new gradient_radial(); break; case 1: innerGradient = new gradient_diamond(); break; case 2: innerGradient = new gradient_x(); break; case 3: innerGradient = new gradient_xy(); break; case 4: innerGradient = new gradient_sqrt_xy(); break; case 5: innerGradient = new gradient_conic(); break; } IGradient outerGradient = null; switch (m_GradWrapRBox.SelectedIndex) { case 0: outerGradient = new gradient_reflect_adaptor(innerGradient); break; case 1: outerGradient = new gradient_repeat_adaptor(innerGradient); break; case 2: outerGradient = new gradient_clamp_adaptor(innerGradient); break; } span_allocator span_alloc = new span_allocator(); color_function_profile colors = new color_function_profile(color_profile, m_profile.gamma()); span_interpolator_linear inter = new span_interpolator_linear(mtx_g1); span_gradient span_gen = new span_gradient(inter, outerGradient, colors, 0, 150); ras.add_path(t1); scanlineRenderer.GenerateAndRender(ras, sl, clippingProxy, span_alloc, span_gen); base.OnDraw(graphics2D); }