public MeshViewerApplication(string meshFileToLoad = "")
            : base(800, 600)
        {
            BackgroundColor = RGBA_Bytes.White;
            MinimumSize = new VectorMath.Vector2(200, 200);
            Title = "MatterHackers MeshViewr";
            UseOpenGL = true;

            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainer.AnchorAll();

            viewArea = new GuiWidget();

            viewArea.AnchorAll();

            Vector3 viewerVolume = new Vector3(200, 200, 200);
            double scale = 1;
            meshViewerWidget = new MeshViewerWidget(viewerVolume, scale, MeshViewerWidget.BedShape.Rectangular, "No Part Loaded");

            meshViewerWidget.AnchorAll();

            viewArea.AddChild(meshViewerWidget);

            mainContainer.AddChild(viewArea);

            FlowLayoutWidget buttonPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonPanel.HAnchor = HAnchor.ParentLeftRight;
            buttonPanel.Padding = new BorderDouble(3, 3);
            buttonPanel.BackgroundColor = RGBA_Bytes.DarkGray;

            if (meshFileToLoad != "")
            {
                meshViewerWidget.LoadMesh(meshFileToLoad);
            }
            else
            {
                openFileButton = new Button("Open 3D File", 0, 0);
                openFileButton.Click += new Button.ButtonEventHandler(openFileButton_ButtonClick);
                buttonPanel.AddChild(openFileButton);
            }

            bedCheckBox = new CheckBox("Bed");
            bedCheckBox.Checked = true;
            buttonPanel.AddChild(bedCheckBox);

            wireframeCheckBox = new CheckBox("Wireframe");
            buttonPanel.AddChild(wireframeCheckBox);

            GuiWidget leftRightSpacer = new GuiWidget();
            leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
            buttonPanel.AddChild(leftRightSpacer);

            mainContainer.AddChild(buttonPanel);

            this.AddChild(mainContainer);
            this.AnchorAll();

            AddHandlers();
        }
		public FatFlatClickWidget(TextWidget textWidget)
		{
			overlay = new GuiWidget();
			overlay.AnchorAll();
			overlay.BackgroundColor = ActiveTheme.Instance.TransparentDarkOverlay;
			overlay.Visible = false;

			this.GetChildClicks = true;

			this.AddChild(textWidget);
			this.AddChild(overlay);
		}
		public View3DTextCreator(Vector3 viewerVolume, Vector2 bedCenter, MeshViewerWidget.BedShape bedShape)
		{
			boldTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationSans-Bold.svg")));

			MeshGroupExtraData = new List<PlatingMeshGroupData>();

			FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
			mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

			FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
			centerPartPreviewAndControls.AnchorAll();

			GuiWidget viewArea = new GuiWidget();
			viewArea.AnchorAll();
			{
				meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
				meshViewerWidget.AllowBedRenderingWhenEmpty = true;
				meshViewerWidget.AnchorAll();
			}
			viewArea.AddChild(meshViewerWidget);

			centerPartPreviewAndControls.AddChild(viewArea);
			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

			FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.Padding = new BorderDouble(3, 3);
			buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);

			// add in the plater tools
			{
				FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				processingProgressControl = new ProgressControl("Finding Parts:".Localize(), ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
				processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
				editToolBar.AddChild(processingProgressControl);
				editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;

				editPlateButtonsContainer = new FlowLayoutWidget();

				MHTextEditWidget textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter Text Here".Localize());
				textToAddWidget.VAnchor = VAnchor.ParentCenter;
				textToAddWidget.Margin = new BorderDouble(5);
				editPlateButtonsContainer.AddChild(textToAddWidget);
				textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				Button insertTextButton = textImageButtonFactory.Generate("Insert".Localize());
				editPlateButtonsContainer.AddChild(insertTextButton);
				insertTextButton.Click += (sender, e) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				KeyDown += (sender, e) =>
				{
					KeyEventArgs keyEvent = e as KeyEventArgs;
					if (keyEvent != null && !keyEvent.Handled)
					{
						if (keyEvent.KeyCode == Keys.Escape)
						{
							if (meshSelectInfo.downOnPart)
							{
								meshSelectInfo.downOnPart = false;

								ScaleRotateTranslate translated = SelectedMeshTransform;
								translated.translation *= transformOnMouseDown;
								SelectedMeshTransform = translated;

								Invalidate();
							}
						}
					}
				};

				editToolBar.AddChild(editPlateButtonsContainer);
				buttonBottomPanel.AddChild(editToolBar);
			}

			GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
			centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
			buttonRightPanelHolder.AddChild(buttonRightPanel);

			viewControls3D = new ViewControls3D(meshViewerWidget);

			buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
			buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
			buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
			LockEditControls();

			GuiWidget leftRightSpacer = new GuiWidget();
			leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.AddChild(leftRightSpacer);

			closeButton = textImageButtonFactory.Generate("Close".Localize());
			buttonBottomPanel.AddChild(closeButton);

			mainContainerTopToBottom.AddChild(buttonBottomPanel);

			this.AddChild(mainContainerTopToBottom);
			this.AnchorAll();

			meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(viewControls3D);

			// set the view to be a good angle and distance
			meshViewerWidget.TrackballTumbleWidget.TrackBallController.Scale = .06;
			meshViewerWidget.TrackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .02, 0, 0)));

			AddHandlers();
			UnlockEditControls();
			// but make sure we can't use the right panel yet
			buttonRightPanelDisabledCover.Visible = true;
		}
		public EePromMarlinWindow()
			: base(650 * GuiWidget.DeviceScale, 480 * GuiWidget.DeviceScale)
		{
			AlwaysOnTopOfMain = true;
			Title = "Marlin Firmware EEPROM Settings".Localize();

			currentEePromSettings = new EePromMarlinSettings();
			currentEePromSettings.eventAdded += SetUiToPrinterSettings;

			GuiWidget mainContainer = new GuiWidget();
			mainContainer.AnchorAll();
			mainContainer.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
			mainContainer.Padding = new BorderDouble(3, 0);

			// space filling color
			GuiWidget spaceFiller = new GuiWidget(0, 500);
			spaceFiller.VAnchor = VAnchor.ParentBottom;
			spaceFiller.HAnchor = HAnchor.ParentLeftRight;
			spaceFiller.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
			spaceFiller.Padding = new BorderDouble(top: 3);
			mainContainer.AddChild(spaceFiller);

			double topBarHeight = 0;
			// the top button bar
			{
				FlowLayoutWidget topButtonBar = new FlowLayoutWidget();
				topButtonBar.HAnchor = HAnchor.ParentLeftRight;
				topButtonBar.VAnchor = VAnchor.FitToChildren | VAnchor.ParentTop;
				topButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

				topButtonBar.Margin = new BorderDouble(0, 3);

				Button buttonSetToFactorySettings = textImageButtonFactory.Generate("Reset to Factory Defaults".Localize());
				topButtonBar.AddChild(buttonSetToFactorySettings);

				buttonSetToFactorySettings.Click += (sender, e) =>
				{
					currentEePromSettings.SetPrinterToFactorySettings();
					currentEePromSettings.Update();
				};

				mainContainer.AddChild(topButtonBar);

				topBarHeight = topButtonBar.Height;
			}

			// the center content
			FlowLayoutWidget conterContent = new FlowLayoutWidget(FlowDirection.TopToBottom);
			conterContent.VAnchor = VAnchor.FitToChildren | VAnchor.ParentTop;
			conterContent.HAnchor = HAnchor.ParentLeftRight;
			conterContent.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
			conterContent.Padding = new BorderDouble(top: 3);
			conterContent.Margin = new BorderDouble(top: topBarHeight);

			conterContent.AddChild(Create4FieldSet("Steps per mm:".Localize(),
				"X:", ref stepsPerMmX,
				"Y:", ref stepsPerMmY,
				"Z:", ref stepsPerMmZ,
				"E:", ref stepsPerMmE));

			conterContent.AddChild(Create4FieldSet("Maximum feedrates [mm/s]:".Localize(),
				"X:", ref maxFeedrateMmPerSX,
				"Y:", ref maxFeedrateMmPerSY,
				"Z:", ref maxFeedrateMmPerSZ,
				"E:", ref maxFeedrateMmPerSE));

			conterContent.AddChild(Create4FieldSet("Maximum Acceleration [mm/s²]:".Localize(),
				"X:", ref maxAccelerationMmPerSSqrdX,
				"Y:", ref maxAccelerationMmPerSSqrdY,
				"Z:", ref maxAccelerationMmPerSSqrdZ,
				"E:", ref maxAccelerationMmPerSSqrdE));

			conterContent.AddChild(CreateField("Acceleration:".Localize(), ref acceleration));
			conterContent.AddChild(CreateField("Retract Acceleration:".Localize(), ref retractAcceleration));

			conterContent.AddChild(Create3FieldSet("PID settings:".Localize(),
				"P:", ref pidP,
				"I:", ref pidI,
				"D:", ref pidD));

			conterContent.AddChild(Create3FieldSet("Homing Offset:".Localize(),
				"X:", ref homingOffsetX,
				"Y:", ref homingOffsetY,
				"Z:", ref homingOffsetZ));

			conterContent.AddChild(CreateField("Min feedrate [mm/s]:".Localize(), ref minFeedrate));
			conterContent.AddChild(CreateField("Min travel feedrate [mm/s]:".Localize(), ref minTravelFeedrate));
			conterContent.AddChild(CreateField("Minimum segment time [ms]:".Localize(), ref minSegmentTime));
			conterContent.AddChild(CreateField("Maximum X-Y jerk [mm/s]:".Localize(), ref maxXYJerk));
			conterContent.AddChild(CreateField("Maximum Z jerk [mm/s]:".Localize(), ref maxZJerk));

			GuiWidget topBottomSpacer = new GuiWidget(1, 1);
			topBottomSpacer.VAnchor = VAnchor.ParentBottomTop;
			conterContent.AddChild(topBottomSpacer);

			mainContainer.AddChild(conterContent);

			// the bottom button bar
			{
				FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();
				bottomButtonBar.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
				bottomButtonBar.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
				bottomButtonBar.Margin = new BorderDouble(0, 3);

				Button buttonSave = textImageButtonFactory.Generate("Save to EEProm".Localize());
				bottomButtonBar.AddChild(buttonSave);
				buttonSave.Click += (sender, e) =>
				{
					UiThread.RunOnIdle(() =>
					{
						SaveSettingsToActive();
						currentEePromSettings.SaveToEeProm();
						Close();
					});
				};

				CreateSpacer(bottomButtonBar);

				// put in the import button
#if true
				{
					Button buttonImport = textImageButtonFactory.Generate("Import".Localize() + "...");
					buttonImport.Margin = new BorderDouble(0, 3);
					buttonImport.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							FileDialog.OpenFileDialog(
								new OpenFileDialogParams("EEPROM Settings" + "|*.ini")
								{
									ActionButtonLabel = "Import EEPROM Settings".Localize(),
									Title = "Import EEPROM".Localize(),
								},
									(openParams) =>
									{
										if (!string.IsNullOrEmpty(openParams.FileName))
										{
											currentEePromSettings.Import(openParams.FileName);
											SetUiToPrinterSettings(null, null);
                                        }
									});
						});
					};
					bottomButtonBar.AddChild(buttonImport);
				}

				// put in the export button
				{
					Button buttonExport = textImageButtonFactory.Generate("Export".Localize() + "...");
					buttonExport.Margin = new BorderDouble(0, 3);
					buttonExport.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							string defaultFileNameNoPath = "eeprom_settings.ini";
                            FileDialog.SaveFileDialog(
								new SaveFileDialogParams("EEPROM Settings" + "|*.ini")
								{
									ActionButtonLabel = "Export EEPROM Settings".Localize(),
									Title = "Export EEPROM".Localize(),
									FileName = defaultFileNameNoPath
								},
									(saveParams) =>
									{
										if (!string.IsNullOrEmpty(saveParams.FileName)
										&& saveParams.FileName != defaultFileNameNoPath)
										{
											currentEePromSettings.Export(saveParams.FileName);
										}
									});
						});
					};
					bottomButtonBar.AddChild(buttonExport);
				}
