Пример #1
0
        public void ShowPopup(PopupWidget popupWidget)
        {
            this.popupWidget = popupWidget;
            windowToAddTo    = widgetRelativeTo.Parents <SystemWindow>().FirstOrDefault();
            windowToAddTo?.AddChild(popupWidget);

            // Iterate until the first SystemWindow is found
            GuiWidget topParent = widgetRelativeTo.Parent;

            while (topParent.Parent != null &&
                   topParent as SystemWindow == null)
            {
                // Regrettably we don't know who it is that is the window that will actually think it is moving relative to its parent
                // but we need to know anytime our widgetRelativeTo has been moved by any change, so we hook them all.
                if (!hookedParents.Contains(topParent))
                {
                    hookedParents.Add(topParent);
                    topParent.PositionChanged += widgetRelativeTo_PositionChanged;
                    topParent.BoundsChanged   += widgetRelativeTo_PositionChanged;
                }

                topParent = topParent.Parent;
            }

            widgetRelativeTo_PositionChanged(widgetRelativeTo, null);
            widgetRelativeTo.Closed += widgetRelativeTo_Closed;
        }
Пример #2
0
        public void CreateWidgetAndRunInWindow(SystemWindow.PixelTypes bitDepth = SystemWindow.PixelTypes.Depth32, RenderSurface surfaceType = RenderSurface.Bitmap)
		{
			AppWidgetInfo appWidgetInfo = GetAppParameters();
            SystemWindow systemWindow = new SystemWindow(appWidgetInfo.width, appWidgetInfo.height);
            systemWindow.PixelType = bitDepth;
            systemWindow.Title = appWidgetInfo.title;
            if (surfaceType == RenderSurface.OpenGL)
            {
                systemWindow.UseOpenGL = true;
            }
            systemWindow.AddChild(NewWidget());
            systemWindow.ShowAsSystemWindow();
        }
Пример #3
0
        public void CreateWidgetAndRunInWindow(SystemWindow.PixelTypes bitDepth = SystemWindow.PixelTypes.Depth32, RenderSurface surfaceType = RenderSurface.Bitmap)
        {
            AppWidgetInfo appWidgetInfo = GetAppParameters();
            SystemWindow  systemWindow  = new SystemWindow(appWidgetInfo.width, appWidgetInfo.height);

            systemWindow.PixelType = bitDepth;
            systemWindow.Title     = appWidgetInfo.title;
            if (surfaceType == RenderSurface.OpenGL)
            {
                systemWindow.UseOpenGL = true;
            }
            systemWindow.AddChild(NewWidget());
            systemWindow.ShowAsSystemWindow();
        }
Пример #4
0
		public AboutWidget()
		{
			this.HAnchor = HAnchor.ParentLeftRight;
			this.VAnchor = VAnchor.ParentTop;

			this.Padding = new BorderDouble(5);
			this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			FlowLayoutWidget customInfoTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			customInfoTopToBottom.Name = "AboutPageCustomInfo";
			customInfoTopToBottom.HAnchor = HAnchor.ParentLeftRight;
			customInfoTopToBottom.VAnchor = VAnchor.Max_FitToChildren_ParentHeight;
			customInfoTopToBottom.Padding = new BorderDouble(5, 10, 5, 0);

			if (ActiveTheme.Instance.IsTouchScreen)
			{
				customInfoTopToBottom.AddChild(new UpdateControlView());
			}

			//AddMatterHackersInfo(customInfoTopToBottom);
			customInfoTopToBottom.AddChild(new GuiWidget(1, 10));

			string aboutHtmlFile = Path.Combine("OEMSettings", "AboutPage.html");
			string htmlContent = StaticData.Instance.ReadAllText(aboutHtmlFile); 

#if false // test
			{
				SystemWindow releaseNotes = new SystemWindow(640, 480);
				string releaseNotesFile = Path.Combine("OEMSettings", "ReleaseNotes.html");
				string releaseNotesContent = StaticData.Instance.ReadAllText(releaseNotesFile);
				HtmlWidget content = new HtmlWidget(releaseNotesContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				releaseNotes.AddChild(content);
				releaseNotes.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					releaseNotes.ShowAsSystemWindow();
				}, 1);
			}
