Пример #1
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GameImageSequence menuBackground = (GameImageSequence)DataAssetCache.Instance.GetAsset(typeof(GameImageSequence), "CreditsScreen");
            graphics2D.Render(menuBackground.GetImageByIndex(0), 0, 0);

            base.OnDraw(graphics2D);
        }
Пример #2
0
		protected override void DoDraw(Graphics2D destRenderer)
		{
			ImageBuffer imageToDraw = ImageSequenceReference.Instance.GetImageByTime(m_TotalSeconds);
			//Image imageToDraw = m_PlayerShipSequence.GetImageByIndex(m_ImageIndex);
			//IBlender blender = new BlenderBGRA();
			IRecieveBlenderByte recieveBlender = new BlenderPreMultBGR();

			/*
			unsafe
			{
				IImage destBuffer = destRenderer.DestImage;
				byte* pPixels = destBuffer.GetPixelPointerY(200);
				byte[] sourceBuffer = imageToDraw.ByteBuffer;
				for (int y = 0; y < imageToDraw.Height(); y++)
				{
					int SourceYOffset = y * imageToDraw.StrideInBytes();
					int destYOffset = (int)destBuffer.StrideInBytesAbs() * y;
					for (int x = 0; x < imageToDraw.Width(); x++)
					{
						int sourceOffset = SourceYOffset + x * 4;
						RGBA_Bytes sourceColor = new RGBA_Bytes(sourceBuffer[sourceOffset + 2], sourceBuffer[sourceOffset + 1], sourceBuffer[sourceOffset + 0], sourceBuffer[sourceOffset + 3]);
						blender.BlendPixel(&pPixels[destYOffset + x * 4], sourceColor);
					}
				}
			}
			 */
		}
		public static void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, Vector2 offset, double scale, RGBA_Bytes silhouetteColor)
		{
			graphics2D.Rasterizer.gamma(new gamma_power(.3));
			PathStorage polygonProjected = new PathStorage();
			foreach (Face face in meshToDraw.Faces)
			{
				if (face.normal.z > 0)
				{
					polygonProjected.remove_all();
					bool first = true;
					foreach (FaceEdge faceEdge in face.FaceEdges())
					{
						Vector2 position = new Vector2(faceEdge.firstVertex.Position.x, faceEdge.firstVertex.Position.y);
						position += offset;
						position *= scale;
						if (first)
						{
							polygonProjected.MoveTo(position.x, position.y);
							first = false;
						}
						else
						{
							polygonProjected.LineTo(position.x, position.y);
						}
					}
					graphics2D.Render(polygonProjected, silhouetteColor);
				}
			}
			graphics2D.Rasterizer.gamma(new gamma_none());
		}
Пример #4
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			DrawBorder(graphics2D);
			DrawBackground(graphics2D);

			base.OnDraw(graphics2D);
		}
Пример #5
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     RectangleDouble barBounds = bar.BoundsRelativeToParent;
     graphics2D.FillRectangle(barBounds.Left, barBounds.Bottom, barBounds.Left + barBounds.Width * PercentComplete / 100.0, barBounds.Top, ActiveTheme.Instance.PrimaryAccentColor);
     graphics2D.Rectangle(barBounds, RGBA_Bytes.Black);
     base.OnDraw(graphics2D);
 }
 public override void OnDraw(Graphics2D graphics2D)
 {
     base.OnDraw(graphics2D);
     RectangleDouble border = LocalBounds;
     border.Deflate(new BorderDouble(1));
     graphics2D.Rectangle(border, ActiveTheme.Instance.SecondaryBackgroundColor, 4);
 }
Пример #7
0
        public override void OnDraw(MatterHackers.Agg.Graphics2D graphics2D)
        {
            //graphics2D.Clear(new RGBA_Bytes(255, 255, 255, 0));
            //Gl.glClearColor(1, 1, 1, 1);
            Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT); // Clear the Depth Buffer
            //Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);	// Clear the Depth Buffer

            SetGlContext();
            SetTransforms(Width, Height);

            Gl.glTranslatef(0.0f, 0.0f, -7.0f);

            Gl.glPushMatrix();
            Gl.glMultMatrixd(mainTrackBallController.GetTransform4X4().GetAsDoubleArray());

            OnDrawGlContent();

            Gl.glPopMatrix();
            Gl.glDisable(Gl.GL_LIGHTING);

            UnsetGlContext();

            mainTrackBallController.DrawRadius(graphics2D);

            base.OnDraw(graphics2D);
        }
Пример #8
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);
        }
Пример #9
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            GameImageSequence background = (GameImageSequence)DataAssetCache.Instance.GetAsset(typeof(GameImageSequence), "GameBackground");
            graphics2D.Render(background.GetImageByIndex(0), 0, 0);

            m_Playfield.Draw(graphics2D);

            base.OnDraw(graphics2D);
        }
