Exemple #1
0
        public static ImageBuffer LoadImageFromDisk(string stlHashCode)
        {
            try
            {
                ImageBuffer tempImage     = new ImageBuffer(BigRenderSize.x, BigRenderSize.y);
                string      imageFileName = GetImageFileName(stlHashCode);

                if (File.Exists(imageFileName))
                {
                    if (partExtension == ".png")
                    {
                        if (ImageIO.LoadImageData(imageFileName, tempImage))
                        {
                            return(tempImage);
                        }
                    }
                    else
                    {
                        if (ImageTgaIO.LoadImageData(tempImage, imageFileName))
                        {
                            return(tempImage);
                        }
                    }
                }
            }
            catch
            {
            }

            return(null);
        }
Exemple #2
0
        public PanelSeparator()
            : base(4, 1)
        {
            AddHandlers();

            defaultBackgroundColor = new RGBA_Bytes(200, 200, 200);
            hoverBackgroundColor   = new RGBA_Bytes(100, 100, 100);

            Agg.Image.ImageBuffer arrowImage = new Agg.Image.ImageBuffer();
            ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "icon_arrow_left_16x16.png"), arrowImage);
            arrowIndicator         = new ImageWidget(arrowImage);
            arrowIndicator.HAnchor = Agg.UI.HAnchor.ParentCenter;
            arrowIndicator.VAnchor = Agg.UI.VAnchor.ParentCenter;
            arrowIndicator.Visible = true;

            this.AddChild(arrowIndicator);

            this.Hidden          = false;
            this.BackgroundColor = defaultBackgroundColor;
            this.VAnchor         = VAnchor.ParentBottomTop;
            this.Margin          = new BorderDouble(8, 0);
            this.Cursor          = Cursors.Hand;

            SetDisplayState();
        }
        public RadioButton GenerateRadioButton(string label, string iconImageName = null)
        {
            ImageBuffer iconImage = null;

            if (iconImageName != null)
            {
                iconImage = new ImageBuffer();
                ImageIO.LoadImageData(this.GetImageLocation(iconImageName), iconImage);
                if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
                {
                    InvertLightness.DoInvertLightness(iconImage);
                }
            }

            BorderDouble          internalMargin           = new BorderDouble(0);
            TextImageWidget       nomalState               = new TextImageWidget(label, normalFillColor, normalBorderColor, normalTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
            TextImageWidget       hoverState               = new TextImageWidget(label, hoverFillColor, hoverBorderColor, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
            TextImageWidget       checkingState            = new TextImageWidget(label, hoverFillColor, RGBA_Bytes.White, hoverTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
            TextImageWidget       checkedState             = new TextImageWidget(label, pressedFillColor, RGBA_Bytes.White, pressedTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
            TextImageWidget       disabledState            = new TextImageWidget(label, disabledFillColor, disabledBorderColor, disabledTextColor, borderWidth, internalMargin, iconImage, flowDirection: flowDirection, fontSize: this.fontSize, height: this.FixedHeight, width: this.FixedWidth, centerText: true);
            RadioButtonViewStates checkBoxButtonViewWidget = new RadioButtonViewStates(nomalState, hoverState, checkingState, checkedState, disabledState);
            RadioButton           radioButton              = new RadioButton(checkBoxButtonViewWidget);

            radioButton.Margin = Margin;
            return(radioButton);
        }
        void client_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            byte[]      raw           = e.Result;
            Stream      stream        = new MemoryStream(raw);
            ImageBuffer unScaledImage = new ImageBuffer(10, 10, 32, new BlenderBGRA());

            ImageIO.LoadImageData(stream, unScaledImage);
            // If the source image (the one we downloaded) is more than twice as big as our dest image.
            while (unScaledImage.Width > Image.Width * 2)
            {
                // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
                // So we scale as many times as we need to to get the Image to be the right size.
                // If this were going to be a non-uniform scale we could do the x and y separatly to get better results.
                ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
                halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
                unScaledImage = halfImage;
            }
            Image.NewGraphics2D().Render(unScaledImage, 0, 0, 0, Image.Width / (double)unScaledImage.Width, Image.Height / (double)unScaledImage.Height);
            Image.MarkImageChanged();
            Invalidate();

            if (LoadComplete != null)
            {
                LoadComplete(this, null);
            }
        }
        public ImageLinkAdvancedX(string url)
        {
            HAnchor  = HAnchor.Fit;
            VAnchor  = VAnchor.Fit;
            this.Url = url;

            var imageBuffer = new ImageBuffer(icon);
            var imageWidget = new ImageWidget(imageBuffer);

            this.AddChild(imageWidget);

            try
            {
                if (url.StartsWith("http"))
                {
                    client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead).ContinueWith(task =>
                    {
                        var response = task.Result;

                        if (response.IsSuccessStatusCode)
                        {
                            response.Content.ReadAsStreamAsync().ContinueWith(streamTask =>
                            {
                                // response.Headers.TryGetValues("", s[""] == "" ||
                                if (string.Equals(Path.GetExtension(url), ".svg", StringComparison.OrdinalIgnoreCase))
                                {
                                    // Load svg into SvgWidget, swap for ImageWidget
                                    try
                                    {
                                        var svgWidget = new SvgWidget(streamTask.Result, 1)
                                        {
                                            Border      = 1,
                                            BorderColor = Color.YellowGreen
                                        };

                                        this.ReplaceChild(imageWidget, svgWidget);
                                    }
                                    catch (Exception svgEx)
                                    {
                                        Debug.WriteLine("Error loading svg: {0} :: {1}", url, svgEx.Message);
                                    }
                                }
                                else
                                {
                                    // Load img
                                    if (!ImageIO.LoadImageData(streamTask.Result, imageBuffer))
                                    {
                                        Debug.WriteLine("Error loading image: " + url);
                                    }
                                }
                            });
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemple #6
0
        private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode, Point2D size)
        {
            ImageBuffer tempImage     = new ImageBuffer(size.x, size.y, 32, new BlenderBGRA());
            string      imageFileName = GetFilenameForSize(stlHashCode, size);

            if (File.Exists(imageFileName))
            {
                if (partExtension == ".png")
                {
                    if (ImageIO.LoadImageData(imageFileName, tempImage))
                    {
                        return(tempImage);
                    }
                }
                else
                {
                    if (ImageTgaIO.LoadImageData(imageFileName, tempImage))
                    {
                        return(tempImage);
                    }
                }
            }

            return(null);
        }
Exemple #7
0
        public image1Widget()
        {
            AnchorAll();
            string img_name = "spheres.bmp";

            if (!ImageIO.LoadImageData(img_name, sourceImage))
            {
                string buf;
                buf = "File not found: "
                      + img_name
                      + ".bmp"
                      + ". Download http://www.antigrain.com/" + img_name + ".bmp" + "\n"
                      + "or copy it from another directory if available.";
                MessageBox.ShowMessageBox(buf, "Missing Files");
            }
            else
            {
                WindowSize.x = sourceImage.Width + 20;
                WindowSize.y = sourceImage.Height + 40 + 20;
            }

            drawAngle = new MatterHackers.Agg.UI.Slider(new Vector2(5, 5 + 15), new Vector2(295, 7));
            drawScale = new MatterHackers.Agg.UI.Slider(new Vector2(5, 5 + 55), new Vector2(295, 7));
            drawAngle.ValueChanged += new EventHandler(NeedsRedraw);
            drawScale.ValueChanged += new EventHandler(NeedsRedraw);

            AddChild(drawAngle);
            AddChild(drawScale);
            //drawAngle.Text = "Angle={0:F2}";
            //drawScale.Text = "Scale={0:F2}";
            drawAngle.SetRange(-180.0, 180.0);
            drawAngle.Value = 0.0;
            drawScale.SetRange(0.1, 5.0);
            drawScale.Value = 1.0;
        }
Exemple #8
0
        private FlowLayoutWidget GetEEPromControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(0, 4);


            TextWidget notificationSettingsLabel = new TextWidget("EEProm Settings");

            notificationSettingsLabel.AutoExpandBoundsToText = true;
            notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            notificationSettingsLabel.VAnchor   = VAnchor.ParentCenter;


            Agg.Image.ImageBuffer eePromImage = new Agg.Image.ImageBuffer();
            ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), eePromImage);
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(eePromImage);
            }
            ImageWidget eePromIcon = new ImageWidget(eePromImage);

            eePromIcon.Margin = new BorderDouble(right: 6);

            configureEePromButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper());

            //buttonRow.AddChild(eePromIcon);
            buttonRow.AddChild(notificationSettingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(configureEePromButton);

            return(buttonRow);
        }
Exemple #9
0
        private double PrintTopOfPage(ImageBuffer plateInventoryImage, Graphics2D plateGraphics)
        {
            plateGraphics.Clear(RGBA_Bytes.White);

            double currentlyPrintingHeightPixels = plateInventoryImage.Height - PageMarginMM.Top * PixelPerMM;

            string logoPathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "PartSheetLogo.png");

            if (File.Exists(logoPathAndFile))
            {
                ImageBuffer logoImage = new ImageBuffer();
                ImageIO.LoadImageData(logoPathAndFile, logoImage);
                currentlyPrintingHeightPixels -= logoImage.Height;
                plateGraphics.Render(logoImage, (plateInventoryImage.Width - logoImage.Width) / 2, currentlyPrintingHeightPixels);
            }

            currentlyPrintingHeightPixels -= PartPaddingPixels;

            double          underlineHeightMM = 1;
            RectangleDouble lineBounds        = new RectangleDouble(0, 0, plateInventoryImage.Width - PageMarginPixels.Left * 2, underlineHeightMM * PixelPerMM);

            lineBounds.Offset(PageMarginPixels.Left, currentlyPrintingHeightPixels - lineBounds.Height);
            plateGraphics.FillRectangle(lineBounds, RGBA_Bytes.Black);

            return(currentlyPrintingHeightPixels - (lineBounds.Height + PartPaddingPixels));
        }
        private static ImageBuffer LoadImageFromDisk(PartThumbnailWidget thumbnailWidget, string stlHashCode)
        {
            ImageBuffer tempImage     = new ImageBuffer(BigRenderSize.x, BigRenderSize.y);
            string      imageFileName = GetImageFileName(stlHashCode);

            if (File.Exists(imageFileName))
            {
                if (partExtension == ".png")
                {
                    if (ImageIO.LoadImageData(imageFileName, tempImage))
                    {
                        return(tempImage);
                    }
                }
                else
                {
                    if (ImageTgaIO.LoadImageData(imageFileName, tempImage))
                    {
                        return(tempImage);
                    }
                }
            }

            return(null);
        }
Exemple #11
0
        ImageBuffer LoadImage(string imageName)
        {
            string      path   = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
            ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());

            ImageIO.LoadImageData(path, buffer);
            return(buffer);
        }
        ImageBuffer LoadUpButtonImage(string imageName)
        {
            string      path   = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, imageName);
            ImageBuffer buffer = new ImageBuffer(10, 10, 32, new BlenderBGRA());

            ImageIO.LoadImageData(path, buffer);

            if (!ActiveTheme.Instance.IsDarkTheme && AllowThemeToAdjustImage)
            {
                InvertLightness.DoInvertLightness(buffer);
            }
            return(buffer);
        }
