Beispiel #1
0
        public PowerControls()
        {
            AltGroupBox fanControlsGroupBox = new AltGroupBox(new TextWidget("ATX Power Control".Localize(), pointSize: 18, textColor: ActiveTheme.Instance.SecondaryAccentColor));

            fanControlsGroupBox.Margin      = new BorderDouble(0);
            fanControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            fanControlsGroupBox.HAnchor    |= Agg.UI.HAnchor.ParentLeftRight;
            this.AddChild(fanControlsGroupBox);

            atxPowertoggleSwitch        = ImageButtonFactory.CreateToggleSwitch(false);
            atxPowertoggleSwitch.Margin = new BorderDouble(6, 0, 6, 6);
            atxPowertoggleSwitch.CheckedStateChanged += (sender, e) =>
            {
                PrinterConnectionAndCommunication.Instance.AtxPowerEnabled = atxPowertoggleSwitch.Checked;
            };

            FlowLayoutWidget paddingContainer = new FlowLayoutWidget();

            paddingContainer.Padding = new BorderDouble(3, 5, 3, 0);
            {
                paddingContainer.AddChild(atxPowertoggleSwitch);
            }
            fanControlsGroupBox.AddChild(paddingContainer);

            UpdateControlVisibility(null, null);

            PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(this.UpdateControlVisibility, ref unregisterEvents);
            PrinterConnectionAndCommunication.Instance.AtxPowerStateChanged.RegisterEvent(this.UpdatePowerSwitch, ref unregisterEvents);

            this.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
            this.HAnchor = HAnchor.ParentLeftRight;
            this.VAnchor = VAnchor.ParentBottomTop;
        }
Beispiel #2
0
        protected override void AddChildElements()
        {
            AltGroupBox fanControlsGroupBox = new AltGroupBox(new TextWidget("ATX Power Control".Localize(), pointSize: 18, textColor: ActiveTheme.Instance.SecondaryAccentColor));

            fanControlsGroupBox.Margin      = new BorderDouble(0);
            fanControlsGroupBox.BorderColor = ActiveTheme.Instance.PrimaryTextColor;
            fanControlsGroupBox.HAnchor    |= Agg.UI.HAnchor.ParentLeftRight;
            this.AddChild(fanControlsGroupBox);

            atxPowertoggleSwitch        = ImageButtonFactory.CreateToggleSwitch(false);
            atxPowertoggleSwitch.Margin = new BorderDouble(6, 0, 6, 6);
            atxPowertoggleSwitch.CheckedStateChanged += (sender, e) =>
            {
                PrinterConnectionAndCommunication.Instance.AtxPowerEnabled = atxPowertoggleSwitch.Checked;
            };

            FlowLayoutWidget paddingContainer = new FlowLayoutWidget();

            paddingContainer.Padding = new BorderDouble(3, 5, 3, 0) * TextWidget.GlobalPointSizeScaleRatio;
            {
                paddingContainer.AddChild(atxPowertoggleSwitch);
            }
            fanControlsGroupBox.AddChild(paddingContainer);

            UpdateControlVisibility(null, null);
        }
        private FlowLayoutWidget GetNotificationControls()
        {
            FlowLayoutWidget notificationSettingsContainer = new FlowLayoutWidget();

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

            this.textImageButtonFactory.FixedHeight = TallButtonHeight;

            ImageBuffer notifiImage = StaticData.Instance.LoadIcon("notify-24x24.png").InvertLightness();

            notifiImage.SetRecieveBlender(new BlenderPreMultBGRA());
            int iconSize = (int)(24 * GuiWidget.DeviceScale);

            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                notifiImage.InvertLightness();
            }

            ImageWidget notificationSettingsIcon = new ImageWidget(notifiImage);

            notificationSettingsIcon.VAnchor = VAnchor.ParentCenter;
            notificationSettingsIcon.Margin  = new BorderDouble(right: 6, bottom: 6);

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

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

            GuiWidget printNotificationsSwitchContainer = new FlowLayoutWidget();

            printNotificationsSwitchContainer.VAnchor = VAnchor.ParentCenter;
            printNotificationsSwitchContainer.Margin  = new BorderDouble(left: 16);

            CheckBox enablePrintNotificationsSwitch = ImageButtonFactory.CreateToggleSwitch(UserSettings.Instance.get("PrintNotificationsEnabled") == "true");

            enablePrintNotificationsSwitch.VAnchor              = VAnchor.ParentCenter;
            enablePrintNotificationsSwitch.CheckedStateChanged += (sender, e) =>
            {
                UserSettings.Instance.set("PrintNotificationsEnabled", enablePrintNotificationsSwitch.Checked ? "true" : "false");
            };
            printNotificationsSwitchContainer.AddChild(enablePrintNotificationsSwitch);
            printNotificationsSwitchContainer.SetBoundsToEncloseChildren();

            notificationSettingsContainer.AddChild(notificationSettingsIcon);
            notificationSettingsContainer.AddChild(notificationSettingsLabel);
            notificationSettingsContainer.AddChild(new HorizontalSpacer());
            notificationSettingsContainer.AddChild(configureNotificationSettingsButton);
            notificationSettingsContainer.AddChild(printNotificationsSwitchContainer);

            return(notificationSettingsContainer);
        }
