Exemplo n.º 1
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value);
			IRecieveBlenderByte NormalBlender = new BlenderBGR();
			IRecieveBlenderByte GammaBlender = new BlenderGammaBGR(gamma);
			ImageBuffer rasterNormal = new ImageBuffer();
			rasterNormal.Attach(graphics2D.DestImage, NormalBlender);
			ImageBuffer rasterGamma = new ImageBuffer();
			rasterGamma.Attach(graphics2D.DestImage, GammaBlender);
			ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
			ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

			clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1));

			ScanlineRasterizer ras = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();

			int size_mul = (int)pixelSizeSlider.Value;

			renderer_enlarged ren_en = new renderer_enlarged(size_mul);

			StyledTypeFace type = new StyledTypeFace(LiberationSansFont.Instance, 12);
			IVertexSource character = type.GetGlyphForCharacter('E');
			character.rewind(0);
			ras.reset();
			ras.add_path(character);
			ren_en.RenderSolid(clippingProxyGamma, ras, sl, RGBA_Bytes.Black);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(clippingProxyGamma, ras, sl, RGBA_Bytes.Black);

			ras.gamma(new gamma_none());

			PathStorage ps = new PathStorage();
			Stroke pg = new Stroke(ps);
			pg.width(2);

			DrawBigA(graphics2D);

			base.OnDraw(graphics2D);
		}
Exemplo n.º 2
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			GammaLookUpTable gamma = new GammaLookUpTable(gammaSlider.Value);
			IRecieveBlenderByte NormalBlender = new BlenderBGRA();
			IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
			ImageBuffer rasterGamma = new ImageBuffer();
			rasterGamma.Attach(widgetsSubImage, GammaBlender);
			ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(widgetsSubImage);
			ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

			clippingProxyNormal.clear(new RGBA_Floats(1, 1, 1));

			ScanlineRasterizer rasterizer = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();

			int size_mul = (int)pixelSizeSlider.Value;

			renderer_enlarged ren_en = new renderer_enlarged(size_mul);

			rasterizer.reset();
			rasterizer.move_to_d(m_x[0] / size_mul, m_y[0] / size_mul);
			rasterizer.line_to_d(m_x[1] / size_mul, m_y[1] / size_mul);
			rasterizer.line_to_d(m_x[2] / size_mul, m_y[2] / size_mul);
			ren_en.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderSolid(clippingProxyGamma, rasterizer, sl, RGBA_Bytes.Black);

			rasterizer.gamma(new gamma_none());

			PathStorage ps = new PathStorage();
			Stroke pg = new Stroke(ps);
			pg.width(2);

			ps.remove_all();
			ps.MoveTo(m_x[0], m_y[0]);
			ps.LineTo(m_x[1], m_y[1]);
			ps.LineTo(m_x[2], m_y[2]);
			ps.LineTo(m_x[0], m_y[0]);
			rasterizer.add_path(pg);
			scanlineRenderer.RenderSolid(clippingProxyNormal, rasterizer, sl, new RGBA_Bytes(0, 150, 160, 200));

			base.OnDraw(graphics2D);
		}
Exemplo n.º 3
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			if (!didInit)
			{
				didInit = true;
				OnInitialize();
			}

			if (m_gamma.Value != m_old_gamma)
			{
				m_gamma_lut.SetGamma(m_gamma.Value);
				ImageIO.LoadImageData("spheres.bmp", m_SourceImage);
				//m_SourceImage.apply_gamma_dir(m_gamma_lut);
				m_old_gamma = m_gamma.Value;
			}

			ImageBuffer pixf = new ImageBuffer();
			switch (widgetsSubImage.BitDepth)
			{
				case 24:
					pixf.Attach(widgetsSubImage, new BlenderBGR());
					break;

				case 32:
					pixf.Attach(widgetsSubImage, new BlenderBGRA());
					break;

				default:
					throw new NotImplementedException();
			}

			ImageClippingProxy clippingProxy = new ImageClippingProxy(pixf);

			clippingProxy.clear(new RGBA_Floats(1, 1, 1));

			if (m_trans_type.SelectedIndex < 2)
			{
				// For the affine parallelogram transformations we
				// calculate the 4-th (implicit) point of the parallelogram
				m_quad.SetXN(3, m_quad.GetXN(0) + (m_quad.GetXN(2) - m_quad.GetXN(1)));
				m_quad.SetYN(3, m_quad.GetYN(0) + (m_quad.GetYN(2) - m_quad.GetYN(1)));
			}

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			// draw a background to show how the alpha is working
			int RectWidth = 70;
			int xoffset = 50;
			int yoffset = 50;
			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();

						g_rasterizer.add_path(rect);
						scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.2, .2, .2));
					}
				}
			}

			//--------------------------
			// Render the "quad" tool and controls
			g_rasterizer.add_path(m_quad);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.1));

			// Prepare the polygon to rasterize. Here we need to fill
			// the destination (transformed) polygon.
			g_rasterizer.SetVectorClipBox(0, 0, Width, Height);
			g_rasterizer.reset();
			int b = 0;
			g_rasterizer.move_to_d(m_quad.GetXN(0) - b, m_quad.GetYN(0) - b);
			g_rasterizer.line_to_d(m_quad.GetXN(1) + b, m_quad.GetYN(1) - b);
			g_rasterizer.line_to_d(m_quad.GetXN(2) + b, m_quad.GetYN(2) + b);
			g_rasterizer.line_to_d(m_quad.GetXN(3) - b, m_quad.GetYN(3) + b);

			//typedef agg::span_allocator<color_type> span_alloc_type;
			span_allocator sa = new span_allocator();
			image_filter_bilinear filter_kernel = new image_filter_bilinear();
			ImageFilterLookUpTable filter = new ImageFilterLookUpTable(filter_kernel, true);

			ImageBufferAccessorClamp source = new ImageBufferAccessorClamp(m_SourceImage);

			stopwatch.Restart();

			switch (m_trans_type.SelectedIndex)
			{
				case 0:
					{
						/*
								agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);

								typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
								interpolator_type interpolator(tr);

								typedef image_filter_2x2_type<source_type,
															  interpolator_type> span_gen_type;
								span_gen_type sg(source, interpolator, filter);
								agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
						 */
						break;
					}

				case 1:
					{
						/*
								agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);

								typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
								typedef image_resample_affine_type<source_type> span_gen_type;

								interpolator_type interpolator(tr);
								span_gen_type sg(source, interpolator, filter);
								sg.blur(m_blur.Value);
								agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
						 */
						break;
					}

				case 2:
					{
						/*
								agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								if(tr.is_valid())
								{
									typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective> interpolator_type;
									interpolator_type interpolator(tr);

									typedef image_filter_2x2_type<source_type,
																  interpolator_type> span_gen_type;
									span_gen_type sg(source, interpolator, filter);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}

				case 3:
					{
						/*
								agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								if(tr.is_valid())
								{
									typedef agg::span_interpolator_trans<agg::trans_perspective> interpolator_type;
									interpolator_type interpolator(tr);

									typedef image_filter_2x2_type<source_type,
																  interpolator_type> span_gen_type;
									span_gen_type sg(source, interpolator, filter);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}

				case 4:
					{
						//typedef agg::span_interpolator_persp_lerp<> interpolator_type;
						//typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;

						span_interpolator_persp_lerp interpolator = new span_interpolator_persp_lerp(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
						span_subdiv_adaptor subdiv_adaptor = new span_subdiv_adaptor(interpolator);

						span_image_resample sg = null;
						if (interpolator.is_valid())
						{
							switch (source.SourceImage.BitDepth)
							{
								case 24:
									sg = new span_image_resample_rgb(source, subdiv_adaptor, filter);
									break;

								case 32:
									sg = new span_image_resample_rgba(source, subdiv_adaptor, filter);
									break;
							}

							sg.blur(m_blur.Value);
							scanlineRenderer.GenerateAndRender(g_rasterizer, g_scanline, clippingProxy, sa, sg);
						}
						break;
					}

				case 5:
					{
						/*
								typedef agg::span_interpolator_persp_exact<> interpolator_type;
								typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;

								interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
								subdiv_adaptor_type subdiv_adaptor(interpolator);

								if(interpolator.is_valid())
								{
									typedef image_resample_type<source_type,
																subdiv_adaptor_type> span_gen_type;
									span_gen_type sg(source, subdiv_adaptor, filter);
									sg.blur(m_blur.Value);
									agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
								}
						 */
						break;
					}
			}

			double tm = stopwatch.ElapsedMilliseconds;
			//pixf.apply_gamma_inv(m_gamma_lut);

			gsv_text t = new gsv_text();
			t.SetFontSize(10.0);

			Stroke pt = new Stroke(t);
			pt.width(1.5);

			string buf = string.Format("{0:F2} ms", tm);
			t.start_point(10.0, 70.0);
			t.text(buf);

			g_rasterizer.add_path(pt);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0, 0));

			//--------------------------
			//m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
			//m_gamma.Render(g_rasterizer, g_scanline, clippingProxy);
			//m_blur.Render(g_rasterizer, g_scanline, clippingProxy);
			base.OnDraw(graphics2D);
		}
