private void DEBUG_saveImageBuffer(ImageBuffer buf) { int hash = 0; var bounds = buf.GetBounds(); System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(bounds.Width, bounds.Height, PixelFormat.Format32bppArgb); for (int x = 0; x < bounds.Width; x++) { for (int y = 0; y < bounds.Height; y++) { var pcolor = buf.GetPixel(x, y); var wcolor = Color.FromArgb(pcolor.alpha, pcolor.red, pcolor.green, pcolor.green); hash += wcolor.ToArgb() ^ 0x1f2f019f; hash <<= 1; bitmap.SetPixel(x, y, wcolor); } } string filename = String.Format(@"C:\tmp\masktest-{0}.bmp", hash); if (!System.IO.File.Exists(filename)) { bitmap.Save(filename, ImageFormat.Bmp); } }
public Button Generate(string normalImageName, string hoverImageName, string pressedImageName = null, string disabledImageName = null) { if (pressedImageName == null) { pressedImageName = hoverImageName; } if (disabledImageName == null) { disabledImageName = normalImageName; } ImageBuffer normalImage = StaticData.Instance.LoadIcon(normalImageName); ImageBuffer pressedImage = StaticData.Instance.LoadIcon(pressedImageName); ImageBuffer hoverImage = StaticData.Instance.LoadIcon(hoverImageName); ImageBuffer disabledImage = StaticData.Instance.LoadIcon(disabledImageName); if (!ActiveTheme.Instance.IsDarkTheme && invertImageColor) { InvertLightness.DoInvertLightness(normalImage); InvertLightness.DoInvertLightness(pressedImage); InvertLightness.DoInvertLightness(hoverImage); InvertLightness.DoInvertLightness(disabledImage); } if (ActiveTheme.Instance.IsTouchScreen) { //normalImage.NewGraphics2D().Line(0, 0, normalImage.Width, normalImage.Height, RGBA_Bytes.Violet); RoundedRect rect = new RoundedRect(pressedImage.GetBounds(), 0); pressedImage.NewGraphics2D().Render(new Stroke(rect, 3), ActiveTheme.Instance.PrimaryTextColor); } ButtonViewStates buttonViewWidget = new ButtonViewStates( new ImageWidget(normalImage), new ImageWidget(hoverImage), new ImageWidget(pressedImage), new ImageWidget(disabledImage) ); //Create button based on view container widget Button imageButton = new Button(0, 0, buttonViewWidget); imageButton.Margin = new BorderDouble(0); imageButton.Padding = new BorderDouble(0); return(imageButton); }
public FloodFillDemo() { BackgroundColor = RGBA_Bytes.White; imageToFillOn = new ImageBuffer(400, 300, 32, new BlenderBGRA()); Graphics2D imageToFillGraphics = imageToFillOn.NewGraphics2D(); imageToFillGraphics.Clear(RGBA_Bytes.White); imageToFillGraphics.DrawString("Click to fill", 20, 30); imageToFillGraphics.Circle(new Vector2(200, 150), 35, RGBA_Bytes.Black); imageToFillGraphics.Circle(new Vector2(200, 150), 30, RGBA_Bytes.Green); imageToFillGraphics.Rectangle(20, 50, 210, 280, RGBA_Bytes.Black); imageToFillGraphics.Rectangle(imageToFillOn.GetBounds(), RGBA_Bytes.Blue); Random rand = new Random(); for (int i = 0; i < 20; i++) { Ellipse elipse = new Ellipse(rand.Next(imageToFillOn.Width), rand.Next(imageToFillOn.Height), rand.Next(10, 60), rand.Next(10, 60)); Stroke outline = new Stroke(elipse); imageToFillGraphics.Render(outline, RGBA_Bytes.Black); } m_slider1 = new Slider(new Vector2(80, 10), 510); m_slider2 = new Slider(new Vector2(80, 10 + 20), 510); m_slider1.ValueChanged += new EventHandler(NeedsRedraw); m_slider2.ValueChanged += new EventHandler(NeedsRedraw); AddChild(m_slider1); AddChild(m_slider2); m_slider1.Text = "Pixel size={0:F3}"; m_slider1.SetRange(8, 100); m_slider1.NumTicks = 23; m_slider1.Value = 32; m_slider2.Text = "gamma={0:F3}"; m_slider2.SetRange(0.0, 3.0); m_slider2.Value = 1.0; }
private void GenerateToolLimitsTexture(PrinterConfig printer, int toolIndex, ImageBuffer bedplateImage) { var xScale = bedplateImage.Width / printer.Settings.BedBounds.Width; var yScale = bedplateImage.Height / printer.Settings.BedBounds.Height; int alpha = 80; var graphics = bedplateImage.NewGraphics2D(); RectangleDouble toolBounds; if (toolIndex == 2) { var tool0Bounds = printer.Settings.ToolBounds[0]; var tool1Bounds = printer.Settings.ToolBounds[1]; tool0Bounds.IntersectWithRectangle(tool1Bounds); toolBounds = tool0Bounds; } else { toolBounds = printer.Settings.ToolBounds[toolIndex]; } // move relative to the texture origin, move to the bed lower left position var bedBounds = printer.Settings.BedBounds; toolBounds.Offset(-bedBounds.Left, -bedBounds.Bottom); // Scale toolBounds into textures units toolBounds = new RectangleDouble( toolBounds.Left * xScale, toolBounds.Bottom * yScale, toolBounds.Right * xScale, toolBounds.Top * yScale); var imageBounds = bedplateImage.GetBounds(); var dimRegion = new VertexStorage(); dimRegion.MoveTo(imageBounds.Left, imageBounds.Bottom); dimRegion.LineTo(imageBounds.Right, imageBounds.Bottom); dimRegion.LineTo(imageBounds.Right, imageBounds.Top); dimRegion.LineTo(imageBounds.Left, imageBounds.Top); var targetRect = new VertexStorage(); targetRect.MoveTo(toolBounds.Right, toolBounds.Bottom); targetRect.LineTo(toolBounds.Left, toolBounds.Bottom); targetRect.LineTo(toolBounds.Left, toolBounds.Top); targetRect.LineTo(toolBounds.Right, toolBounds.Top); targetRect.ClosePolygon(); var overlayMinusTargetRect = new CombinePaths(dimRegion, targetRect); graphics.Render(overlayMinusTargetRect, new Color(Color.Black, alpha)); string toolTitle = string.Format("{0} {1}", "Tool ".Localize(), toolIndex + 1); if (toolIndex == 2) { toolTitle = "Tools ".Localize() + "1 & 2"; } var stringPrinter = new TypeFacePrinter(toolTitle, theme.DefaultFontSize, bold: true); var printerBounds = stringPrinter.GetBounds(); int textPadding = 8; var textBounds = printerBounds; textBounds.Inflate(textPadding); var cornerRect = new RectangleDouble(toolBounds.Right - textBounds.Width, toolBounds.Top - textBounds.Height, toolBounds.Right, toolBounds.Top); graphics.Render( new RoundedRectShape(cornerRect, bottomLeftRadius: 6), theme.PrimaryAccentColor); graphics.DrawString( toolTitle, toolBounds.Right - textPadding, cornerRect.Bottom + (cornerRect.Height / 2 - printerBounds.Height / 2) + 1, theme.DefaultFontSize, justification: Justification.Right, baseline: Baseline.Text, color: Color.White, bold: true); graphics.Render(new Stroke(targetRect, 1), theme.PrimaryAccentColor); }