Exemple #13
0
        public override void OnParentChanged(EventArgs e)
        {
            AnchorAll();

            string img_name = "spheres.bmp";

            if (!ImageIO.LoadImageData(img_name, image_resample.m_SourceImage))
            {
                string buf;
                buf = "File not found: "
                      + img_name
                      + ".bmp"
                      + ". Download http://www.antigrain.com/" + img_name + ".bmp" + "\n"
                      + "or copy it from another directory if available.";
                throw new NotImplementedException(buf);
            }
            else
            {
                if (image_resample.m_SourceImage.BitDepth != 32)
                {
                    throw new Exception("we are expecting 32 bit source.");
                }
                // give the image some alpha. [4/6/2009 lbrubaker]
                ImageBuffer image32 = new ImageBuffer(image_resample.m_SourceImage.Width, image_resample.m_SourceImage.Height, 32, new BlenderBGRA());
                int         offset;
                byte[]      source = image_resample.m_SourceImage.GetBuffer(out offset);
                byte[]      dest   = image32.GetBuffer(out offset);
                for (int y = 0; y < image32.Height; y++)
                {
                    for (int x = 0; x < image32.Width; x++)
                    {
                        int i = y * image32.Width + x;
                        dest[i * 4 + 0] = source[i * 4 + 0];
                        dest[i * 4 + 1] = source[i * 4 + 1];
                        dest[i * 4 + 2] = source[i * 4 + 2];
                        Vector2 pixel  = new Vector2(x, y);
                        Vector2 center = new Vector2(image32.Width / 2, image32.Height / 2);
                        Vector2 delta  = pixel - center;
                        int     length = (int)Math.Min(delta.Length * 3, 255);
                        dest[i * 4 + 3] = (byte)length;
                    }
                }
                // and set our new image with alpha
                image_resample.m_SourceImage = image32;
                //image_resample_application.m_SourceImage.SetBlender(new BlenderBGR());
            }

            base.OnParentChanged(e);
        }
        private ImageBuffer LoadImageFromSourceFolder(string imageName)
        {
            string pathToImage = Path.Combine(imageDirectory, imageName);

            if (File.Exists(pathToImage))
            {
                ImageBuffer imageToLookFor = new ImageBuffer();

                if (ImageIO.LoadImageData(pathToImage, imageToLookFor))
                {
                    return(imageToLookFor);
                }
            }

            return(null);
        }
        protected void PutOemImageOnBed()
        {
            // this is to add an image to the bed
            string imagePathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "bedimage.png");

            if (autoRotateEnabled && File.Exists(imagePathAndFile))
            {
                ImageBuffer wattermarkImage = new ImageBuffer();
                ImageIO.LoadImageData(imagePathAndFile, wattermarkImage);

                ImageBuffer bedImage    = meshViewerWidget.BedImage;
                Graphics2D  bedGraphics = bedImage.NewGraphics2D();
                bedGraphics.Render(wattermarkImage,
                                   new Vector2((bedImage.Width - wattermarkImage.Width) / 2, (bedImage.Height - wattermarkImage.Height) / 2));
            }
        }
        public Button Generate(string normalImageName, string hoverImageName, string pressedImageName = null, string disabledImageName = null)
        {
            if (pressedImageName == null)
            {
                pressedImageName = hoverImageName;
            }

            if (disabledImageName == null)
            {
                disabledImageName = normalImageName;
            }

            Agg.Image.ImageBuffer normalImage   = new Agg.Image.ImageBuffer();
            Agg.Image.ImageBuffer pressedImage  = new Agg.Image.ImageBuffer();
            Agg.Image.ImageBuffer hoverImage    = new Agg.Image.ImageBuffer();
            Agg.Image.ImageBuffer disabledImage = new Agg.Image.ImageBuffer();

            ImageIO.LoadImageData(this.GetImageLocation(normalImageName), normalImage);
            ImageIO.LoadImageData(this.GetImageLocation(pressedImageName), pressedImage);
            ImageIO.LoadImageData(this.GetImageLocation(hoverImageName), hoverImage);
            ImageIO.LoadImageData(this.GetImageLocation(disabledImageName), disabledImage);

            if (!ActiveTheme.Instance.IsDarkTheme && invertImageColor)
            {
                InvertLightness.DoInvertLightness(normalImage);
                InvertLightness.DoInvertLightness(pressedImage);
                InvertLightness.DoInvertLightness(hoverImage);
                InvertLightness.DoInvertLightness(disabledImage);
            }

            //normalImage.NewGraphics2D().Line(0, 0, normalImage.Width, normalImage.Height, RGBA_Bytes.Violet);
            //pressedImage.NewGraphics2D().Line(0, 0, normalImage.Width, normalImage.Height, RGBA_Bytes.Violet);

            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);
        }
        private void AddTerminalControls(FlowLayoutWidget controlsTopToBottomLayout)
        {
            GroupBox terminalControlsContainer;

            terminalControlsContainer = new GroupBox(LocalizedString.Get("Communications"));

            terminalControlsContainer.Margin      = new BorderDouble(0);
            terminalControlsContainer.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            terminalControlsContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            terminalControlsContainer.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            terminalControlsContainer.Height      = 68;

            OutputScrollWindow.HookupPrinterOutput();

            {
                FlowLayoutWidget buttonBar = new FlowLayoutWidget();
                buttonBar.HAnchor |= HAnchor.ParentCenter;
                buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                buttonBar.Margin   = new BorderDouble(3, 0, 3, 6);
                buttonBar.Padding  = new BorderDouble(0);

                this.textImageButtonFactory.FixedHeight = TallButtonHeight;

                Agg.Image.ImageBuffer terminalImage = new Agg.Image.ImageBuffer();
                ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "terminal-24x24.png"), terminalImage);
                ImageWidget terminalIcon = new ImageWidget(terminalImage);
                terminalIcon.Margin = new BorderDouble(right: 6);

                Button showTerminal = textImageButtonFactory.Generate("Show Terminal".Localize().ToUpper());
                showTerminal.Margin = new BorderDouble(0);
                showTerminal.Click += (sender, e) =>
                {
                    OutputScrollWindow.Show();
                };

                //buttonBar.AddChild(terminalIcon);
                buttonBar.AddChild(showTerminal);

                terminalControlsContainer.AddChild(buttonBar);
            }

            terminalCommunicationsContainer = new DisableableWidget();
            terminalCommunicationsContainer.AddChild(terminalControlsContainer);

            controlsTopToBottomLayout.AddChild(terminalCommunicationsContainer);
        }
        private async Task <ImageBuffer> LoadImage(ILibraryItem item)
        {
            // Load the image at its native size, let the caller scale or resize
            if (item is ILibraryAssetStream streamInterface)
            {
                using (var streamAndLength = await streamInterface.GetStream(null))
                {
                    var imageBuffer = new ImageBuffer();
                    if (ImageIO.LoadImageData(streamAndLength.Stream, imageBuffer))
                    {
                        imageBuffer.SetRecieveBlender(new BlenderPreMultBGRA());
                        return(imageBuffer);
                    }
                }
            }

            return(null);
        }
