Beispiel #1
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        // Set up the menu bar items
        FileButton = GetNode <MenuButton>("MenuBar/btnFile");
        PopupMenu FileButtonPopup = FileButton.GetPopup();

        EditButton = GetNode <MenuButton>("MenuBar/btnEdit");
        PopupMenu EditButtonPopup = EditButton.GetPopup();

        ViewButton = GetNode <MenuButton>("MenuBar/btnView");
        HelpButton = GetNode <MenuButton>("MenuBar/btnHelp");

        // Populate file
        FileButtonPopup.AddItem("New");
        FileButtonPopup.AddItem("Open");
        FileButtonPopup.AddItem("Import");
        FileButtonPopup.AddSeparator();
        FileButtonPopup.AddItem("Save");
        FileButtonPopup.AddItem("Save As");
        FileButtonPopup.AddSeparator();
        FileButtonPopup.AddItem("Preferences");
        FileButtonPopup.AddSeparator();
        FileButtonPopup.AddItem("Exit");
        FileButtonPopup.Connect("id_pressed", this, "FileButtonPressed");

        PreferencesWindow = GetNode <WindowDialog>("/root/main/UI/PreferencesWindow");
        ImportWindow      = GetNode <FileDialog>("/root/main/UI/ImportWindow");
        // Populate edit

        // Create Insert shape submenu
        PopupMenu AddShapeMenu = new PopupMenu();

        AddShapeMenu.Name = "Shape";
        AddShapeMenu.AddItem("Square");
        AddShapeMenu.AddItem("Sphere");
        AddShapeMenu.AddItem("Cylinder");
        AddShapeMenu.AddItem("Prism");
        AddShapeMenu.AddItem("Capsule");
        EditButtonPopup.AddChild(AddShapeMenu);

        EditButtonPopup.AddSubmenuItem("Add Shape", "Shape");



        // Populate view
        ViewButton.GetPopup().AddItem("1");
        ViewButton.GetPopup().AddItem("2");
        ViewButton.GetPopup().AddItem("2alt");
        ViewButton.GetPopup().AddItem("3");
        ViewButton.GetPopup().AddItem("3alt");
        ViewButton.GetPopup().AddItem("4");
        ViewButton.GetPopup().Connect("id_pressed", GetNode("/root/main/UI/AppWindow/EnvironmentContainer/4WayViewport/"), "toolbarViewItemPressed");

        this.Connect("gui_input", this, "TitleBarGUIInputHandler");
        GD.Print("TITLEBAR.CS: READY");
    }
        protected override void OnClick(MouseEventArgs mouseEvent)
        {
            if (mouseEvent.Button == MouseButtons.Right)
            {
                var theme      = ApplicationController.Instance.MenuTheme;
                var printTasks = PrintHistoryData.Instance.GetHistoryItems(1000);

                var popupMenu          = new PopupMenu(theme);
                var printHistoryEditor = new PrintHistoryEditor(null, theme, printTask, printTasks);
                var qualityWidget      = PrintHistoryEditor.GetQualityWidget(theme,
                                                                             printTask,
                                                                             () =>
                {
                    popupMenu.Unfocus();
                    printInfoWidget.Text = GetPrintInfo();
                    SetIndicatorColor();
                },
                                                                             theme.DefaultFontSize);

                var menuItem = new PopupMenu.MenuItem(qualityWidget, theme)
                {
                    HAnchor    = HAnchor.Fit | HAnchor.Stretch,
                    VAnchor    = VAnchor.Fit,
                    HoverColor = Color.Transparent,
                };
                popupMenu.AddChild(menuItem);

                printHistoryEditor.AddNotesMenu(popupMenu, printTasks, () =>
                {
                    printInfoWidget.Text = GetPrintInfo();
                });

                popupMenu.CreateSeparator();

                AddExportMenu(popupMenu, printTasks);

                popupMenu.CreateSeparator();

                AddClearHistorMenu(popupMenu, printTasks);

                popupMenu.ShowMenu(this, mouseEvent);
            }

            base.OnClick(mouseEvent);
        }