#endif

			HtmlWidget htmlWidget = new HtmlWidget(htmlContent, ActiveTheme.Instance.PrimaryTextColor);

			customInfoTopToBottom.AddChild(htmlWidget);

			this.AddChild(customInfoTopToBottom);
		}
        private void DoShowToolTip()
        {
            if (widgetThatWantsToShowToolTip != null &&
                widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip)
            {
                RectangleDouble screenBounds = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds);
                if (screenBounds.Contains(mousePosition))
                {
                    RemoveToolTip();
                    widgetThatIsShowingToolTip = null;

                    toolTipText   = widgetThatWantsToShowToolTip.ToolTipText;
                    toolTipWidget = new FlowLayoutWidget()
                    {
                        BackgroundColor      = RGBA_Bytes.White,
                        OriginRelativeParent = new Vector2((int)mousePosition.x, (int)mousePosition.y),
                        Padding    = new BorderDouble(3),
                        Selectable = false,
                    };

                    toolTipWidget.Name = "ToolTipWidget";

                    toolTipWidget.AfterDraw += (sender, drawEventHandler) =>
                    {
                        drawEventHandler.graphics2D.Rectangle(toolTipWidget.LocalBounds, RGBA_Bytes.Black);
                    };

                    // Make sure we wrap long text
                    toolTipWidget.AddChild(new WrappedTextWidget(toolTipText)
                    {
                        Width   = 350 * GuiWidget.DeviceScale,
                        HAnchor = HAnchor.FitToChildren,
                    });

                    // Increase the delay to make long text stay on screen long enough to read
                    double RatioOfExpectedText = Math.Max(1, (widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0));
                    CurrentAutoPopDelay = RatioOfExpectedText * AutoPopDelay;

                    owner.AddChild(toolTipWidget);
                    if (ToolTipShown != null)
                    {
                        ToolTipShown(this, new StringEventArgs(CurrentText));
                    }

                    //timeCurrentToolTipHasBeenShowing.Reset();
                    //timeCurrentToolTipHasBeenShowingWasRunning = true;
                    timeCurrentToolTipHasBeenShowing.Restart();

                    RectangleDouble toolTipBounds = toolTipWidget.LocalBounds;

                    toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23);

                    Vector2         offset      = Vector2.Zero;
                    RectangleDouble ownerBounds = owner.LocalBounds;
                    RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent;

                    if (toolTipBoundsRelativeToParent.Right > ownerBounds.Right - 3)
                    {
                        offset.x = ownerBounds.Right - toolTipBoundsRelativeToParent.Right - 3;
                    }

                    if (toolTipBoundsRelativeToParent.Bottom < ownerBounds.Bottom + 3)
                    {
                        offset.y = ownerBounds.Bottom - toolTipBoundsRelativeToParent.Bottom + 3;
                    }

                    toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset;

                    widgetThatIsShowingToolTip   = widgetThatWantsToShowToolTip;
                    widgetThatWantsToShowToolTip = null;
                }
            }
        }
Пример #6
0
        private void DoShowToolTip()
        {
            if (widgetThatWantsToShowToolTip != null &&
                widgetThatWantsToShowToolTip != widgetThatIsShowingToolTip &&
                widgetThatWasShowingToolTip != widgetThatWantsToShowToolTip)
            {
                RectangleDouble screenBoundsShowingTT = widgetThatWantsToShowToolTip.TransformToScreenSpace(widgetThatWantsToShowToolTip.LocalBounds);
                if (screenBoundsShowingTT.Contains(mousePosition))
                {
                    RemoveToolTip();
                    widgetThatIsShowingToolTip = null;

                    toolTipText   = widgetThatWantsToShowToolTip.ToolTipText;
                    toolTipWidget = new FlowLayoutWidget()
                    {
                        OriginRelativeParent = new Vector2((int)mousePosition.X, (int)mousePosition.Y),
                        Selectable           = false,
                    };

                    toolTipWidget.Name = "ToolTipWidget";

                    // Make sure we wrap long text
                    toolTipWidget.AddChild(CreateToolTip(toolTipText));

                    // Increase the delay to make long text stay on screen long enough to read
                    double ratioOfExpectedText = Math.Max(1, widgetThatWantsToShowToolTip.ToolTipText.Length / 50.0);
                    CurrentAutoPopDelay = ratioOfExpectedText * AutoPopDelay;

                    systemWindow.AddChild(toolTipWidget);

                    ToolTipShown?.Invoke(this, new StringEventArgs(CurrentText));

                    // timeCurrentToolTipHasBeenShowing.Reset();
                    // timeCurrentToolTipHasBeenShowingWasRunning = true;
                    timeCurrentToolTipHasBeenShowing.Restart();

                    RectangleDouble toolTipBounds = toolTipWidget.LocalBounds;

                    toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + new Vector2(0, -toolTipBounds.Bottom - toolTipBounds.Height - 23);

                    Vector2         offset                        = Vector2.Zero;
                    RectangleDouble systemWindowBounds            = systemWindow.LocalBounds;
                    RectangleDouble toolTipBoundsRelativeToParent = toolTipWidget.BoundsRelativeToParent;

                    if (toolTipBoundsRelativeToParent.Right > systemWindowBounds.Right - 3)
                    {
                        offset.X = systemWindowBounds.Right - toolTipBoundsRelativeToParent.Right - 3;
                    }

                    if (toolTipBoundsRelativeToParent.Bottom < systemWindowBounds.Bottom + 3)
                    {
                        offset.Y = screenBoundsShowingTT.Top - toolTipBoundsRelativeToParent.Bottom + 3;
                    }

                    toolTipWidget.OriginRelativeParent = toolTipWidget.OriginRelativeParent + offset;

                    widgetThatIsShowingToolTip   = widgetThatWantsToShowToolTip;
                    widgetThatWantsToShowToolTip = null;
                    widgetThatWasShowingToolTip  = null;
                }
            }
        }