Exemple #19
0
        public PartThumbnailWidget(PrintItemWrapper item, string noThumbnailFileName, string buildingThumbnailFileName, ImageSizes size)
        {
            this.PrintItem = item;

            // Set Display Attributes
            this.Margin  = new BorderDouble(0);
            this.Padding = new BorderDouble(5);
            Size         = size;
            switch (size)
            {
            case ImageSizes.Size50x50:
                this.Width       = 50;
                this.Height      = 50;
                this.MinimumSize = new Vector2(50, 50);
                break;

            case ImageSizes.Size115x115:
                this.Width       = 115;
                this.Height      = 115;
                this.MinimumSize = new Vector2(115, 115);
                break;

            default:
                throw new NotImplementedException();
            }

            this.BackgroundColor = normalBackgroundColor;
            this.Cursor          = Cursors.Hand;

            // set background images
            if (noThumbnailImage.Width == 0)
            {
                ImageIO.LoadImageData(this.GetImageLocation(noThumbnailFileName), noThumbnailImage);
                ImageIO.LoadImageData(this.GetImageLocation(buildingThumbnailFileName), buildingThumbnailImage);
            }
            this.tumbnailImage = new ImageBuffer(buildingThumbnailImage);

            // Add Handlers
            this.Click            += new ButtonEventHandler(onMouseClick);
            this.MouseEnterBounds += new EventHandler(onEnter);
            this.MouseLeaveBounds += new EventHandler(onExit);
            ActiveTheme.Instance.ThemeChanged.RegisterEvent(onThemeChanged, ref unregisterEvents);
        }