Exemplo n.º 4
0
		private void render_gpc(Graphics2D graphics2D)
		{
			switch (m_polygons.SelectedIndex)
			{
				case 0:
					{
						//------------------------------------
						// Two simple paths
						//
						PathStorage ps1 = new PathStorage();
						PathStorage ps2 = new PathStorage();

						double x = m_x - Width / 2 + 100;
						double y = m_y - Height / 2 + 100;
						ps1.MoveTo(x + 140, y + 145);
						ps1.LineTo(x + 225, y + 44);
						ps1.LineTo(x + 296, y + 219);
						ps1.ClosePolygon();

						ps1.LineTo(x + 226, y + 289);
						ps1.LineTo(x + 82, y + 292);

						ps1.MoveTo(x + 220, y + 222);
						ps1.LineTo(x + 363, y + 249);
						ps1.LineTo(x + 265, y + 331);

						ps1.MoveTo(x + 242, y + 243);
						ps1.LineTo(x + 268, y + 309);
						ps1.LineTo(x + 325, y + 261);

						ps1.MoveTo(x + 259, y + 259);
						ps1.LineTo(x + 273, y + 288);
						ps1.LineTo(x + 298, y + 266);

						ps2.MoveTo(100 + 32, 100 + 77);
						ps2.LineTo(100 + 473, 100 + 263);
						ps2.LineTo(100 + 351, 100 + 290);
						ps2.LineTo(100 + 354, 100 + 374);

						graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
						graphics2D.Render(ps2, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, ps1, ps2);
					}
					break;

				case 1:
					{
						//------------------------------------
						// Closed stroke
						//
						PathStorage ps1 = new PathStorage();
						PathStorage ps2 = new PathStorage();
						Stroke stroke = new Stroke(ps2);
						stroke.width(10.0);

						double x = m_x - Width / 2 + 100;
						double y = m_y - Height / 2 + 100;
						ps1.MoveTo(x + 140, y + 145);
						ps1.LineTo(x + 225, y + 44);
						ps1.LineTo(x + 296, y + 219);
						ps1.ClosePolygon();

						ps1.LineTo(x + 226, y + 289);
						ps1.LineTo(x + 82, y + 292);

						ps1.MoveTo(x + 220 - 50, y + 222);
						ps1.LineTo(x + 265 - 50, y + 331);
						ps1.LineTo(x + 363 - 50, y + 249);
						ps1.close_polygon(ShapePath.FlagsAndCommand.FlagCCW);

						ps2.MoveTo(100 + 32, 100 + 77);
						ps2.LineTo(100 + 473, 100 + 263);
						ps2.LineTo(100 + 351, 100 + 290);
						ps2.LineTo(100 + 354, 100 + 374);
						ps2.ClosePolygon();

						graphics2D.Render(ps1, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());
						graphics2D.Render(stroke, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, ps1, stroke);
					}
					break;

				case 2:
					{
						//------------------------------------
						// Great Britain and Arrows
						//
						PathStorage gb_poly = new PathStorage();
						PathStorage arrows = new PathStorage();
						GreatBritanPathStorage.Make(gb_poly);
						make_arrows(arrows);

						Affine mtx1 = Affine.NewIdentity();
						Affine mtx2 = Affine.NewIdentity();
						mtx1 *= Affine.NewTranslation(-1150, -1150);
						mtx1 *= Affine.NewScaling(2.0);

						mtx2 = mtx1;
						mtx2 *= Affine.NewTranslation(m_x - Width / 2, m_y - Height / 2);

						VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);
						VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx2);

						graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

						Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
						stroke_gb_poly.Width = 0.1;
						graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

						graphics2D.Render(trans_arrows, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, trans_gb_poly, trans_arrows);
					}
					break;

				case 3:
					{
						//------------------------------------
						// Great Britain and a Spiral
						//
						spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0);
						Stroke stroke = new Stroke(sp);
						stroke.width(15.0);

						PathStorage gb_poly = new PathStorage();
						GreatBritanPathStorage.Make(gb_poly);

						Affine mtx = Affine.NewIdentity(); ;
						mtx *= Affine.NewTranslation(-1150, -1150);
						mtx *= Affine.NewScaling(2.0);

						VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx);

						graphics2D.Render(trans_gb_poly, new RGBA_Floats(0.5, 0.5, 0, 0.1).GetAsRGBA_Bytes());

						Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
						stroke_gb_poly.width(0.1);
						graphics2D.Render(stroke_gb_poly, new RGBA_Floats(0, 0, 0).GetAsRGBA_Bytes());

						graphics2D.Render(stroke, new RGBA_Floats(0.0, 0.5, 0.5, 0.1).GetAsRGBA_Bytes());

						CreateAndRenderCombined(graphics2D, trans_gb_poly, stroke);
					}
					break;

				case 4:
					{
						//------------------------------------
						// Spiral and glyph
						//
						spiral sp = new spiral(m_x, m_y, 10, 150, 30, 0.0);
						Stroke stroke = new Stroke(sp);
						stroke.width(15.0);

						PathStorage glyph = new PathStorage();
						glyph.MoveTo(28.47, 6.45);
						glyph.curve3(21.58, 1.12, 19.82, 0.29);
						glyph.curve3(17.19, -0.93, 14.21, -0.93);
						glyph.curve3(9.57, -0.93, 6.57, 2.25);
						glyph.curve3(3.56, 5.42, 3.56, 10.60);
						glyph.curve3(3.56, 13.87, 5.03, 16.26);
						glyph.curve3(7.03, 19.58, 11.99, 22.51);
						glyph.curve3(16.94, 25.44, 28.47, 29.64);
						glyph.LineTo(28.47, 31.40);
						glyph.curve3(28.47, 38.09, 26.34, 40.58);
						glyph.curve3(24.22, 43.07, 20.17, 43.07);
						glyph.curve3(17.09, 43.07, 15.28, 41.41);
						glyph.curve3(13.43, 39.75, 13.43, 37.60);
						glyph.LineTo(13.53, 34.77);
						glyph.curve3(13.53, 32.52, 12.38, 31.30);
						glyph.curve3(11.23, 30.08, 9.38, 30.08);
						glyph.curve3(7.57, 30.08, 6.42, 31.35);
						glyph.curve3(5.27, 32.62, 5.27, 34.81);
						glyph.curve3(5.27, 39.01, 9.57, 42.53);
						glyph.curve3(13.87, 46.04, 21.63, 46.04);
						glyph.curve3(27.59, 46.04, 31.40, 44.04);
						glyph.curve3(34.28, 42.53, 35.64, 39.31);
						glyph.curve3(36.52, 37.21, 36.52, 30.71);
						glyph.LineTo(36.52, 15.53);
						glyph.curve3(36.52, 9.13, 36.77, 7.69);
						glyph.curve3(37.01, 6.25, 37.57, 5.76);
						glyph.curve3(38.13, 5.27, 38.87, 5.27);
						glyph.curve3(39.65, 5.27, 40.23, 5.62);
						glyph.curve3(41.26, 6.25, 44.19, 9.18);
						glyph.LineTo(44.19, 6.45);
						glyph.curve3(38.72, -0.88, 33.74, -0.88);
						glyph.curve3(31.35, -0.88, 29.93, 0.78);
						glyph.curve3(28.52, 2.44, 28.47, 6.45);
						glyph.ClosePolygon();

						glyph.MoveTo(28.47, 9.62);
						glyph.LineTo(28.47, 26.66);
						glyph.curve3(21.09, 23.73, 18.95, 22.51);
						glyph.curve3(15.09, 20.36, 13.43, 18.02);
						glyph.curve3(11.77, 15.67, 11.77, 12.89);
						glyph.curve3(11.77, 9.38, 13.87, 7.06);
						glyph.curve3(15.97, 4.74, 18.70, 4.74);
						glyph.curve3(22.41, 4.74, 28.47, 9.62);
						glyph.ClosePolygon();

						Affine mtx = Affine.NewIdentity();
						mtx *= Affine.NewScaling(4.0);
						mtx *= Affine.NewTranslation(220, 200);
						VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
						FlattenCurves curve = new FlattenCurves(trans);

						CreateAndRenderCombined(graphics2D, stroke, curve);

						graphics2D.Render(stroke, new RGBA_Floats(0, 0, 0, 0.1).GetAsRGBA_Bytes());

						graphics2D.Render(curve, new RGBA_Floats(0, 0.6, 0, 0.1).GetAsRGBA_Bytes());
					}
					break;
			}
		}
