public LayerNavigationWidget(ViewGcodeWidget gcodeViewWidget)
            : base(FlowDirection.LeftToRight)
        {
            this.gcodeViewWidget = gcodeViewWidget;

            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;

            prevLayerButton        = textImageButtonFactory.Generate("<<");
            prevLayerButton.Click += new EventHandler(prevLayer_ButtonClick);
            this.AddChild(prevLayerButton);

            layerCountTextWidget           = new TextWidget("/1____", 12);
            layerCountTextWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            layerCountTextWidget.VAnchor   = VAnchor.ParentCenter;
            layerCountTextWidget.AutoExpandBoundsToText = true;
            layerCountTextWidget.Margin = new BorderDouble(5, 0);
            this.AddChild(layerCountTextWidget);

            nextLayerButton        = textImageButtonFactory.Generate(">>");
            nextLayerButton.Click += new EventHandler(nextLayer_ButtonClick);
            this.AddChild(nextLayerButton);
        }
        private GuiWidget CreateGCodeViewWidget(string pathAndFileName)
        {
            gcodeViewWidget                         = new ViewGcodeWidget(new Vector2(viewerVolume.x, viewerVolume.y), bedCenter);
            gcodeViewWidget.DoneLoading            += DoneLoadingGCode;
            gcodeViewWidget.LoadingProgressChanged += LoadingProgressChanged;
            partToStartLoadingOnFirstDraw           = pathAndFileName;

            return(gcodeViewWidget);
        }
        public SetLayerWidget(ViewGcodeWidget gcodeViewWidget)
            : base(FlowDirection.LeftToRight)
        {
            this.gcodeViewWidget = gcodeViewWidget;

            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;

            editCurrentLayerIndex               = new NumberEdit(1, pixelWidth: 40);
            editCurrentLayerIndex.VAnchor       = VAnchor.ParentCenter;
            editCurrentLayerIndex.Margin        = new BorderDouble(5, 0);
            editCurrentLayerIndex.EditComplete += new EventHandler(editCurrentLayerIndex_EditComplete);
            this.AddChild(editCurrentLayerIndex);
            gcodeViewWidget.ActiveLayerChanged += new EventHandler(gcodeViewWidget_ActiveLayerChanged);

            setLayerButton         = textImageButtonFactory.Generate(LocalizedString.Get("Go"));
            setLayerButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
            setLayerButton.Click  += new EventHandler(layerCountTextWidget_EditComplete);
            this.AddChild(setLayerButton);
        }
		private GuiWidget CreateGCodeViewWidget(string pathAndFileName)
		{
			gcodeViewWidget = new ViewGcodeWidget(new Vector2(viewerVolume.x, viewerVolume.y), bedCenter);
			gcodeViewWidget.DoneLoading += DoneLoadingGCode;
			gcodeViewWidget.LoadingProgressChanged += LoadingProgressChanged;
			partToStartLoadingOnFirstDraw = pathAndFileName;

			return gcodeViewWidget;
		}
		private void CreateAndAddChildren()
		{
			TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
			textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;

			CloseAllChildren();
			gcodeViewWidget = null;
			gcodeProcessingStateInfoText = null;

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

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

			generateGCodeButton = textImageButtonFactory.Generate(LocalizedString.Get("Generate"));
			generateGCodeButton.Click += new EventHandler(generateButton_Click);
			buttonBottomPanel.AddChild(generateGCodeButton);

			layerSelectionButtonsPanel = new FlowLayoutWidget(FlowDirection.RightToLeft);
			layerSelectionButtonsPanel.HAnchor = HAnchor.ParentLeftRight;
			layerSelectionButtonsPanel.Padding = new BorderDouble(0);

			GuiWidget holdPanelOpen = new GuiWidget(1, generateGCodeButton.Height);
			layerSelectionButtonsPanel.AddChild(holdPanelOpen);

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

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

			gcodeDisplayWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop);
			string firstProcessingMessage = "Press 'Add' to select an item.".Localize();

			if (printItem != null)
			{
				firstProcessingMessage = "Loading G-Code...".Localize();
				if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE")
				{
					gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation));
				}
				else
				{
					if (File.Exists(printItem.FileLocation))
					{
						string gcodePathAndFileName = printItem.GetGCodePathAndFileName();
						bool gcodeFileIsComplete = printItem.IsGCodeFileComplete(gcodePathAndFileName);

						if (printItem.SlicingHadError)
						{
							firstProcessingMessage = slicingErrorMessage;
						}
						else
						{
							firstProcessingMessage = pressGenerateMessage;
						}

						if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete)
						{
							gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName));
						}

						// we only hook these up to make sure we can regenerate the gcode when we want
						printItem.SlicingOutputMessage += sliceItem_SlicingOutputMessage;
						printItem.SlicingDone += sliceItem_Done;
					}
					else
					{
						firstProcessingMessage = string.Format("{0}\n'{1}'", fileNotFoundMessage, printItem.Name);
					}
				}
			}
			else
			{
				generateGCodeButton.Visible = false;
			}

			SetProcessingMessage(firstProcessingMessage);
			centerPartPreviewAndControls.AddChild(gcodeDisplayWidget);

			buttonRightPanel = CreateRightButtonPanel();
			buttonRightPanel.Visible = false;
			centerPartPreviewAndControls.AddChild(buttonRightPanel);

			// add in a spacer
			layerSelectionButtonsPanel.AddChild(new GuiWidget(HAnchor.ParentLeftRight));
			buttonBottomPanel.AddChild(layerSelectionButtonsPanel);

			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);
			mainContainerTopToBottom.AddChild(buttonBottomPanel);
			this.AddChild(mainContainerTopToBottom);

			meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape, "".Localize());
			meshViewerWidget.AnchorAll();
			meshViewerWidget.AllowBedRenderingWhenEmpty = true;
			gcodeDisplayWidget.AddChild(meshViewerWidget);
			meshViewerWidget.Visible = false;
			meshViewerWidget.TrackballTumbleWidget.DrawGlContent += new EventHandler(TrackballTumbleWidget_DrawGlContent);

			viewControls2D = new ViewControls2D();
			AddChild(viewControls2D);

			viewControls2D.ResetView += (sender, e) =>
			{
				SetDefaultView2D();
			};

			viewControls3D = new ViewControls3D(meshViewerWidget);
			viewControls3D.PartSelectVisible = false;
			AddChild(viewControls3D);

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

			viewControls3D.ActiveButton = ViewControls3DButtons.Rotate;
			viewControls3D.Visible = false;

			viewControlsToggle = new ViewControlsToggle();
			viewControlsToggle.HAnchor = Agg.UI.HAnchor.ParentRight;
			AddChild(viewControlsToggle);
			viewControlsToggle.Visible = false;

			//viewControls3D.translateButton.ClickButton(null);

			SetDefaultView();

			viewControls2D.translateButton.Click += (sender, e) =>
			{
				gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Move;
			};
			viewControls2D.scaleButton.Click += (sender, e) =>
			{
				gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Scale;
			};

			AddHandlers();
		}
		public LayerNavigationWidget(ViewGcodeWidget gcodeViewWidget)
			: base(FlowDirection.LeftToRight)
		{
			this.gcodeViewWidget = gcodeViewWidget;

			textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;

			prevLayerButton = textImageButtonFactory.Generate("<<");
			prevLayerButton.Click += new EventHandler(prevLayer_ButtonClick);
			this.AddChild(prevLayerButton);

			layerCountTextWidget = new TextWidget("/1____", 12);
			layerCountTextWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			layerCountTextWidget.VAnchor = VAnchor.ParentCenter;
			layerCountTextWidget.AutoExpandBoundsToText = true;
			layerCountTextWidget.Margin = new BorderDouble(5, 0);
			this.AddChild(layerCountTextWidget);

			nextLayerButton = textImageButtonFactory.Generate(">>");
			nextLayerButton.Click += new EventHandler(nextLayer_ButtonClick);
			this.AddChild(nextLayerButton);
		}
		public SetLayerWidget(ViewGcodeWidget gcodeViewWidget)
			: base(FlowDirection.LeftToRight)
		{
			this.gcodeViewWidget = gcodeViewWidget;

			textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.hoverTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
			textImageButtonFactory.pressedTextColor = ActiveTheme.Instance.PrimaryTextColor;

			editCurrentLayerIndex = new NumberEdit(1, pixelWidth: 40);
			editCurrentLayerIndex.VAnchor = VAnchor.ParentCenter;
			editCurrentLayerIndex.Margin = new BorderDouble(5, 0);
			editCurrentLayerIndex.EditComplete += new EventHandler(editCurrentLayerIndex_EditComplete);
			this.AddChild(editCurrentLayerIndex);
			gcodeViewWidget.ActiveLayerChanged += new EventHandler(gcodeViewWidget_ActiveLayerChanged);

			setLayerButton = textImageButtonFactory.Generate(LocalizedString.Get("Go"));
			setLayerButton.VAnchor = Agg.UI.VAnchor.ParentCenter;
			setLayerButton.Click += new EventHandler(layerCountTextWidget_EditComplete);
			this.AddChild(setLayerButton);
		}
        void CreateAndAddChildren(object state)
        {
            TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();

            textImageButtonFactory.normalTextColor   = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.hoverTextColor    = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.disabledTextColor = ActiveTheme.Instance.PrimaryTextColor;
            textImageButtonFactory.pressedTextColor  = ActiveTheme.Instance.PrimaryTextColor;

            CloseAndRemoveAllChildren();
            gcodeViewWidget = null;
            gcodeProcessingStateInfoText = null;

            FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);

            mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
            mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

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

            generateGCodeButton        = textImageButtonFactory.Generate(LocalizedString.Get("Generate"));
            generateGCodeButton.Click += new EventHandler(generateButton_Click);
            buttonBottomPanel.AddChild(generateGCodeButton);

            layerSelectionButtonsPanel         = new FlowLayoutWidget(FlowDirection.RightToLeft);
            layerSelectionButtonsPanel.HAnchor = HAnchor.ParentLeftRight;
            layerSelectionButtonsPanel.Padding = new BorderDouble(0);

            GuiWidget holdPanelOpen = new GuiWidget(1, generateGCodeButton.Height);

            layerSelectionButtonsPanel.AddChild(holdPanelOpen);

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

            FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);

            centerPartPreviewAndControls.AnchorAll();

            gcodeDisplayWidget = new GuiWidget(HAnchor.ParentLeftRight, Agg.UI.VAnchor.ParentBottomTop);

            SetProcessingMessage("Press 'Add' to select an item.".Localize());
            if (printItem != null)
            {
                SetProcessingMessage(LocalizedString.Get("Loading GCode..."));
                if (Path.GetExtension(printItem.FileLocation).ToUpper() == ".GCODE")
                {
                    gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(printItem.FileLocation));
                }
                else
                {
                    if (File.Exists(printItem.FileLocation))
                    {
                        string gcodePathAndFileName = printItem.GetGCodePathAndFileName();
                        bool   gcodeFileIsComplete  = printItem.IsGCodeFileComplete(gcodePathAndFileName);

                        if (printItem.SlicingHadError)
                        {
                            SetProcessingMessage(slicingErrorMessage);
                        }
                        else
                        {
                            SetProcessingMessage(pressGenerateMessage);
                        }

                        if (File.Exists(gcodePathAndFileName) && gcodeFileIsComplete)
                        {
                            gcodeDisplayWidget.AddChild(CreateGCodeViewWidget(gcodePathAndFileName));
                        }

                        // we only hook these up to make sure we can regenerate the gcode when we want
                        printItem.SlicingOutputMessage.RegisterEvent(sliceItem_SlicingOutputMessage, ref unregisterEvents);
                        printItem.SlicingDone.RegisterEvent(sliceItem_Done, ref unregisterEvents);
                    }
                    else
                    {
                        SetProcessingMessage(string.Format("{0}\n'{1}'", fileNotFoundMessage, printItem.Name));
                    }
                }
            }
            else
            {
                generateGCodeButton.Visible = false;
            }

            centerPartPreviewAndControls.AddChild(gcodeDisplayWidget);

            buttonRightPanel         = CreateRightButtonPanel();
            buttonRightPanel.Visible = false;
            centerPartPreviewAndControls.AddChild(buttonRightPanel);

            // add in a spacer
            layerSelectionButtonsPanel.AddChild(new GuiWidget(HAnchor.ParentLeftRight));
            buttonBottomPanel.AddChild(layerSelectionButtonsPanel);

            mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);
            mainContainerTopToBottom.AddChild(buttonBottomPanel);
            this.AddChild(mainContainerTopToBottom);

            meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape, "".Localize());
            meshViewerWidget.AnchorAll();
            meshViewerWidget.AllowBedRenderingWhenEmpty = true;
            gcodeDisplayWidget.AddChild(meshViewerWidget);
            meshViewerWidget.Visible = false;
            meshViewerWidget.TrackballTumbleWidget.DrawGlContent += new EventHandler(TrackballTumbleWidget_DrawGlContent);

            viewControls2D = new ViewControls2D();
            AddChild(viewControls2D);
            viewControls3D = new ViewControls3D(meshViewerWidget);
            viewControls3D.PartSelectVisible = false;
            AddChild(viewControls3D);
            viewControls3D.rotateButton.ClickButton(null);
            viewControls3D.Visible = false;

            viewControlsToggle         = new ViewControlsToggle();
            viewControlsToggle.HAnchor = Agg.UI.HAnchor.ParentRight;
            AddChild(viewControlsToggle);
            viewControlsToggle.Visible = false;

            //viewControls3D.translateButton.ClickButton(null);

            // move things into the right place and scale
            {
                Vector3 bedCenter3D = new Vector3(bedCenter, 0);
                meshViewerWidget.PrinterBed.Translate(bedCenter3D);
                meshViewerWidget.TrackballTumbleWidget.TrackBallController.Scale = .05;
                meshViewerWidget.TrackballTumbleWidget.TrackBallController.Translate(-bedCenter3D);
            }

            viewControls2D.translateButton.Click += (sender, e) =>
            {
                gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Move;
            };
            viewControls2D.scaleButton.Click += (sender, e) =>
            {
                gcodeViewWidget.TransformState = ViewGcodeWidget.ETransformState.Scale;
            };

            AddHandlers();
        }