Exemple #20
0
        private void AddWatermark()
        {
            string imagePathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "watermark.png");

            if (File.Exists(imagePathAndFile))
            {
                ImageBuffer wattermarkImage = new ImageBuffer();
                ImageIO.LoadImageData(imagePathAndFile, wattermarkImage);
                //if (!ActiveTheme.Instance.IsDarkTheme)
                //{
                //    InvertLightness.DoInvertLightness(wattermarkImage);
                //}

                GuiWidget watermarkWidget = new ImageWidget(wattermarkImage);
                watermarkWidget.VAnchor = Agg.UI.VAnchor.ParentCenter;
                watermarkWidget.HAnchor = Agg.UI.HAnchor.ParentCenter;
                this.AddChildToBackground(watermarkWidget);
            }
        }
 static line_patterns_application()
 {
     if (!ImageIO.LoadImageData("1.bmp", line_patterns_application.rbuf_img0) ||
         !ImageIO.LoadImageData("2.bmp", line_patterns_application.rbuf_img1) ||
         !ImageIO.LoadImageData("3.bmp", line_patterns_application.rbuf_img2) ||
         !ImageIO.LoadImageData("4.bmp", line_patterns_application.rbuf_img3) ||
         !ImageIO.LoadImageData("5.bmp", line_patterns_application.rbuf_img4) ||
         !ImageIO.LoadImageData("6.bmp", line_patterns_application.rbuf_img5) ||
         !ImageIO.LoadImageData("7.bmp", line_patterns_application.rbuf_img6) ||
         !ImageIO.LoadImageData("8.bmp", line_patterns_application.rbuf_img7) ||
         !ImageIO.LoadImageData("9.bmp", line_patterns_application.rbuf_img8))
     {
         String buf = "There must be files 1%s...9%s\n"
                      + "Download and unzip:\n"
                      + "http://www.antigrain.com/line_patterns.bmp.zip\n"
                      + "or\n"
                      + "http://www.antigrain.com/line_patterns.ppm.tar.gz\n";
         throw new System.Exception(buf);
     }
 }
Exemple #22
0
        private FlowLayoutWidget GetNotificationControls()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor |= HAnchor.ParentLeftRight;
            buttonRow.VAnchor |= Agg.UI.VAnchor.ParentCenter;
            buttonRow.Margin   = new BorderDouble(0, 0, 0, 0);
            buttonRow.Padding  = new BorderDouble(0);

            this.textImageButtonFactory.FixedHeight = TallButtonHeight;

            Agg.Image.ImageBuffer notificationSettingsImage = new Agg.Image.ImageBuffer();
            ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "notify-24x24.png"), notificationSettingsImage);
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(notificationSettingsImage);
            }

            ImageWidget levelingIcon = new ImageWidget(notificationSettingsImage);

            levelingIcon.Margin = new BorderDouble(right: 6, bottom: 6);

            configureNotificationSettingsButton         = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
            configureNotificationSettingsButton.Margin  = new BorderDouble(left: 6);
            configureNotificationSettingsButton.VAnchor = VAnchor.ParentCenter;
            configureNotificationSettingsButton.Click  += new EventHandler(configureNotificationSettingsButton_Click);

            notificationSettingsLabel = new TextWidget(LocalizedString.Get("Notification Settings"));
            notificationSettingsLabel.AutoExpandBoundsToText = true;
            notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            notificationSettingsLabel.VAnchor   = VAnchor.ParentCenter;

            buttonRow.AddChild(levelingIcon);
            buttonRow.AddChild(notificationSettingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(configureNotificationSettingsButton);
            return(buttonRow);
        }
        private GuiWidget CreatePrintLevelingControlsContainer()
        {
            Button   editButton;
            GroupBox printLevelingControlsContainer = new GroupBox(textImageButtonFactory.GenerateGroupBoxLabelWithEdit(LocalizedString.Get("Automatic Calibration"), out editButton));

            editButton.Click += (sender, e) =>
            {
                if (editLevelingSettingsWindow == null)
                {
                    editLevelingSettingsWindow         = new EditLevelingSettingsWindow();
                    editLevelingSettingsWindow.Closed += (popupWindowSender, popupWindowSenderE) => { editLevelingSettingsWindow = null; };
                }
                else
                {
                    editLevelingSettingsWindow.BringToFront();
                }
            };

            printLevelingControlsContainer.Margin      = new BorderDouble(0);
            printLevelingControlsContainer.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingControlsContainer.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            printLevelingControlsContainer.Height      = 68;

            {
                FlowLayoutWidget buttonBar = new FlowLayoutWidget();
                buttonBar.HAnchor |= HAnchor.ParentLeftRight;
                buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                buttonBar.Margin   = new BorderDouble(0, 0, 0, 0);
                buttonBar.Padding  = new BorderDouble(0);

                this.textImageButtonFactory.FixedHeight = TallButtonHeight;

                Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
                runPrintLevelingButton.Margin  = new BorderDouble(left: 6);
                runPrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                runPrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(runPrintLeveling_Click);

                Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer();
                ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage);
                if (!ActiveTheme.Instance.IsDarkTheme)
                {
                    InvertLightness.DoInvertLightness(levelingImage);
                }

                ImageWidget levelingIcon = new ImageWidget(levelingImage);
                levelingIcon.Margin = new BorderDouble(right: 6);

                enablePrintLevelingButton         = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
                enablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
                enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                enablePrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(enablePrintLeveling_Click);

                disablePrintLevelingButton         = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
                disablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
                disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
                disablePrintLevelingButton.Click  += new ButtonBase.ButtonEventHandler(disablePrintLeveling_Click);

                CheckBox doLevelingCheckBox = new CheckBox(LocalizedString.Get("Enable Automatic Print Leveling"));
                doLevelingCheckBox.Margin    = new BorderDouble(left: 3);
                doLevelingCheckBox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                doLevelingCheckBox.VAnchor   = VAnchor.ParentCenter;
                doLevelingCheckBox.Checked   = ActivePrinterProfile.Instance.DoPrintLeveling;

                printLevelingStatusLabel = new TextWidget("");
                printLevelingStatusLabel.AutoExpandBoundsToText = true;
                printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                printLevelingStatusLabel.VAnchor   = VAnchor.ParentCenter;

                GuiWidget hSpacer = new GuiWidget();
                hSpacer.HAnchor = HAnchor.ParentLeftRight;

                buttonBar.AddChild(levelingIcon);
                //buttonBar.AddChild(doLevelingCheckBox);
                buttonBar.AddChild(printLevelingStatusLabel);
                buttonBar.AddChild(hSpacer);
                buttonBar.AddChild(enablePrintLevelingButton);
                buttonBar.AddChild(disablePrintLevelingButton);
                buttonBar.AddChild(runPrintLevelingButton);
                doLevelingCheckBox.CheckedStateChanged += (sender, e) =>
                {
                    ActivePrinterProfile.Instance.DoPrintLeveling = doLevelingCheckBox.Checked;
                };
                ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) =>
                {
                    SetPrintLevelButtonVisiblity();
                }, ref unregisterEvents);

                printLevelingControlsContainer.AddChild(buttonBar);
            }
            SetPrintLevelButtonVisiblity();
            return(printLevelingControlsContainer);
        }