Пример #10
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			base.OnDraw(graphics2D);
			if (this.Width != TargetWidth)
			{
				SetSlidePosition();
				Invalidate();
			}
		}
Пример #11
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			base.OnDraw(graphics2D);

			if (Focused)
			{
				graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
			}
		}
Пример #12
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			int thumbHeight = 10;
			//graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Black);
			double bottom = textScrollWidget.Position0To1 * (Height - thumbHeight);// the 2 is the border
			RectangleDouble thumb = new RectangleDouble(0, bottom, Width, bottom + thumbHeight);// the 1 is the border
			graphics2D.FillRectangle(thumb, RGBA_Bytes.DarkGray);
			base.OnDraw(graphics2D);
		}
Пример #13
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			base.OnDraw(graphics2D);
			if (currentPanelIndex != desiredPanelIndex)
			{
				SetSlidePosition();
				Invalidate();
			}
		}
Пример #14
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Black);

            RoundedRect boundsRect = new RoundedRect(dragBar.BoundsRelativeToParent, 0);
            graphics2D.Render(boundsRect, DragBarColor);

            base.OnDraw(graphics2D);
        }
Пример #15
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			SetNoContentFieldDescriptionVisibility();
			base.OnDraw(graphics2D);

			if (ContainsFocus)
			{
				graphics2D.Rectangle(LocalBounds, RGBA_Bytes.Orange);
			}
		}
Пример #16
0
		private void DrawBorder(Graphics2D graphics2D)
		{
			if (borderColor.Alpha0To255 > 0)
			{
				RectangleDouble boarderRectangle = LocalBounds;

				RoundedRect rectBorder = new RoundedRect(boarderRectangle, 0);

				graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
			}
		}
Пример #17
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);
		}
Пример #18
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			RectangleDouble Bounds = LocalBounds;
			RoundedRect rectBorder = new RoundedRect(Bounds, this.borderRadius);

			graphics2D.Render(rectBorder, borderColor);

			RectangleDouble insideBounds = Bounds;
			insideBounds.Inflate(-this.borderWidth);
			RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

			graphics2D.Render(rectInside, this.fillColor);

			base.OnDraw(graphics2D);
		}
Пример #19
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (!putUpDiagnostics)
            {
                //DiagnosticWidget diagnosticView = new DiagnosticWidget(this);
                putUpDiagnostics = true;
            }
            this.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255));

            base.OnDraw(graphics2D);

            long milliseconds = totalTime.ElapsedMilliseconds;
            graphics2D.DrawString("ms: ", Width - 60, Height - 14);
            graphics2D.DrawString(milliseconds.ToString() + "  ", Width, Height - 14, justification: Justification.Right);
            totalTime.Restart();
        }
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (!startedLoad)
			{
				try
				{
					startedLoad = true;
					WebClient client = new WebClient();
					client.DownloadDataCompleted += client_DownloadDataCompleted;
					client.DownloadDataAsync(new Uri(uriToLoad));
				}
				catch (Exception)
				{
				}
			}

			base.OnDraw(graphics2D);
		}
Пример #21
0
		public DebugRenderToImage(Mesh meshToRender)
		{
			this.meshToRender = meshToRender;
			image = new ImageBuffer(xResolution, yResolution, 32, new BlenderBGRA());
			graphics = image.NewGraphics2D();

			// assume project on y for now
			foreach (Vertex vertex in meshToRender.Vertices)
			{
				min.x = Math.Min(min.x, vertex.Position[xAxis]);
				min.y = Math.Min(min.y, vertex.Position[yAxis]);

				max.x = Math.Max(max.x, vertex.Position[xAxis]);
				max.y = Math.Max(max.y, vertex.Position[yAxis]);
			}

			scale = Math.Min((image.Width - padding * 2) / (max.x - min.x), (image.Height - padding * 2) / (max.y - min.y));
			origin = new Vector2(min.x * scale, min.y * scale) - new Vector2(padding, padding);
		}
Пример #22
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);
		}
Пример #23
0
		private void DrawBigA(Graphics2D graphics2D)
		{
			ScanlineRasterizer m_ras = new ScanlineRasterizer();
			m_ras.SetVectorClipBox(0, 0, Width, Height);
			TypeFacePrinter bigAPrinter = new TypeFacePrinter("a", 150);
			FlattenCurves flattenedBigA = new FlattenCurves(bigAPrinter);
			VertexSourceApplyTransform scaleAndTranslate = new VertexSourceApplyTransform(flattenedBigA, Affine.NewTranslation(155, 55));
			ScanlineCachePacked8 m_sl = new ScanlineCachePacked8();
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

#if false
            ImageProxySubpxelLcd24 clippingProxy = new ImageProxySubpxelLcd24(graphics2D.DestImage, new lcd_distribution_lut());
            VertexSourceApplyTransform scaledWide = new VertexSourceApplyTransform(scaleAndTranslate, Affine.NewScaling(3, 1));
            m_ras.add_path(scaledWide);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#else
			m_ras.add_path(scaleAndTranslate);
			ImageClippingProxy clippingProxy = new ImageClippingProxy(graphics2D.DestImage);
			scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#endif
		}