Beispiel #4
0
        private FlowLayoutWidget GetCameraControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

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

            ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon("camera-24x24.png", 24, 24).InvertLightness();

            cameraIconImage.SetRecieveBlender(new BlenderPreMultBGRA());
            int iconSize = (int)(24 * GuiWidget.DeviceScale);

            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                cameraIconImage.InvertLightness();
            }

            ImageWidget cameraIcon = new ImageWidget(cameraIconImage);

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

            TextWidget cameraLabel = new TextWidget("Camera Monitoring".Localize());

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

            openCameraButton        = textImageButtonFactory.Generate("Preview".Localize().ToUpper());
            openCameraButton.Click += openCameraPreview_Click;
            openCameraButton.Margin = new BorderDouble(left: 6);

            buttonRow.AddChild(cameraIcon);
            buttonRow.AddChild(cameraLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(openCameraButton);

            if (ApplicationSettings.Instance.get(ApplicationSettingsKey.HardwareHasCamera) == "true")
            {
                GuiWidget publishImageSwitchContainer = new FlowLayoutWidget();
                publishImageSwitchContainer.VAnchor = VAnchor.ParentCenter;
                publishImageSwitchContainer.Margin  = new BorderDouble(left: 16);

                CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.publish_bed_image));
                toggleSwitch.CheckedStateChanged += (sender, e) =>
                {
                    CheckBox thisControl = sender as CheckBox;
                    ActiveSliceSettings.Instance.SetValue(SettingsKey.publish_bed_image, thisControl.Checked ? "1" : "0");
                };
                publishImageSwitchContainer.AddChild(toggleSwitch);

                publishImageSwitchContainer.SetBoundsToEncloseChildren();

                buttonRow.AddChild(publishImageSwitchContainer);
            }

            return(buttonRow);
        }
        private FlowLayoutWidget GetCameraControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

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

            Agg.Image.ImageBuffer cameraIconImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "camera-24x24.png"));
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(cameraIconImage);
            }

            ImageWidget cameraIcon = new ImageWidget(cameraIconImage);

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

            TextWidget cameraLabel = new TextWidget("Camera Monitoring");

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

            openCameraButton        = textImageButtonFactory.Generate("Preview".Localize().ToUpper());
            openCameraButton.Click += new EventHandler(openCameraPreview_Click);
            openCameraButton.Margin = new BorderDouble(left: 6);

            buttonRow.AddChild(cameraIcon);
            buttonRow.AddChild(cameraLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(openCameraButton);
#if __ANDROID__
            GuiWidget publishImageSwitchContainer = new FlowLayoutWidget();
            publishImageSwitchContainer.VAnchor = VAnchor.ParentCenter;
            publishImageSwitchContainer.Margin  = new BorderDouble(left: 16);

            CheckBox toggleSwitch = ImageButtonFactory.CreateToggleSwitch(PrinterSettings.Instance.get("PublishBedImage") == "true");
            toggleSwitch.CheckedStateChanged += (sender, e) =>
            {
                CheckBox thisControl = sender as CheckBox;
                PrinterSettings.Instance.set("PublishBedImage", thisControl.Checked ? "true" : "false");
            };
            publishImageSwitchContainer.AddChild(toggleSwitch);

            publishImageSwitchContainer.SetBoundsToEncloseChildren();

            buttonRow.AddChild(publishImageSwitchContainer);
#endif

            return(buttonRow);
        }
        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 = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "notify-24x24.png"));
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(notificationSettingsImage);
            }

            ImageWidget levelingIcon = new ImageWidget(notificationSettingsImage);

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

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

            GuiWidget levelingSwitchContainer = new FlowLayoutWidget();

            levelingSwitchContainer.VAnchor = VAnchor.ParentCenter;
            levelingSwitchContainer.Margin  = new BorderDouble(left: 16);

            CheckBox enablePrintNotificationsSwitch = ImageButtonFactory.CreateToggleSwitch(UserSettings.Instance.get("PrintNotificationsEnabled") == "true");

            enablePrintNotificationsSwitch.VAnchor              = VAnchor.ParentCenter;
            enablePrintNotificationsSwitch.CheckedStateChanged += (sender, e) =>
            {
                UserSettings.Instance.set("PrintNotificationsEnabled", enablePrintNotificationsSwitch.Checked ? "true" : "false");
            };
            levelingSwitchContainer.AddChild(enablePrintNotificationsSwitch);
            levelingSwitchContainer.SetBoundsToEncloseChildren();

            buttonRow.AddChild(levelingIcon);
            buttonRow.AddChild(notificationSettingsLabel);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(levelingSwitchContainer);

            return(buttonRow);
        }
        private GuiWidget CreateFanControls()
        {
            PrinterConnectionAndCommunication.Instance.FanSpeedSet.RegisterEvent(FanSpeedChanged_Event, ref unregisterEvents);

            FlowLayoutWidget leftToRight = new FlowLayoutWidget();

            leftToRight.Padding = new BorderDouble(3, 0, 0, 5);

            //Matt's test editing to add a on/off toggle switch
            bool fanActive = PrinterConnectionAndCommunication.Instance.FanSpeed0To255 != 0;

            toggleSwitch                      = ImageButtonFactory.CreateToggleSwitch(fanActive);
            toggleSwitch.VAnchor              = VAnchor.ParentCenter;
            toggleSwitch.CheckedStateChanged += new EventHandler(ToggleSwitch_Click);
            toggleSwitch.Margin               = new BorderDouble(5, 0);

            leftToRight.AddChild(toggleSwitch);

            return(leftToRight);
        }
        public void TopToBottomContainerAppliesExpectedMarginToToggleView()
        {
            int marginSize = 40;
            int dimensions = 300;

            GuiWidget outerContainer = new GuiWidget(dimensions, dimensions);

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

            outerContainer.AddChild(topToBottomContainer);

            CheckBox toggleBox = ImageButtonFactory.CreateToggleSwitch(true);

            toggleBox.HAnchor         = HAnchor.ParentLeftRight;
            toggleBox.VAnchor         = VAnchor.ParentBottomTop;
            toggleBox.Margin          = new BorderDouble(marginSize);
            toggleBox.BackgroundColor = RGBA_Bytes.Red;
            toggleBox.DebugShowBounds = true;

            topToBottomContainer.AddChild(toggleBox);
            topToBottomContainer.AnchorAll();
            topToBottomContainer.PerformLayout();

            outerContainer.DoubleBuffer = true;
            outerContainer.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
            outerContainer.OnDraw(outerContainer.NewGraphics2D());

            // For troubleshooting or visual validation
            OutputImages(outerContainer, outerContainer);

            var bounds = toggleBox.BoundsRelativeToParent;

            Assert.IsTrue(bounds.Left == marginSize, "Left margin is incorrect");
            Assert.IsTrue(bounds.Right == dimensions - marginSize, "Right margin is incorrect");
            Assert.IsTrue(bounds.Top == dimensions - marginSize, "Top margin is incorrect");
            Assert.IsTrue(bounds.Bottom == marginSize, "Bottom margin is incorrect");
        }
        private FlowLayoutWidget GetAutoLevelControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

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

            TextWidget notificationSettingsLabel = new TextWidget("Software 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(() =>
                {
                    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(() =>
                {
                    LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration);
                });
            };

            Agg.Image.ImageBuffer levelingImage = StaticData.Instance.LoadIcon(Path.Combine("PrintStatusControls", "leveling-24x24.png"));
            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                InvertLightness.DoInvertLightness(levelingImage);
            }

            ImageWidget levelingIcon = new ImageWidget(levelingImage);

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

            CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(ActivePrinterProfile.Instance.DoPrintLeveling);

            printLevelingSwitch.VAnchor              = VAnchor.ParentCenter;
            printLevelingSwitch.Margin               = new BorderDouble(left: 16);
            printLevelingSwitch.CheckedStateChanged += (sender, e) =>
            {
                ActivePrinterProfile.Instance.DoPrintLeveling = printLevelingSwitch.Checked;
            };

            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();
                printLevelingSwitch.Checked = ActivePrinterProfile.Instance.DoPrintLeveling;
            }, ref unregisterEvents);

            buttonRow.AddChild(levelingIcon);
            buttonRow.AddChild(printLevelingStatusLabel);
            buttonRow.AddChild(editButton);
            buttonRow.AddChild(new HorizontalSpacer());
            buttonRow.AddChild(runPrintLevelingButton);
            buttonRow.AddChild(printLevelingSwitch);

            SetPrintLevelButtonVisiblity();
            return(buttonRow);
        }
        private FlowLayoutWidget GetAutoLevelControl()
        {
            FlowLayoutWidget buttonRow = new FlowLayoutWidget();

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

            ImageBuffer levelingImage = StaticData.Instance.LoadIcon("leveling_32x32.png", 24, 24).InvertLightness();

            if (!ActiveTheme.Instance.IsDarkTheme)
            {
                levelingImage.InvertLightness();
            }

            ImageWidget levelingIcon = new ImageWidget(levelingImage);

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

            buttonRow.AddChild(levelingIcon);

            // label
            printLevelingStatusLabel = new TextWidget("")
            {
                AutoExpandBoundsToText = true,
                TextColor = ActiveTheme.Instance.PrimaryTextColor,
                VAnchor   = VAnchor.ParentCenter,
                Text      = "Software Print Leveling".Localize()
            };

            buttonRow.AddChild(printLevelingStatusLabel);

            // edit button
            Button editButton = TextImageButtonFactory.GetThemedEditButton();

            editButton.Margin  = new BorderDouble(2, 2, 2, 0);
            editButton.VAnchor = Agg.UI.VAnchor.ParentTop;

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

            buttonRow.AddChild(editButton);

            buttonRow.AddChild(new HorizontalSpacer());

            // configure button
            runPrintLevelingButton         = textImageButtonFactory.Generate("Configure".Localize().ToUpper());
            runPrintLevelingButton.Margin  = new BorderDouble(left: 6);
            runPrintLevelingButton.VAnchor = VAnchor.ParentCenter;
            runPrintLevelingButton.Click  += (sender, e) =>
            {
                UiThread.RunOnIdle(() => LevelWizardBase.ShowPrintLevelWizard(LevelWizardBase.RuningState.UserRequestedCalibration));
            };
            buttonRow.AddChild(runPrintLevelingButton);

            // put in the switch
            CheckBox printLevelingSwitch = ImageButtonFactory.CreateToggleSwitch(ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled));

            printLevelingSwitch.VAnchor              = VAnchor.ParentCenter;
            printLevelingSwitch.Margin               = new BorderDouble(left: 16);
            printLevelingSwitch.CheckedStateChanged += (sender, e) =>
            {
                ActiveSliceSettings.Instance.Helpers.DoPrintLeveling(printLevelingSwitch.Checked);
            };

            PrinterSettings.PrintLevelingEnabledChanged.RegisterEvent((sender, e) =>
            {
                printLevelingSwitch.Checked = ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_enabled);
            }, ref unregisterEvents);

            // only show the switch if leveling can be turned off (it can't if it is required).
            if (!ActiveSliceSettings.Instance.GetValue <bool>(SettingsKey.print_leveling_required_to_print))
            {
                buttonRow.AddChild(printLevelingSwitch);
            }

            return(buttonRow);
        }