Exemple #24
0
        private FlowLayoutWidget GetAutoLevelControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Margin  = new BorderDouble(0, 4);

            configureAutoLevelButton         = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
            configureAutoLevelButton.Margin  = new BorderDouble(left: 6);
            configureAutoLevelButton.VAnchor = VAnchor.ParentCenter;

            TextWidget notificationSettingsLabel = new TextWidget("Automatic Print Leveling");

            notificationSettingsLabel.AutoExpandBoundsToText = true;
            notificationSettingsLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            notificationSettingsLabel.VAnchor   = VAnchor.ParentCenter;

            Button editButton = textImageButtonFactory.GenerateEditButton();

            editButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
            editButton.Click  += (sender, e) =>
            {
                UiThread.RunOnIdle((state) =>
                {
                    if (editLevelingSettingsWindow == null)
                    {
                        editLevelingSettingsWindow         = new EditLevelingSettingsWindow();
                        editLevelingSettingsWindow.Closed += (sender2, e2) =>
                        {
                            editLevelingSettingsWindow = null;
                        };
                    }
                    else
                    {
                        editLevelingSettingsWindow.BringToFront();
                    }
                });
            };

            Button runPrintLevelingButton = textImageButtonFactory.Generate("Configure".Localize().ToUpper());

            runPrintLevelingButton.Margin  = new BorderDouble(left: 6);
            runPrintLevelingButton.VAnchor = VAnchor.ParentCenter;
            runPrintLevelingButton.Click  += (sender, e) =>
            {
                UiThread.RunOnIdle((state) =>
                {
                    LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration);
                });
            };

            Agg.Image.ImageBuffer levelingImage = new Agg.Image.ImageBuffer();
            ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), levelingImage);
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(levelingImage);
            }

            ImageWidget levelingIcon = new ImageWidget(levelingImage);

            levelingIcon.Margin = new BorderDouble(right: 6);

            enablePrintLevelingButton         = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
            enablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
            enablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
            enablePrintLevelingButton.Click  += new EventHandler(enablePrintLeveling_Click);

            disablePrintLevelingButton         = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
            disablePrintLevelingButton.Margin  = new BorderDouble(left: 6);
            disablePrintLevelingButton.VAnchor = VAnchor.ParentCenter;
            disablePrintLevelingButton.Click  += new EventHandler(disablePrintLeveling_Click);

            printLevelingStatusLabel = new TextWidget("");
            printLevelingStatusLabel.AutoExpandBoundsToText = true;
            printLevelingStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            printLevelingStatusLabel.VAnchor   = VAnchor.ParentCenter;

            GuiWidget hSpacer = new GuiWidget();

            hSpacer.HAnchor = HAnchor.ParentLeftRight;

            ActivePrinterProfile.Instance.DoPrintLevelingChanged.RegisterEvent((sender, e) =>
            {
                SetPrintLevelButtonVisiblity();
            }, ref unregisterEvents);

            buttonRow.AddChild(levelingIcon);
            buttonRow.AddChild(printLevelingStatusLabel);
            buttonRow.AddChild(editButton);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(enablePrintLevelingButton);
            buttonRow.AddChild(disablePrintLevelingButton);
            buttonRow.AddChild(runPrintLevelingButton);
            SetPrintLevelButtonVisiblity();
            return(buttonRow);
        }