Пример #24
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			byte alpha = (byte)(alphaSlider.Value * 255);
			for (int i = 0; i < lionShape.NumPaths; i++)
			{
				lionShape.Colors[i].Alpha0To255 = alpha;
			}

			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);

			// This code renders the lion:
			VertexSourceApplyTransform transformedPathStorage = new VertexSourceApplyTransform(lionShape.Path, transform);
			graphics2D.Render(transformedPathStorage, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

			base.OnDraw(graphics2D);
		}
Пример #25
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

			IImageByte backBuffer = widgetsSubImage;

			if (firstTime)
			{
				firstTime = false;
				m_SuperFast = new MatterHackers.Agg.UI.CheckBox(10, 10, "Run Super Fast");
				AddChild(m_SuperFast);
				m_Controller = new CController(backBuffer, 30, 40, .1, .7, .3, 4, 1, 2000);
			}

			graphics2D.Clear(new RGBA_Floats(1, 1, 1, 1));
			graphics2D.Rasterizer.SetVectorClipBox(0, 0, (int)Width, (int)Height);
			m_Controller.FastRender(m_SuperFast.Checked);
			m_Controller.Render(graphics2D);
			//m_SuperFast.Render(graphics2D);
			base.OnDraw(graphics2D);
		}
Пример #26
0
        private void Initialize(ImageBuffer sourceImage, RectangleInt boundsToCopyFrom)
        {
            if (sourceImage == this)
            {
                throw new Exception("We do not create a temp buffer for this to work.  You must have a source distinct from the dest.");
            }
            Deallocate();
            Allocate(boundsToCopyFrom.Width, boundsToCopyFrom.Height, boundsToCopyFrom.Width * sourceImage.BitDepth / 8, sourceImage.BitDepth);
            SetRecieveBlender(sourceImage.GetRecieveBlender());

            if (width != 0 && height != 0)
            {
                RectangleInt DestRect           = new RectangleInt(0, 0, boundsToCopyFrom.Width, boundsToCopyFrom.Height);
                RectangleInt AbsoluteSourceRect = boundsToCopyFrom;
                // The first thing we need to do is make sure the frame is cleared. LBB [3/15/2004]
                MatterHackers.Agg.Graphics2D graphics2D = NewGraphics2D();
                graphics2D.Clear(new RGBA_Bytes(0, 0, 0, 0));

                int x = -boundsToCopyFrom.Left - (int)sourceImage.OriginOffset.x;
                int y = -boundsToCopyFrom.Bottom - (int)sourceImage.OriginOffset.y;

                graphics2D.Render(sourceImage, x, y, 0, 1, 1);
            }
        }
        public override void OnDraw(Graphics2D graphics2D)
        {
            drawTimer.Start();
            if (borderColor.Alpha0To255 > 0)
            {
                RectangleDouble boarderRectangle = LocalBounds;
                boarderRectangle.Inflate(-borderWidth / 2);
                RoundedRect rectBorder = new RoundedRect(boarderRectangle, this.borderRadius);

                graphics2D.Render(new Stroke(rectBorder, borderWidth), borderColor);
            }

            if (this.fillColor.Alpha0To255 > 0)
            {
                RectangleDouble insideBounds = LocalBounds;
                insideBounds.Inflate(-this.borderWidth);
                RoundedRect rectInside = new RoundedRect(insideBounds, Math.Max(this.borderRadius - this.borderWidth, 0));

                graphics2D.Render(rectInside, this.fillColor);
            }

            base.OnDraw(graphics2D);
            drawTimer.Stop();
        }