Exemplo n.º 5
0
		public polygon_ctrl_impl(int np, double point_radius)
			: base(new Vector2())
		{
			m_ellipse = new MatterHackers.Agg.VertexSource.Ellipse();
			m_polygon = new ArrayPOD<double>(np * 2);
			m_num_points = (np);
			m_node = (-1);
			m_edge = (-1);
			m_vs = new simple_polygon_vertex_source(m_polygon.Array, m_num_points, false);
			m_stroke = new Stroke(m_vs);
			m_point_radius = (point_radius);
			m_status = (0);
			m_dx = (0.0);
			m_dy = (0.0);
			m_in_polygon_check = (true);
			m_stroke.width(1.0);
		}
Exemplo n.º 6
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

            IImageByte backBuffer = widgetsSubImage;
            
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer();
            rasterNormal.Attach(backBuffer, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer();
            rasterGamma.Attach(backBuffer, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(m_white_on_black.Checked ? new RGBA_Floats(0, 0, 0) : new RGBA_Floats(1, 1, 1));

            ScanlineRasterizer ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            double d = m_offset.Value;

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0] + d, m_y[0] + d, m_x[1] + d, m_y[1] + d, m_radius.Value);
            r.normalize_radius();

            // Drawing as an outline
            if (!m_DrawAsOutlineCheckBox.Checked)
            {
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);
            }
            else
            {
                ras.add_path(r);
            }

            scanlineRenderer.render_scanlines_aa_solid(clippingProxyGamma, ras, sl, m_white_on_black.Checked ? new RGBA_Bytes(255, 255, 255) : new RGBA_Bytes(0, 0, 0));

            base.OnDraw(graphics2D);
        }