Exemple #25
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 ColorF(1, 1, 1));

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

            ScanlineRenderer scanlineRenderer = new ScanlineRenderer();
            // draw a background to show how the alpha is working
            int RectWidth = 70;
            int xoffset   = 50;
            int yoffset   = 50;

            for (int i = 0; i < 7; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if ((i + j) % 2 != 0)
                    {
                        VertexSource.RoundedRect rect = new VertexSource.RoundedRect(i * RectWidth + xoffset, j * RectWidth + yoffset,
                                                                                     (i + 1) * RectWidth + xoffset, (j + 1) * RectWidth + yoffset, 2);
                        rect.normalize_radius();

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

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

            // Prepare the polygon to rasterize. Here we need to fill
            // the destination (transformed) polygon.
            g_rasterizer.SetVectorClipBox(0, 0, Width, Height);
            g_rasterizer.reset();
            int b = 0;

            g_rasterizer.move_to_d(m_quad.GetXN(0) - b, m_quad.GetYN(0) - b);
            g_rasterizer.line_to_d(m_quad.GetXN(1) + b, m_quad.GetYN(1) - b);
            g_rasterizer.line_to_d(m_quad.GetXN(2) + b, m_quad.GetYN(2) + b);
            g_rasterizer.line_to_d(m_quad.GetXN(3) - b, m_quad.GetYN(3) + b);

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

            ImageBufferAccessorClamp source = new ImageBufferAccessorClamp(m_SourceImage);

            stopwatch.Restart();

            switch (m_trans_type.SelectedIndex)
            {
            case 0:
            {
                /*
                 *              agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *
                 *              typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
                 *              interpolator_type interpolator(tr);
                 *
                 *              typedef image_filter_2x2_type<source_type,
                 *                                                                        interpolator_type> span_gen_type;
                 *              span_gen_type sg(source, interpolator, filter);
                 *              agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 */
                break;
            }

            case 1:
            {
                /*
                 *              agg::trans_affine tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *
                 *              typedef agg::span_interpolator_linear<agg::trans_affine> interpolator_type;
                 *              typedef image_resample_affine_type<source_type> span_gen_type;
                 *
                 *              interpolator_type interpolator(tr);
                 *              span_gen_type sg(source, interpolator, filter);
                 *              sg.blur(m_blur.Value);
                 *              agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 */
                break;
            }

            case 2:
            {
                /*
                 *              agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *              if(tr.is_valid())
                 *              {
                 *                      typedef agg::span_interpolator_linear_subdiv<agg::trans_perspective> interpolator_type;
                 *                      interpolator_type interpolator(tr);
                 *
                 *                      typedef image_filter_2x2_type<source_type,
                 *                                                                                interpolator_type> span_gen_type;
                 *                      span_gen_type sg(source, interpolator, filter);
                 *                      agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *              }
                 */
                break;
            }

            case 3:
            {
                /*
                 *              agg::trans_perspective tr(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *              if(tr.is_valid())
                 *              {
                 *                      typedef agg::span_interpolator_trans<agg::trans_perspective> interpolator_type;
                 *                      interpolator_type interpolator(tr);
                 *
                 *                      typedef image_filter_2x2_type<source_type,
                 *                                                                                interpolator_type> span_gen_type;
                 *                      span_gen_type sg(source, interpolator, filter);
                 *                      agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *              }
                 */
                break;
            }

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

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

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

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

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

            case 5:
            {
                /*
                 *              typedef agg::span_interpolator_persp_exact<> interpolator_type;
                 *              typedef agg::span_subdiv_adaptor<interpolator_type> subdiv_adaptor_type;
                 *
                 *              interpolator_type interpolator(m_quad.polygon(), g_x1, g_y1, g_x2, g_y2);
                 *              subdiv_adaptor_type subdiv_adaptor(interpolator);
                 *
                 *              if(interpolator.is_valid())
                 *              {
                 *                      typedef image_resample_type<source_type,
                 *                                                                              subdiv_adaptor_type> span_gen_type;
                 *                      span_gen_type sg(source, subdiv_adaptor, filter);
                 *                      sg.blur(m_blur.Value);
                 *                      agg::render_scanlines_aa(g_rasterizer, g_scanline, rb_pre, sa, sg);
                 *              }
                 */
                break;
            }
            }

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

            gsv_text t = new gsv_text();

            t.SetFontSize(10.0);

            Stroke pt = new Stroke(t);

            pt.Width = 1.5;

            string buf = string.Format("{0:F2} ms", tm);

            t.start_point(10.0, 70.0);
            t.text(buf);

            g_rasterizer.add_path(pt);
            scanlineRenderer.RenderSolid(clippingProxy, g_rasterizer, g_scanline, new Color(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);
        }
Exemple #26
0
        public override void OnParentChanged(EventArgs e)
        {
            AnchorAll();

#if SourceDepthFloat
            ImageBufferFloat tempImageToLoadInto = new ImageBufferFloat();
#else
            ImageBuffer tempImageToLoadInto = new ImageBuffer();
#endif

            string img_name = "spheres.bmp";
            if (!ImageIO.LoadImageData(img_name, tempImageToLoadInto))
            {
                string buf;
                buf = "File not found: "
                      + img_name
                      + ".bmp"
                      + ". Download http://www.antigrain.com/" + img_name + "\n"
                      + "or copy it from another directory if available.";
                MessageBox.ShowMessageBox(buf, "Missing Files");
            }
            else
            {
#if SourceDepth24
                image_filters_application.m_TempDestImage = new ImageBuffer(tempImageToLoadInto, new BlenderBGR());

                image_filters_application.m_RotatedImage  = new ImageBuffer(image_filters_application.m_TempDestImage, new BlenderBGR());
                image_filters_application.m_OriginalImage = new ImageBuffer(image_filters_application.m_TempDestImage, new BlenderBGR());

                image_filters_application.m_TempDestImage.SetBlender(new BlenderPreMultBGR());
#else
#if SourceDepthFloat
                image_filters_application.m_TempDestImage = new ImageBufferFloat(tempImageToLoadInto.Width(), tempImageToLoadInto.Height(), 128, new BlenderBGRAFloat());
                image_filters_application.m_TempDestImage.CopyFrom(tempImageToLoadInto);

                image_filters_application.m_RotatedImage  = new ImageBufferFloat(image_filters_application.m_TempDestImage, new BlenderBGRAFloat());
                image_filters_application.m_OriginalImage = new ImageBufferFloat(image_filters_application.m_TempDestImage, new BlenderBGRAFloat());

                //image_filters_application.m_TempDestImage.SetBlender(new BlenderBGRAFloat());
                image_filters_application.m_TempDestImage.SetBlender(new BlenderPreMultBGRAFloat());
#else
                image_filters.m_TempDestImage = new ImageBuffer(tempImageToLoadInto.Width, tempImageToLoadInto.Height, 32, new BlenderBGRA());
                image_filters.m_TempDestImage.CopyFrom(tempImageToLoadInto);

                image_filters.m_RotatedImage  = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGRA());
                image_filters.m_OriginalImage = new ImageBuffer(image_filters.m_TempDestImage, new BlenderBGRA());

                image_filters.m_TempDestImage.SetRecieveBlender(new BlenderPreMultBGRA());
#endif
#endif

                int w = image_filters.m_TempDestImage.Width + 220;
                int h = image_filters.m_TempDestImage.Height + 140;

                if (w < 305)
                {
                    w = 305;
                }
                if (h < 325)
                {
                    h = 325;
                }

                Parent.LocalBounds = new RectangleDouble(0, 0, w, h);

                transform_image(0.0);
            }

            base.OnParentChanged(e);
        }
        private void AddEePromControls(FlowLayoutWidget controlsTopToBottomLayout)
        {
            GroupBox eePromControlsGroupBox = new GroupBox(LocalizedString.Get("EEProm Settings"));

            eePromControlsGroupBox.Margin      = new BorderDouble(0);
            eePromControlsGroupBox.TextColor   = ActiveTheme.Instance.PrimaryTextColor;
            eePromControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            eePromControlsGroupBox.HAnchor     = Agg.UI.HAnchor.ParentLeftRight;
            eePromControlsGroupBox.VAnchor     = Agg.UI.VAnchor.FitToChildren;
            eePromControlsGroupBox.Height      = 68;
            {
                FlowLayoutWidget eePromControlsLayout = new FlowLayoutWidget();
                eePromControlsLayout.HAnchor |= HAnchor.ParentCenter;
                eePromControlsLayout.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                eePromControlsLayout.Margin   = new BorderDouble(3, 0, 3, 6);
                eePromControlsLayout.Padding  = new BorderDouble(0);
                {
                    Agg.Image.ImageBuffer eePromImage = new Agg.Image.ImageBuffer();
                    ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "leveling-24x24.png"), eePromImage);
                    ImageWidget eePromIcon = new ImageWidget(eePromImage);
                    eePromIcon.Margin = new BorderDouble(right: 6);

                    Button openEePromWindow = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
                    openEePromWindow.Click += (sender, e) =>
                    {
#if false // This is to force the creation of the repetier window for testing when we don't have repetier firmware.
                        new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
#else
                        switch (PrinterCommunication.Instance.FirmwareType)
                        {
                        case PrinterCommunication.FirmwareTypes.Repetier:
                            new MatterHackers.MatterControl.EeProm.EePromRepetierWidget();
                            break;

                        case PrinterCommunication.FirmwareTypes.Marlin:
                            new MatterHackers.MatterControl.EeProm.EePromMarlinWidget();
                            break;

                        default:
                            UiThread.RunOnIdle((state) =>
                            {
                                string message = LocalizedString.Get("Oops! There is no eeprom mapping for your printer's firmware.");
                                StyledMessageBox.ShowMessageBox(message, "Warning no eeprom mapping", StyledMessageBox.MessageType.OK);
                            }
                                               );
                            break;
                        }
#endif
                    };
                    //eePromControlsLayout.AddChild(eePromIcon);
                    eePromControlsLayout.AddChild(openEePromWindow);
                }

                eePromControlsGroupBox.AddChild(eePromControlsLayout);
            }

            eePromControlsContainer = new DisableableWidget();
            eePromControlsContainer.AddChild(eePromControlsGroupBox);

            controlsTopToBottomLayout.AddChild(eePromControlsContainer);
        }