Пример #7
0
		public void ShowContentInWindow()
		{
			if(widgetWithPopContent.HasBeenClosed)
			{
				if(systemWindowWithPopContent != null)
				{
					systemWindowWithPopContent.Close();
				}

				return;
			}

			if (systemWindowWithPopContent == null)
			{
				// So the window is open now only change this is we close it.
				UserSettings.Instance.Fields.SetBool(WindowLeftOpenKey, true);

				string windowSize = UserSettings.Instance.get(WindowSizeKey);
				int width = 600;
				int height = 400;
				if (windowSize != null && windowSize != "")
				{
					string[] sizes = windowSize.Split(',');
					width = Math.Max(int.Parse(sizes[0]), (int)minSize.x);
					height = Math.Max(int.Parse(sizes[1]), (int)minSize.y);
				}

				systemWindowWithPopContent = new SystemWindow(width, height);
				systemWindowWithPopContent.Padding = new BorderDouble(3);
				systemWindowWithPopContent.Title = windowTitle;
				systemWindowWithPopContent.AlwaysOnTopOfMain = true;
				systemWindowWithPopContent.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
				systemWindowWithPopContent.Closing += SystemWindow_Closing;
				if (widgetWithPopContent.Children.Count == 1)
				{
					GuiWidget child = widgetWithPopContent.Children[0];
					widgetWithPopContent.RemoveChild(child);
					child.ClearRemovedFlag();
					widgetWithPopContent.AddChild(CreateContentForEmptyControl());
					systemWindowWithPopContent.AddChild(child);
				}
				systemWindowWithPopContent.ShowAsSystemWindow();

				systemWindowWithPopContent.MinimumSize = minSize;
				string desktopPosition = UserSettings.Instance.get(PositionKey);
				if (desktopPosition != null && desktopPosition != "")
				{
					string[] sizes = desktopPosition.Split(',');

					//If the desktop position is less than -10,-10, override
					int xpos = Math.Max(int.Parse(sizes[0]), -10);
					int ypos = Math.Max(int.Parse(sizes[1]), -10);
					systemWindowWithPopContent.DesktopPosition = new Point2D(xpos, ypos);
				}
			}
			else
			{
				systemWindowWithPopContent.BringToFront();
			}
		}
Пример #8
0
        public override void OnDraw(Graphics2D graphics2D)
        {
#if false
            if (firstDraw)
            {
                firstDraw = false;
                SystemWindow testAbout = new SystemWindow(600, 300);

                string path = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "AboutPage.html");
                string htmlText = File.ReadAllText(path);
                HTMLCanvas canvas = new HTMLCanvas(htmlText);
                canvas.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

                canvas.AddReplacementString("textColor", RGBA_Bytes.White.GetAsHTMLString());

                canvas.AnchorAll();
                testAbout.AddChild(canvas);

                testAbout.ShowAsSystemWindow();
            }
