Esempio n. 1
0
        public PrintingWindow(Action onCloseCallback, bool mockMode = false)
            : base(1280, 750)
        {
            this.BackgroundColor = new RGBA_Bytes(35, 40, 49);
            this.onCloseCallback = onCloseCallback;
            this.Title           = "Print Monitor".Localize();

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

            this.AddChild(topToBottom);

            var actionBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentTop | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentLeftRight,
                BackgroundColor = new RGBA_Bytes(34, 38, 46),
                //DebugShowBounds = true
            };

            topToBottom.AddChild(actionBar);

            var logo = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "logo.png")));

            actionBar.AddChild(logo);

            actionBar.AddChild(new HorizontalSpacer());

            var pauseButton  = CreateButton("Pause".Localize().ToUpper());
            var resumeButton = CreateButton("Resume".Localize().ToUpper());

            pauseButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.RequestPause();
                    pauseButton.Visible  = false;
                    resumeButton.Visible = true;
                });
            };
            actionBar.AddChild(pauseButton);

            resumeButton.Visible = false;
            resumeButton.Click  += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    //PrinterConnectionAndCommunication.Instance.Resume();
                    resumeButton.Visible = false;
                    pauseButton.Visible  = true;
                });
            };
            actionBar.AddChild(resumeButton);

            actionBar.AddChild(CreateVerticalLine());

            var cancelButton = CreateButton("Cancel".Localize().ToUpper());

            //cancelButton.Click += (sender, e) => UiThread.RunOnIdle(CancelButton_Click);
            actionBar.AddChild(cancelButton);

            actionBar.AddChild(CreateVerticalLine());

            var advancedButton = CreateButton("Advanced".Localize().ToUpper());

            actionBar.AddChild(advancedButton);

            var bodyContainer = new GuiWidget()
            {
                VAnchor         = VAnchor.ParentBottomTop,
                HAnchor         = HAnchor.ParentLeftRight,
                Padding         = new BorderDouble(50),
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
            };

            topToBottom.AddChild(bodyContainer);

            var bodyRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor = VAnchor.ParentBottomTop,
                HAnchor = HAnchor.ParentLeftRight,
                //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
            };

            bodyContainer.AddChild(bodyRow);

            // Thumbnail section
            {
                ImageBuffer imageBuffer = null;

                string stlHashCode = PrinterConnectionAndCommunication.Instance.ActivePrintItem?.FileHashCode.ToString();
                if (!string.IsNullOrEmpty(stlHashCode) && stlHashCode != "0")
                {
                    imageBuffer = PartThumbnailWidget.LoadImageFromDisk(stlHashCode);
                    if (imageBuffer != null)
                    {
                        imageBuffer = ImageBuffer.CreateScaledImage(imageBuffer, 500, 500);
                    }
                }

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

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

            bodyRow.AddChild(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,
                    //BackgroundColor = new RGBA_Bytes(125, 255, 46, 20),
                };
                expandingContainer.AddChild(progressContainer);

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

                var timeContainer = new FlowLayoutWidget()
                {
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(timeContainer);

                var timeImage = new ImageWidget(StaticData.Instance.LoadIcon(Path.Combine("Screensaver", "time.png")));
                timeContainer.AddChild(timeImage);

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

                timeContainer.AddChild(timeWidget);

                printerName = new TextWidget(ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };

                progressContainer.AddChild(printerName);

                partName = new TextWidget(PrinterConnectionAndCommunication.Instance.ActivePrintItem.GetFriendlyName(), pointSize: 16, textColor: ActiveTheme.Instance.PrimaryTextColor)
                {
                    AutoExpandBoundsToText = true,
                    HAnchor = HAnchor.ParentLeftRight,
                    Margin  = new BorderDouble(50, 3)
                };
                progressContainer.AddChild(partName);
            }

            bodyRow.AddChild(CreateVerticalLine());

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

            var footerBar = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                VAnchor         = VAnchor.ParentBottom | VAnchor.FitToChildren,
                HAnchor         = HAnchor.ParentCenter | HAnchor.FitToChildren,
                BackgroundColor = new RGBA_Bytes(35, 40, 49),
                Margin          = new BorderDouble(bottom: 30)
            };

            topToBottom.AddChild(footerBar);

            int extruderCount = mockMode ? 3 : ActiveSliceSettings.Instance.GetValue <int>(SettingsKey.extruder_count);

            var borderColor = bodyContainer.BackgroundColor.AdjustLightness(1.5).GetAsRGBA_Bytes();

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

            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(() =>
            {
                if (mockMode)
                {
                    MockProgress();
                }
                else
                {
                    CheckOnPrinter();
                }
            });

            PrinterConnectionAndCommunication.Instance.ExtruderTemperatureRead.RegisterEvent((s, e) =>
            {
                var eventArgs = e as TemperatureEventArgs;
                if (eventArgs != null && eventArgs.Index0Based < extruderStatusWidgets.Count)
                {
                    extruderStatusWidgets[eventArgs.Index0Based].UpdateTemperatures();
                }
            }, ref unregisterEvents);
        }
Esempio n. 2
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();
            });
        }