Пример #28
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            ImageBuffer        widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());
            ImageClippingProxy clippingProxy   = new ImageClippingProxy(widgetsSubImage);

            clippingProxy.clear(new RGBA_Floats(1, 1, 1));
            m_ras.SetVectorClipBox(0, 0, Width, Height);

            Affine move = Affine.NewTranslation(10, 10);

            Perspective shadow_persp = new Perspective(m_shape_bounds.Left, m_shape_bounds.Bottom,
                                                       m_shape_bounds.Right, m_shape_bounds.Top,
                                                       m_shadow_ctrl.polygon());

            IVertexSource shadow_trans;

            if (m_FlattenCurves.Checked)
            {
                shadow_trans = new VertexSourceApplyTransform(m_shape, shadow_persp);
            }
            else
            {
                shadow_trans = new VertexSourceApplyTransform(m_path, shadow_persp);
                // this will make it very smooth after the transform
                //shadow_trans = new conv_curve(shadow_trans);
            }


            // Render shadow
            m_ras.add_path(shadow_trans);
            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

            scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, new RGBA_Floats(0.2, 0.3, 0).GetAsRGBA_Bytes());

            // Calculate the bounding box and extend it by the blur radius
            RectangleDouble bbox = new RectangleDouble();

            bounding_rect.bounding_rect_single(shadow_trans, 0, ref bbox);

            bbox.Left   -= m_radius.Value;
            bbox.Bottom -= m_radius.Value;
            bbox.Right  += m_radius.Value;
            bbox.Top    += m_radius.Value;

            if (m_method.SelectedIndex == 1)
            {
                // The recursive blur method represents the true Gaussian Blur,
                // with theoretically infinite kernel. The restricted window size
                // results in extra influence of edge pixels. It's impossible to
                // solve correctly, but extending the right and top areas to another
                // radius value produces fair result.
                //------------------
                bbox.Right += m_radius.Value;
                bbox.Top   += m_radius.Value;
            }

            stopwatch.Restart();

            if (m_method.SelectedIndex != 2)
            {
                // Create a new pixel renderer and attach it to the main one as a child image.
                // It returns true if the attachment succeeded. It fails if the rectangle
                // (bbox) is fully clipped.
                //------------------
#if SourceDepth24
                ImageBuffer image2 = new ImageBuffer(new BlenderBGR());
#else
                ImageBuffer image2 = new ImageBuffer(new BlenderBGRA());
#endif
                if (image2.Attach(widgetsSubImage, (int)bbox.Left, (int)bbox.Bottom, (int)bbox.Right, (int)bbox.Top))
                {
                    // Blur it
                    if (m_method.SelectedIndex == 0)
                    {
                        // More general method, but 30-40% slower.
                        //------------------
                        //m_stack_blur.blur(pixf2, agg::uround(m_radius.Value));

                        // Faster, but bore specific.
                        // Works only for 8 bits per channel and only with radii <= 254.
                        //------------------
                        stack_blur test = new stack_blur();
                        test.Blur(image2, agg_basics.uround(m_radius.Value), agg_basics.uround(m_radius.Value));
                    }
                    else
                    {
                        // True Gaussian Blur, 3-5 times slower than Stack Blur,
                        // but still constant time of radius. Very sensitive
                        // to precision, doubles are must here.
                        //------------------
                        m_recursive_blur.blur(image2, m_radius.Value);
                    }
                }
            }
            else
            {
                /*
                 * // Blur separate channels
                 * //------------------
                 * if(m_channel_r.Checked)
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 2> pixfmt_gray8r;
                 *
                 *  pixfmt_gray8r pixf2r(m_rbuf2);
                 *  if(pixf2r.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2r, agg::uround(m_radius.Value),
                 *                                    agg::uround(m_radius.Value));
                 *  }
                 * }
                 *
                 * if(m_channel_g.Checked)
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 1> pixfmt_gray8g;
                 *
                 *  pixfmt_gray8g pixf2g(m_rbuf2);
                 *  if(pixf2g.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2g, agg::uround(m_radius.Value),
                 *                                    agg::uround(m_radius.Value));
                 *  }
                 * }
                 *
                 * if(m_channel_b.Checked)
                 * {
                 *  typedef agg::pixfmt_alpha_blend_gray<
                 *      agg::blender_gray8,
                 *      agg::rendering_buffer,
                 *      3, 0> pixfmt_gray8b;
                 *
                 *  pixfmt_gray8b pixf2b(m_rbuf2);
                 *  if(pixf2b.attach(pixf, int(bbox.x1), int(bbox.y1), int(bbox.x2), int(bbox.y2)))
                 *  {
                 *      agg::stack_blur_gray8(pixf2b, agg::uround(m_radius.Value),
                 *                                    agg::uround(m_radius.Value));
                 *  }
                 * }
                 */
            }

            double tm = stopwatch.ElapsedMilliseconds;

            // Render the shape itself
            //------------------
            if (m_FlattenCurves.Checked)
            {
                m_ras.add_path(m_shape);
            }
            else
            {
                m_ras.add_path(m_path);
            }

            scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, new RGBA_Floats(0.6, 0.9, 0.7, 0.8).GetAsRGBA_Bytes());

            graphics2D.DrawString(string.Format("{0:F2} ms", tm), 140, 30);
            base.OnDraw(graphics2D);
        }
Пример #29
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);
        }
Пример #30
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);
        }
Пример #31
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     base.OnDraw(graphics2D);
     LiberationSansFont.Instance.ShowDebugInfo(graphics2D);
 }