Exemplo n.º 7
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            {
                ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());
                Graphics2D subGraphics2D = widgetsSubImage.NewGraphics2D();

                subGraphics2D.Clear(new RGBA_Bytes(255, 255, 255));
                for (int y = 0; y < MomsGame.GetHeight(); y++)
                {
                    for (int x = 0; x < MomsGame.GetWidth(); x++)
                    {
                        DrawCard(subGraphics2D, x, y);
                    }
                }

                String whatToDo = "Select any open space marked with an 'O'";
                RGBA_Bytes backFillCollor = new RGBA_Bytes(0xe1, 0xe0, 0xf6);

                if (MomsGame.GetWaitingForKing())
                {
                    backFillCollor = new RGBA_Bytes(0xf8, 0x89, 0x78);
                    whatToDo = "Select a King for the hole";
                }
                else if (MomsGame.IsSolved())
                {
                    backFillCollor = new RGBA_Bytes(0xf8, 0x89, 0x78);
                    whatToDo = "You win!";
                }
                else if (!MomsGame.MoveAvailable())
                {
                    backFillCollor = new RGBA_Bytes(0xf8, 0x89, 0x78);
                    whatToDo = "No more moves! Shuffle to continue.";
                }

                if (whatToDo != null)
                {
                    TextWidget stringToDraw = new TextWidget(whatToDo, 12);
                    RectangleDouble Size = stringToDraw.Printer.LocalBounds;
                    double TextX = m_BoardX + CARD_WIDTH * 4;
                    double TextY = m_BoardY - 34;
                    RoundedRect BackFill = new RoundedRect(Size.Left - 6, Size.Bottom - 3, Size.Right + 6, Size.Top + 6, 3);
                    Stroke BackBorder = new Stroke(BackFill);
                    BackBorder.width(2);

                    subGraphics2D.SetTransform(Affine.NewTranslation(TextX, TextY));
                    subGraphics2D.Render(BackFill, backFillCollor);
                    subGraphics2D.Render(BackBorder, new RGBA_Bytes(0, 0, 0));
                    subGraphics2D.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));
                }

                String ShufflesString;
                ShufflesString = "Number of shuffles so far = ";
                ShufflesString += MomsGame.GetNumShuffles().ToString();

                TextWidget shuffelStringToDraw = new TextWidget(ShufflesString, 12);
                subGraphics2D.SetTransform(Affine.NewTranslation(m_BoardX, 350));
                subGraphics2D.Render(shuffelStringToDraw.Printer, new RGBA_Bytes(0, 0, 0));

                subGraphics2D.SetTransform(Affine.NewIdentity());
            }
            base.OnDraw(graphics2D);
        }
Exemplo n.º 8
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;

			IImageByte destImage = backBuffer;
			ImageClippingProxy clippingProxy = new ImageClippingProxy(destImage);
			clippingProxy.clear(new RGBA_Floats(0, 0, 0));

			ScanlineRasterizer ras = new ScanlineRasterizer();
			scanline_unpacked_8 sl = new scanline_unpacked_8();
			scanline_bin sl_bin = new scanline_bin();

			rasterizer_compound_aa rasc = new rasterizer_compound_aa();
			span_allocator alloc = new span_allocator();

			int i;
			styles_gouraud styles = new styles_gouraud(m_mesh, m_gamma);
			stopwatch.Restart();
			rasc.reset();
			//rasc.clip_box(40, 40, width() - 40, height() - 40);
			for (i = 0; i < m_mesh.num_edges(); i++)
			{
				mesh_edge e = m_mesh.edge(i);
				mesh_point p1 = m_mesh.vertex(e.p1);
				mesh_point p2 = m_mesh.vertex(e.p2);
				rasc.styles(e.tl, e.tr);
				rasc.move_to_d(p1.x, p1.y);
				rasc.line_to_d(p2.x, p2.y);
			}

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			scanlineRenderer.RenderCompound(rasc, sl, sl_bin, clippingProxy, alloc, styles);
			double tm = stopwatch.ElapsedMilliseconds;

			gsv_text t = new gsv_text();
			t.SetFontSize(10.0);

			Stroke pt = new Stroke(t);
			pt.width(1.5);
			pt.line_cap(LineCap.Round);
			pt.line_join(LineJoin.Round);

			string buf = string.Format("{0:F2} ms, {1} triangles, {2:F0} tri/sec",
				tm,
				m_mesh.num_triangles(),
				m_mesh.num_triangles() / tm * 1000.0);
			t.start_point(10.0, 10.0);
			t.text(buf);

			ras.add_path(pt);
			scanlineRenderer.RenderSolid(clippingProxy, ras, sl, new RGBA_Bytes(255, 255, 255));

			if (m_gamma.GetGamma() != 1.0)
			{
				((ImageBuffer)destImage).apply_gamma_inv(m_gamma);
			}

			base.OnDraw(graphics2D);
		}
