Beispiel #1
0
 public override void OnClosed(ClosedEventArgs e)
 {
     basicBody?.Close();
     unregisterEvents?.Invoke(this, null);
     instance = null;
     base.OnClosed(e);
 }
Beispiel #2
0
        public override void OnClosed(ClosedEventArgs e)
        {
            unregisterEvents?.Invoke(this, null);

            instance = null;
            base.OnClosed(e);
            onCloseCallback();
        }
Beispiel #3
0
 public static void Show(Action onCloseCallback)
 {
     if (instance == null)
     {
         instance = new PrintingWindow(onCloseCallback);
         instance.ShowAsSystemWindow();
     }
 }
 public static void Show()
 {
     if (instance == null)
     {
         instance = new PrintingWindow();
         instance.ShowAsSystemWindow();
     }
 }
Beispiel #5
0
        public override void OnLoad(EventArgs args)
        {
            base.OnLoad(args);

            bool smallScreen = Parent.Width <= 1180;

            Padding = smallScreen ? new BorderDouble(20, 5) : new BorderDouble(50, 30);

            var topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight
            };

            AddChild(topToBottom);

            var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight,
                Margin  = smallScreen ? new BorderDouble(30, 5, 30, 0) : new BorderDouble(30, 20, 30, 0),               // the -12 is to take out the top bar
            };

            topToBottom.AddChild(bodyRow);

            // Thumbnail section
            {
                int         imageSize   = smallScreen ? 300 : 500;
                ImageBuffer imageBuffer = PartThumbnailWidget.GetImageForItem(PrinterConnectionAndCommunication.Instance.ActivePrintItem, imageSize, imageSize);

                if (imageBuffer == null)
                {
                    imageBuffer = StaticData.Instance.LoadImage(Path.Combine("Images", "Screensaver", "part_thumbnail.png"));
                }

                WhiteToColor.DoWhiteToColor(imageBuffer, ActiveTheme.Instance.PrimaryAccentColor);

                var partThumbnail = new ImageWidget(imageBuffer)
                {
                    VAnchor = VAnchor.ParentCenter,
                    Margin  = smallScreen ? new BorderDouble(right: 20) : new BorderDouble(right: 50),
                };
                bodyRow.AddChild(partThumbnail);
            }

            bodyRow.AddChild(PrintingWindow.CreateVerticalLine());

            // Progress section
            {
                var expandingContainer = new HorizontalSpacer()
                {
                    VAnchor = VAnchor.FitToChildren | VAnchor.ParentCenter
                };
                bodyRow.AddChild(expandingContainer);

                var progressContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
                {
                    Margin  = new BorderDouble(50, 0),
                    VAnchor = VAnchor.ParentCenter | VAnchor.FitToChildren,
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                };
                expandingContainer.AddChild(progressContainer);

                progressDial = new ProgressDial()
                {
                    HAnchor = HAnchor.ParentCenter,
                    Height  = 200 * DeviceScale,
                    Width   = 200 * DeviceScale
                };
                progressContainer.AddChild(progressDial);

                var timeContainer = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                    Margin  = 3
                };
                progressContainer.AddChild(timeContainer);

                var timeImage = StaticData.Instance.LoadImage(Path.Combine("Images", "Screensaver", "time.png"));
                if (!ActiveTheme.Instance.IsDarkTheme)
                {
                    timeImage.InvertLightness();
                }

                timeContainer.AddChild(new ImageWidget(timeImage));

                timeWidget = new TextWidget("", pointSize: 22, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    Margin  = new BorderDouble(10, 0, 0, 0),
                    VAnchor = VAnchor.ParentCenter,
                };

                timeContainer.AddChild(timeWidget);

                int maxTextWidth = 350;
                printerName = new TextWidget(ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    HAnchor     = HAnchor.ParentCenter,
                    MinimumSize = new Vector2(maxTextWidth, MinimumSize.y),
                    Width       = maxTextWidth,
                    Margin      = new BorderDouble(0, 3),
                };

                progressContainer.AddChild(printerName);

                partName = new TextWidget(PrinterConnectionAndCommunication.Instance.ActivePrintItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    HAnchor     = HAnchor.ParentCenter,
                    MinimumSize = new Vector2(maxTextWidth, MinimumSize.y),
                    Width       = maxTextWidth,
                    Margin      = new BorderDouble(0, 3)
                };
                progressContainer.AddChild(partName);
            }

            bodyRow.AddChild(PrintingWindow.CreateVerticalLine());

            // ZControls
            {
                var widget = new ZAxisControls(smallScreen)
                {
                    Margin  = new BorderDouble(left: 50),
                    VAnchor = VAnchor.ParentCenter,
                    Width   = 135
                };
                bodyRow.AddChild(widget);
            }

            var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottom | VAnchor.FitToChildren,
                HAnchor = HAnchor.ParentCenter | HAnchor.FitToChildren,
                Margin  = new BorderDouble(bottom: 0),
            };

            topToBottom.AddChild(footerBar);

            int extruderCount = ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            extruderStatusWidgets = Enumerable.Range(0, extruderCount).Select((i) => new ExtruderStatusWidget(i)).ToList();

            bool hasHeatedBed = ActiveSliceSettings.Instance.GetValue <bool>("has_heated_bed");

            if (hasHeatedBed)
            {
                var extruderColumn = new FlowLayoutWidget(FlowDirection.TopToBottom);
                footerBar.AddChild(extruderColumn);

                // Add each status widget into the scene, placing into the appropriate column
                for (var i = 0; i < extruderCount; i++)
                {
                    var widget = extruderStatusWidgets[i];
                    widget.Margin = new BorderDouble(right: 20);
                    extruderColumn.AddChild(widget);
                }

                footerBar.AddChild(new BedStatusWidget(smallScreen)
                {
                    VAnchor = VAnchor.ParentCenter,
                });
            }
            else
            {
                if (extruderCount == 1)
                {
                    footerBar.AddChild(extruderStatusWidgets[0]);
                }
                else
                {
                    var columnA = new FlowLayoutWidget(FlowDirection.TopToBottom);
                    footerBar.AddChild(columnA);

                    var columnB = new FlowLayoutWidget(FlowDirection.TopToBottom);
                    footerBar.AddChild(columnB);

                    // Add each status widget into the scene, placing into the appropriate column
                    for (var i = 0; i < extruderCount; i++)
                    {
                        var widget = extruderStatusWidgets[i];
                        if (i % 2 == 0)
                        {
                            widget.Margin = new BorderDouble(right: 20);
                            columnA.AddChild(widget);
                        }
                        else
                        {
                            columnB.AddChild(widget);
                        }
                    }
                }
            }

            UiThread.RunOnIdle(() =>
            {
                CheckOnPrinter();
            });
        }