#endif

				Button buttonAbort = textImageButtonFactory.Generate("Close".Localize());
				bottomButtonBar.AddChild(buttonAbort);
				buttonAbort.Click += buttonAbort_Click;

				mainContainer.AddChild(bottomButtonBar);
			}

			PrinterConnectionAndCommunication.Instance.CommunicationUnconditionalFromPrinter.RegisterEvent(currentEePromSettings.Add, ref unregisterEvents);

#if __ANDROID__
			this.AddChild(new SoftKeyboardContentOffset(mainContainer));
#else
			AddChild(mainContainer);
#endif

			ShowAsSystemWindow();

			// and ask the printer to send the settings
			currentEePromSettings.Update();

			foreach (GuiWidget widget in leftStuffToSize)
			{
				widget.Width = maxWidthOfLeftStuff;
			}
		}
        public void AddElements()
        {
			Title = LocalizedString.Get("Design Add-ons");            

            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);
            {
				string elementHeaderLabelBeg = LocalizedString.Get("Select a Design Tool");
				string elementHeaderLabelFull = string.Format("{0}:", elementHeaderLabelBeg);
				string elementHeaderLabel = elementHeaderLabelFull;
				TextWidget elementHeader = new TextWidget(string.Format(elementHeaderLabel), pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor = HAnchor.ParentLeftRight;
                elementHeader.VAnchor = Agg.UI.VAnchor.ParentBottom;

                headerRow.AddChild(elementHeader);
            }

            topToBottom.AddChild(headerRow);

            GuiWidget presetsFormContainer = new GuiWidget();
            {
                presetsFormContainer.HAnchor = HAnchor.ParentLeftRight;
                presetsFormContainer.VAnchor = VAnchor.ParentBottomTop;
                presetsFormContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            FlowLayoutWidget pluginRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            pluginRowContainer.AnchorAll();
            presetsFormContainer.AddChild(pluginRowContainer);            
            
            unlockButtonFactory.Margin = new BorderDouble(10,0);
            if (ActiveTheme.Instance.IsDarkTheme)
            {
                unlockButtonFactory.normalFillColor = new RGBA_Bytes(0, 0, 0, 100);
                unlockButtonFactory.normalBorderColor = new RGBA_Bytes(0, 0, 0, 100);
                unlockButtonFactory.hoverFillColor = new RGBA_Bytes(0, 0, 0, 50);
                unlockButtonFactory.hoverBorderColor = new RGBA_Bytes(0, 0, 0, 50);
            }
            else
            {
                unlockButtonFactory.normalFillColor = new RGBA_Bytes(0, 0, 0, 50);
                unlockButtonFactory.normalBorderColor = new RGBA_Bytes(0, 0, 0, 50);
                unlockButtonFactory.hoverFillColor = new RGBA_Bytes(0, 0, 0, 100);
                unlockButtonFactory.hoverBorderColor = new RGBA_Bytes(0, 0, 0, 100);
            }

            foreach(CreatorInformation creatorInfo in RegisteredCreators.Instance.Creators)
            {
                FlowLayoutWidget pluginListingContainer = new FlowLayoutWidget();
                pluginListingContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                pluginListingContainer.BackgroundColor = RGBA_Bytes.White;
                pluginListingContainer.Padding = new BorderDouble(0);
                pluginListingContainer.Margin = new BorderDouble(6, 0, 6, 6);                
                
                ClickWidget pluginRow = new ClickWidget();
                pluginRow.Margin = new BorderDouble(6, 0, 6, 0);        
                pluginRow.Height = 38;
                pluginRow.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                GuiWidget overlay = new GuiWidget();
                overlay.AnchorAll();
                overlay.Cursor = Cursors.Hand;
                
                FlowLayoutWidget macroRow = new FlowLayoutWidget();
                macroRow.AnchorAll();
                macroRow.BackgroundColor = RGBA_Bytes.White;

                if (creatorInfo.iconPath != "")
                {
                    ImageBuffer imageBuffer = LoadImage(creatorInfo.iconPath);
                    ImageWidget imageWidget = new ImageWidget(imageBuffer);
                    imageWidget.VAnchor = Agg.UI.VAnchor.ParentCenter;
                    macroRow.AddChild(imageWidget);
                }

                bool userHasPermission;
                if (!creatorInfo.paidAddOnFlag)
                {
                    userHasPermission = true;
                }
                else
                {
                    userHasPermission = creatorInfo.permissionFunction();
                }

                string addOnDescription;
                addOnDescription = creatorInfo.description;
                TextWidget buttonLabel = new TextWidget(addOnDescription, pointSize: 14);
                buttonLabel.Margin = new BorderDouble(left: 10);
                buttonLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
                macroRow.AddChild(buttonLabel);

                if (!userHasPermission)
                {                    
                    TextWidget demoLabel = new TextWidget("(demo)", pointSize: 10);

                    demoLabel.Margin = new BorderDouble(left: 4);
                    demoLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;
                    macroRow.AddChild(demoLabel);
                }

                FlowLayoutWidget hSpacer = new FlowLayoutWidget();
                hSpacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                macroRow.AddChild(hSpacer);

                CreatorInformation callCorrectFunctionHold = creatorInfo;
                pluginRow.Click += (sender, e) =>
                {
                    if (RegisteredCreators.Instance.Creators.Count > 0)
                    {
                        callCorrectFunctionHold.functionToLaunchCreator(null, null);
                    }
                    UiThread.RunOnIdle(CloseOnIdle);
                };

                pluginRow.AddChild(macroRow);
                pluginRow.AddChild(overlay);

                pluginListingContainer.AddChild(pluginRow);

                if (!userHasPermission)
                {
                    Button unlockButton = unlockButtonFactory.Generate("Unlock");
                    unlockButton.Margin = new BorderDouble(0);
                    unlockButton.Cursor = Cursors.Hand;
                    unlockButton.Click += (sender, e) =>
                    {
                        callCorrectFunctionHold.unlockFunction();
                    };
                    pluginListingContainer.AddChild(unlockButton);
                }

                pluginRowContainer.AddChild(pluginListingContainer);
                if (callCorrectFunctionHold.unlockRegisterFunction != null)
                {
                    callCorrectFunctionHold.unlockRegisterFunction(TriggerReload, ref unregisterEvents);
                }
            }

            topToBottom.AddChild(presetsFormContainer);
            BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			Button cancelPresetsButton = textImageButtonFactory.Generate(LocalizedString.Get("Cancel"));
            cancelPresetsButton.Click += (sender, e) => {
                UiThread.RunOnIdle(CloseOnIdle);            
            };

            FlowLayoutWidget buttonRow = new FlowLayoutWidget();
            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Padding = new BorderDouble(0, 3);

            GuiWidget hButtonSpacer = new GuiWidget();
            hButtonSpacer.HAnchor = HAnchor.ParentLeftRight;
            
            buttonRow.AddChild(hButtonSpacer);
            buttonRow.AddChild(cancelPresetsButton);

            topToBottom.AddChild(buttonRow);

            AddChild(topToBottom);
        }
		private void SetProcessingMessage(string message)
		{
			if (gcodeProcessingStateInfoText == null)
			{
				gcodeProcessingStateInfoText = new TextWidget(message);
				gcodeProcessingStateInfoText.HAnchor = HAnchor.ParentCenter;
				gcodeProcessingStateInfoText.VAnchor = VAnchor.ParentCenter;
				gcodeProcessingStateInfoText.AutoExpandBoundsToText = true;

				GuiWidget labelContainer = new GuiWidget();
				labelContainer.AnchorAll();
				labelContainer.AddChild(gcodeProcessingStateInfoText);
				labelContainer.Selectable = false;

				gcodeDisplayWidget.AddChild(labelContainer);
			}

			if (message == "")
			{
				gcodeProcessingStateInfoText.BackgroundColor = new RGBA_Bytes();
			}
			else
			{
				gcodeProcessingStateInfoText.BackgroundColor = RGBA_Bytes.White;
			}

			gcodeProcessingStateInfoText.Text = message;
		}
		public SlicePresetsWindow(PresetsContext presetsContext)
				: base(641, 481)
		{
			this.presetsContext = presetsContext;
			this.AlwaysOnTopOfMain = true;
			this.Title = LocalizedString.Get("Slice Presets Editor");
			this.MinimumSize = new Vector2(640, 480);
			this.AnchorAll();

			var linkButtonFactory = new LinkButtonFactory()
			{
				fontSize = 8,
				textColor = ActiveTheme.Instance.SecondaryAccentColor
			};

			var buttonFactory = new TextImageButtonFactory()
			{
				normalTextColor = ActiveTheme.Instance.PrimaryTextColor,
				hoverTextColor = ActiveTheme.Instance.PrimaryTextColor,
				disabledTextColor = ActiveTheme.Instance.PrimaryTextColor,
				pressedTextColor = ActiveTheme.Instance.PrimaryTextColor,
				borderWidth = 0
			};

			FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
			{
				Padding = new BorderDouble(3)
			};
			mainContainer.AnchorAll();

			middleRow = new GuiWidget();
			middleRow.AnchorAll();
			middleRow.AddChild(CreateSliceSettingsWidget(presetsContext.PersistenceLayer));

			mainContainer.AddChild(GetTopRow());
			mainContainer.AddChild(middleRow);
			mainContainer.AddChild(GetBottomRow(buttonFactory));

			this.AddChild(mainContainer);

			BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
		}
Exemple #8
0
		public SoftKeyboardContentOffset(GuiWidget content)
		{
			this.content = content;
			AnchorAll();
			contentOffsetHolder = new GuiWidget(Width, Height);
			contentOffsetHolder.AnchorAll();
			contentOffsetHolder.AddChild(content);
			AddChild(contentOffsetHolder);

			TextEditWidget.ShowSoftwareKeyboard += EnsureEditControlIsVisible;
			TextEditWidget.KeyboardCollapsed += MoveContentBackDown;
		}
		public View3DBrailleBuilder(Vector3 viewerVolume, Vector2 bedCenter, BedShape bedShape)
		{
			monoSpacedTypeFace = ApplicationController.MonoSpacedTypeFace;

			brailTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "Braille.svg")));

			MeshGroupExtraData = new List<PlatingMeshGroupData>();

			FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
			mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

			FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
			centerPartPreviewAndControls.AnchorAll();

			GuiWidget viewArea = new GuiWidget();
			viewArea.AnchorAll();
			{
				meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
				meshViewerWidget.AllowBedRenderingWhenEmpty = true;
				meshViewerWidget.AnchorAll();
			}
			viewArea.AddChild(meshViewerWidget);

			centerPartPreviewAndControls.AddChild(viewArea);
			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

			FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.Padding = new BorderDouble(3, 3);
			buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);

			// add in the plater tools
			{
				FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				processingProgressControl = new ProgressControl("Finding Parts:".Localize(), ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
				processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
				editToolBar.AddChild(processingProgressControl);
				editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;

				editPlateButtonsContainer = new FlowLayoutWidget();

				textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter Text Here".Localize());
				textToAddWidget.VAnchor = VAnchor.ParentCenter;
				textToAddWidget.Margin = new BorderDouble(5);
				editPlateButtonsContainer.AddChild(textToAddWidget);
				textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				Button insertTextButton = textImageButtonFactory.Generate("Insert".Localize());
				editPlateButtonsContainer.AddChild(insertTextButton);
				insertTextButton.Click += (sender, e) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				editToolBar.AddChild(editPlateButtonsContainer);
				buttonBottomPanel.AddChild(editToolBar);
			}

			GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
			centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
			buttonRightPanelHolder.AddChild(buttonRightPanel);

			viewControls3D = new ViewControls3D(meshViewerWidget);

			viewControls3D.ResetView += (sender, e) =>
			{
				meshViewerWidget.ResetView();
			};

			buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
			buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
			buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
			LockEditControls();

			GuiWidget leftRightSpacer = new GuiWidget();
			leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.AddChild(leftRightSpacer);

			closeButton = textImageButtonFactory.Generate("Close".Localize());
			buttonBottomPanel.AddChild(closeButton);

			mainContainerTopToBottom.AddChild(buttonBottomPanel);

			this.AddChild(mainContainerTopToBottom);
			this.AnchorAll();

			meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(viewControls3D);

			// set the view to be a good angle and distance
			meshViewerWidget.ResetView();

			AddHandlers();
			UnlockEditControls();
			// but make sure we can't use the right panel yet
			buttonRightPanelDisabledCover.Visible = true;

			//meshViewerWidget.RenderType = RenderTypes.Outlines;
			viewControls3D.PartSelectVisible = false;
			meshViewerWidget.ResetView();
		}
        public View3DTransformPart(PrintItemWrapper printItemWrapper, Vector3 viewerVolume, MeshViewerWidget.BedShape bedShape)
        {
            MeshExtraData = new List<PlatingMeshData>();
            MeshExtraData.Add(new PlatingMeshData());

            this.printItemWrapper = printItemWrapper;

            FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
            mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

            FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
            centerPartPreviewAndControls.AnchorAll();

            GuiWidget viewArea = new GuiWidget();
            viewArea.AnchorAll();
            {
                meshViewerWidget = new MeshViewerWidget(viewerVolume, 1, bedShape);
                SetMeshViewerDisplayTheme();
                meshViewerWidget.AnchorAll();
            }
            viewArea.AddChild(meshViewerWidget);

            centerPartPreviewAndControls.AddChild(viewArea);
            mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

            meshViewerWidget.LoadMesh(printItemWrapper.FileLocation);
            meshViewerWidget.LoadDone += new EventHandler(meshViewerWidget_LoadDone);

            FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
            buttonBottomPanel.Padding = new BorderDouble(3, 3);
            buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            buttonRightPanel = CreateRightButtonPannel(viewerVolume.y);

            CreateOptionsContent();

            // add in the plater tools
            {
                FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				string progressFindPartsLbl = new LocalizedString ("Finding Parts").Translated;
				string progressFindPartsLblFull = string.Format ("{0}:", progressFindPartsLbl);

				processingProgressControl = new ProgressControl(progressFindPartsLblFull);
                processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
                editToolBar.AddChild(processingProgressControl);
                editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                processingProgressControl.Visible = false;

				editPlateButton = textImageButtonFactory.Generate(new LocalizedString("Edit").Translated);
                editToolBar.AddChild(editPlateButton);

                editPlateButtonsContainer = new FlowLayoutWidget();
                editPlateButtonsContainer.Visible = false;

				Button addButton = textImageButtonFactory.Generate(new LocalizedString("Add").Translated, "icon_circle_plus.png");
                addButton.Margin = new BorderDouble(right: 10);
                editPlateButtonsContainer.AddChild(addButton);
                addButton.Click += (sender, e) =>
                {
                    UiThread.RunOnIdle((state) =>
                    {
                        OpenFileDialogParams openParams = new OpenFileDialogParams("Select an STL file|*.stl", multiSelect: true);

                        FileDialog.OpenFileDialog(ref openParams);
                        LoadAndAddPartsToPlate(openParams.FileNames);
                    });
                };

				Button copyButton = textImageButtonFactory.Generate(new LocalizedString("Copy").Translated);
                editPlateButtonsContainer.AddChild(copyButton);
                copyButton.Click += (sender, e) =>
                {
                    MakeCopyOfMesh();
                };

				Button deleteButton = textImageButtonFactory.Generate(new LocalizedString("Delete").Translated);
                deleteButton.Margin = new BorderDouble(left: 20);
                editPlateButtonsContainer.AddChild(deleteButton);
                deleteButton.Click += (sender, e) =>
                {
                    DeleteSelectedMesh();
                };

                KeyDown += (sender, e) =>
                {
                    KeyEventArgs keyEvent = e as KeyEventArgs;
                    if (keyEvent != null && !keyEvent.Handled)
                    {
                        if (keyEvent.KeyCode == Keys.Delete || keyEvent.KeyCode == Keys.Back)
                        {
                            DeleteSelectedMesh();
                        }

                        if (keyEvent.KeyCode == Keys.Escape)
                        {
                            if (meshSelectInfo.downOnPart)
                            {
                                meshSelectInfo.downOnPart = false;
                                SelectedMeshTransform = transformOnMouseDown;
                                Invalidate();
                            }
                        }
                    }
                };

                editToolBar.AddChild(editPlateButtonsContainer);
                buttonBottomPanel.AddChild(editToolBar);

                editPlateButton.Click += (sender, e) =>
                {
                    editPlateButton.Visible = false;

                    EnterEditAndSplitIntoMeshes();
                };
            }

            autoArrangeButton.Click += (sender, e) =>
            {
                AutoArangePartsInBackground();
            };

            GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
            centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
            buttonRightPanelHolder.AddChild(buttonRightPanel);

            buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
            buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
            buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
            LockEditControls();

            GuiWidget leftRightSpacer = new GuiWidget();
            leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
            buttonBottomPanel.AddChild(leftRightSpacer);

			closeButton = textImageButtonFactory.Generate(new LocalizedString("Close").Translated);
            buttonBottomPanel.AddChild(closeButton);

            mainContainerTopToBottom.AddChild(buttonBottomPanel);

            this.AddChild(mainContainerTopToBottom);
            this.AnchorAll();

            meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
            AddViewControls();

            AddHandlers();
        }