Exemplo n.º 9
0
        public void DrawCard(Graphics2D DestGraphics, int CardX, int CardY)
        {
            double StartX = CardX * CARD_WIDTH + m_BoardX;
            double StartY = CardY * CARD_HEIGHT + m_BoardY;

            RectangleDouble CardBounds = new RectangleDouble(StartX + 1.5, StartY + 1.5, StartX + CARD_WIDTH - 1.5, StartY + CARD_HEIGHT - 1.5);
            RoundedRect CardFiledRoundedRect = new RoundedRect(CardBounds.Left, CardBounds.Bottom, CardBounds.Right, CardBounds.Top, 5);
            Stroke CardRectBounds = new Stroke(CardFiledRoundedRect);
            CardRectBounds.width(1);

            CCard Card = MomsGame.GetCard(CardX, CardY);
            int CardValue = Card.GetValue();
            int CardSuit = Card.GetSuit();
            String ValueString = "Uninitialized ";
            if (CardValue > (int)CCard.CARD_VALUE.VALUE_ACE)
            {
                DestGraphics.SetTransform(Affine.NewIdentity());
                DestGraphics.Render(CardRectBounds, new RGBA_Bytes(0, 0, 0));
                if (CardValue > 10)
                {
                    switch (CardValue)
                    {
                        case 11:
                            ValueString = "J";
                            break;

                        case 12:
                            ValueString = "Q";
                            break;

                        case 13:
                            ValueString = "K";
                            break;

                        default:
                            throw new Exception();
                    }
                }
                else
                {
                    ValueString = CardValue.ToString();
                }

                TextWidget stringToDraw = new TextWidget(ValueString, 10);
                RectangleDouble textBounds = stringToDraw.Printer.LocalBounds;
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 2, CardBounds.Top - 8 - textBounds.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 4 - textBounds.Width, CardBounds.Bottom + 9 - textBounds.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));

                RGBA_Bytes SuitColor = new RGBA_Bytes(0, 0, 0);
                IVertexSource suitPath = new PathStorage();
                
                switch (CardSuit)
                {
                    case (int)CCard.CARD_SUIT.SUIT_DIAMOND:
                        {
                            SuitColor = new RGBA_Bytes(0xFF, 0x11, 0x11);
                            suitPath = m_DiamondShape;
                        }
                        break;

                    case (int)CCard.CARD_SUIT.SUIT_CLUB:
                        {
                            SuitColor = new RGBA_Bytes(0x22, 0x22, 0x66);
                            suitPath = new FlattenCurves(m_ClubShape);
                        }
                        break;

                    case (int)CCard.CARD_SUIT.SUIT_HEART: 
                        {
                            SuitColor = new RGBA_Bytes(0xBB, 0x00, 0x00);
                            suitPath = new FlattenCurves(m_HeartShape);
                        }
                        break;

                    case (int)CCard.CARD_SUIT.SUIT_SPADE:
                        {
                            SuitColor = new RGBA_Bytes(0x00, 0x00, 0x00);
                            suitPath = new FlattenCurves(m_SpadeShape);
                        }
                        break;

                    default:
                        break;
                }

                textBounds = stringToDraw.Printer.LocalBounds;

                if (CardValue < 11)
                {
                    for (int CurDot = 0; CurDot < CardValue; CurDot++)
                    {
                        double OffsetX = 0, OffsetY = 0;
                        GetSuitOffset(ref OffsetX, ref OffsetY, CurDot, (int)CardValue);
                        DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + OffsetX, CardBounds.Bottom + OffsetY));
                        DestGraphics.Render(suitPath, SuitColor);
                    }
                }
                else
                {
                    DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 9, CardBounds.Bottom + 17));
                    DestGraphics.Render(suitPath, SuitColor);
                    DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 9, CardBounds.Top - 17));
                    DestGraphics.Render(suitPath, SuitColor);

                    stringToDraw = new TextWidget(ValueString, 22);
                    textBounds = stringToDraw.Printer.LocalBounds;
                    DestGraphics.SetTransform(Affine.NewTranslation(-1 + CardBounds.Left + CardBounds.Width / 2 - textBounds.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - textBounds.Height / 2));
                    DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0));
                }
            }
            else
            {
                RGBA_Bytes HoleColor = new RGBA_Bytes(0, 0, 0);

                String OpenSpaceString;

				if (!MomsGame.SpaceIsClickable(CardX, CardY))
                {
                    HoleColor = new RGBA_Bytes(0xf8, 0xe2, 0xe8);
                    OpenSpaceString = "X";
                }
                else
                {
                    HoleColor = new RGBA_Bytes(0xe1, 0xe0, 0xf6);
                    OpenSpaceString = "O";
                }

                TextWidget stringToDraw = new TextWidget(OpenSpaceString, 35);
                RectangleDouble Size = stringToDraw.Printer.LocalBounds;
                DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + CardBounds.Width / 2 - Size.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - Size.Height / 2));
                DestGraphics.Render(stringToDraw.Printer, HoleColor);
            }
        }
Exemplo n.º 10
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;

			if (!didInit)
			{
				didInit = true;
				OnInitialize();
			}
			ImageBuffer image;
			if (backBuffer.BitDepth == 32)
			{
				image = new ImageBuffer();
				image.Attach(backBuffer, new BlenderBGRA());
			}
			else
			{
				if (backBuffer.BitDepth != 24)
				{
					throw new System.NotSupportedException();
				}
				image = new ImageBuffer();
				image.Attach(backBuffer, new BlenderBGR());
			}
			ImageClippingProxy clippingProxy = new ImageClippingProxy(image);
			clippingProxy.clear(new RGBA_Floats(1, 1, 1));

			g_rasterizer.SetVectorClipBox(0, 0, Width, Height);

			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
			if (transformationTypeRadioButton.SelectedIndex == 0)
			{
				Bilinear tr = new Bilinear(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
				if (tr.is_valid())
				{
					//--------------------------
					// Render transformed lion
					//
					VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr);

					scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);
					//--------------------------

					//--------------------------
					// Render transformed ellipse
					//
					VertexSource.Ellipse ell = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
									 (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
									 200);
					Stroke ell_stroke = new Stroke(ell);
					ell_stroke.width(3.0);
					VertexSourceApplyTransform trans_ell = new VertexSourceApplyTransform(ell, tr);

					VertexSourceApplyTransform trans_ell_stroke = new VertexSourceApplyTransform(ell_stroke, tr);

					g_rasterizer.add_path(trans_ell);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

					g_rasterizer.add_path(trans_ell_stroke);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
				}
			}
			else
			{
				Perspective tr = new Perspective(lionShape.Bounds.Left, lionShape.Bounds.Bottom, lionShape.Bounds.Right, lionShape.Bounds.Top, quadPolygonControl.polygon());
				if (tr.is_valid())
				{
					// Render transformed lion
					VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, tr);

					scanlineRenderer.RenderSolidAllPaths(clippingProxy, g_rasterizer, g_scanline, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

					// Render transformed ellipse
					VertexSource.Ellipse FilledEllipse = new MatterHackers.Agg.VertexSource.Ellipse((lionShape.Bounds.Left + lionShape.Bounds.Right) * 0.5, (lionShape.Bounds.Bottom + lionShape.Bounds.Top) * 0.5,
									 (lionShape.Bounds.Right - lionShape.Bounds.Left) * 0.5, (lionShape.Bounds.Top - lionShape.Bounds.Bottom) * 0.5,
									 200);

					Stroke EllipseOutline = new Stroke(FilledEllipse);
					EllipseOutline.width(3.0);
					VertexSourceApplyTransform TransformedFilledEllipse = new VertexSourceApplyTransform(FilledEllipse, tr);

					VertexSourceApplyTransform TransformedEllipesOutline = new VertexSourceApplyTransform(EllipseOutline, tr);

					g_rasterizer.add_path(TransformedFilledEllipse);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.5, 0.3, 0.0, 0.3));

					g_rasterizer.add_path(TransformedEllipesOutline);
					scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0.0, 0.3, 0.2, 1.0));
				}
			}

			//--------------------------
			// Render the "quad" tool and controls
			g_rasterizer.add_path(quadPolygonControl);
			scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(0, 0.3, 0.5, 0.6));
			//m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
			base.OnDraw(graphics2D);
		}