Beispiel #3
0
        public FlowLayoutWidget CreateMenuItems(PopupMenu popupMenu, IEnumerable <NamedAction> menuActions)
        {
            // Create menu items in the DropList for each element in this.menuActions
            foreach (var menuAction in menuActions)
            {
                if (menuAction is ActionSeparator)
                {
                    popupMenu.CreateSeparator();
                }
                else
                {
                    if (menuAction is NamedActionGroup namedActionButtons)
                    {
                        var content = new FlowLayoutWidget()
                        {
                            HAnchor = HAnchor.Fit | HAnchor.Stretch
                        };

                        var textWidget = new TextWidget(menuAction.Title, pointSize: this.DefaultFontSize, textColor: this.TextColor)
                        {
                            // Padding = MenuPadding,
                            VAnchor = VAnchor.Center
                        };
                        content.AddChild(textWidget);

                        content.AddChild(new HorizontalSpacer());

                        foreach (var actionButton in namedActionButtons.Group)
                        {
                            var button = new TextButton(actionButton.Title, this)
                            {
                                Border      = new BorderDouble(1, 0, 0, 0),
                                BorderColor = this.MinimalShade,
                                HoverColor  = this.AccentMimimalOverlay,
                                Enabled     = actionButton.IsEnabled()
                            };

                            content.AddChild(button);

                            if (actionButton.IsEnabled())
                            {
                                button.Click += (s, e) =>
                                {
                                    actionButton.Action();
                                    popupMenu.Unfocus();
                                };
                            }
                        }

                        var menuItem = new PopupMenu.MenuItem(content, this)
                        {
                            HAnchor    = HAnchor.Fit | HAnchor.Stretch,
                            VAnchor    = VAnchor.Fit,
                            HoverColor = Color.Transparent,
                        };
                        popupMenu.AddChild(menuItem);
                        menuItem.Padding = new BorderDouble(menuItem.Padding.Left,
                                                            menuItem.Padding.Bottom,
                                                            0,
                                                            menuItem.Padding.Top);
                    }
                    else
                    {
                        PopupMenu.MenuItem menuItem;

                        if (menuAction is NamedBoolAction boolAction)
                        {
                            menuItem = popupMenu.CreateBoolMenuItem(menuAction.Title, boolAction.GetIsActive, boolAction.SetIsActive);
                        }
                        else
                        {
                            menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon, menuAction.Shortcut);
                        }

                        menuItem.Name = $"{menuAction.Title} Menu Item";

                        menuItem.Enabled = menuAction is NamedActionGroup ||
                                           (menuAction.Action != null && menuAction.IsEnabled?.Invoke() != false);

                        menuItem.ClearRemovedFlag();

                        if (menuItem.Enabled)
                        {
                            menuItem.Click += (s, e) =>
                            {
                                menuAction.Action();
                            };
                        }
                    }
                }
            }

            return(popupMenu);
        }
        public void AddQualityMenu(PopupMenu popupMenu, Action notesChanged)
        {
            var theme = ApplicationController.Instance.MenuTheme;

            var content = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Fit | HAnchor.Stretch
            };

            var textWidget = new TextWidget("Print Quality".Localize() + ":", pointSize: theme.DefaultFontSize, textColor: theme.TextColor)
            {
                // Padding = MenuPadding,
                VAnchor = VAnchor.Center
            };

            content.AddChild(textWidget);

            content.AddChild(new HorizontalSpacer());

            var siblings = new List <GuiWidget>();

            for (int i = 0; i < QualityNames.Length; i++)
            {
                var button = new RadioButton(new TextWidget(i.ToString(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor))
                {
                    Enabled     = printTask.PrintComplete,
                    Checked     = printTask.QualityWasSet && printTask.PrintQuality == i,
                    ToolTipText = QualityNames[i],
                    Margin      = 0,
                    Padding     = 5,
                    HAnchor     = HAnchor.Fit,
                    VAnchor     = VAnchor.Fit,
                };

                button.MouseEnterBounds += (s, e) =>
                {
                    button.BackgroundColor = theme.AccentMimimalOverlay;
                };

                button.MouseLeaveBounds += (s, e) =>
                {
                    button.BackgroundColor = button.Checked ? theme.AccentMimimalOverlay : Color.Transparent;
                };

                siblings.Add(button);

                if (button.Checked && button.Enabled)
                {
                    button.BackgroundColor = theme.AccentMimimalOverlay;
                }

                button.SiblingRadioButtonList = siblings;

                content.AddChild(button);

                button.Click += (s, e) =>
                {
                    printTask.PrintQuality  = siblings.IndexOf((GuiWidget)s);
                    printTask.QualityWasSet = true;
                    printTask.Commit();
                    popupMenu.Unfocus();
                    notesChanged();
                };
            }

            var menuItem = new PopupMenu.MenuItem(content, theme)
            {
                HAnchor    = HAnchor.Fit | HAnchor.Stretch,
                VAnchor    = VAnchor.Fit,
                HoverColor = Color.Transparent,
            };

            popupMenu.AddChild(menuItem);
        }