Пример #32
0
        private void render_gpc(Graphics2D graphics2D)
        {
            switch (m_polygons.SelectedIndex)
            {
            case 0:
            {
                //------------------------------------
                // Two simple paths
                //
                VertexStorage ps1 = new VertexStorage();
                VertexStorage ps2 = new VertexStorage();

                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 ColorF(0, 0, 0, 0.1).ToColor());
                graphics2D.Render(ps2, new ColorF(0, 0.6, 0, 0.1).ToColor());

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

            case 1:
            {
                //------------------------------------
                // Closed stroke
                //
                VertexStorage ps1    = new VertexStorage();
                VertexStorage ps2    = new VertexStorage();
                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 ColorF(0, 0, 0, 0.1).ToColor());
                graphics2D.Render(stroke, new ColorF(0, 0.6, 0, 0.1).ToColor());

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

            case 2:
            {
                //------------------------------------
                // Great Britain and Arrows
                //
                VertexStorage gb_poly = new VertexStorage();
                VertexStorage arrows  = new VertexStorage();
                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 ColorF(0.5, 0.5, 0, 0.1).ToColor());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.Width = 0.1;
                graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor());

                graphics2D.Render(trans_arrows, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor());

                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;

                VertexStorage gb_poly = new VertexStorage();
                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 ColorF(0.5, 0.5, 0, 0.1).ToColor());

                Stroke stroke_gb_poly = new Stroke(trans_gb_poly);
                stroke_gb_poly.Width = 0.1;
                graphics2D.Render(stroke_gb_poly, new ColorF(0, 0, 0).ToColor());

                graphics2D.Render(stroke, new ColorF(0.0, 0.5, 0.5, 0.1).ToColor());

                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;

                VertexStorage glyph = new VertexStorage();
                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 ColorF(0, 0, 0, 0.1).ToColor());

                graphics2D.Render(curve, new ColorF(0, 0.6, 0, 0.1).ToColor());
            }
            break;
            }
        }
Пример #33
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 ColorF(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.LineCap  = LineCap.Round;
            pt.LineJoin = 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 Color(255, 255, 255));

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

            base.OnDraw(graphics2D);
        }
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Render(image, 0, 0);
     base.OnDraw(graphics2D);
 }
Пример #35
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.RenderSolid(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.RenderSolid(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.RenderSolid(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);
        }
Пример #36
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (graphics2D.DestImage != null)
            {
                ImageBuffer widgetsSubImage = ImageBuffer.NewSubImageReference(graphics2D.DestImage, graphics2D.GetClippingRect());

                IImageByte backBuffer = widgetsSubImage;

                int         distBetween    = backBuffer.GetBytesBetweenPixelsInclusive();
                ImageBuffer redImageBuffer = new ImageBuffer();
                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
                ImageBuffer greenImageBuffer = new ImageBuffer();
                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
                ImageBuffer blueImageBuffer = new ImageBuffer();
                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

                ImageClippingProxy clippingProxy      = new ImageClippingProxy(backBuffer);
                ImageClippingProxy clippingProxyRed   = new ImageClippingProxy(redImageBuffer);
                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
                ImageClippingProxy clippingProxyBlue  = new ImageClippingProxy(blueImageBuffer);

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

                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
                clippingProxy.clear(clearColor);
                alphaSlider.View.BackgroundColor = clearColor;

                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

                VertexSource.Ellipse er = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(er);
                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

                VertexSource.Ellipse eg = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(eg);
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

                VertexSource.Ellipse eb = new MatterHackers.Agg.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                ras.add_path(eb);
                scanlineRenderer.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
            }
            else if (graphics2D.DestImageFloat != null)
            {
#if false
                IImageFloat backBuffer = graphics2D.DestImageFloat;

                int distBetween = backBuffer.GetFloatsBetweenPixelsInclusive();
                ImageBufferFloat redImageBuffer = new ImageBufferFloat();
                redImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 2, 8);
                ImageBufferFloat greenImageBuffer = new ImageBufferFloat();
                greenImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 1, 8);
                ImageBufferFloat blueImageBuffer = new ImageBufferFloat();
                blueImageBuffer.Attach(backBuffer, new blender_gray(distBetween), distBetween, 0, 8);

                ImageClippingProxy clippingProxy      = new ImageClippingProxy(backBuffer);
                ImageClippingProxy clippingProxyRed   = new ImageClippingProxy(redImageBuffer);
                ImageClippingProxy clippingProxyGreen = new ImageClippingProxy(greenImageBuffer);
                ImageClippingProxy clippingProxyBlue  = new ImageClippingProxy(blueImageBuffer);

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

                RGBA_Bytes clearColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(0, 0, 0) : new RGBA_Bytes(255, 255, 255);
                clippingProxy.clear(clearColor);
                alphaSlider.View.BackGroundColor = clearColor;

                RGBA_Bytes FillColor = useBlackBackgroundCheckbox.Checked ? new RGBA_Bytes(255, 255, 255, (int)(alphaSlider.Value)) : new RGBA_Bytes(0, 0, 0, (int)(alphaSlider.Value));

                VertexSource.Ellipse er = new AGG.VertexSource.Ellipse(Width / 2 - 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(er);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyRed, ras, sl, FillColor);

                VertexSource.Ellipse eg = new AGG.VertexSource.Ellipse(Width / 2 + 0.87 * 50, Height / 2 - 0.5 * 50, 100, 100, 100);
                ras.add_path(eg);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyGreen, ras, sl, FillColor);

                VertexSource.Ellipse eb = new AGG.VertexSource.Ellipse(Width / 2, Height / 2 + 50, 100, 100, 100);
                ras.add_path(eb);
                agg_renderer_scanline.Default.render_scanlines_aa_solid(clippingProxyBlue, ras, sl, FillColor);