Exemple #28
0
        private FlowLayoutWidget GetCloudMonitorControls()
        {
            FlowLayoutWidget buttonBar = new FlowLayoutWidget();

            buttonBar.HAnchor |= HAnchor.ParentLeftRight;
            buttonBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
            buttonBar.Margin   = new BorderDouble(0, 0, 0, 0);
            buttonBar.Padding  = new BorderDouble(0);

            this.textImageButtonFactory.FixedHeight = TallButtonHeight;

            Agg.Image.ImageBuffer cloudMonitorImage = new Agg.Image.ImageBuffer();
            ImageIO.LoadImageData(Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", "PrintStatusControls", "cloud-24x24.png"), cloudMonitorImage);
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(cloudMonitorImage);
            }

            ImageWidget cloudMonitoringIcon = new ImageWidget(cloudMonitorImage);

            cloudMonitoringIcon.Margin = new BorderDouble(right: 6);

            enableCloudMonitorButton         = textImageButtonFactory.Generate("Enable".Localize().ToUpper());
            enableCloudMonitorButton.Margin  = new BorderDouble(left: 6);
            enableCloudMonitorButton.VAnchor = VAnchor.ParentCenter;
            enableCloudMonitorButton.Click  += new EventHandler(enableCloudMonitor_Click);

            disableCloudMonitorButton         = textImageButtonFactory.Generate("Disable".Localize().ToUpper());
            disableCloudMonitorButton.Margin  = new BorderDouble(left: 6);
            disableCloudMonitorButton.VAnchor = VAnchor.ParentCenter;
            disableCloudMonitorButton.Click  += new EventHandler(disableCloudMonitor_Click);

            cloudMonitorInstructionsLink         = linkButtonFactory.Generate("More Info".Localize().ToUpper());
            cloudMonitorInstructionsLink.VAnchor = VAnchor.ParentCenter;
            cloudMonitorInstructionsLink.Click  += new EventHandler(goCloudMonitoringInstructionsButton_Click);
            cloudMonitorInstructionsLink.Margin  = new BorderDouble(left: 6);

            goCloudMonitoringWebPageButton         = linkButtonFactory.Generate("View Status".Localize().ToUpper());
            goCloudMonitoringWebPageButton.VAnchor = VAnchor.ParentCenter;
            goCloudMonitoringWebPageButton.Click  += new EventHandler(goCloudMonitoringWebPageButton_Click);
            goCloudMonitoringWebPageButton.Margin  = new BorderDouble(left: 6);

            cloudMonitorStatusLabel = new TextWidget("");
            cloudMonitorStatusLabel.AutoExpandBoundsToText = true;
            cloudMonitorStatusLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            cloudMonitorStatusLabel.VAnchor   = VAnchor.ParentCenter;

            GuiWidget hSpacer = new GuiWidget();

            hSpacer.HAnchor = HAnchor.ParentLeftRight;

            buttonBar.AddChild(cloudMonitoringIcon);
            buttonBar.AddChild(cloudMonitorStatusLabel);
            buttonBar.AddChild(cloudMonitorInstructionsLink);
            buttonBar.AddChild(goCloudMonitoringWebPageButton);
            buttonBar.AddChild(hSpacer);
            buttonBar.AddChild(enableCloudMonitorButton);
            buttonBar.AddChild(disableCloudMonitorButton);

            return(buttonBar);
        }
Exemple #29
0
        private FlowLayoutWidget GetHomeButtonBar()
        {
            FlowLayoutWidget homeButtonBar = new FlowLayoutWidget();

            homeButtonBar.HAnchor = HAnchor.ParentLeftRight;
            homeButtonBar.Margin  = new BorderDouble(3, 0, 3, 6) * TextWidget.GlobalPointSizeScaleRatio;
            homeButtonBar.Padding = new BorderDouble(0);

            textImageButtonFactory.borderWidth       = 1;
            textImageButtonFactory.normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);
            textImageButtonFactory.hoverBorderColor  = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200);

            string      homeIconFile  = "icon_home_white_24x24.png";
            string      fileAndPath   = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "Icons", homeIconFile);
            ImageBuffer helpIconImage = new ImageBuffer();

            ImageIO.LoadImageData(fileAndPath, helpIconImage);
            ImageWidget homeIconImageWidget = new ImageWidget(helpIconImage);

            homeIconImageWidget.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
            homeIconImageWidget.OriginRelativeParent += new Vector2(0, 2) * TextWidget.GlobalPointSizeScaleRatio;
            RGBA_Bytes oldColor = this.textImageButtonFactory.normalFillColor;

            textImageButtonFactory.normalFillColor = new RGBA_Bytes(180, 180, 180);
            homeAllButton = textImageButtonFactory.Generate(LocalizedString.Get("ALL"));
            this.textImageButtonFactory.normalFillColor = oldColor;
            homeAllButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
            homeAllButton.Click += new EventHandler(homeAll_Click);

            textImageButtonFactory.FixedWidth = (int)homeAllButton.Width;
            homeXButton        = textImageButtonFactory.Generate("X", centerText: true);
            homeXButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
            homeXButton.Click += new EventHandler(homeXButton_Click);

            homeYButton        = textImageButtonFactory.Generate("Y", centerText: true);
            homeYButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
            homeYButton.Click += new EventHandler(homeYButton_Click);

            homeZButton        = textImageButtonFactory.Generate("Z", centerText: true);
            homeZButton.Margin = new BorderDouble(0, 0, 6, 0) * TextWidget.GlobalPointSizeScaleRatio;
            homeZButton.Click += new EventHandler(homeZButton_Click);

            textImageButtonFactory.normalFillColor = RGBA_Bytes.White;
            textImageButtonFactory.FixedWidth      = 0;

            GuiWidget spacer = new GuiWidget();

            spacer.HAnchor = HAnchor.ParentLeftRight;

            disableMotors        = textImageButtonFactory.Generate("Release".Localize().ToUpper());
            disableMotors.Margin = new BorderDouble(0);
            disableMotors.Click += new EventHandler(disableMotors_Click);

            GuiWidget spacerReleaseShow = new GuiWidget(10 * TextWidget.GlobalPointSizeScaleRatio, 0);

            homeButtonBar.AddChild(homeIconImageWidget);
            homeButtonBar.AddChild(homeAllButton);
            homeButtonBar.AddChild(homeXButton);
            homeButtonBar.AddChild(homeYButton);
            homeButtonBar.AddChild(homeZButton);
            homeButtonBar.AddChild(spacer);
            homeButtonBar.AddChild(disableMotors);
            homeButtonBar.AddChild(spacerReleaseShow);

            return(homeButtonBar);
        }