Exemplo n.º 11
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GammaLookUpTable gamma = new GammaLookUpTable(m_gamma.Value);
            IRecieveBlenderByte NormalBlender = new BlenderBGRA();
            IRecieveBlenderByte GammaBlender = new BlenderGammaBGRA(gamma);
            ImageBuffer rasterNormal = new ImageBuffer(NewGraphics2D().DestImage, NormalBlender);
            ImageBuffer rasterGamma = new ImageBuffer(NewGraphics2D().DestImage, GammaBlender);
            ImageClippingProxy clippingProxyNormal = new ImageClippingProxy(rasterNormal);
            ImageClippingProxy clippingProxyGamma = new ImageClippingProxy(rasterGamma);

            clippingProxyNormal.clear(new RGBA_Floats(0, 0, 0));

            ScanlineRasterizer ras = new ScanlineRasterizer();
            ScanlineCachePacked8 sl = new ScanlineCachePacked8();

            VertexSource.Ellipse e = new VertexSource.Ellipse();

            // TODO: If you drag the control circles below the bottom of the window we get an exception.  This does not happen in AGG.
            // It needs to be debugged.  Turning on clipping fixes it.  But standard agg works without clipping.  Could be a bigger problem than this.
            //ras.clip_box(0, 0, width(), height());

            // Render two "control" circles
            e.init(m_x[0], m_y[0], 3, 3, 16);
            ras.add_path(e);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));
            e.init(m_x[1], m_y[1], 3, 3, 16);
            ras.add_path(e);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxyNormal, ras, sl, new RGBA_Bytes(127, 127, 127));

            // Creating a rounded rectangle
            VertexSource.RoundedRect r = new VertexSource.RoundedRect(m_x[0], m_y[0], m_x[1], m_y[1], 10);
            r.normalize_radius();

            // Drawing as an outline
                Stroke p = new Stroke(r);
                p.width(1.0);
                ras.add_path(p);

                //Renderer.RenderSolid(clippingProxyGamma, ras, sl, new RGBA_Bytes(0, 0, 0));
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyGamma, ras, sl, new RGBA_Bytes(255, 1, 1));








            /*            
                    int i;

                    // radial line test
                    //-------------------------
                    dashed_line<rasterizer_type, 
                                renderer_scanline_type, 
                                scanline_type> dash(ras, ren_sl, sl);

                    double cx = width() / 2.0;
                    double cy = height() / 2.0;

                    ren_sl.color(agg::rgba(1.0, 1.0, 1.0, 0.2));
                    for(i = 180; i > 0; i--) 
                    {
                        double n = 2.0 * agg::pi * i / 180.0;
                        dash.draw(cx + min(cx, cy) * sin(n), cy + min(cx, cy) * cos(n),
                                  cx, cy, 
                                  1.0, (i < 90) ? i : 0.0);
                    }


                    typedef agg::gradient_x gradient_func_type;
                    typedef agg::span_interpolator_linear<> interpolator_type;
                    typedef agg::span_allocator<color_type> span_allocator_type;
                    typedef agg::pod_auto_array<color_type, 256> color_array_type;
                    typedef agg::span_gradient<color_type, 
                                               interpolator_type, 
                                               gradient_func_type, 
                                               color_array_type> span_gradient_type;

                    typedef agg::renderer_scanline_aa<renderer_base_type, 
                                                      span_allocator_type,
                                                      span_gradient_type> renderer_gradient_type;

                    gradient_func_type  gradient_func;                   // The gradient function
                    agg::trans_affine   gradient_mtx;                    // Affine transformer
                    interpolator_type   span_interpolator(gradient_mtx); // Span interpolator
                    span_allocator_type span_allocator;                  // Span Allocator
                    color_array_type    gradient_colors;                 // The gradient colors
                    span_gradient_type  span_gradient(span_interpolator, 
                                                      gradient_func, 
                                                      gradient_colors, 
                                                      0, 100);

                    renderer_gradient_type ren_gradient(ren_base, span_allocator, span_gradient);

                    dashed_line<rasterizer_type, 
                                renderer_gradient_type, 
                                scanline_type> dash_gradient(ras, ren_gradient, sl);

                    double x1, y1, x2, y2;

                    for(i = 1; i <= 20; i++)
                    {
                        ren_sl.color(agg::rgba(1,1,1));

                        // integral point sizes 1..20
                        //----------------
                        agg::ellipse ell;
            
                        ell.init(20 + i * (i + 1) + 0.5, 
                                 20.5, 
                                 i / 2.0, 
                                 i / 2.0, 
                                 8 + i);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);
            

                        // fractional point sizes 0..2
                        //----------------
                        ell.init(18 + i * 4 + 0.5, 33 + 0.5, 
                                 i/20.0, i/20.0, 
                                 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // fractional point positioning
                        //---------------
                        ell.init(18 + i * 4 + (i-1) / 10.0 + 0.5, 
                                 27 + (i - 1) / 10.0 + 0.5, 
                                 0.5, 0.5, 8);
                        ras.reset();
                        ras.add_path(ell);
                        agg::render_scanlines(ras, sl, ren_sl);


                        // integral line widths 1..20
                        //----------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));

                        x1 = 20 + i* (i + 1);
                        y1 = 40.5;
                        x2 = 20 + i * (i + 1) + (i - 1) * 4;
                        y2 = 100.5;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, i, 0);


                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(0,0,1));

                        // fractional line lengths H (red/blue)
                        //----------------
                        x1 = 17.5 + i * 4;
                        y1 = 107;
                        x2 = 17.5 + i * 4 + i/6.66666667;
                        y2 = 107;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line lengths V (red/blue)
                        //---------------
                        x1 = 18 + i * 4;
                        y1 = 112.5;
                        x2 = 18 + i * 4;
                        y2 = 112.5 + i / 6.66666667;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);

                        // fractional line positioning (red)
                        //---------------
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,0,0), 
                                         agg::rgba(1,1,1));
                        x1 = 21.5;
                        y1 = 120 + (i - 1) * 3.1;
                        x2 = 52.5;
                        y2 = 120 + (i - 1) * 3.1;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 1.0, 0);


                        // fractional line width 2..0 (green)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,1,0), 
                                         agg::rgba(1,1,1));
                        x1 = 52.5;
                        y1 = 118 + i * 3;
                        x2 = 83.5;
                        y2 = 118 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 0);

                        // stippled fractional width 2..0 (blue)
                        fill_color_array(gradient_colors, 
                                         agg::rgba(0,0,1), 
                                         agg::rgba(1,1,1));
                        x1 = 83.5;
                        y1 = 119 + i * 3;
                        x2 = 114.5;
                        y2 = 119 + i * 3;
                        calc_linear_gradient_transform(x1, y1, x2, y2, gradient_mtx);
                        dash_gradient.draw(x1, y1, x2, y2, 2.0 - (i - 1) / 10.0, 3.0);


                        ren_sl.color(agg::rgba(1,1,1));
                        if(i <= 10)
                        {
                            // integral line width, horz aligned (mipmap test)
                            //-------------------
                            dash.draw(125.5, 119.5 + (i + 2) * (i / 2.0),
                                      135.5, 119.5 + (i + 2) * (i / 2.0),
                                      i, 0.0);
                        }

                        // fractional line width 0..2, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4, 192, 18.5 + i * 4, 192, i / 10.0, 0);

                        // fractional line positioning, 1 px H
                        //-----------------
                        dash.draw(17.5 + i * 4 + (i - 1) / 10.0, 186, 
                                  18.5 + i * 4 + (i - 1) / 10.0, 186,
                                  1.0, 0);
                    }


                    // Triangles
                    //---------------
                    for (int i = 1; i <= 13; i++) 
                    {
                        fill_color_array(gradient_colors, 
                                         agg::rgba(1,1,1), 
                                         agg::rgba(i % 2, (i % 3) * 0.5, (i % 5) * 0.25));
                        calc_linear_gradient_transform(width()  - 150, 
                                                       height() - 20 - i * (i + 1.5),
                                                       width()  - 20,  
                                                       height() - 20 - i * (i + 1),
                                                       gradient_mtx);
                        ras.reset();
                        ras.move_to_d(width() - 150, height() - 20 - i * (i + 1.5));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 1));
                        ras.line_to_d(width() - 20,  height() - 20 - i * (i + 2));
                        agg::render_scanlines(ras, sl, ren_gradient);
                    }
             */










            base.OnDraw(graphics2D);
        }