Exemple #11
0
 public TabPage(GuiWidget widgetToAddToPage, string tabTitle)
     : this(tabTitle)
 {
     widgetToAddToPage.AnchorAll();
     AddChild(widgetToAddToPage);
 }
        public View3DTransformPart(PrintItemWrapper printItemWrapper, Vector3 viewerVolume, Vector2 bedCenter, MeshViewerWidget.BedShape bedShape, WindowType windowType, AutoRotate autoRotate)
        {
            this.windowType = windowType;
            autoRotateEnabled = (autoRotate == AutoRotate.Enabled);
            MeshExtraData = new List<PlatingMeshData>();
            MeshExtraData.Add(new PlatingMeshData());

            this.printItemWrapper = printItemWrapper;

            FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
            mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

            FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
            centerPartPreviewAndControls.AnchorAll();

            GuiWidget viewArea = new GuiWidget();
            viewArea.AnchorAll();
            {
                meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape, "Press 'Add' to select an item.".Localize());
                
                // this is to add an image to the bed
                string imagePathAndFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "bedimage.png");
                if (autoRotateEnabled && File.Exists(imagePathAndFile))
                {
                    ImageBuffer wattermarkImage = new ImageBuffer();
                    ImageIO.LoadImageData(imagePathAndFile, wattermarkImage);

                    ImageBuffer bedImage = meshViewerWidget.BedImage;
                    Graphics2D bedGraphics = bedImage.NewGraphics2D();
                    bedGraphics.Render(wattermarkImage, 
                        new Vector2((bedImage.Width - wattermarkImage.Width) / 2, (bedImage.Height - wattermarkImage.Height)/2));
                }

                meshViewerWidget.AnchorAll();
            }
            viewArea.AddChild(meshViewerWidget);

            centerPartPreviewAndControls.AddChild(viewArea);
            mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

            FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
            buttonBottomPanel.Padding = new BorderDouble(3, 3);
            buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);

            CreateOptionsContent();

            // add in the plater tools
            {
                FlowLayoutWidget editToolBar = new FlowLayoutWidget();

                string progressFindPartsLabel = LocalizedString.Get("Finding Parts");
                string progressFindPartsLabelFull = "{0}:".FormatWith(progressFindPartsLabel);

                processingProgressControl = new ProgressControl(progressFindPartsLabelFull, ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
                processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
                editToolBar.AddChild(processingProgressControl);
                editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
                processingProgressControl.Visible = false;

                // If the window is embeded (in the center pannel) and there is no item loaded then don't show the add button
                enterEditButtonsContainer = new FlowLayoutWidget();
                {
                    Button addButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png");
                    addButton.Margin = new BorderDouble(right: 10);
                    enterEditButtonsContainer.AddChild(addButton);
                    addButton.Click += (sender, e) =>
                    {
                        UiThread.RunOnIdle((state) =>
                        {
                            EnterEditAndSplitIntoMeshes();
                            OpenAddDialogWhenDone = true;
                        });
                    };

                    Button enterEdittingButton = textImageButtonFactory.Generate(LocalizedString.Get("Edit"));
                    enterEdittingButton.Click += (sender, e) =>
                    {
                        EnterEditAndSplitIntoMeshes();
                    };

                    enterEditButtonsContainer.AddChild(enterEdittingButton);
                }
                editToolBar.AddChild(enterEditButtonsContainer);

                doEdittingButtonsContainer = new FlowLayoutWidget();
                doEdittingButtonsContainer.Visible = false;

                {
                    Button addButton = textImageButtonFactory.Generate(LocalizedString.Get("Add"), "icon_circle_plus.png");
                    addButton.Margin = new BorderDouble(right: 10);
                    doEdittingButtonsContainer.AddChild(addButton);
                    addButton.Click += (sender, e) =>
                    {
                        UiThread.RunOnIdle((state) =>
                        {
                            OpenFileDialogParams openParams = new OpenFileDialogParams("Select an STL file|*.stl", multiSelect: true);

                            FileDialog.OpenFileDialog(ref openParams);
                            LoadAndAddPartsToPlate(openParams.FileNames);
                        });
                    };

                    Button copyButton = textImageButtonFactory.Generate(LocalizedString.Get("Copy"));
                    doEdittingButtonsContainer.AddChild(copyButton);
                    copyButton.Click += (sender, e) =>
                    {
                        MakeCopyOfMesh();
                    };

                    Button deleteButton = textImageButtonFactory.Generate(LocalizedString.Get("Delete"));
                    deleteButton.Margin = new BorderDouble(left: 20);
                    doEdittingButtonsContainer.AddChild(deleteButton);
                    deleteButton.Click += (sender, e) =>
                    {
                        DeleteSelectedMesh();
                    };
                }

                KeyDown += (sender, e) =>
                {
                    KeyEventArgs keyEvent = e as KeyEventArgs;
                    if (keyEvent != null && !keyEvent.Handled)
                    {
                        if (keyEvent.KeyCode == Keys.Delete || keyEvent.KeyCode == Keys.Back)
                        {
                            DeleteSelectedMesh();
                        }

                        if (keyEvent.KeyCode == Keys.Escape)
                        {
                            if (meshSelectInfo.downOnPart)
                            {
                                meshSelectInfo.downOnPart = false;
                                
                                ScaleRotateTranslate translated = SelectedMeshTransform;
                                translated.translation *= transformOnMouseDown;
                                SelectedMeshTransform = translated;

                                Invalidate();
                            }
                        }
                    }
                };

                editToolBar.AddChild(doEdittingButtonsContainer);
                buttonBottomPanel.AddChild(editToolBar);
            }

            autoArrangeButton.Click += (sender, e) =>
            {
                AutoArangePartsInBackground();
            };

            GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
            centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
            buttonRightPanelHolder.AddChild(buttonRightPanel);

            viewControls3D = new ViewControls3D(meshViewerWidget);

            buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
            buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
            buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
            LockEditControls();

            GuiWidget leftRightSpacer = new GuiWidget();
            leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
            buttonBottomPanel.AddChild(leftRightSpacer);

            if (windowType == WindowType.StandAlone)
            {
                Button closeButton = textImageButtonFactory.Generate(LocalizedString.Get("Close"));
                buttonBottomPanel.AddChild(closeButton);
                closeButton.Click += (sender, e) =>
                {
                    CloseOnIdle();
                };
            }

            mainContainerTopToBottom.AddChild(buttonBottomPanel);

            this.AddChild(mainContainerTopToBottom);
            this.AnchorAll();

            meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
            AddChild(viewControls3D);
            viewControls3D.PartSelectVisible = false;

            AddHandlers();

            if (printItemWrapper != null)
            {
                // don't load the mesh until we get all the rest of the interface built
                meshViewerWidget.LoadMesh(printItemWrapper.FileLocation);
                meshViewerWidget.LoadDone += new EventHandler(meshViewerWidget_LoadDone);
            }

            UiThread.RunOnIdle(AutoSpin);

            if (printItemWrapper == null && windowType == WindowType.Embeded)
            {
                enterEditButtonsContainer.Visible = false;
            }

            if (windowType == WindowType.Embeded)
            {
                PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(SetEditControlsBasedOnPrinterState, ref unregisterEvents);
                if (windowType == WindowType.Embeded)
                {
                    // make sure we lock the controls if we are printing or paused
                    switch (PrinterConnectionAndCommunication.Instance.CommunicationState)
                    {
                        case PrinterConnectionAndCommunication.CommunicationStates.Printing:
                        case PrinterConnectionAndCommunication.CommunicationStates.Paused:
                            LockEditControls();
                            break;
                    }
                }
            }

            ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);
        }
        public void LoadMesh(string meshPathAndFileName)
        {
            backgroundWorker = new BackgroundWorker();
            backgroundWorker.WorkerReportsProgress = true;
            backgroundWorker.WorkerSupportsCancellation = true;

            backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
            backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker_RunWorkerCompleted);

            bool loadingMeshFile = false;
            switch(Path.GetExtension(meshPathAndFileName).ToUpper())
            {
                case ".STL":
                    {
                        StlProcessing stlLoader = new StlProcessing();
                        stlLoader.LoadInBackground(backgroundWorker, meshPathAndFileName);
                        loadingMeshFile = true;
                    }
                    break;

                case ".AMF":
                    {
                        AmfProcessing amfLoader = new AmfProcessing();
                        amfLoader.LoadInBackground(backgroundWorker, meshPathAndFileName);
                        loadingMeshFile = true;
                    }
                    break;

                default:
                    loadingMeshFile = false;
                    break;
            }

            if (loadingMeshFile)
            {
                meshLoadingStateInfoText = new TextWidget("Loading Mesh...");
                meshLoadingStateInfoText.HAnchor = HAnchor.ParentCenter;
                meshLoadingStateInfoText.VAnchor = VAnchor.ParentCenter;
                meshLoadingStateInfoText.AutoExpandBoundsToText = true;

                GuiWidget labelContainer = new GuiWidget();
                labelContainer.AnchorAll();
                labelContainer.AddChild(meshLoadingStateInfoText);
                labelContainer.Selectable = false;

                this.AddChild(labelContainer);
            }
            else
            {
                TextWidget no3DView = new TextWidget(string.Format("No 3D view for this file type '{0}'.", Path.GetExtension(meshPathAndFileName).ToUpper()));
                no3DView.Margin = new BorderDouble(0, 0, 0, 0);
                no3DView.VAnchor = Agg.UI.VAnchor.ParentCenter;
                no3DView.HAnchor = Agg.UI.HAnchor.ParentCenter;
                this.AddChild(no3DView);
            }
        }
        private void DoLayout()
        {
            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainer.AnchorAll();

            FlowLayoutWidget labelContainer = new FlowLayoutWidget();
            labelContainer.HAnchor = HAnchor.ParentLeftRight;

            TextWidget formLabel = new TextWidget("After a Print is Finished:".Localize(), pointSize: 16);
            formLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            formLabel.VAnchor = VAnchor.ParentCenter;
            formLabel.Margin = new BorderDouble(10, 0,10, 12);
            labelContainer.AddChild(formLabel);
            mainContainer.AddChild(labelContainer);

            centerContainer = new GuiWidget();
            centerContainer.AnchorAll();
            centerContainer.Padding = new BorderDouble(10);

            messageContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            messageContainer.AnchorAll();
            messageContainer.Visible = false;
            messageContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            messageContainer.Padding = new BorderDouble(10);
            
            submissionStatus = new TextWidget("Saving your settings...".Localize(), pointSize: 13);
            submissionStatus.AutoExpandBoundsToText = true;
            submissionStatus.Margin = new BorderDouble(0, 5);
            submissionStatus.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            submissionStatus.HAnchor = HAnchor.ParentLeft;

            messageContainer.AddChild(submissionStatus);

            formContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            formContainer.AnchorAll();
            formContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            formContainer.Padding = new BorderDouble(10);
            {
                FlowLayoutWidget smsLabelContainer = new FlowLayoutWidget(FlowDirection.LeftToRight);
                smsLabelContainer.Margin = new BorderDouble(0, 2, 0, 4);
                smsLabelContainer.HAnchor |= Agg.UI.HAnchor.ParentLeft;
                
                //Add sms notification option
                notifySendTextCheckbox = new CheckBox("Send an SMS notification".Localize());
                notifySendTextCheckbox.Margin = new BorderDouble(0);
                notifySendTextCheckbox.VAnchor = Agg.UI.VAnchor.ParentBottom;
                notifySendTextCheckbox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                notifySendTextCheckbox.Cursor = Cursors.Hand;
                notifySendTextCheckbox.Checked = (UserSettings.Instance.get("AfterPrintFinishedSendTextMessage") == "true");
                notifySendTextCheckbox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(OnSendTextChanged);

                TextWidget experimentalLabel = new TextWidget("Experimental".Localize(), pointSize: 10);
                experimentalLabel.TextColor = ActiveTheme.Instance.SecondaryAccentColor;
                experimentalLabel.VAnchor = Agg.UI.VAnchor.ParentBottom;
                experimentalLabel.Margin = new BorderDouble(left:10);

                smsLabelContainer.AddChild(notifySendTextCheckbox);
                smsLabelContainer.AddChild(experimentalLabel);

                formContainer.AddChild(smsLabelContainer);
                formContainer.AddChild(LabelGenerator("Have MatterControl send you a text message after your print is finished".Localize(), 9, 14));

                phoneNumberContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
                phoneNumberContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                phoneNumberLabel = LabelGenerator("Your Phone Number*".Localize());
                phoneNumberHelperLabel = LabelGenerator("A U.S. or Canadian mobile phone number".Localize(), 9, 14);
                

                phoneNumberContainer.AddChild(phoneNumberLabel);
                phoneNumberContainer.AddChild(phoneNumberHelperLabel);

                phoneNumberInput = new MHTextEditWidget();
                phoneNumberInput.HAnchor = HAnchor.ParentLeftRight;

                string phoneNumber = UserSettings.Instance.get("NotificationPhoneNumber");
                if (phoneNumber != null)
                {
                    phoneNumberInput.Text = phoneNumber;
                }

                phoneNumberContainer.AddChild(phoneNumberInput);

                phoneNumberErrorMessage = ErrorMessageGenerator();
                phoneNumberContainer.AddChild(phoneNumberErrorMessage);

                formContainer.AddChild(phoneNumberContainer);
            }

            {
                //Add email notification option
                notifySendEmailCheckbox = new CheckBox("Send an email notification".Localize());
                notifySendEmailCheckbox.Margin = new BorderDouble(0, 2, 0, 16);
                notifySendEmailCheckbox.HAnchor = Agg.UI.HAnchor.ParentLeft;
                notifySendEmailCheckbox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                notifySendEmailCheckbox.Cursor = Cursors.Hand;
                notifySendEmailCheckbox.Checked = (UserSettings.Instance.get("AfterPrintFinishedSendEmail") == "true");
                notifySendEmailCheckbox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(OnSendEmailChanged);

                formContainer.AddChild(notifySendEmailCheckbox);
                formContainer.AddChild(LabelGenerator("Have MatterControl send you an email message after your print is finished".Localize(), 9, 14));

                emailAddressContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
                emailAddressContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

                emailAddressLabel = LabelGenerator("Your Email Address*".Localize());

                emailAddressHelperLabel = LabelGenerator("A valid email address".Localize(), 9, 14);

                emailAddressContainer.AddChild(emailAddressLabel);
                emailAddressContainer.AddChild(emailAddressHelperLabel);

                emailAddressInput = new MHTextEditWidget();
                emailAddressInput.HAnchor = HAnchor.ParentLeftRight;

                string emailAddress = UserSettings.Instance.get("NotificationEmailAddress");
                if (emailAddress != null)
                {
                    emailAddressInput.Text = emailAddress;
                }

                emailAddressContainer.AddChild(emailAddressInput);

                emailAddressErrorMessage = ErrorMessageGenerator();
                emailAddressContainer.AddChild(emailAddressErrorMessage);

                formContainer.AddChild(emailAddressContainer);
            }

            notifyPlaySoundCheckbox = new CheckBox("Play a Sound".Localize());
            notifyPlaySoundCheckbox.Margin = new BorderDouble(0, 2, 0, 16);
            notifyPlaySoundCheckbox.HAnchor = Agg.UI.HAnchor.ParentLeft;
            notifyPlaySoundCheckbox.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            notifyPlaySoundCheckbox.Checked = (UserSettings.Instance.get("AfterPrintFinishedPlaySound") == "true");
            notifyPlaySoundCheckbox.Cursor = Cursors.Hand;

            formContainer.AddChild(notifyPlaySoundCheckbox);
            formContainer.AddChild(LabelGenerator("Play a sound after your print is finished".Localize(), 9, 14));

            centerContainer.AddChild(formContainer);

            mainContainer.AddChild(centerContainer);
            
            FlowLayoutWidget buttonBottomPanel = GetButtonButtonPanel();
            buttonBottomPanel.AddChild(saveButton);
            buttonBottomPanel.AddChild(cancelButton);
            buttonBottomPanel.AddChild(doneButton);

            mainContainer.AddChild(buttonBottomPanel);

            this.AddChild(mainContainer);

            SetVisibleStates();
        }
        public CSGOpenGLApplication(string meshFileToLoad = "")
            : base(800, 600)
        {
            MinimumSize = new VectorMath.Vector2(200, 200);
            Title = "MatterHackers MeshViewr";
            UseOpenGL = true;
            StencilBufferDepth = 8;
            BitDepth = ValidDepthVaules.Depth24;

            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainer.AnchorAll();

            viewArea = new GuiWidget();

            viewArea.AnchorAll();

            double bedXSize = 200;
            double bedYSize = 200;
            double scale = 1;
            meshViewerWidget = new MeshViewerWidget(bedXSize, bedYSize, scale);

            MeshViewWidget.AnchorAll();

            viewArea.AddChild(MeshViewWidget);

            mainContainer.AddChild(viewArea);

            FlowLayoutWidget buttonPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
            buttonPanel.HAnchor = HAnchor.ParentLeftRight;
            buttonPanel.Padding = new BorderDouble(3, 3);
            buttonPanel.BackgroundColor = RGBA_Bytes.DarkGray;

            if (meshFileToLoad != "")
            {
                MeshViewWidget.LoadMesh(meshFileToLoad);
            }
            else
            {
                openFileButton = new Button("Open 3D File", 0, 0);
                openFileButton.Click += new Button.ButtonEventHandler(openFileButton_ButtonClick);
                buttonPanel.AddChild(openFileButton);
            }

            bedCheckBox = new CheckBox("Bed");
            bedCheckBox.Checked = true;
            buttonPanel.AddChild(bedCheckBox);

            wireframeCheckBox = new CheckBox("Wireframe");
            buttonPanel.AddChild(wireframeCheckBox);

            GuiWidget leftRightSpacer = new GuiWidget();
            leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
            buttonPanel.AddChild(leftRightSpacer);

            mainContainer.AddChild(buttonPanel);

            this.AddChild(mainContainer);
            this.AnchorAll();

            bedCheckBox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(bedCheckBox_CheckedStateChanged);
            wireframeCheckBox.CheckedStateChanged += new CheckBox.CheckedStateChangedEventHandler(wireframeCheckBox_CheckedStateChanged);
        }
        public PluginChooserWindow()
            : base(360, 300)
        {
			Title = new LocalizedString("Installed Plugins").Translated;

            FlowLayoutWidget topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
            topToBottom.AnchorAll();
            topToBottom.Padding = new BorderDouble(3, 0, 3, 5);

            FlowLayoutWidget headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight);
            headerRow.HAnchor = HAnchor.ParentLeftRight;
            headerRow.Margin = new BorderDouble(0, 3, 0, 0);
            headerRow.Padding = new BorderDouble(0, 3, 0, 3);

            {
				string elementHeaderLblBeg = new LocalizedString("Select a Design Tool").Translated;
				string elementHeaderLblFull = string.Format("{0}:", elementHeaderLblBeg);
				string elementHeaderLbl = elementHeaderLblFull;
				TextWidget elementHeader = new TextWidget(string.Format(elementHeaderLbl), pointSize: 14);
                elementHeader.TextColor = ActiveTheme.Instance.PrimaryTextColor;
                elementHeader.HAnchor = HAnchor.ParentLeftRight;
                elementHeader.VAnchor = Agg.UI.VAnchor.ParentBottom;

                headerRow.AddChild(elementHeader);
            }

            topToBottom.AddChild(headerRow);

            GuiWidget presetsFormContainer = new GuiWidget();
            //ListBox printerListContainer = new ListBox();
            {
                presetsFormContainer.HAnchor = HAnchor.ParentLeftRight;
                presetsFormContainer.VAnchor = VAnchor.ParentBottomTop;
                presetsFormContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            }

            FlowLayoutWidget pluginRowContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            pluginRowContainer.AnchorAll();
            presetsFormContainer.AddChild(pluginRowContainer);

            foreach(CreatorInformation creatorInfo in RegisteredCreators.Instance.Creators)
            {
                ClickWidget pluginRow = new ClickWidget();         
                pluginRow.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                pluginRow.Height = 38;
			    pluginRow.BackgroundColor = RGBA_Bytes.White;
                pluginRow.Padding = new BorderDouble(3);
                pluginRow.Margin = new BorderDouble(6,0,6,6);                

                GuiWidget overlay = new GuiWidget();
                overlay.AnchorAll();
                overlay.Cursor = Cursors.Hand;
                
                FlowLayoutWidget macroRow = new FlowLayoutWidget();
                macroRow.AnchorAll();
                macroRow.BackgroundColor = RGBA_Bytes.White;

                if (creatorInfo.iconPath != "")
                {
                    ImageBuffer imageBuffer = LoadImage(creatorInfo.iconPath);
                    ImageWidget imageWidget = new ImageWidget(imageBuffer);
                    macroRow.AddChild(imageWidget);
                }

                TextWidget buttonLabel = new TextWidget(creatorInfo.description, pointSize: 14);

                buttonLabel.Margin = new BorderDouble(left: 10);
                buttonLabel.VAnchor = Agg.UI.VAnchor.ParentCenter;                
                macroRow.AddChild(buttonLabel);

                FlowLayoutWidget hSpacer = new FlowLayoutWidget();
                hSpacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                macroRow.AddChild(hSpacer);

                CreatorInformation callCorrectFunctionHold = creatorInfo;
                pluginRow.Click += (sender, e) =>
                {
                    if (RegisteredCreators.Instance.Creators.Count > 0)
                    {
                        callCorrectFunctionHold.functionToLaunchCreator(null, null);
                    }
                    UiThread.RunOnIdle(CloseOnIdle);
                };
                pluginRow.AddChild(macroRow);
                pluginRow.AddChild(overlay);
                pluginRowContainer.AddChild(pluginRow);
            }

            topToBottom.AddChild(presetsFormContainer);
            BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

            //ShowAsSystemWindow();

			Button cancelPresetsButton = textImageButtonFactory.Generate(new LocalizedString("Cancel").Translated);
            cancelPresetsButton.Click += (sender, e) => { Close(); };

            FlowLayoutWidget buttonRow = new FlowLayoutWidget();
            buttonRow.HAnchor = HAnchor.ParentLeftRight;
            buttonRow.Padding = new BorderDouble(0, 3);

            GuiWidget hButtonSpacer = new GuiWidget();
            hButtonSpacer.HAnchor = HAnchor.ParentLeftRight;
            
            buttonRow.AddChild(hButtonSpacer);
            buttonRow.AddChild(cancelPresetsButton);

            topToBottom.AddChild(buttonRow);

            AddChild(topToBottom);
        }
		public WizardPage(string unlocalizedTextForCancelButton = "Cancel", string unlocalizedTextForTitle = "Setup Wizard")
		{
			whiteImageButtonFactory = new TextImageButtonFactory()
			{
				normalFillColor = RGBA_Bytes.White,
				disabledFillColor = RGBA_Bytes.White,
				fontSize = 16,
				borderWidth = 1,

				normalBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),
				hoverBorderColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryTextColor, 200),

				disabledTextColor = RGBA_Bytes.DarkGray,
				hoverTextColor = ActiveTheme.Instance.PrimaryTextColor,
				normalTextColor = RGBA_Bytes.Black,
				pressedTextColor = ActiveTheme.Instance.PrimaryTextColor,
				FixedWidth = 200
			};

			if (!UserSettings.Instance.IsTouchScreen)
			{
				textImageButtonFactory = new TextImageButtonFactory()
				{
					normalTextColor = ActiveTheme.Instance.PrimaryTextColor,
					hoverTextColor = ActiveTheme.Instance.PrimaryTextColor,
					disabledTextColor = ActiveTheme.Instance.PrimaryTextColor,
					pressedTextColor = ActiveTheme.Instance.PrimaryTextColor,
					borderWidth = 0
				};

				linkButtonFactory.textColor = ActiveTheme.Instance.PrimaryTextColor;
				linkButtonFactory.fontSize = 10;

				this.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
				this.Padding = new BorderDouble(0); //To be re-enabled once native borders are turned off
			}

			this.AnchorAll();

			cancelButton = textImageButtonFactory.Generate(unlocalizedTextForCancelButton.Localize());
			cancelButton.Name = "Cancel Wizard Button";
			cancelButton.Click += (s, e) =>
			{
				UiThread.RunOnIdle(() => WizardWindow?.Close());
			};

			// Create the main container
			mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom)
			{
				Padding = new BorderDouble(12, 12, 12, 0),
				BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor
			};
			mainContainer.AnchorAll();

			// Create the header row for the widget
			headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
			{
				Margin = new BorderDouble(0, 3, 0, 0),
				Padding = new BorderDouble(0, 12),
				HAnchor = HAnchor.ParentLeftRight
			};

			headerLabel = new TextWidget(unlocalizedTextForTitle.Localize(), pointSize: 24, textColor: ActiveTheme.Instance.SecondaryAccentColor)
			{
				AutoExpandBoundsToText = true
			};
			headerRow.AddChild(headerLabel);

			// Create the main control container
			contentRow = new FlowLayoutWidget(FlowDirection.TopToBottom)
			{
				Padding = new BorderDouble(10),
				BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor,
				HAnchor = HAnchor.ParentLeftRight,
				VAnchor = VAnchor.ParentBottomTop
			};

			// Create the footer (button) container
			footerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
			{
				HAnchor = HAnchor.ParentLeft | HAnchor.ParentRight,
				Margin = new BorderDouble(0, 6)
			};

			mainContainer.AddChild(headerRow);
			mainContainer.AddChild(contentRow);
			mainContainer.AddChild(footerRow);

			if (!UserSettings.Instance.IsTouchScreen)
			{
				mainContainer.Padding = new BorderDouble(3, 5, 3, 5);
				headerRow.Padding = new BorderDouble(0, 3, 0, 3);

				headerLabel.PointSize = 14;
				headerLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
				contentRow.Padding = new BorderDouble(5);
				footerRow.Margin = new BorderDouble(0, 3);
			}

			this.AddChild(mainContainer);
		}
		public PrintProgressBar(bool widgetIsExtended = true)
		{
			MinimumSize = new Vector2(0, 24);

			HAnchor = HAnchor.ParentLeftRight;
			BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
			Margin = new BorderDouble(0);

			FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);
			container.AnchorAll();
			container.Padding = new BorderDouble(6, 0);

			printTimeElapsed = new TextWidget("", pointSize: 11);
			printTimeElapsed.Printer.DrawFromHintedCache = true;
			printTimeElapsed.AutoExpandBoundsToText = true;
			printTimeElapsed.VAnchor = Agg.UI.VAnchor.ParentCenter;

			printTimeRemaining = new TextWidget("", pointSize: 11);
			printTimeRemaining.Printer.DrawFromHintedCache = true;
			printTimeRemaining.AutoExpandBoundsToText = true;
			printTimeRemaining.VAnchor = Agg.UI.VAnchor.ParentCenter;

			GuiWidget spacer = new GuiWidget();
			spacer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;

			container.AddChild(printTimeElapsed);
			container.AddChild(spacer);
			container.AddChild(printTimeRemaining);

			AddChild(container);

			if (ActiveTheme.Instance.IsTouchScreen)
			{
				upImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_up_32x24.png");
				downImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_down_32x24.png");

				indicatorWidget = new ImageWidget(upImageBuffer);
				indicatorWidget.HAnchor = HAnchor.ParentCenter;
				indicatorWidget.VAnchor = VAnchor.ParentCenter;

				WidgetIsExtended = widgetIsExtended;

				GuiWidget indicatorOverlay = new GuiWidget();
				indicatorOverlay.AnchorAll();
				indicatorOverlay.AddChild(indicatorWidget);

				AddChild(indicatorOverlay);
			}

			ClickWidget clickOverlay = new ClickWidget();
			clickOverlay.AnchorAll();
			clickOverlay.Click += onProgressBarClick;

			AddChild(clickOverlay);

			AddHandlers();
			SetThemedColors();
			UpdatePrintStatus();
			UiThread.RunOnIdle(OnIdle);
		}
		public PrintProgressBar(bool widgetIsExtended = true)
		{
			MinimumSize = new Vector2(0, 24);

			HAnchor = HAnchor.ParentLeftRight;
			BackgroundColor = ActiveTheme.Instance.SecondaryAccentColor;
			Margin = new BorderDouble(0);

			FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.LeftToRight);
			container.AnchorAll();
			container.Padding = new BorderDouble(6, 0);

			printTimeElapsed = new TextWidget("", pointSize: 11);
			printTimeElapsed.Printer.DrawFromHintedCache = true;
			printTimeElapsed.AutoExpandBoundsToText = true;
			printTimeElapsed.VAnchor = VAnchor.ParentCenter;

			printTimeRemaining = new TextWidget("", pointSize: 11);
			printTimeRemaining.Printer.DrawFromHintedCache = true;
			printTimeRemaining.AutoExpandBoundsToText = true;
			printTimeRemaining.VAnchor = VAnchor.ParentCenter;

			container.AddChild(printTimeElapsed);
			container.AddChild(new HorizontalSpacer());
			container.AddChild(printTimeRemaining);

			AddChild(container);

			if (UserSettings.Instance.IsTouchScreen)
			{
				upImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_up_32x24.png");
				downImageBuffer = StaticData.Instance.LoadIcon("TouchScreen/arrow_down_32x24.png");

				indicatorWidget = new ImageWidget(upImageBuffer);
				indicatorWidget.HAnchor = HAnchor.ParentCenter;
				indicatorWidget.VAnchor = VAnchor.ParentCenter;

				WidgetIsExtended = widgetIsExtended;

				GuiWidget indicatorOverlay = new GuiWidget();
				indicatorOverlay.AnchorAll();
				indicatorOverlay.AddChild(indicatorWidget);

				AddChild(indicatorOverlay);
			}

			var clickOverlay = new GuiWidget();
			clickOverlay.AnchorAll();
			clickOverlay.Click += (s, e) =>
			{
				// In touchscreen mode, expand or collapse the print status row when clicked
				ApplicationView mainView = ApplicationController.Instance.MainView;
				if(mainView is TouchscreenView)
				{
					((TouchscreenView)mainView).ToggleTopContainer();
				}
			};
			AddChild(clickOverlay);

			PrinterConnectionAndCommunication.Instance.ActivePrintItemChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);
			PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(Instance_PrintItemChanged, ref unregisterEvents);

			SetThemedColors();
			UpdatePrintStatus();
			UiThread.RunOnIdle(OnIdle);
		}
        private void AddProcessingMessage(string message)
        {
            gcodeProcessingStateInfoText = new TextWidget(message);
            gcodeProcessingStateInfoText.HAnchor = HAnchor.ParentCenter;
            gcodeProcessingStateInfoText.VAnchor = VAnchor.ParentCenter;
            gcodeProcessingStateInfoText.AutoExpandBoundsToText = true;

            GuiWidget labelContainer = new GuiWidget();
            labelContainer.AnchorAll();
            labelContainer.AddChild(gcodeProcessingStateInfoText);
            labelContainer.Selectable = false;

            gcodeDispalyWidget.AddChild(labelContainer);
        }
        private void DoLayout(string subjectText, string bodyText)
        {
            FlowLayoutWidget mainContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            mainContainer.AnchorAll();

            GuiWidget labelContainer = new GuiWidget();
            labelContainer.HAnchor = HAnchor.ParentLeftRight;
            labelContainer.Height = 30;

            TextWidget formLabel = new TextWidget(LocalizedString.Get("How can we help?"), pointSize: 16);
            formLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            formLabel.VAnchor = VAnchor.ParentTop;
            formLabel.HAnchor = HAnchor.ParentLeft;
            formLabel.Margin = new BorderDouble(6, 3,6,6);
            labelContainer.AddChild(formLabel);
            mainContainer.AddChild(labelContainer);

            centerContainer = new GuiWidget();
            centerContainer.AnchorAll();
            centerContainer.Padding = new BorderDouble(3,0,3,3);

            messageContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            messageContainer.AnchorAll();
            messageContainer.Visible = false;
            messageContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            messageContainer.Padding = new BorderDouble(10);

            submissionStatus = new TextWidget(LocalizedString.Get("Submitting your information..."), pointSize: 13);
            submissionStatus.AutoExpandBoundsToText = true;
            submissionStatus.Margin = new BorderDouble(0, 5);
			submissionStatus.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            submissionStatus.HAnchor = HAnchor.ParentLeft;

            messageContainer.AddChild(submissionStatus);

            formContainer = new FlowLayoutWidget(FlowDirection.TopToBottom);
            formContainer.AnchorAll();
            formContainer.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
            formContainer.Padding = new BorderDouble(10);

            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Question*")));
            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Briefly describe your question"), 9, 14));

            questionInput = new MHTextEditWidget(subjectText);
            questionInput.HAnchor = HAnchor.ParentLeftRight;
            formContainer.AddChild(questionInput);

            questionErrorMessage = ErrorMessageGenerator();
            formContainer.AddChild(questionErrorMessage);

            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Details*")));
            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Fill in the details here"), 9, 14));

            detailInput = new MHTextEditWidget(bodyText, pixelHeight: 120, multiLine: true);
            detailInput.HAnchor = HAnchor.ParentLeftRight;
            formContainer.AddChild(detailInput);

            detailErrorMessage = ErrorMessageGenerator();
            formContainer.AddChild(detailErrorMessage);

            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Your Email Address*")));

            emailInput = new MHTextEditWidget();
            emailInput.HAnchor = HAnchor.ParentLeftRight;
            formContainer.AddChild(emailInput);

            emailErrorMessage = ErrorMessageGenerator();
            formContainer.AddChild(emailErrorMessage);

            formContainer.AddChild(LabelGenerator(LocalizedString.Get("Your Name*")));

            nameInput = new MHTextEditWidget();
            nameInput.HAnchor = HAnchor.ParentLeftRight;
            formContainer.AddChild(nameInput);

            nameErrorMessage = ErrorMessageGenerator();
            formContainer.AddChild(nameErrorMessage);           

            centerContainer.AddChild(formContainer);

            mainContainer.AddChild(centerContainer);
            
            FlowLayoutWidget buttonBottomPanel = GetButtonButtonPanel();
            buttonBottomPanel.AddChild(submitButton);
            buttonBottomPanel.AddChild(cancelButton);
            buttonBottomPanel.AddChild(doneButton);

            mainContainer.AddChild(buttonBottomPanel);

            this.AddChild(mainContainer);
        }
		public MeshViewerWidget(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape, string startingTextMessage = "")
		{
			RenderType = RenderTypes.Shaded;
			RenderBed = true;
			RenderBuildVolume = false;
			//SetMaterialColor(1, RGBA_Bytes.LightGray, RGBA_Bytes.White);
			BedColor = new RGBA_Floats(.8, .8, .8, .7).GetAsRGBA_Bytes();
			BuildVolumeColor = new RGBA_Floats(.2, .8, .3, .2).GetAsRGBA_Bytes();

			trackballTumbleWidget = new TrackballTumbleWidget();
			trackballTumbleWidget.DrawRotationHelperCircle = false;
			trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
			trackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(trackballTumbleWidget);

			CreatePrintBed(displayVolume, bedCenter, bedShape);

			trackballTumbleWidget.AnchorAll();

			partProcessingInfo = new PartProcessingInfo(startingTextMessage);

			GuiWidget labelContainer = new GuiWidget();
			labelContainer.AnchorAll();
			labelContainer.AddChild(partProcessingInfo);
			labelContainer.Selectable = false;

			this.AddChild(labelContainer);
		}
		public View3DWidget(PrintItemWrapper printItemWrapper, Vector3 viewerVolume, Vector2 bedCenter, MeshViewerWidget.BedShape bedShape, WindowMode windowType, AutoRotate autoRotate, OpenMode openMode = OpenMode.Viewing)
		{
			this.openMode = openMode;
			this.windowType = windowType;
			allowAutoRotate = (autoRotate == AutoRotate.Enabled);
			autoRotating = allowAutoRotate;
			MeshGroupExtraData = new List<PlatingMeshGroupData>();
			MeshGroupExtraData.Add(new PlatingMeshGroupData());

			this.printItemWrapper = printItemWrapper;

			FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
			mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

			FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
			centerPartPreviewAndControls.Name = "centerPartPreviewAndControls";
			centerPartPreviewAndControls.AnchorAll();

			GuiWidget viewArea = new GuiWidget();
			viewArea.AnchorAll();
			{
				meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape, "Press 'Add' to select an item.".Localize());

				PutOemImageOnBed();

				meshViewerWidget.AnchorAll();
			}
			viewArea.AddChild(meshViewerWidget);

			centerPartPreviewAndControls.AddChild(viewArea);
			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

			FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.Padding = new BorderDouble(3, 3);
			buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);
			buttonRightPanel.Name = "buttonRightPanel";
			buttonRightPanel.Visible = false;

			CreateOptionsContent();

			// add in the plater tools
			{
				FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				string progressFindPartsLabel = "Entering Editor".Localize();
				string progressFindPartsLabelFull = "{0}:".FormatWith(progressFindPartsLabel);

				processingProgressControl = new ProgressControl(progressFindPartsLabelFull, ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
				processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
				editToolBar.AddChild(processingProgressControl);
				editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;
				processingProgressControl.Visible = false;

				// If the window is embeded (in the center pannel) and there is no item loaded then don't show the add button
				enterEditButtonsContainer = new FlowLayoutWidget();
				{
					Button addButton = textImageButtonFactory.Generate("Insert".Localize(), "icon_insert_32x32.png");
					addButton.ToolTipText = "Insert an .stl, .amf or .zip file".Localize();
					addButton.Margin = new BorderDouble(right: 0);
					enterEditButtonsContainer.AddChild(addButton);
					addButton.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							DoAddFileAfterCreatingEditData = true;
							EnterEditAndCreateSelectionData();
						});
					};
					if (printItemWrapper != null 
						&& printItemWrapper.PrintItem.ReadOnly)
					{
						addButton.Enabled = false;
					}

					Button enterEdittingButton = textImageButtonFactory.Generate("Edit".Localize(), "icon_edit_32x32.png");
					enterEdittingButton.Margin = new BorderDouble(right: 4);
					enterEdittingButton.Click += (sender, e) =>
					{
						EnterEditAndCreateSelectionData();
					};
					
					if (printItemWrapper != null 
						&& printItemWrapper.PrintItem.ReadOnly)
					{
						enterEdittingButton.Enabled = false;
					}

					Button exportButton = textImageButtonFactory.Generate("Export...".Localize());
					if (printItemWrapper != null && 
						(printItemWrapper.PrintItem.Protected || printItemWrapper.PrintItem.ReadOnly))
					{
						exportButton.Enabled = false;
					}

					exportButton.Margin = new BorderDouble(right: 10);
					exportButton.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							OpenExportWindow();
						});
					};

					enterEditButtonsContainer.AddChild(enterEdittingButton);
					enterEditButtonsContainer.AddChild(exportButton);
				}
				editToolBar.AddChild(enterEditButtonsContainer);

				doEdittingButtonsContainer = new FlowLayoutWidget();
				doEdittingButtonsContainer.Visible = false;

				{
					Button addButton = textImageButtonFactory.Generate("Insert".Localize(), "icon_insert_32x32.png");
					addButton.Margin = new BorderDouble(right: 10);
					doEdittingButtonsContainer.AddChild(addButton);
					addButton.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							FileDialog.OpenFileDialog(
								new OpenFileDialogParams(ApplicationSettings.OpenDesignFileParams, multiSelect: true),
								(openParams) =>
								{
									LoadAndAddPartsToPlate(openParams.FileNames);
								});
						});
					};

					GuiWidget separator = new GuiWidget(1, 2);
					separator.BackgroundColor = ActiveTheme.Instance.PrimaryTextColor;
					separator.Margin = new BorderDouble(4, 2);
					separator.VAnchor = VAnchor.ParentBottomTop;
					doEdittingButtonsContainer.AddChild(separator);

					Button ungroupButton = textImageButtonFactory.Generate("Ungroup".Localize());
					doEdittingButtonsContainer.AddChild(ungroupButton);
					ungroupButton.Click += (sender, e) =>
					{
						UngroupSelectedMeshGroup();
					};

					Button groupButton = textImageButtonFactory.Generate("Group".Localize());
					doEdittingButtonsContainer.AddChild(groupButton);
					groupButton.Click += (sender, e) =>
					{
						GroupSelectedMeshs();
					};

					Button alignButton = textImageButtonFactory.Generate("Align".Localize());
					doEdittingButtonsContainer.AddChild(alignButton);
					alignButton.Click += (sender, e) =>
					{
						AlignToSelectedMeshGroup();
					};

					Button arrangeButton = textImageButtonFactory.Generate("Arrange".Localize());
					doEdittingButtonsContainer.AddChild(arrangeButton);
					arrangeButton.Click += (sender, e) =>
					{
						AutoArrangePartsInBackground();
					};

					GuiWidget separatorTwo = new GuiWidget(1, 2);
					separatorTwo.BackgroundColor = ActiveTheme.Instance.PrimaryTextColor;
					separatorTwo.Margin = new BorderDouble(4, 2);
					separatorTwo.VAnchor = VAnchor.ParentBottomTop;
					doEdittingButtonsContainer.AddChild(separatorTwo);

					Button copyButton = textImageButtonFactory.Generate("Copy".Localize());
					doEdittingButtonsContainer.AddChild(copyButton);
					copyButton.Click += (sender, e) =>
					{
						MakeCopyOfGroup();
					};

					Button deleteButton = textImageButtonFactory.Generate("Remove".Localize());
					doEdittingButtonsContainer.AddChild(deleteButton);
					deleteButton.Click += (sender, e) =>
					{
						DeleteSelectedMesh();
					};

					GuiWidget separatorThree = new GuiWidget(1, 2);
					separatorThree.BackgroundColor = ActiveTheme.Instance.PrimaryTextColor;
					separatorThree.Margin = new BorderDouble(4, 1);
					separatorThree.VAnchor = VAnchor.ParentBottomTop;
					doEdittingButtonsContainer.AddChild(separatorThree);

					Button leaveEditModeButton = textImageButtonFactory.Generate("Cancel".Localize(), centerText: true);
					leaveEditModeButton.Click += (sender, e) =>
					{
						UiThread.RunOnIdle(() =>
						{
							if (saveButtons.Visible)
							{
								StyledMessageBox.ShowMessageBox(ExitEditingAndSaveIfRequired, "Would you like to save your changes before exiting the editor?", "Save Changes", StyledMessageBox.MessageType.YES_NO);
							}
							else
							{
								if (partHasBeenEdited)
								{
									ExitEditingAndSaveIfRequired(false);
								}
								else
								{
									SwitchStateToNotEditing();
								}
							}
						});
					};
					doEdittingButtonsContainer.AddChild(leaveEditModeButton);

					// put in the save button
					AddSaveAndSaveAs(doEdittingButtonsContainer);
				}

				KeyDown += (sender, e) =>
				{
					KeyEventArgs keyEvent = e as KeyEventArgs;
					if (keyEvent != null && !keyEvent.Handled)
					{
						if (keyEvent.KeyCode == Keys.Delete || keyEvent.KeyCode == Keys.Back)
						{
							DeleteSelectedMesh();
						}

						if (keyEvent.KeyCode == Keys.Escape)
						{
							if (meshSelectInfo.downOnPart)
							{
								meshSelectInfo.downOnPart = false;

								ScaleRotateTranslate translated = SelectedMeshGroupTransform;
								translated.translation = transformOnMouseDown;
								SelectedMeshGroupTransform = translated;

								Invalidate();
							}
						}
					}
				};

				editToolBar.AddChild(doEdittingButtonsContainer);
				buttonBottomPanel.AddChild(editToolBar);
			}

			GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
			buttonRightPanelHolder.Name = "buttonRightPanelHolder";
			centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
			buttonRightPanelHolder.AddChild(buttonRightPanel);

			viewControls3D = new ViewControls3D(meshViewerWidget);

			buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
			buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
			buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);

			viewControls3D.PartSelectVisible = false;
			LockEditControls();

			GuiWidget leftRightSpacer = new GuiWidget();
			leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.AddChild(leftRightSpacer);

			if (windowType == WindowMode.StandAlone)
			{
				Button closeButton = textImageButtonFactory.Generate("Close".Localize());
				buttonBottomPanel.AddChild(closeButton);
				closeButton.Click += (sender, e) =>
				{
					CloseOnIdle();
				};
			}

			mainContainerTopToBottom.AddChild(buttonBottomPanel);

			this.AddChild(mainContainerTopToBottom);
			this.AnchorAll();

			meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;
			AddChild(viewControls3D);

			AddHandlers();

			UiThread.RunOnIdle(AutoSpin);

			if (printItemWrapper == null && windowType == WindowMode.Embeded)
			{
				enterEditButtonsContainer.Visible = false;
			}

			if (windowType == WindowMode.Embeded)
			{
				PrinterConnectionAndCommunication.Instance.CommunicationStateChanged.RegisterEvent(SetEditControlsBasedOnPrinterState, ref unregisterEvents);
				if (windowType == WindowMode.Embeded)
				{
					// make sure we lock the controls if we are printing or paused
					switch (PrinterConnectionAndCommunication.Instance.CommunicationState)
					{
						case PrinterConnectionAndCommunication.CommunicationStates.Printing:
						case PrinterConnectionAndCommunication.CommunicationStates.Paused:
							LockEditControls();
							break;
					}
				}
			}

			ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);

			upArrow = new UpArrow3D(this);
			heightDisplay = new HeightValueDisplay(this);
			heightDisplay.Visible = false;
			meshViewerWidget.interactionVolumes.Add(upArrow);

			// make sure the colors are set correctl
			ThemeChanged(this, null);

			saveButtons.VisibleChanged += (sender, e) =>
			{
				partHasBeenEdited = true;
			};
		}
		public TemperatureWidgetBase(string textValue)
			: base(52 * TextWidget.GlobalPointSizeScaleRatio, 52 * TextWidget.GlobalPointSizeScaleRatio)
		{
			whiteButtonFactory.FixedHeight = 18 * TextWidget.GlobalPointSizeScaleRatio;
			whiteButtonFactory.fontSize = 7;
			whiteButtonFactory.normalFillColor = RGBA_Bytes.White;
			whiteButtonFactory.normalTextColor = RGBA_Bytes.DarkGray;

			FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
			container.AnchorAll();

			this.BackgroundColor = new RGBA_Bytes(255, 255, 255, 200);
			this.Margin = new BorderDouble(0, 2) * TextWidget.GlobalPointSizeScaleRatio;

			GuiWidget labelContainer = new GuiWidget();
			labelContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
			labelContainer.Height = 18 * TextWidget.GlobalPointSizeScaleRatio;

			labelTextWidget = new TextWidget("", pointSize: 8);
			labelTextWidget.AutoExpandBoundsToText = true;
			labelTextWidget.HAnchor = HAnchor.ParentCenter;
			labelTextWidget.VAnchor = VAnchor.ParentCenter;
			labelTextWidget.TextColor = ActiveTheme.Instance.SecondaryAccentColor;
			labelTextWidget.Visible = false;

			labelContainer.AddChild(labelTextWidget);

			GuiWidget indicatorContainer = new GuiWidget();
			indicatorContainer.AnchorAll();

			indicatorTextWidget = new TextWidget(textValue, pointSize: 11);
			indicatorTextWidget.TextColor = ActiveTheme.Instance.PrimaryAccentColor;
			indicatorTextWidget.HAnchor = HAnchor.ParentCenter;
			indicatorTextWidget.VAnchor = VAnchor.ParentCenter;
			indicatorTextWidget.AutoExpandBoundsToText = true;

			indicatorContainer.AddChild(indicatorTextWidget);

			GuiWidget buttonContainer = new GuiWidget();
			buttonContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
			buttonContainer.Height = 18 * TextWidget.GlobalPointSizeScaleRatio;

			preheatButton = whiteButtonFactory.Generate("Preheat".Localize().ToUpper());
			preheatButton.Cursor = Cursors.Hand;
			preheatButton.Visible = false;

			buttonContainer.AddChild(preheatButton);

			container.AddChild(labelContainer);
			container.AddChild(indicatorContainer);
			container.AddChild(buttonContainer);

			this.AddChild(container);
			ActiveTheme.Instance.ThemeChanged.RegisterEvent(ThemeChanged, ref unregisterEvents);

			this.MouseEnterBounds += onEnterBounds;
			this.MouseLeaveBounds += onLeaveBounds;
			this.preheatButton.Click += onPreheatButtonClick;
		}