#endif
            }

            base.OnDraw(graphics2D);
        }
Пример #37
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            RectangleDouble borderRectangle = LocalBounds;
            RoundedRect rectBorder = new RoundedRect(borderRectangle, 0);

            graphics2D.Render(new Stroke(rectBorder, BorderWidth), BorderColor);
            base.OnDraw(graphics2D);
        }
Пример #38
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     base.OnDraw(graphics2D);
 }
Пример #39
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.render_scanlines_aa_solid(clippingProxy, g_rasterizer, g_scanline, new RGBA_Bytes(.2, .2, .2));
                    }
                }
            }

            //--------------------------
            // Render the "quad" tool and controls
            g_rasterizer.add_path(m_quad);
            scanlineRenderer.render_scanlines_aa_solid(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.render_scanlines_aa_solid(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);
        }
Пример #40
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (loadedGCode != null)
			{
				Affine transform = TotalTransform;

				CreateGrid(transform);

				double gridLineWidths = 0.2 * layerScale;
				Stroke stroke = new Stroke(grid, gridLineWidths);

				if (RenderGrid)
				{
                    graphics2D.Render(stroke, new RGBA_Bytes(190, 190, 190, 255));
				}

				RenderType renderType = RenderType.Extrusions;
				if (RenderMoves)
				{
					renderType |= RenderType.Moves;
				}
				if (RenderRetractions)
				{
					renderType |= RenderType.Retractions;
				}
                if (RenderSpeeds)
                {
                    renderType |= RenderType.SpeedColors;
                }
                if (SimulateExtrusion)
                {
                    renderType |= RenderType.SimulateExtrusion;
                }

				gCodeRenderer.Render(graphics2D, activeLayerIndex, transform, layerScale, renderType, 
					FeatureToStartOnRatio0To1, FeatureToEndOnRatio0To1);
			}

			base.OnDraw(graphics2D);
		}
Пример #41
0
        public static void Main(string[] args)
        {
            // first we will show how to use the simple drawing functions in graphics 2D
            {
                ImageBuffer simpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  simpleImageGraphics2D = simpleImage.NewGraphics2D();
                // clear the image to white
                simpleImageGraphics2D.Clear(RGBA_Bytes.White);
                // draw a circle
                simpleImageGraphics2D.Circle(50, 50, 30, RGBA_Bytes.Blue);
                // draw a line
                simpleImageGraphics2D.Line(10, 100, 520, 50, new RGBA_Bytes(20, 200, 200));
                // draw a filled box
                simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, RGBA_Bytes.Yellow);
                // and an outline around it
                simpleImageGraphics2D.Rectangle(60, 260, 200, 280, RGBA_Bytes.Magenta);
                // draw some text
                simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

                // and save this image out
                ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
            }

            // now we will we will show how to use the render function to draw more complex things
            {
                ImageBuffer lessSimpleImage           = new ImageBuffer(640, 480, 32, new BlenderBGRA());
                Graphics2D  lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
                // clear the image to white
                lessSimpleImageGraphics2D.Clear(RGBA_Bytes.White);
                // draw a circle
                Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
                for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
                {
                    VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
                    VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
                    lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, RGBA_Bytes.Yellow);
                    Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
                    lessSimpleImageGraphics2D.Render(ellipseOutline, RGBA_Bytes.Blue);
                }

                // and a little polygon
                PathStorage littlePoly = new PathStorage();
                littlePoly.MoveTo(50, 50);
                littlePoly.LineTo(150, 50);
                littlePoly.LineTo(200, 200);
                littlePoly.LineTo(50, 150);
                littlePoly.LineTo(50, 50);
                lessSimpleImageGraphics2D.Render(littlePoly, RGBA_Bytes.Cyan);

                // draw some text
                TypeFacePrinter textPrinter    = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
                IVertexSource   translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
                lessSimpleImageGraphics2D.Render(translatedText, RGBA_Bytes.Red);
                Stroke strokedText = new Stroke(translatedText);
                lessSimpleImageGraphics2D.Render(strokedText, RGBA_Bytes.Black);

                IVertexSource rotatedText           = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
                IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
                lessSimpleImageGraphics2D.Render(rotatedTranslatedText, RGBA_Bytes.Black);

                // and save this image out
                ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
            }
        }
Пример #42
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            RecalculateProjection();

            base.OnDraw(graphics2D);
        }