Exemplo n.º 12
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			int width = (int)widgetsSubImage.Width;
			int height = (int)widgetsSubImage.Height;

			ImageBuffer clippedSubImage = new ImageBuffer();
			clippedSubImage.Attach(widgetsSubImage, new BlenderBGRA());
			ImageClippingProxy imageClippingProxy = new ImageClippingProxy(clippedSubImage);
			imageClippingProxy.clear(new RGBA_Floats(1, 1, 1));

			Affine transform = Affine.NewIdentity();
			transform *= Affine.NewTranslation(-lionShape.Center.x, -lionShape.Center.y);
			transform *= Affine.NewScaling(lionScale, lionScale);
			transform *= Affine.NewRotation(angle + Math.PI);
			transform *= Affine.NewSkewing(skewX / 1000.0, skewY / 1000.0);
			transform *= Affine.NewTranslation(width / 2, height / 2);

			if (renderAsScanlineCheckBox.Checked)
			{
				rasterizer.SetVectorClipBox(0, 0, width, height);

				Stroke stroke = new Stroke(lionShape.Path);
				stroke.width(widthSlider.Value);
				stroke.line_join(LineJoin.Round);
				VertexSourceApplyTransform trans = new VertexSourceApplyTransform(stroke, transform);
				ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
				scanlineRenderer.RenderSolidAllPaths(imageClippingProxy, rasterizer, scanlineCache, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);
			}
			else
			{
				double w = widthSlider.Value * transform.GetScale();

				LineProfileAnitAlias lineProfile = new LineProfileAnitAlias(w, new gamma_none());
				OutlineRenderer outlineRenderer = new OutlineRenderer(imageClippingProxy, lineProfile);
				rasterizer_outline_aa rasterizer = new rasterizer_outline_aa(outlineRenderer);

				rasterizer.line_join(renderAccurateJoinsCheckBox.Checked ?
					rasterizer_outline_aa.outline_aa_join_e.outline_miter_accurate_join
					: rasterizer_outline_aa.outline_aa_join_e.outline_round_join);
				rasterizer.round_cap(true);

				VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);

				rasterizer.RenderAllPaths(trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);
			}

			base.OnDraw(graphics2D);
		}
