private void CloseContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; switch (elementState.TypeName) { case "a": GuiWidget aWidget = elementsUnderConstruction.Pop(); if (aWidget.Name != "a") { throw new Exception("Should have been 'a'."); } elementsUnderConstruction.Peek().AddChild(aWidget); break; case "p": GuiWidget pWidget = elementsUnderConstruction.Pop(); if (pWidget.Name != "p") { throw new Exception("Should have been 'p'."); } elementsUnderConstruction.Peek().AddChild(pWidget); break; case "div": GuiWidget divWidget = elementsUnderConstruction.Pop(); if (divWidget.Name != "div") { throw new Exception("Should have been 'div'."); } elementsUnderConstruction.Peek().AddChild(divWidget); break; case "table": break; case "span": break; case "tr": GuiWidget trWidget = elementsUnderConstruction.Pop(); if (trWidget.Name != "tr") { throw new Exception("Should have been 'tr'."); } elementsUnderConstruction.Peek().AddChild(trWidget); break; case "td": break; case "img": break; default: throw new NotImplementedException(); } }
private void AddContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; string decodedHtml = HtmlParser.UrlDecode(htmlContent); switch (elementState.TypeName) { case "p": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "p"; elementsUnderConstruction.Peek().HAnchor = HAnchor.ParentLeftRight; if (decodedHtml != null && decodedHtml != "") { WrappingTextWidget content = new WrappingTextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); //content.VAnchor = VAnchor.ParentTop; elementsUnderConstruction.Peek().AddChild(content); } } break; case "div": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "div"; if (decodedHtml != null && decodedHtml != "") { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); elementsUnderConstruction.Peek().AddChild(content); } } break; case "!DOCTYPE": break; case "body": break; case "img": { ImageBuffer image = new ImageBuffer(elementState.SizeFixed.x, elementState.SizeFixed.y, 32, new BlenderBGRA()); ImageWidget_AsyncLoadOnDraw imageWidget = new ImageWidget_AsyncLoadOnDraw(image, elementState.src); // put the image into the widget when it is done downloading. if (elementsUnderConstruction.Peek().Name == "a") { Button linkButton = new Button(0, 0, imageWidget); linkButton.Cursor = Cursors.Hand; linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } else { elementsUnderConstruction.Peek().AddChild(imageWidget); } } break; case "a": { elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "a"; if (decodedHtml != null && decodedHtml != "") { Button linkButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; linkButton.OriginRelativeParent = new VectorMath.Vector2(linkButton.OriginRelativeParent.x, linkButton.OriginRelativeParent.y + descentInPixels); linkButton.Click += (sender, mouseEvent) => { MatterControlApplication.Instance.LaunchBrowser(elementState.Href); }; elementsUnderConstruction.Peek().AddChild(linkButton); } } break; case "table": break; case "td": case "span": GuiWidget widgetToAdd; if (elementState.Classes.Contains("translate")) { decodedHtml = decodedHtml.Localize(); } if (elementState.Classes.Contains("toUpper")) { decodedHtml = decodedHtml.ToUpper(); } if (elementState.Classes.Contains("versionNumber")) { decodedHtml = VersionInfo.Instance.ReleaseVersion; } if (elementState.Classes.Contains("buildNumber")) { decodedHtml = VersionInfo.Instance.BuildVersion; } Button createdButton = null; if (elementState.Classes.Contains("centeredButton")) { createdButton = textImageButtonFactory.Generate(decodedHtml); widgetToAdd = createdButton; } else if (elementState.Classes.Contains("linkButton")) { double oldFontSize = linkButtonFactory.fontSize; linkButtonFactory.fontSize = elementState.PointSize; createdButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; createdButton.OriginRelativeParent = new VectorMath.Vector2(createdButton.OriginRelativeParent.x, createdButton.OriginRelativeParent.y + descentInPixels); widgetToAdd = createdButton; linkButtonFactory.fontSize = oldFontSize; } else { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); widgetToAdd = content; } if (createdButton != null) { if (elementState.Id == "sendFeedback") { createdButton.Click += (sender, mouseEvent) => { ContactFormWindow.Open(); }; } else if (elementState.Id == "clearCache") { createdButton.Click += (sender, mouseEvent) => { AboutWidget.DeleteCacheData(); }; } } if (elementState.VerticalAlignment == ElementState.VerticalAlignType.top) { widgetToAdd.VAnchor = VAnchor.ParentTop; } elementsUnderConstruction.Peek().AddChild(widgetToAdd); break; case "tr": elementsUnderConstruction.Push(new FlowLayoutWidget()); elementsUnderConstruction.Peek().Name = "tr"; if (elementState.SizePercent.y == 100) { elementsUnderConstruction.Peek().VAnchor = VAnchor.ParentBottomTop; } if (elementState.Alignment == ElementState.AlignType.center) { elementsUnderConstruction.Peek().HAnchor |= HAnchor.ParentCenter; } break; default: throw new NotImplementedException("Don't know what to do with {0}".FormatWith(elementState.TypeName)); } }
private void AddContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; string decodedHtml = HtmlParser.UrlDecode(htmlContent); switch (elementState.TypeName) { case "a": { Button linkButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; linkButton.OriginRelativeParent = new VectorMath.Vector2(linkButton.OriginRelativeParent.x, linkButton.OriginRelativeParent.y + descentInPixels); linkButton.Click += (sender, mouseEvent) => { System.Diagnostics.Process.Start(elementState.Href); }; currentRow.AddChild(linkButton); } break; case "table": break; case "td": case "span": GuiWidget widgetToAdd; if (elementState.Classes.Contains("translate")) { decodedHtml = decodedHtml.Localize(); } if (elementState.Classes.Contains("toUpper")) { decodedHtml = decodedHtml.ToUpper(); } if (elementState.Classes.Contains("versionNumber")) { decodedHtml = VersionInfo.Instance.ReleaseVersion; } if (elementState.Classes.Contains("buildNumber")) { decodedHtml = VersionInfo.Instance.BuildVersion; } Button createdButton = null; if (elementState.Classes.Contains("centeredButton")) { createdButton = textImageButtonFactory.Generate(decodedHtml); widgetToAdd = createdButton; } else if (elementState.Classes.Contains("linkButton")) { double oldFontSize = linkButtonFactory.fontSize; linkButtonFactory.fontSize = elementState.PointSize; createdButton = linkButtonFactory.Generate(decodedHtml); StyledTypeFace styled = new StyledTypeFace(LiberationSansFont.Instance, elementState.PointSize); double descentInPixels = styled.DescentInPixels; createdButton.OriginRelativeParent = new VectorMath.Vector2(createdButton.OriginRelativeParent.x, createdButton.OriginRelativeParent.y + descentInPixels); widgetToAdd = createdButton; linkButtonFactory.fontSize = oldFontSize; } else { TextWidget content = new TextWidget(decodedHtml, pointSize: elementState.PointSize, textColor: ActiveTheme.Instance.PrimaryTextColor); widgetToAdd = content; } if (createdButton != null) { if (elementState.Id == "sendFeedback") { createdButton.Click += (sender, mouseEvent) => { ContactFormWindow.Open(); }; } else if (elementState.Id == "clearCache") { createdButton.Click += (sender, mouseEvent) => { DeleteCacheData(); }; } } if (elementState.VerticalAlignment == ElementState.VerticalAlignType.top) { widgetToAdd.VAnchor = VAnchor.ParentTop; } currentRow.AddChild(widgetToAdd); break; case "tr": currentRow = new FlowLayoutWidget(); if (elementState.HeightPercent == 100) { currentRow.VAnchor = VAnchor.ParentBottomTop; } if (elementState.Alignment == ElementState.AlignType.center) { currentRow.HAnchor |= HAnchor.ParentCenter; } break; default: throw new NotImplementedException("Don't know what to do with {0}".FormatWith(elementState.TypeName)); } }
private void CloseContent(HtmlParser htmlParser, string htmlContent) { ElementState elementState = htmlParser.CurrentElementState; switch (elementState.TypeName) { case "a": break; case "table": break; case "span": break; case "tr": htmlWidget.AddChild(currentRow); currentRow = null; break; case "td": break; default: throw new NotImplementedException(); } }
public AboutPage() { this.HAnchor = HAnchor.ParentLeftRight; this.VAnchor = VAnchor.ParentTop; this.Padding = new BorderDouble(5); this.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor; linkButtonFactory.fontSize = 12; linkButtonFactory.textColor = aboutTextColor; textImageButtonFactory.normalFillColor = RGBA_Bytes.Gray; textImageButtonFactory.normalTextColor = ActiveTheme.Instance.PrimaryTextColor; 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); customInfoTopToBottom.AddChild(new UpdateControlView()); //AddMatterHackersInfo(customInfoTopToBottom); customInfoTopToBottom.AddChild(new GuiWidget(1, 10)); HtmlParser htmlParser = new HtmlParser(); if (htmlContent == null) { string aboutHtmlFile = Path.Combine(ApplicationDataStorage.Instance.ApplicationStaticDataPath, "OEMSettings", "AboutPage.html"); htmlContent = File.ReadAllText(aboutHtmlFile); } htmlWidget = new FlowLayoutWidget(FlowDirection.TopToBottom); htmlWidget.VAnchor = VAnchor.Max_FitToChildren_ParentHeight; htmlWidget.HAnchor |= HAnchor.ParentCenter; htmlParser.ParseHtml(htmlContent, AddContent, CloseContent); customInfoTopToBottom.AddChild(htmlWidget); this.AddChild(customInfoTopToBottom); }