public GuiWidget Create(IObject3D item, ThemeConfig theme) { var column = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.MaxFitOrStretch }; var imageObject = item as ImageObject3D; var activeImage = imageObject.Image; var imageSection = new SearchableSectionWidget("Image".Localize(), new FlowLayoutWidget(FlowDirection.TopToBottom), theme, emptyText: "Search Google".Localize()); imageSection.SearchInvoked += (s, e) => { string imageType = " silhouette"; if (item.Parent.GetType().Name.Contains("Lithophane")) { imageType = ""; } ApplicationController.Instance.LaunchBrowser($"http://www.google.com/search?q={e.Data}{imageType}&tbm=isch"); }; theme.ApplyBoxStyle(imageSection, margin: 0); column.AddChild(imageSection); ImageBuffer thumbnailImage = SetImage(theme, imageObject); ImageWidget thumbnailWidget; imageSection.ContentPanel.AddChild(thumbnailWidget = new ImageWidget(thumbnailImage) { Margin = new BorderDouble(bottom: 5), HAnchor = HAnchor.Center }); thumbnailWidget.Click += (s, e) => { if (e.Button == MouseButtons.Right) { var popupMenu = new PopupMenu(theme); var pasteMenu = popupMenu.CreateMenuItem("Paste".Localize()); pasteMenu.Click += (s2, e2) => { activeImage = Clipboard.Instance.GetImage(); thumbnailWidget.Image = activeImage; // Persist string filePath = ApplicationDataStorage.Instance.GetNewLibraryFilePath(".png"); AggContext.ImageIO.SaveImageData( filePath, activeImage); imageObject.AssetPath = filePath; imageObject.Mesh = null; thumbnailWidget.Image = SetImage(theme, imageObject); column.Invalidate(); imageObject.Invalidate(new InvalidateArgs(imageObject, InvalidateType.Image)); }; pasteMenu.Enabled = Clipboard.Instance.ContainsImage; var copyMenu = popupMenu.CreateMenuItem("Copy".Localize()); copyMenu.Click += (s2, e2) => { Clipboard.Instance.SetImage(thumbnailWidget.Image); }; var popupBounds = new RectangleDouble(e.X + 1, e.Y + 1, e.X + 1, e.Y + 1); var systemWindow = column.Parents <SystemWindow>().FirstOrDefault(); systemWindow.ShowPopup( new MatePoint(thumbnailWidget) { Mate = new MateOptions(MateEdge.Left, MateEdge.Bottom), AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) }, new MatePoint(popupMenu) { Mate = new MateOptions(MateEdge.Left, MateEdge.Top), AltMate = new MateOptions(MateEdge.Left, MateEdge.Top) }, altBounds: popupBounds); } }; // add in the invert checkbox and change image button var changeButton = new TextButton("Change".Localize(), theme) { BackgroundColor = theme.MinimalShade }; changeButton.Click += (sender, e) => { UiThread.RunOnIdle(() => { // we do this using to make sure that the stream is closed before we try and insert the Picture AggContext.FileDialogs.OpenFileDialog( new OpenFileDialogParams( "Select an image file|*.jpg;*.png;*.bmp;*.gif;*.pdf", multiSelect: false, title: "Add Image".Localize()), (openParams) => { if (!File.Exists(openParams.FileName)) { return; } imageObject.AssetPath = openParams.FileName; imageObject.Mesh = null; thumbnailWidget.Image = SetImage(theme, imageObject); column.Invalidate(); imageObject.Invalidate(new InvalidateArgs(imageObject, InvalidateType.Image)); }); }); }; var row = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, }; imageSection.ContentPanel.AddChild(row); // Invert checkbox var invertCheckbox = new CheckBox(new CheckBoxViewText("Invert".Localize(), textColor: theme.Colors.PrimaryTextColor)) { Checked = imageObject.Invert, Margin = new BorderDouble(0), }; invertCheckbox.CheckedStateChanged += (s, e) => { imageObject.Invert = invertCheckbox.Checked; }; row.AddChild(invertCheckbox); row.AddChild(new HorizontalSpacer()); row.AddChild(changeButton); imageObject.Invalidated += (s, e) => { if (e.InvalidateType == InvalidateType.Image && activeImage != imageObject.Image) { thumbnailImage = SetImage(theme, imageObject); thumbnailWidget.Image = thumbnailImage; activeImage = imageObject.Image; } }; return(column); }
public GuiWidget Create(IObject3D item, UndoBuffer undoBuffer, ThemeConfig theme) { var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch }; if (item != null) { var context = new PPEContext() { item = item }; // CreateEditor AddUnlockLinkIfRequired(context.item, mainContainer, theme); GuiWidget scope = mainContainer; // Create a field editor for each editable property detected via reflection foreach (var property in GetEditablePropreties(context.item)) { if (property.PropertyInfo.GetCustomAttributes(true).OfType <HideFromEditorAttribute>().Any()) { continue; } // Create SectionWidget for SectionStartAttributes if (property.PropertyInfo.GetCustomAttributes(true).OfType <SectionStartAttribute>().FirstOrDefault() is SectionStartAttribute sectionStart) { var column = new FlowLayoutWidget() { FlowDirection = FlowDirection.TopToBottom, Padding = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0) }; bool expanded = true; var sectionState = item as ISectionState; if (sectionState != null) { expanded = sectionState.GetSectionExpansion(sectionStart.Title); } var section = new SectionWidget(sectionStart.Title, column, theme, expanded: expanded); theme.ApplyBoxStyle(section); if (sectionState != null) { section.ExpandedChanged += (s, e) => sectionState.SectionExpansionChanged(sectionStart.Title, e); } mainContainer.AddChild(section); scope = column; } // Create SectionWidget for SectionStartAttributes if (property.PropertyInfo.GetCustomAttributes(true).OfType <SectionEndAttribute>().Any()) { // Push scope back to mainContainer on scope = mainContainer; } var editor = CreatePropertyEditor(property, undoBuffer, context, theme); if (editor != null) { scope.AddChild(editor); } } AddFunctionButtons(item, mainContainer, theme); AddWebPageLinkIfRequired(context, mainContainer, theme); // add in an Update button if applicable if (context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() is ShowUpdateButtonAttribute showUpdate) { var updateButton = new TextButton("Update".Localize(), theme) { Margin = 5, BackgroundColor = theme.MinimalShade, HAnchor = HAnchor.Right, VAnchor = VAnchor.Absolute }; updateButton.Click += (s, e) => { context.item.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties)); }; mainContainer.AddChild(updateButton); } // Init with custom 'UpdateControls' hooks (context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button")); } return(mainContainer); }
public PrintPopupMenu(PrinterConfig printer, ThemeConfig theme) : base(theme) { this.printer = printer; this.DrawArrow = true; this.BackgroundColor = theme.ToolbarButtonBackground; this.HoverColor = theme.ToolbarButtonHover; this.MouseDownColor = theme.ToolbarButtonDown; this.Name = "PrintPopupMenu"; this.HAnchor = HAnchor.Fit; this.VAnchor = VAnchor.Fit; settingsContext = new SettingsContext(printer, null, NamedSettingsLayers.All); this.DynamicPopupContent = () => { var menuTheme = ApplicationController.Instance.MenuTheme; int tabIndex = 0; allUiFields.Clear(); var column = new FlowLayoutWidget(FlowDirection.TopToBottom) { Padding = 10, BackgroundColor = menuTheme.Colors.PrimaryBackgroundColor }; column.AddChild(new TextWidget("Options".Localize(), textColor: menuTheme.Colors.PrimaryTextColor) { HAnchor = HAnchor.Left }); var optionsPanel = new IgnoredFlowLayout() { Name = "PrintPopupMenu Panel", HAnchor = HAnchor.Fit | HAnchor.Left, VAnchor = VAnchor.Fit, Padding = 5, MinimumSize = new Vector2(400, 65), Margin = new BorderDouble(top: 10), }; column.AddChild(optionsPanel); foreach (var key in new[] { "layer_height", "fill_density", "support_material", "create_raft" }) { var settingsData = SettingsOrganizer.Instance.GetSettingsData(key); var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields); SliceSettingsRow.AddBordersToEditFields(row); optionsPanel.AddChild(row); } var subPanel = new FlowLayoutWidget(FlowDirection.TopToBottom); var sectionWidget = new SectionWidget("Advanced", subPanel, menuTheme, expanded: true) { Name = "Advanced Section", HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, Margin = 0 }; column.AddChild(sectionWidget); bool anySettingOverridden = false; anySettingOverridden |= printer.Settings.GetValue <bool>(SettingsKey.spiral_vase); anySettingOverridden |= !string.IsNullOrWhiteSpace(printer.Settings.GetValue(SettingsKey.layer_to_pause)); sectionWidget.Load += (s, e) => { sectionWidget.Checkbox.Checked = anySettingOverridden; }; foreach (var key in new[] { SettingsKey.spiral_vase, SettingsKey.layer_to_pause }) { var settingsData = SettingsOrganizer.Instance.GetSettingsData(key); var row = SliceSettingsTabView.CreateItemRow(settingsData, settingsContext, printer, menuTheme, ref tabIndex, allUiFields); SliceSettingsRow.AddBordersToEditFields(row); subPanel.AddChild(row); } theme.ApplyBoxStyle(sectionWidget); sectionWidget.Margin = new BorderDouble(0, 10); sectionWidget.ContentPanel.Children <SettingsRow>().First().Border = new BorderDouble(0, 1); sectionWidget.ContentPanel.Children <SettingsRow>().Last().Border = 0; var button = new TextButton("Start Print".Localize(), menuTheme) { Name = "Start Print Button", HAnchor = HAnchor.Right, VAnchor = VAnchor.Absolute, }; button.Click += (s, e) => { // Exit if the bed is not GCode and the bed has no printable items if ((printer.Bed.EditContext.SourceItem as ILibraryAsset)?.ContentType != "gcode" && !printer.PrintableItems(printer.Bed.EditContext.Content).Any()) { return; } UiThread.RunOnIdle(async() => { // Save any pending changes before starting print operation await ApplicationController.Instance.Tasks.Execute("Saving Changes".Localize(), printer.Bed.SaveChanges); await ApplicationController.Instance.PrintPart( printer.Bed.EditContext, printer, null, CancellationToken.None); }); }; column.AddChild(button); theme.ApplyPrimaryActionStyle(button); return(column); }; this.AddChild(new TextButton("Print".Localize(), theme) { Selectable = false, Padding = theme.TextButtonPadding.Clone(right: 5) }); PrinterSettings.SettingChanged.RegisterEvent((s, e) => { if (e is StringEventArgs stringEvent) { string settingsKey = stringEvent.Data; if (allUiFields.TryGetValue(settingsKey, out UIField uifield)) { string currentValue = settingsContext.GetValue(settingsKey); if (uifield.Value != currentValue || settingsKey == "com_port") { uifield.SetValue( currentValue, userInitiated: false); } } } }, ref unregisterEvents); }
public AddPrinterWidget(ThemeConfig theme, Action <bool> nextButtonEnabled) : base(theme) { this.nextButtonEnabled = nextButtonEnabled; this.ExistingPrinterNames = new HashSet <string>(ProfileManager.Instance.ActiveProfiles.Select(p => p.Name)); this.Name = "AddPrinterWidget"; horizontalSplitter.Panel2.Padding = theme.DefaultContainerPadding; treeView.AfterSelect += this.TreeView_AfterSelect; UiThread.RunOnIdle(() => { foreach (var oem in OemSettings.Instance.OemProfiles.OrderBy(o => o.Key)) { var rootNode = this.CreateTreeNode(oem); rootNode.Expandable = true; rootNode.TreeView = treeView; rootNode.Load += (s, e) => { var image = OemSettings.Instance.GetIcon(oem.Key); SetImage(rootNode, image); }; contentPanel.AddChild(rootNode); } this.TreeLoaded = true; }); var container = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0) }; var panel2Column = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch }; panel2Column.AddChild(new TextWidget("Select a printer to continue".Localize(), pointSize: theme.DefaultFontSize, textColor: theme.TextColor)); nameSection = new SectionWidget("New Printer Name".Localize(), container, theme, expandingContent: false) { HAnchor = HAnchor.Stretch, Padding = theme.ToolbarPadding, Enabled = false }; theme.ApplyBoxStyle(nameSection); // Reset right margin nameSection.Margin = nameSection.Margin.Clone(right: theme.DefaultContainerPadding); printerInfo = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit }; nameSection.BackgroundColor = theme.MinimalShade; nameSection.Margin = new BorderDouble(theme.DefaultContainerPadding).Clone(left: 0); panel2Column.AddChild(nameSection); panel2Column.AddChild(PrinterNameError = new TextWidget("", 0, 0, 10) { TextColor = Color.Red, HAnchor = HAnchor.Stretch, Margin = new BorderDouble(top: 3) }); var scrollable = new ScrollableWidget(autoScroll: true) { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Stretch, }; scrollable.ScrollArea.HAnchor = HAnchor.Stretch; // Padding allows space for scrollbar printerInfo.Padding = new BorderDouble(right: theme.DefaultContainerPadding + 2); scrollable.AddChild(printerInfo); panel2Column.AddChild(scrollable); horizontalSplitter.Panel2.Padding = horizontalSplitter.Panel2.Padding.Clone(right: 0, bottom: 0); horizontalSplitter.Panel2.AddChild(panel2Column); printerNameInput = new MHTextEditWidget("", theme) { HAnchor = HAnchor.Stretch, }; printerNameInput.ActualTextEditWidget.EditComplete += (s, e) => { this.ValidateControls(); this.usingDefaultName = false; }; container.AddChild(printerNameInput); }
public GuiWidget Create(IObject3D item, ThemeConfig theme) { var column = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.MaxFitOrStretch }; var imageObject = item as ImageObject3D; var activeImage = imageObject.Image; var imageSection = new SectionWidget( "Image".Localize(), new FlowLayoutWidget(FlowDirection.TopToBottom), theme); theme.ApplyBoxStyle(imageSection, margin: 0); column.AddChild(imageSection); ImageBuffer thumbnailImage = SetImage(theme, imageObject); ImageWidget thumbnailWidget; imageSection.ContentPanel.AddChild(thumbnailWidget = new ImageWidget(thumbnailImage) { Margin = new BorderDouble(bottom: 5), HAnchor = HAnchor.Center }); bool addImageSearch = true; if (addImageSearch) { // add a search Google box var searchRow = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, }; imageSection.ContentPanel.AddChild(searchRow); MHTextEditWidget textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Search Google".Localize()); textToAddWidget.HAnchor = HAnchor.Stretch; searchRow.AddChild(textToAddWidget); textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) => { UiThread.RunOnIdle(() => { textToAddWidget.Unfocus(); string search = "http://www.google.com/search?q={0} silhouette&tbm=isch".FormatWith(textToAddWidget.Text); ApplicationController.Instance.LaunchBrowser(search); }); }; } // add in the invert checkbox and change image button var changeButton = new TextButton("Change".Localize(), theme) { BackgroundColor = theme.MinimalShade }; changeButton.Click += (sender, e) => { UiThread.RunOnIdle(() => { // we do this using to make sure that the stream is closed before we try and insert the Picture AggContext.FileDialogs.OpenFileDialog( new OpenFileDialogParams( "Select an image file|*.jpg;*.png;*.bmp;*.gif;*.pdf", multiSelect: false, title: "Add Image".Localize()), (openParams) => { if (!File.Exists(openParams.FileName)) { return; } imageObject.AssetPath = openParams.FileName; imageObject.Mesh = null; thumbnailWidget.Image = SetImage(theme, imageObject); column.Invalidate(); imageObject.Invalidate(new InvalidateArgs(imageObject, InvalidateType.Image)); }); }); }; var row = new FlowLayoutWidget() { HAnchor = HAnchor.Stretch, VAnchor = VAnchor.Fit, }; imageSection.ContentPanel.AddChild(row); // Invert checkbox var invertCheckbox = new CheckBox(new CheckBoxViewText("Invert".Localize(), textColor: theme.Colors.PrimaryTextColor)) { Checked = imageObject.Invert, Margin = new BorderDouble(0), }; invertCheckbox.CheckedStateChanged += (s, e) => { imageObject.Invert = invertCheckbox.Checked; }; row.AddChild(invertCheckbox); row.AddChild(new HorizontalSpacer()); row.AddChild(changeButton); imageObject.Invalidated += (s, e) => { if (e.InvalidateType == InvalidateType.Image && activeImage != imageObject.Image) { thumbnailImage = SetImage(theme, imageObject); thumbnailWidget.Image = thumbnailImage; activeImage = imageObject.Image; } }; return(column); }
public GuiWidget Create(IObject3D item, ThemeConfig theme) { var mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom) { HAnchor = HAnchor.Stretch }; // TODO: Long term we should have a solution where editors can extend Draw and Undo without this hack var view3DWidget = ApplicationController.Instance.DragDropData.View3DWidget; var undoBuffer = view3DWidget.sceneContext.Scene.UndoBuffer; if (item != null) { var context = new PPEContext() { item = item }; // CreateEditor AddUnlockLinkIfRequired(context, mainContainer, theme); GuiWidget scope = mainContainer; // Create a field editor for each editable property detected via reflection foreach (var property in GetEditablePropreties(context.item)) { // Create SectionWidget for SectionStartAttributes if (property.PropertyInfo.GetCustomAttributes(true).OfType <SectionStartAttribute>().FirstOrDefault() is SectionStartAttribute sectionStart) { var column = new FlowLayoutWidget() { FlowDirection = FlowDirection.TopToBottom, Padding = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0) }; var section = new SectionWidget(sectionStart.Title, column, theme); theme.ApplyBoxStyle(section); mainContainer.AddChild(section); scope = column; } // Create SectionWidget for SectionStartAttributes if (property.PropertyInfo.GetCustomAttributes(true).OfType <SectionEndAttribute>().Any()) { // Push scope back to mainContainer on scope = mainContainer; } var editor = CreatePropertyEditor(property, undoBuffer, context, theme); if (editor != null) { scope.AddChild(editor); } } AddWebPageLinkIfRequired(context, mainContainer, theme); // add in an Update button if applicable var showUpdate = context.item.GetType().GetCustomAttributes(typeof(ShowUpdateButtonAttribute), true).FirstOrDefault() as ShowUpdateButtonAttribute; if (showUpdate != null) { var updateButton = new TextButton("Update".Localize(), theme) { Margin = 5, BackgroundColor = theme.MinimalShade, HAnchor = HAnchor.Right, VAnchor = VAnchor.Absolute }; updateButton.Click += (s, e) => { context.item.Invalidate(new InvalidateArgs(context.item, InvalidateType.Properties)); }; mainContainer.AddChild(updateButton); } // Init with custom 'UpdateControls' hooks (context.item as IPropertyGridModifier)?.UpdateControls(new PublicPropertyChange(context, "Update_Button")); } return(mainContainer); }