Exemple #30
0
        public static IObject3D Load(Stream fileStream, Action <double, string> reportProgress = null, IObject3D source = null)
        {
            IObject3D root = source ?? new Object3D();

            var time = Stopwatch.StartNew();

            // LOAD THE MESH DATA
            var objFile = new Obj();

            objFile.LoadObj(fileStream);

            IObject3D context = new Object3D();

            root.Children.Add(context);

            var mesh = new Mesh();

            context.SetMeshDirect(mesh);

            foreach (var vertex in objFile.VertexList)
            {
                mesh.Vertices.Add(new Vector3Float(vertex.X, vertex.Y, vertex.Z));
            }

            foreach (var face in objFile.FaceList)
            {
                for (int i = 0; i < face.VertexIndexList.Length; i++)
                {
                    if (face.VertexIndexList[i] >= objFile.TextureList.Count)
                    {
                        int a = 0;
                    }
                }

                mesh.Faces.Add(face.VertexIndexList[0] - 1, face.VertexIndexList[1] - 1, face.VertexIndexList[2] - 1, mesh.Vertices);
                if (face.VertexIndexList.Length == 4)
                {
                    // add the other side of the quad
                    mesh.Faces.Add(face.VertexIndexList[0] - 1, face.VertexIndexList[2] - 1, face.VertexIndexList[3] - 1, mesh.Vertices);
                }
            }

            // load and apply any texture
            if (objFile.Material != "")
            {
                // TODO: have consideration for this being in a shared zip file
                string pathToObj = Path.GetDirectoryName(((FileStream)fileStream).Name);
                //Try-catch block for when objFile.Material is not found
                try
                {
                    using (var materialsStream = File.OpenRead(Path.Combine(pathToObj, objFile.Material)))
                    {
                        var mtl = new Mtl();
                        mtl.LoadMtl(materialsStream);

                        foreach (var material in mtl.MaterialList)
                        {
                            if (!string.IsNullOrEmpty(material.DiffuseTextureFileName))
                            {
                                var pathToTexture = Path.Combine(pathToObj, material.DiffuseTextureFileName);
                                if (File.Exists(pathToTexture))
                                {
                                    var diffuseTexture = new ImageBuffer();

                                    // TODO: have consideration for this being in a shared zip file
                                    using (var imageStream = File.OpenRead(pathToTexture))
                                    {
                                        if (Path.GetExtension(material.DiffuseTextureFileName).ToLower() == ".tga")
                                        {
                                            ImageTgaIO.LoadImageData(diffuseTexture, imageStream, 32);
                                        }
                                        else
                                        {
                                            ImageIO.LoadImageData(imageStream, diffuseTexture);
                                        }
                                    }

                                    if (diffuseTexture.Width > 0 && diffuseTexture.Height > 0)
                                    {
                                        int meshFace = 0;
                                        for (int objFace = 0; objFace < objFile.FaceList.Count; objFace++, meshFace++)
                                        {
                                            var face = mesh.Faces[meshFace];

                                            var faceData = objFile.FaceList[objFace];

                                            int textureIndex0 = faceData.TextureVertexIndexList[0] - 1;
                                            var uv0           = new Vector2Float(objFile.TextureList[textureIndex0].X, objFile.TextureList[textureIndex0].Y);
                                            int textureIndex1 = faceData.TextureVertexIndexList[1] - 1;
                                            var uv1           = new Vector2Float(objFile.TextureList[textureIndex1].X, objFile.TextureList[textureIndex1].Y);
                                            int textureIndex2 = faceData.TextureVertexIndexList[2] - 1;
                                            var uv2           = new Vector2Float(objFile.TextureList[textureIndex2].X, objFile.TextureList[textureIndex2].Y);

                                            mesh.FaceTextures.Add(meshFace, new FaceTextureData(diffuseTexture, uv0, uv1, uv2));

                                            if (faceData.TextureVertexIndexList.Length == 4)
                                            {
                                                meshFace++;

                                                int textureIndex3 = faceData.TextureVertexIndexList[3] - 1;
                                                var uv3           = new Vector2Float(objFile.TextureList[textureIndex3].X, objFile.TextureList[textureIndex3].Y);

                                                mesh.FaceTextures.Add(meshFace, new FaceTextureData(diffuseTexture, uv0, uv2, uv3));
                                            }
                                        }

                                        context.Color = Color.White;
                                        root.Color    = Color.White;
                                    }
                                }
                            }
                        }
                    }
                }
                catch (FileNotFoundException)
                {
                    // Just continue as if obj.Material == "" to show object
                }
            }

            time.Stop();
            Debug.WriteLine(string.Format("OBJ Load in {0:0.00}s", time.Elapsed.TotalSeconds));

            time.Restart();
            bool hasValidMesh = root.Children.Where(item => item.Mesh.Faces.Count > 0).Any();

            Debug.WriteLine("hasValidMesh: " + time.ElapsedMilliseconds);

            reportProgress?.Invoke(1, "");

            return(hasValidMesh ? root : null);
        }