private void LoadGame(string sourcePath) { m_sourcePath = sourcePath; m_domTree = m_domTreeBuilder.Build(m_sourcePath); m_styleRules = m_styleRulesBuilder.Build(m_domTree); m_renderTree = m_renderTreeBuilder.Build(m_domTree, m_styleRules); }
public UserFormTest() { // We're testing a Telerik application RenderTree.Add <TelerikRootComponent>(); /// Add Root Component AddMockDataService(); }
public void BuildRender_InheritStylesWithParent_RenderLayout() { var _renderTree = new RenderTree(); var loader = new HtmlLoader(); var window = loader.LoadFromFile("Contents/test_html_inherit_styles_with_parent.html"); _renderTree.Build(window); var root = _renderTree.LayoutRoot; var html = root.Layouts.FirstOrDefault(); var body = html.Layouts.LastOrDefault(); var mainDiv = body.Layouts.FirstOrDefault(); mainDiv.CssRule.Should().NotBeNull(); mainDiv.Layouts.FirstOrDefault().CssRule.SelectorText.Should().BeEquivalentTo(".oneLevel"); var twoLevelDiv = mainDiv.Layouts.LastOrDefault(); twoLevelDiv.CssRule.SelectorText.Should().BeEquivalentTo(".twoLevel"); var twoLevelA = twoLevelDiv.Layouts.FirstOrDefault(); twoLevelA.CssRule.SelectorText.Should().BeEquivalentTo(".twoLevel"); var twoStyle = twoLevelA.CssRule.Style; var oneStyle = mainDiv.CssRule.Style; twoStyle.Color.Should().BeEquivalentTo(oneStyle.Color); twoStyle.Background.Color.Should().BeEquivalentTo(new CSSColor(17, 17, 17)); }
public void InvokeRenderTree() { if (RenderTree != null) { RenderTree.Invoke(); } }
public static void EndLayoutGroup(this RenderTree renderTree) { if (renderTree.CurrentContainer == renderTree.Root) { throw new InvalidOperationException("BeginLayoutGroup/EndLayoutGroup mismatch."); } renderTree.CurrentContainer = renderTree.CurrentContainer.Parent; }
public UserFormTest() { // We're testing a Telerik application RenderTree.Add <TelerikRootComponent>(); // Add Root Component AddMockDataService(); JSInterop.Mode = JSRuntimeMode.Loose; }
public void Render(RenderTree renderTree) { var image = _renderer.Render(renderTree); var stream = new MemoryStream(); image.SaveAsBmp(stream); viewOutput.Image = Image.FromStream(stream); }
public void RenderLayoutCompositor_AbsolutePosition_ReturnOffsetPosition() { var _renderTree = new RenderTree(); var loader = new HtmlLoader(); var window = loader.LoadFromFile("Contents/test_compositor_absolute_position.html"); _renderTree.Build(window); var root = _renderTree.LayoutRoot; var html = root.Layouts.FirstOrDefault(); var body = html.Layouts.LastOrDefault(); }
public static void BeginLayoutGroup(this RenderTree renderTree, int id, bool isVertical, LayoutOptions?options = null, string str_id = null) { var group = renderTree.CurrentContainer.Children.Find(n => n.Id == id); if (group == null) { group = new Node(id, str_id ?? "group"); group.AttachLayoutGroup(isVertical); renderTree.CurrentContainer.AppendChild(group); } group.RuleSet.ApplyOptions(options); renderTree.CurrentContainer = group; }
public void BuildRenderBindStyleTest() { var _renderTree = new RenderTree(); var loader = new HtmlLoader(); var window = loader.LoadFromFile("Contents/test_html_bind_style.html"); _renderTree.Build(window); var root = _renderTree.LayoutRoot; var html = root.Layouts.FirstOrDefault(); var body = html.Layouts.LastOrDefault(); var button = body.Layouts.FirstOrDefault(); button.CssRule.Should().NotBeNull(); }
private void EnsureRootComponent() { if (rootComponent is not null) { return; } // add a Telerik Root Component to hold all Telerik components and other content rootComponent = (IRenderedComponent <TelerikRootComponent>)Renderer.RenderComponent <TelerikRootComponent>(new ComponentParameterCollection()); // provide the Telerik Root Component to the child components that need it (the Telerik components) RenderTree.TryAdd <CascadingValue <TelerikRootComponent> >(p => { p.Add(parameters => parameters.IsFixed, true); p.Add(parameters => parameters.Value, RootComponent.Instance); }); }
private void LoadFile(string path) { if (string.IsNullOrWhiteSpace(path)) { return; } var package = LoadPackageFromChunk(path); // window title _currentPackage = package; _currentRenderTree = RenderTree.Create(package); PopulateTreeView(package, _currentRenderTree); viewOutput.Init(Path.Combine(Path.GetDirectoryName(path) ?? "", "textures")); Render(); Text = package.Name; }
private static int RunApplication(Options options) { if (!File.Exists(options.InputFile)) { Console.Error.WriteLine("File not found: {0}", options.InputFile); return(1); } var package = LoadPackageFromChunk(options.InputFile); PackageDumper.DumpPackage(package); var outputFile = options.OutputFile; if (!string.IsNullOrWhiteSpace(outputFile)) { var renderer = new ImageRenderTreeRenderer(); renderer.LoadTextures(options.TextureDir); var img = renderer.Render(RenderTree.Create(package)); using var fs = File.OpenWrite(outputFile); img.SaveAsPng(fs); if (!options.NoOpen) { Process.Start(new ProcessStartInfo(outputFile) { UseShellExecute = true }); } } //Console.WriteLine(JsonConvert.SerializeObject(package, Formatting.Indented, new JsonSerializerSettings() //{ // TypeNameHandling = TypeNameHandling.Auto, // PreserveReferencesHandling = PreserveReferencesHandling.Objects, // Converters = // { // new StringEnumConverter(new DefaultNamingStrategy()) // } //})); return(0); }
/// <summary> /// Renders nodes from a <see cref="RenderTree"/> to a surface. /// </summary> /// <param name="tree">The <see cref="RenderTree"/> to render.</param> public void Render(RenderTree tree) { _gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT); _gl.LoadIdentity(); // disable depth _gl.DepthMask(0); PrepareNodes(tree, Matrix4x4.Identity); RenderTree(tree); _stopwatch.Restart(); if (SelectedNode != null) { RenderNode(SelectedNode, true); } _gl.MatrixMode(MatrixMode.Projection); _gl.Ortho(0, 640, 480, 0, -1, 1); _gl.Flush(); }
public void BuildRender_InheritStyles_RenderLayout() { var _renderTree = new RenderTree(); var loader = new HtmlLoader(); var window = loader.LoadFromFile("Contents/test_html_layout_ingerit_styles.html"); _renderTree.Build(window); var root = _renderTree.LayoutRoot; var html = root.Layouts.FirstOrDefault(); var body = html.Layouts.LastOrDefault(); var baseDiv = body.Layouts.FirstOrDefault(); baseDiv.CssRule.Should().NotBeNull(); var childrenDiv = baseDiv.Layouts; foreach (var renderLayout in childrenDiv) { renderLayout.CssRule.Should().BeEquivalentTo(baseDiv.CssRule); } }
public void GetRectInsideGroup() { GUIStyle.Default.CellSpacing = (0, 0);//reset the cell-spacing of any group to 0 var renderTree = new RenderTree(0, Point.Zero, new Size(800, 600)); var size = new Size(200, 300); renderTree.BeginLayoutGroup(1, true); var node = new Node(2); node.AttachLayoutEntry(size); renderTree.CurrentContainer.AppendChild(node); renderTree.EndLayoutGroup(); renderTree.Root.Layout(); var rect = node.Rect; Assert.Equal(0, rect.X); Assert.Equal(0, rect.Y); Assert.Equal(200, rect.Width); Assert.Equal(300, rect.Height); }
public DummyRenderElement(RenderTree renderTree) : base(renderTree) { }
public CameraRenderElement(RenderTree renderTree) : base(renderTree) { }
public void BuildRenderTreeFromDocumentTest() { var _renderTree = new RenderTree(); var loader = new HtmlLoader(); var window = loader.LoadFromFile("Contents/test_html_layout.html"); _renderTree.Build(window); var root = _renderTree.LayoutRoot; root.Element.Should().BeNull(); root.CssRule.Should().BeNull(); root.Parent.Should().BeNull(); root.Layouts.Should().HaveCount(1); var html = root.Layouts.FirstOrDefault(); html.Should().NotBeNull(); html.Parent.Should().BeNull(); html.Element.TagName.Should().BeEquivalentTo("HTML"); html.Layouts.Should().HaveCount(2); #region Head var head = html.Layouts.FirstOrDefault(); head.Should().NotBeNull(); head.Parent.Should().BeEquivalentTo(html); head.Element.NodeName.Should().BeEquivalentTo("head"); head.Layouts.Should().HaveCount(2); var meta = head.Layouts.FirstOrDefault(); meta.Should().NotBeNull(); meta.Parent.Should().BeEquivalentTo(head); meta.Element.NodeName.Should().BeEquivalentTo("meta"); meta.Layouts.Should().HaveCount(0); var title = head.Layouts.LastOrDefault(); title.Should().NotBeNull(); title.Parent.Should().BeEquivalentTo(head); title.Element.NodeName.Should().BeEquivalentTo("title"); title.Layouts.Should().HaveCount(1); #endregion #region Body var body = html.Layouts.LastOrDefault(); body.Should().NotBeNull(); body.Parent.Should().BeEquivalentTo(html); body.Element.NodeName.Should().BeEquivalentTo("body"); body.Layouts.Should().HaveCount(3); // First div var firstDiv = body.Layouts[0]; firstDiv.Parent.Should().BeEquivalentTo(body); firstDiv.Element.NodeName.Should().BeEquivalentTo("div"); firstDiv.Layouts.Should().HaveCount(3); var firstDivButton = firstDiv.Layouts[0]; firstDivButton.Parent.Should().BeEquivalentTo(firstDiv); firstDivButton.Element.NodeName.Should().BeEquivalentTo("button"); firstDivButton.Layouts.Should().HaveCount(0); var firstDivAnchor = firstDiv.Layouts[1]; firstDivAnchor.Parent.Should().BeEquivalentTo(firstDiv); firstDivAnchor.Element.NodeName.Should().BeEquivalentTo("a"); firstDivAnchor.Layouts.Should().HaveCount(1); firstDivAnchor.Layouts.FirstOrDefault().Element.NodeName.Should().BeEquivalentTo("span"); // Second div var secondDiv = body.Layouts[1]; secondDiv.Parent.Should().BeEquivalentTo(body); secondDiv.Element.NodeName.Should().BeEquivalentTo("div"); secondDiv.Layouts.Should().HaveCount(0); // Three div var threeDiv = body.Layouts[2]; threeDiv.Parent.Should().BeEquivalentTo(body); threeDiv.Element.NodeName.Should().BeEquivalentTo("div"); threeDiv.Layouts.Should().HaveCount(0); #endregion }
public BoxRenderElement(RenderTree renderTree) : base(renderTree) { }
public Window(string name, Point position, Size size, WindowFlags Flags) { Form form = Form.current; GUIContext g = form.uiContext; WindowManager w = g.WindowManager; this.ID = name.GetHashCode(); this.Name = name; this.Active = this.WasActive = false; this.Position = position; this.FullSize = size; this.Flags = Flags; this.AbsoluteVisualList = new List <Visual>(); this.RenderTree = new RenderTree(this.ID, position, size); this.IDStack.Push(this.ID); this.MoveID = this.GetID("#MOVE"); #region Window nodes { var windowContainer = new Node(this.GetID("window"), "window"); this.WindowContainer = windowContainer; var style = windowContainer.RuleSet; style.BackgroundColor = Color.White; style.Border = (1, 1, 1, 1); style.BorderColor = (Color.Black, Color.Black, Color.Black, Color.Black); style.Set(GUIStyleName.BorderTopColor, Color.Blue, GUIState.Active); style.Set(GUIStyleName.BorderRightColor, Color.Blue, GUIState.Active); style.Set(GUIStyleName.BorderBottomColor, Color.Blue, GUIState.Active); style.Set(GUIStyleName.BorderLeftColor, Color.Blue, GUIState.Active); style.Set(GUIStyleName.BorderTopColor, Color.Gray, GUIState.Hover); style.Set(GUIStyleName.BorderRightColor, Color.Gray, GUIState.Hover); style.Set(GUIStyleName.BorderBottomColor, Color.Gray, GUIState.Hover); style.Set(GUIStyleName.BorderLeftColor, Color.Gray, GUIState.Hover); style.Set(GUIStyleName.BorderTop, 1.0); style.Set(GUIStyleName.BorderRight, 1.0); style.Set(GUIStyleName.BorderBottom, 1.0); style.Set(GUIStyleName.BorderLeft, 1.0); style.Set(GUIStyleName.PaddingTop, 5.0); style.Set(GUIStyleName.PaddingRight, 10.0); style.Set(GUIStyleName.PaddingBottom, 5.0); style.Set(GUIStyleName.PaddingLeft, 10.0); style.Set(GUIStyleName.WindowBorderColor, Color.Rgb(255, 0, 0), GUIState.Normal); style.Set(GUIStyleName.WindowBorderColor, Color.Rgb(0, 0, 255), GUIState.Active); style.Set(GUIStyleName.WindowShadowColor, Color.Argb(100, 227, 227, 227)); style.Set(GUIStyleName.WindowShadowWidth, 15.0); style.Set(GUIStyleName.BackgroundColor, Color.White); style.Set(GUIStyleName.ResizeGripColor, Color.Argb(75, 102, 102, 102)); style.Set(GUIStyleName.ResizeGripColor, Color.Argb(150, 102, 102, 102), GUIState.Hover); style.Set(GUIStyleName.ResizeGripColor, Color.Argb(225, 102, 102, 102), GUIState.Active); style.Set(GUIStyleName.WindowRounding, 20.0); style.Set(GUIStyleName.ScrollBarWidth, CurrentOS.IsDesktopPlatform ? 10.0 : 20.0); style.Set(GUIStyleName.ScrollBarBackgroundColor, Color.Rgb(240)); style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(205), GUIState.Normal); style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(166), GUIState.Hover); style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(96), GUIState.Active); windowContainer.AttachLayoutGroup(true); windowContainer.UseBoxModel = true; var windowStyleOptions = GUILayout.Width(this.FullSize.Width).Height( this.Collapsed ? this.CollapsedHeight : this.FullSize.Height ); windowContainer.RuleSet.ApplyOptions(windowStyleOptions); this.RenderTree.Root.AppendChild(windowContainer); } //title bar { var titleBarContainer = new Node(this.GetID("titleBar"), "title bar"); this.titleBarNode = titleBarContainer; titleBarContainer.AttachLayoutGroup(false); titleBarContainer.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(this.TitleBarHeight)); titleBarContainer.UseBoxModel = true; StyleRuleSetBuilder b = new StyleRuleSetBuilder(titleBarContainer); b.Padding((top: 8, right: 8, bottom: 8, left: 8)) .FontColor(Color.Black) .FontSize(12) .BackgroundColor(Color.White) .AlignmentVertical(Alignment.Center) .AlignmentHorizontal(Alignment.Start); var icon = new Node(this.GetID("icon"), "icon"); icon.AttachLayoutEntry(new Size(20, 20)); icon.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20)); icon.UseBoxModel = false; icon.Primitive = new ImagePrimitive(@"assets/images/logo.png"); var title = new Node(this.GetID("title"), "title"); var contentSize = title.RuleSet.CalcSize(this.Name, GUIState.Normal); title.AttachLayoutEntry(contentSize); title.RuleSet.ApplyOptions(GUILayout.Height(20)); title.UseBoxModel = false; title.Primitive = new TextPrimitive(this.Name); this.titleBarTitleNode = title; var closeButton = new Node(this.GetID("close button"), "close button"); closeButton.AttachLayoutEntry(new Size(20, 20)); closeButton.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20)); closeButton.UseBoxModel = false; PathPrimitive path = new PathPrimitive(); path.PathRect(new Rect(0, 0, 20, 20)); closeButton.Primitive = path; titleBarContainer.AppendChild(icon); titleBarContainer.AppendChild(title); //titleBarContainer.AppendChild(closeButton); this.WindowContainer.AppendChild(titleBarContainer); } //client area { var node = new Node(this.GetID("client area"), "client area"); node.AttachLayoutGroup(true); node.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).ExpandHeight(true)); node.UseBoxModel = true; node.RuleSet.OutlineWidth = 1; node.RuleSet.OutlineColor = Color.Red; node.RuleSet.refNode = node; this.ClientAreaNode = node; this.WindowContainer.AppendChild(node); } //resize grip (lasy-initialized) this.ShowWindowTitleBar(true); this.ShowWindowClientArea(!this.Collapsed); #endregion }
public IRenderElement(RenderTree renderTree) { Children = new List <IRenderElement>(); Box = new BoxModel(); RenderTree = renderTree; }
public ViewportRenderElement(RenderTree renderTree) : base(renderTree) { }
public Window(Form form, string name, Point position, Size size, WindowFlags flags) { this.ID = name.GetHashCode(); this.Name = name; this.Active = this.WasActive = false; this.Position = position; this.ViewportPosition = form.Pos; this.FullSize = size; this.Flags = flags; this.AbsoluteVisualList = new List <Visual>(); this.RenderTree = new RenderTree(this.ID, position, size); this.RenderContext = new RenderContext(this.geometryRenderer, this.MeshList); this.IDStack.Push(this.ID); this.MoveId = this.GetID("#MOVE"); this.MeshList.OwnerName = this.Name; //bool insideMainForm = w.MainForm.ClientRect.Contains(new Rect(position, size)); if (Flags.HaveFlag(WindowFlags.Popup))//TODO consider insideMainForm when multiple-form is ready { Viewport = new Form(position, size, name, WindowTypes.ClientAreaOnly); Viewport.Window = this; Application.AddFrom(Viewport); } else { Viewport = Application.ImGuiContext.WindowManager.MainForm; } #region Window nodes { var windowContainer = new Node(this.GetID("WindowContainer"), "Window Container"); this.WindowContainer = windowContainer; var style = windowContainer.RuleSet; style.BackgroundColor = Color.White; style.BorderRadius = (2, 2, 2, 2); style.BorderColor = (Color.Rgb(0x707070), Color.Rgb(0x707070), Color.Rgb(0x707070), Color.Rgb(0x707070)); style.Set(StylePropertyName.BorderTopColor, Color.Blue, GUIState.Active); style.Set(StylePropertyName.BorderRightColor, Color.Blue, GUIState.Active); style.Set(StylePropertyName.BorderBottomColor, Color.Blue, GUIState.Active); style.Set(StylePropertyName.BorderLeftColor, Color.Blue, GUIState.Active); style.Set(StylePropertyName.BorderTopColor, Color.Gray, GUIState.Hover); style.Set(StylePropertyName.BorderRightColor, Color.Gray, GUIState.Hover); style.Set(StylePropertyName.BorderBottomColor, Color.Gray, GUIState.Hover); style.Set(StylePropertyName.BorderLeftColor, Color.Gray, GUIState.Hover); style.Set(StylePropertyName.BorderTop, 1.0); style.Set(StylePropertyName.BorderRight, 1.0); style.Set(StylePropertyName.BorderBottom, 1.0); style.Set(StylePropertyName.BorderLeft, 1.0); style.Set(StylePropertyName.PaddingTop, 5.0); style.Set(StylePropertyName.PaddingRight, 10.0); style.Set(StylePropertyName.PaddingBottom, 5.0); style.Set(StylePropertyName.PaddingLeft, 10.0); style.Set(StylePropertyName.WindowBorderColor, Color.Rgb(255, 0, 0), GUIState.Normal); style.Set(StylePropertyName.WindowBorderColor, Color.Rgb(0, 0, 255), GUIState.Active); style.Set(StylePropertyName.WindowShadowColor, Color.Argb(100, 227, 227, 227)); style.Set(StylePropertyName.WindowShadowWidth, 15.0); style.Set(StylePropertyName.ResizeGripColor, Color.Argb(0x77303030)); style.Set(StylePropertyName.ResizeGripColor, Color.Argb(0xAA303030), GUIState.Hover); style.Set(StylePropertyName.ResizeGripColor, Color.Argb(0xFF303030), GUIState.Active); style.Set(StylePropertyName.WindowRounding, 20.0); windowContainer.AttachLayoutGroup(true); windowContainer.UseBoxModel = true; var windowStyleOptions = GUILayout.Width(this.FullSize.Width).Height( this.Collapsed ? this.CollapsedHeight : this.FullSize.Height ); windowContainer.RuleSet.ApplyOptions(windowStyleOptions); this.RenderTree.Root.AppendChild(windowContainer); } //title bar if (!flags.HaveFlag(WindowFlags.NoTitleBar)) { this.titleBar = new Node(this.GetID("titleBar"), "title bar"); titleBar.AttachLayoutGroup(false); titleBar.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(this.TitleBarHeight)); titleBar.UseBoxModel = true; StyleRuleSetBuilder b = new StyleRuleSetBuilder(titleBar); b.Padding((top: 8, right: 8, bottom: 8, left: 8)) .FontColor(Color.Black) .FontSize(12) .BackgroundColor(Color.White) .AlignmentVertical(Alignment.Center) .AlignmentHorizontal(Alignment.Start); this.titleIcon = new Node(this.GetID("icon"), "icon"); titleIcon.AttachLayoutEntry(new Size(20, 20)); titleIcon.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20)); titleIcon.UseBoxModel = false; this.titleText = new Node(this.GetID("title"), "title"); var contentSize = titleText.RuleSet.CalcContentBoxSize(this.Name, GUIState.Normal); titleText.AttachLayoutEntry(contentSize); titleText.RuleSet.ApplyOptions(GUILayout.Height(20)); titleText.UseBoxModel = false; var closeButton = new Node(this.GetID("close button"), "close button"); closeButton.AttachLayoutEntry(new Size(20, 20)); closeButton.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20)); closeButton.UseBoxModel = false; titleBar.AppendChild(titleIcon); titleBar.AppendChild(titleText); this.WindowContainer.AppendChild(titleBar); } //client area { this.clientArea = new Node(this.GetID("Client Area"), "Client Area"); clientArea.AttachLayoutGroup(true); clientArea.RuleSet.BackgroundColor = Color.White; clientArea.RuleSet.Set(StylePropertyName.OverflowY, (int)OverflowPolicy.Scroll); clientArea.RuleSet.Set(StylePropertyName.ScrollBarWidth, CurrentOS.IsDesktopPlatform ? 10.0 : 20.0); clientArea.RuleSet.Set(StylePropertyName.ScrollBarBackgroundColor, Color.Rgb(240)); clientArea.RuleSet.Set(StylePropertyName.ScrollBarButtonColor, Color.Rgb(205), GUIState.Normal); clientArea.RuleSet.Set(StylePropertyName.ScrollBarButtonColor, Color.Rgb(166), GUIState.Hover); clientArea.RuleSet.Set(StylePropertyName.ScrollBarButtonColor, Color.Rgb(96), GUIState.Active); clientArea.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).ExpandHeight(true)); clientArea.UseBoxModel = true; clientArea.RuleSet.refNode = clientArea; #if ShowClientAreaOutline clientArea.RuleSet.OutlineWidth = 1; clientArea.RuleSet.OutlineColor = Color.DarkRed; #endif this.ClientAreaNode = clientArea; this.WindowContainer.AppendChild(clientArea); } //resize grip (lasy-initialized) if (!flags.HaveFlag(WindowFlags.NoTitleBar)) { this.ShowWindowTitleBar(true); } this.ShowWindowClientArea(!this.Collapsed); #endregion }