Пример #43
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            render_gpc(graphics2D);

            base.OnDraw(graphics2D);
        }
Пример #44
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;

            if (numMasksSlider.Value != sliderValue)
            {
                generate_alpha_mask(width, height);
                sliderValue = numMasksSlider.Value;
            }

            rasterizer.SetVectorClipBox(0, 0, width, height);

            unsafe
            {
                alphaMaskImageBuffer.AttachBuffer(alphaByteArray, 0, width, height, width, 8, 1);

                MatterHackers.Agg.Image.AlphaMaskAdaptor imageAlphaMaskAdaptor = new MatterHackers.Agg.Image.AlphaMaskAdaptor(widgetsSubImage, alphaMask);
                ImageClippingProxy alphaMaskClippingProxy = new ImageClippingProxy(imageAlphaMaskAdaptor);
                ImageClippingProxy clippingProxy          = new ImageClippingProxy(widgetsSubImage);

                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);

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

                ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
                // draw a background to show how the mask is working better
                int RectWidth = 30;
                for (int i = 0; i < 40; i++)
                {
                    for (int j = 0; j < 40; j++)
                    {
                        if ((i + j) % 2 != 0)
                        {
                            VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth, j * RectWidth, (i + 1) * RectWidth, (j + 1) * RectWidth, 0);
                            rect.normalize_radius();

                            // Drawing as an outline
                            rasterizer.add_path(rect);
                            scanlineRenderer.RenderSolid(clippingProxy, rasterizer, scanlineCache, new RGBA_Bytes(.9, .9, .9));
                        }
                    }
                }

                //int x, y;

                // Render the lion
                VertexSourceApplyTransform trans = new VertexSourceApplyTransform(lionShape.Path, transform);
                scanlineRenderer.RenderSolidAllPaths(alphaMaskClippingProxy, rasterizer, scanlineCache, trans, lionShape.Colors, lionShape.PathIndex, lionShape.NumPaths);

                /*
                 * // Render random Bresenham lines and markers
                 * agg::renderer_markers<amask_ren_type> m(r);
                 * for(i = 0; i < 50; i++)
                 * {
                 *      m.line_color(agg::rgba8(randGenerator.Next() & 0x7F,
                 *                                                      randGenerator.Next() & 0x7F,
                 *                                                      randGenerator.Next() & 0x7F,
                 *                                                      (randGenerator.Next() & 0x7F) + 0x7F));
                 *      m.fill_color(agg::rgba8(randGenerator.Next() & 0x7F,
                 *                                                      randGenerator.Next() & 0x7F,
                 *                                                      randGenerator.Next() & 0x7F,
                 *                                                      (randGenerator.Next() & 0x7F) + 0x7F));
                 *
                 *      m.line(m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height),
                 *                 m.coord(randGenerator.Next() % width), m.coord(randGenerator.Next() % height));
                 *
                 *      m.marker(randGenerator.Next() % width, randGenerator.Next() % height, randGenerator.Next() % 10 + 5,
                 *                       agg::marker_e(randGenerator.Next() % agg::end_of_markers));
                 * }
                 *
                 * // Render random anti-aliased lines
                 * double w = 5.0;
                 * agg::line_profile_aa profile;
                 * profile.width(w);
                 *
                 * typedef agg::renderer_outline_aa<amask_ren_type> renderer_type;
                 * renderer_type ren(r, profile);
                 *
                 * typedef agg::rasterizer_outline_aa<renderer_type> rasterizer_type;
                 * rasterizer_type ras(ren);
                 * ras.round_cap(true);
                 *
                 * for(i = 0; i < 50; i++)
                 * {
                 *      ren.Color = agg::rgba8(randGenerator.Next() & 0x7F,
                 *                                               randGenerator.Next() & 0x7F,
                 *                                               randGenerator.Next() & 0x7F,
                 *                                               //255));
                 *                                               (randGenerator.Next() & 0x7F) + 0x7F);
                 *      ras.move_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                 *      ras.line_to_d(randGenerator.Next() % width, randGenerator.Next() % height);
                 *      ras.render(false);
                 * }
                 *
                 * // Render random circles with gradient
                 * typedef agg::gradient_linear_color<color_type> grad_color;
                 * typedef agg::gradient_circle grad_func;
                 * typedef agg::span_interpolator_linear<> interpolator_type;
                 * typedef agg::span_gradient<color_type,
                 *                                                interpolator_type,
                 *                                                grad_func,
                 *                                                grad_color> span_grad_type;
                 *
                 * agg::trans_affine grm;
                 * grad_func grf;
                 * grad_color grc(agg::rgba8(0,0,0), agg::rgba8(0,0,0));
                 * agg::ellipse ell;
                 * agg::span_allocator<color_type> sa;
                 * interpolator_type inter(grm);
                 * span_grad_type sg(inter, grf, grc, 0, 10);
                 * agg::renderer_scanline_aa<amask_ren_type,
                 *                                                agg::span_allocator<color_type>,
                 *                                                span_grad_type> rg(r, sa, sg);
                 * for(i = 0; i < 50; i++)
                 * {
                 *      x = randGenerator.Next() % width;
                 *      y = randGenerator.Next() % height;
                 *      double r = randGenerator.Next() % 10 + 5;
                 *      grm.reset();
                 *      grm *= agg::trans_affine_scaling(r / 10.0);
                 *      grm *= agg::trans_affine_translation(x, y);
                 *      grm.invert();
                 *      grc.colors(agg::rgba8(255, 255, 255, 0),
                 *                         agg::rgba8(randGenerator.Next() & 0x7F,
                 *                                                randGenerator.Next() & 0x7F,
                 *                                                randGenerator.Next() & 0x7F,
                 *                                                255));
                 *      sg.color_function(grc);
                 *      ell.init(x, y, r, r, 32);
                 *      g_rasterizer.add_path(ell);
                 *      agg::render_scanlines(g_rasterizer, g_scanline, rg);
                 * }
                 */

                //m_num_cb.Render(g_rasterizer, g_scanline, clippingProxy);
            }
            alphaMaskImageBuffer.DettachBuffer();
            base.OnDraw(graphics2D);
        }