Exemplo n.º 13
0
        private void RenderPolygonToPathAgainst(Graphics2D graphics2D)
        {
            IVertexSource pathToUse = null;
            switch (shapeTypeRadioGroup.SelectedIndex)
            {
                case 0:// simple polygon map
                    {
                        PathStorage ps1 = new PathStorage();

                        ps1.MoveTo(85, 417);
                        ps1.LineTo(338, 428);
                        ps1.LineTo(344, 325);
                        ps1.LineTo(399, 324);
                        ps1.LineTo(400, 421);
                        ps1.LineTo(644, 415);
                        ps1.LineTo(664, 75);
                        ps1.LineTo(98, 81);
                        ps1.ClosePolygon();

                        ps1.MoveTo(343, 290);
                        ps1.LineTo(159, 235);
                        ps1.LineTo(154, 162);
                        ps1.LineTo(340, 114);
                        ps1.ClosePolygon();

                        ps1.MoveTo(406, 121);
                        ps1.LineTo(587, 158);
                        ps1.LineTo(591, 236);
                        ps1.LineTo(404, 291);
                        ps1.ClosePolygon();

                        pathToUse = ps1;
                    }
                    break;

                case 1: // multiple pegs
                    {
                        PathStorage ps2 = new PathStorage();

                        double x = 0;
                        double y = 0;

                        ps2.MoveTo(100 + 32, 100 + 77);
                        ps2.LineTo(100 + 473, 100 + 263);
                        ps2.LineTo(100 + 351, 100 + 290);
                        ps2.LineTo(100 + 354, 100 + 374);

                        pathToUse = ps2;
                    }
                    break;

                case 2:
                    {
                        // circle holes
                        PathStorage ps1 = new PathStorage();

                        double x = 0;
                        double y = 0;
                        ps1.MoveTo(x + 140, y + 145);
                        ps1.LineTo(x + 225, y + 44);
                        ps1.LineTo(x + 296, y + 219);
                        ps1.ClosePolygon();

                        ps1.LineTo(x + 226, y + 289);
                        ps1.LineTo(x + 82, y + 292);
                        ps1.ClosePolygon();

                        ps1.MoveTo(x + 220 - 50, y + 222);
                        ps1.LineTo(x + 265 - 50, y + 331);
                        ps1.LineTo(x + 363 - 50, y + 249);
                        ps1.ClosePolygon();

                        pathToUse = ps1;
                    }
                    break;

                case 3: // Great Britain
                    {
                        PathStorage gb_poly = new PathStorage();
                        GreatBritanPathStorage.Make(gb_poly);

                        Affine mtx1 = Affine.NewIdentity();
                        Affine mtx2 = Affine.NewIdentity();
                        mtx1 *= Affine.NewTranslation(-1150, -1150);
                        mtx1 *= Affine.NewScaling(2.0);

                        mtx2 = mtx1;
                        mtx2 *= Affine.NewTranslation(Width / 2, Height / 2);

                        VertexSourceApplyTransform trans_gb_poly = new VertexSourceApplyTransform(gb_poly, mtx1);

                        pathToUse = trans_gb_poly;
                    }
                    break;

                case 4: // Arrows
                    {
                        PathStorage arrows = new PathStorage();
                        make_arrows(arrows);

                        Affine mtx1 = Affine.NewIdentity();
                        mtx1 *= Affine.NewTranslation(-1150, -1150);
                        mtx1 *= Affine.NewScaling(2.0);

                        VertexSourceApplyTransform trans_arrows = new VertexSourceApplyTransform(arrows, mtx1);

                        pathToUse = trans_arrows;
                    }
                    break;

                case 5: // Spiral
                    {
                        spiral sp = new spiral(Width / 2, Height / 2, 10, 150, 30, 0.0);
                        Stroke stroke = new Stroke(sp);
                        stroke.width(15.0);

                        Affine mtx = Affine.NewIdentity(); ;
                        mtx *= Affine.NewTranslation(-1150, -1150);
                        mtx *= Affine.NewScaling(2.0);

                        pathToUse = stroke;
                    }
                    break;

                case 6: // Glyph
                    {
                        //------------------------------------
                        // Spiral and glyph
                        //
                        PathStorage glyph = new PathStorage();
                        glyph.MoveTo(28.47, 6.45);
                        glyph.curve3(21.58, 1.12, 19.82, 0.29);
                        glyph.curve3(17.19, -0.93, 14.21, -0.93);
                        glyph.curve3(9.57, -0.93, 6.57, 2.25);
                        glyph.curve3(3.56, 5.42, 3.56, 10.60);
                        glyph.curve3(3.56, 13.87, 5.03, 16.26);
                        glyph.curve3(7.03, 19.58, 11.99, 22.51);
                        glyph.curve3(16.94, 25.44, 28.47, 29.64);
                        glyph.LineTo(28.47, 31.40);
                        glyph.curve3(28.47, 38.09, 26.34, 40.58);
                        glyph.curve3(24.22, 43.07, 20.17, 43.07);
                        glyph.curve3(17.09, 43.07, 15.28, 41.41);
                        glyph.curve3(13.43, 39.75, 13.43, 37.60);
                        glyph.LineTo(13.53, 34.77);
                        glyph.curve3(13.53, 32.52, 12.38, 31.30);
                        glyph.curve3(11.23, 30.08, 9.38, 30.08);
                        glyph.curve3(7.57, 30.08, 6.42, 31.35);
                        glyph.curve3(5.27, 32.62, 5.27, 34.81);
                        glyph.curve3(5.27, 39.01, 9.57, 42.53);
                        glyph.curve3(13.87, 46.04, 21.63, 46.04);
                        glyph.curve3(27.59, 46.04, 31.40, 44.04);
                        glyph.curve3(34.28, 42.53, 35.64, 39.31);
                        glyph.curve3(36.52, 37.21, 36.52, 30.71);
                        glyph.LineTo(36.52, 15.53);
                        glyph.curve3(36.52, 9.13, 36.77, 7.69);
                        glyph.curve3(37.01, 6.25, 37.57, 5.76);
                        glyph.curve3(38.13, 5.27, 38.87, 5.27);
                        glyph.curve3(39.65, 5.27, 40.23, 5.62);
                        glyph.curve3(41.26, 6.25, 44.19, 9.18);
                        glyph.LineTo(44.19, 6.45);
                        glyph.curve3(38.72, -0.88, 33.74, -0.88);
                        glyph.curve3(31.35, -0.88, 29.93, 0.78);
                        glyph.curve3(28.52, 2.44, 28.47, 6.45);
                        glyph.ClosePolygon();

                        glyph.MoveTo(28.47, 9.62);
                        glyph.LineTo(28.47, 26.66);
                        glyph.curve3(21.09, 23.73, 18.95, 22.51);
                        glyph.curve3(15.09, 20.36, 13.43, 18.02);
                        glyph.curve3(11.77, 15.67, 11.77, 12.89);
                        glyph.curve3(11.77, 9.38, 13.87, 7.06);
                        glyph.curve3(15.97, 4.74, 18.70, 4.74);
                        glyph.curve3(22.41, 4.74, 28.47, 9.62);
                        glyph.ClosePolygon();

                        Affine mtx = Affine.NewIdentity();
                        mtx *= Affine.NewScaling(4.0);
                        mtx *= Affine.NewTranslation(220, 200);
                        VertexSourceApplyTransform trans = new VertexSourceApplyTransform(glyph, mtx);
                        FlattenCurves curve = new FlattenCurves(trans);

                        pathToUse = curve;
                    }
                    break;
            }

            graphics2D.Render(pathToUse, fillColor);

            PathStorage travelLine = new PathStorage();
            travelLine.MoveTo(lineStart);
            travelLine.LineTo(mousePosition);

            Polygons polygonsToPathAround = VertexSourceToClipperPolygons.CreatePolygons(pathToUse, 1);
            polygonsToPathAround = FixWinding(polygonsToPathAround);

            Polygons travelPolysLine = VertexSourceToClipperPolygons.CreatePolygons(travelLine, 1);

            CreateAndRenderPathing(graphics2D, polygonsToPathAround, travelPolysLine);
        }