#endif

            graphics2D.FillRectangle(new RectangleDouble(0, this.Height - 1, this.Width, this.Height), RGBA_Bytes.White);
            base.OnDraw(graphics2D);
        }
		private static void HtmlWindowTest()
		{
			try
			{
				SystemWindow htmlTestWindow = new SystemWindow(640, 480);
				string htmlContent = "";
				if (true)
				{
					string releaseNotesFile = Path.Combine("C:\\Users\\lbrubaker\\Downloads", "test1.html");
					htmlContent = File.ReadAllText(releaseNotesFile);
				}
				else
				{
					WebClient webClient = new WebClient();
					htmlContent = webClient.DownloadString("http://www.matterhackers.com/s/store?q=pla");
				}

				HtmlWidget content = new HtmlWidget(htmlContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				htmlTestWindow.AddChild(content);
				htmlTestWindow.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					htmlTestWindow.ShowAsSystemWindow();
				}, 1);
			}
			catch
			{
				int stop = 1;
			}
		}
        public override void OnDraw(Graphics2D graphics2D)
		{
			totalDrawTime.Restart();
			GuiWidget.DrawCount = 0;
			using (new PerformanceTimer("Draw Timer", "MC Draw"))
			{
				base.OnDraw(graphics2D);
			}
			totalDrawTime.Stop();

			millisecondTimer.Update((int)totalDrawTime.ElapsedMilliseconds);

			if (ShowMemoryUsed)
			{
				long memory = GC.GetTotalMemory(false);
				this.Title = "Allocated = {0:n0} : {1:000}ms, d{2} Size = {3}x{4}, onIdle = {5:00}:{6:00}, widgetsDrawn = {7}".FormatWith(memory, millisecondTimer.GetAverage(), drawCount++, this.Width, this.Height, UiThread.CountExpired, UiThread.Count, GuiWidget.DrawCount);
				if (DoCGCollectEveryDraw)
				{
					GC.Collect();
				}
			}

			if (firstDraw)
			{
				UiThread.RunOnIdle(DoAutoConnectIfRequired);

				firstDraw = false;
				foreach (string arg in commandLineArgs)
				{
					string argExtension = Path.GetExtension(arg).ToUpper();
					if (argExtension.Length > 1
						&& MeshFileIo.ValidFileExtensions().Contains(argExtension))
					{
						QueueData.Instance.AddItem(new PrintItemWrapper(new DataStorage.PrintItem(Path.GetFileName(arg), Path.GetFullPath(arg))));
					}
				}

				TerminalWindow.ShowIfLeftOpen();

#if false
			{
				SystemWindow releaseNotes = new SystemWindow(640, 480);
				string releaseNotesFile = Path.Combine("C:/Users/LarsBrubaker/Downloads", "test1.html");
				string releaseNotesContent = StaticData.Instance.ReadAllText(releaseNotesFile);
				HtmlWidget content = new HtmlWidget(releaseNotesContent, RGBA_Bytes.Black);
				content.AddChild(new GuiWidget(HAnchor.AbsolutePosition, VAnchor.ParentBottomTop));
				content.VAnchor |= VAnchor.ParentTop;
				content.BackgroundColor = RGBA_Bytes.White;
				releaseNotes.AddChild(content);
				releaseNotes.BackgroundColor = RGBA_Bytes.Cyan;
				UiThread.RunOnIdle((state) =>
				{
					releaseNotes.ShowAsSystemWindow();
				}, 1);
			}
#endif

				AfterFirstDraw?.Invoke();
			}

			//msGraph.AddData("ms", totalDrawTime.ElapsedMilliseconds);
			//msGraph.Draw(MatterHackers.Agg.Transform.Affine.NewIdentity(), graphics2D);
		}
Пример #11
0
        /// <summary>
        /// Creates or connects a PlatformWindow to the given SystemWindow
        /// </summary>
        public virtual void ShowSystemWindow(SystemWindow systemWindow)
        {
            if (_openWindows.Count == 0)
            {
                this._openWindows.Add(systemWindow);
            }
            else
            {
                if (systemWindow.PlatformWindow != null)
                {
                    return;
                }

                var overlayWindow = new SystemWindow(_openWindows.FirstOrDefault().Width, _openWindows.FirstOrDefault().Height)
                {
                    PlatformWindow = platformWindow
                };

                systemWindow.HAnchor = HAnchor.Stretch;
                systemWindow.VAnchor = VAnchor.Stretch;

                var theme = ApplicationController.Instance.Theme;

                var movable = new WindowWidget(systemWindow)
                {
                    WindowBorderColor = new Color(theme.Colors.PrimaryAccentColor, 175)
                };
                overlayWindow.AddChild(movable);

                var closeButton = theme.CreateSmallResetButton();
                closeButton.HAnchor     = HAnchor.Right;
                closeButton.ToolTipText = "Close".Localize();
                closeButton.Click      += (s, e) =>
                {
                    systemWindow.Close();
                };

                var titleBarRow = new Toolbar(theme, closeButton)
                {
                    HAnchor = HAnchor.Stretch,
                    VAnchor = VAnchor.Fit | VAnchor.Center,
                };

                titleBarRow.AddChild(new ImageWidget(AggContext.StaticData.LoadIcon("mh.png", 16, 16, theme.InvertIcons))
                {
                    Margin  = new BorderDouble(4, 0, 6, 0),
                    VAnchor = VAnchor.Center
                });

                titleBarRow.ActionArea.AddChild(new TextWidget(systemWindow.Title ?? "", pointSize: theme.DefaultFontSize - 1, textColor: theme.Colors.PrimaryTextColor)
                {
                    VAnchor = VAnchor.Center,
                });

                movable.TitleBar.BackgroundColor = theme.TabBarBackground;

                movable.TitleBar.AddChild(titleBarRow);

                systemWindow.Closed += (s, e) =>
                {
                    overlayWindow.Close();
                };

                movable.Width += 1;

                movable.Position = new VectorMath.Vector2((overlayWindow.Width - movable.Width) / 2, (overlayWindow.Height - movable.Height) / 2);

                this._openWindows.Add(overlayWindow);
            }

            TopWindow = _openWindows.LastOrDefault();

            platformWindow.ShowSystemWindow(TopWindow);
        }