Example #1
0
		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.RenderSolid(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);
		}
Example #2
0
        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);
        }