Пример #45
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (firstDraw)
			{
				ClearBedAndLoadPrintItemWrapper(printItemWrapper);
				firstDraw = false;
			}

			if (HaveSelection)
			{
				upArrow.SetPosition();
				heightDisplay.SetPosition();
			}

			hasDrawn = true;
			base.OnDraw(graphics2D);
			DrawStuffForSelectedPart(graphics2D);
		}
Пример #46
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 ColorF(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
                    //
                    foreach (var shape in lionShape.Shapes)
                    {
                        g_rasterizer.add_path(new VertexSourceApplyTransform(shape.VertexStorage, tr));
                        scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color);
                    }
                    //--------------------------

                    //--------------------------
                    // 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 Color(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.add_path(trans_ell_stroke);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(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
                    foreach (var shape in lionShape.Shapes)
                    {
                        VertexSourceApplyTransform trans = new VertexSourceApplyTransform(shape.VertexStorage, tr);
                        g_rasterizer.reset();
                        g_rasterizer.add_path(trans);
                        scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, shape.Color);
                    }

                    // 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 Color(0.5, 0.3, 0.0, 0.3));

                    g_rasterizer.add_path(TransformedEllipesOutline);
                    scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(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 Color(0, 0.3, 0.5, 0.6));
            //m_trans_type.Render(g_rasterizer, g_scanline, clippingProxy);
            base.OnDraw(graphics2D);
        }
Пример #47
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            if (this.showHoverText == true && this.Text != hoverHelpMessage)
            {
                this.Text = hoverHelpMessage;
            }
            else
            {
                if (this.Text != defaultHelpMessage)
                {
                    this.Text = defaultHelpMessage;
                }
            }

            base.OnDraw(graphics2D);
        }
Пример #48
0
 public override void OnDraw(Graphics2D graphics2D)
 {
     graphics2D.Line(Width / 2, 0, Width / 2, Height, RGBA_Bytes.Red);
     graphics2D.Line(0, Height / 2, Width, Height / 2, RGBA_Bytes.Red);
     base.OnDraw(graphics2D);
 }
Пример #49
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			if (this.libraryDataView.EditMode && !this.IsViewHelperItem)
			{
				this.selectionCheckBox.Checked = this.IsSelectedItem;
				selectionCheckBoxContainer.Visible = true;
				rightButtonOverlay.Visible = false;
			}
			else
			{
				selectionCheckBoxContainer.Visible = false;
			}

			base.OnDraw(graphics2D);

			if (this.IsSelectedItem && !this.IsViewHelperItem)
			{
				this.BackgroundColor = ActiveTheme.Instance.PrimaryAccentColor;
				this.partLabel.TextColor = RGBA_Bytes.White;
				this.selectionCheckBox.TextColor = RGBA_Bytes.White;
			}
			else if (this.IsHoverItem)
			{
				RectangleDouble Bounds = LocalBounds;
				RoundedRect rectBorder = new RoundedRect(Bounds, 0);

				this.BackgroundColor = RGBA_Bytes.White;
				this.partLabel.TextColor = RGBA_Bytes.Black;
				this.selectionCheckBox.TextColor = RGBA_Bytes.Black;

				graphics2D.Render(new Stroke(rectBorder, 3), ActiveTheme.Instance.SecondaryAccentColor);
			}
			else
			{
				this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 255);
				this.partLabel.TextColor = RGBA_Bytes.Black;
				this.selectionCheckBox.TextColor = RGBA_Bytes.Black;
			}
		}
Пример #50
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            this.NewGraphics2D().Clear(new RGBA_Bytes(255, 255, 255));

            base.OnDraw(graphics2D);
        }