/// <summary> /// Checks if the provided render node is visible. /// </summary> /// <param name="node">The node to check for visibility.</param> /// <returns>True if its visible, otherwise false.</returns> public static Boolean IsVisible(this IRenderNode node) { var hasOwner = node.Ref.Owner != null; if (hasOwner) { if (node is ElementRenderNode element) { var style = element.ComputedStyle; if (element.Ref is IHtmlElement htmlElement && htmlElement.IsHidden) { return(false); } else if (style.GetDisplay() == CssKeywords.None) { return(false); } else if (style.GetVisibility() == CssKeywords.Hidden) { return(false); } } return(true); }
public static HorizontalStraightLayoutNode AttachTo(NodeBase node, IRenderNode renderNode, HorizontalStraightLayoutNode parent) { var layoutNode = new HorizontalStraightLayoutNode(renderNode, parent); node.LayoutData = layoutNode; return(layoutNode); }
private HorizontalStraightLayoutNode(IRenderNode renderNode, HorizontalStraightLayoutNode parent) { this.parent = parent; this.renderSize = renderNode.RenderSize; this.renderNode = renderNode; TreeSize = renderNode.RenderSize; }
public void AddControl(IRenderNode control) { if (control == null) { throw new ArgumentNullException(nameof(control)); } _controlList.Add(control); }
private void CalculatePreviewPosition() { parentRenderNode = Scene.FindRenderNode(parent); var factor = parent is RootNode ? 0.5f : 1.0f; var x = CalculateX(factor); var y = CalculateY(); position = new Vector2(x, y); }
public OptionsMenu() { _crosshair = new MenuCursor(); _background = new Background(); _titles = new FontRender("Titles"); _titles.LoadContent("titlescreen"); _titles.Location = new Vector2(150, _fontY); _titles.Shadow = true; _container = new UIContainer("OptionsMenu"); int startYPosition = 600; _soundEffectsOnOff = new CheckBox("SoundEffectsOnOff", new SoundEffectsOnOffHandler()) { Width = 500, Height = 70, Location = new Vector2(700, startYPosition), Text = "Sound Effects On/Off", DrawWindowChrome = true, ControlTexture = "ButtonBackground" }; ((CheckBox)_soundEffectsOnOff).Checked = SoundEffectPlayer.PlaySoundEffects; startYPosition += 80; _backToMainMenu = new Button("ExitToMainMenu", new ExitToMainMenuButtonHandler()) { Width = 500, Height = 70, Location = new Vector2(700, startYPosition), Text = "<-- Exit to Main Menu", DrawWindowChrome = true, ControlTexture = "ButtonBackground" }; _container.AddControl(_soundEffectsOnOff); _container.AddControl(_backToMainMenu); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER1, _background); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _titles); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER5, _crosshair); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER4, _container); }
public void TestNode(IRenderNode node) { if (!(node is Node)) { throw new ExceptionFreeserf(ErrorSystemType.Render, "The given render node is not valid for this renderer."); } if ((node as Node).Shape != renderBuffer.Shape) { throw new ExceptionFreeserf(ErrorSystemType.Render, $"Only nodes with shape {Enum.GetName(typeof(Shape), renderBuffer.Shape)} are allowed for this layer."); } if (node is ColoredRect && renderBufferColorRects == null) { throw new ExceptionFreeserf(ErrorSystemType.Render, "This layer does not support colored rects."); } }
public void AddSpriteToLayer(RenderLayerEnum layer, IRenderNode node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } if (string.IsNullOrEmpty(node.Name)) { throw new InvalidOperationException("Render node can not have an empty name."); } if (node.IsAssetOfType(typeof(Sprite)) || node.IsAssetOfType(typeof(AnimatedSprite))) { CollisionManager.AddSpriteToCollisionManager(node.GetSprite(), node.Name); } switch (layer) { case RenderLayerEnum.LAYER1: Layer1.Add(node); break; case RenderLayerEnum.LAYER2: Layer2.Add(node); break; case RenderLayerEnum.LAYER3: Layer3.Add(node); break; case RenderLayerEnum.LAYER4: Layer4.Add(node); break; case RenderLayerEnum.LAYER5: Layer5.Add(node); break; default: break; } }
/// <summary> /// Downloads the referenced resources from the node if visible. /// /// Included resources: /// /// - Background images /// </summary> /// <param name="node">The node to use as a starting base.</param> /// <param name="cancellationToken">The cancellation token to use, if any.</param> public static Task DownloadResources(this IRenderNode node, CancellationToken cancellationToken = default) { var context = node.Ref.Owner?.Context ?? throw new InvalidOperationException("The node needs to be inside a browsing context."); var loader = context.GetService <IResourceLoader>() ?? throw new InvalidOperationException("A resource loader is required. Check your configuration."); var tasks = new List <Task>(); if (node.IsVisible() && node is ElementRenderNode element) { var elementRef = element.Ref as IElement; var style = element.ComputedStyle; var value = style.GetProperty(PropertyNames.BackgroundImage).RawValue; if (value is CssListValue list) { var url = new Url(list.AsUrl()); var request = new ResourceRequest(elementRef, url); var download = loader.FetchAsync(request); cancellationToken.Register(download.Cancel); tasks.Add(download.Task); } } return(Task.WhenAll(tasks)); }
public IAdornerRenderNode CreateAdorner(IRenderNode renderNode) { return(scene.CreateAdorner(renderNode)); }
public MainMenu() { _crosshair = new MenuCursor(); _background = new Background(); MusicPlayer.LoadMusic("banjo"); _fontY = -200; _titles = new FontRender("Titles"); _titles.LoadContent("titlescreen"); _titles.Location = new Vector2(150, _fontY); _titles.Shadow = true; _container = new UIContainer("MainMenu"); int startYPosition = 450; _playGameButton = new Button("PlayGameButton", new NewGameButtonHandler()) { Width = 500, Height = 70, Location = new Vector2(700, startYPosition), Text = "Play Duck Attack", DrawWindowChrome = true, ControlTexture = "ButtonBackground" }; startYPosition += 80; _optionsButton = new Button("OptionsGameButton", new OptionsButtonHandler()) { Width = 500, Height = 70, Location = new Vector2(700, startYPosition), Text = "Options", DrawWindowChrome = true, ControlTexture = "ButtonBackground" }; startYPosition += 80; _exitButton = new Button("ExitGameButton", new ExitButtonHandler()) { Width = 500, Height = 70, Location = new Vector2(700, startYPosition), Text = "Exit Game", DrawWindowChrome = true, ControlTexture = "ButtonBackground" }; _container.AddControl(_playGameButton); _container.AddControl(_optionsButton); _container.AddControl(_exitButton); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER1, _background); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER2, _titles); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER5, _crosshair); _scene.AddSpriteToLayer(RenderLayerEnum.LAYER4, _container); MusicPlayer.Play("banjo"); MusicPlayer.Looped = true; }
/// <summary> /// Adds an output node to this node /// </summary> /// <param name="node">Output node to add</param> /// <exception cref="ArgumentNullException">Thrown if node is null</exception> /// <remarks> /// If the output node does not contain this node as an iput, then this node is added to the /// output node (<see cref="AddInputNode"/>) /// </remarks> public void AddOutputNode( IRenderNode node ) { if ( node == null ) { throw new ArgumentNullException( "node" ); } if ( !m_OutputNodes.Contains( node ) ) { m_OutputNodes.Add( node ); if ( OutputNodeAdded != null ) { OutputNodeAdded( node ); } } bool outputContainsThis = false; foreach ( IRenderNode inputNode in node.InputNodes ) { if ( inputNode == this ) { outputContainsThis = true; break; } } if ( !outputContainsThis ) { node.AddInputNode( this ); } }
/// <summary> /// Visits all the nodes in a render node graph. /// </summary> /// <param name="startNodes">Initial nodes</param> /// <param name="visitor">Visitor object</param> /// <remarks> /// A node is only visited once all its input nodes have been visited first. /// </remarks> public static void Walk( IRenderNode[] startNodes, IRenderNodeVisitor visitor ) { Walk( startNodes, visitor, 32 ); }
/// <summary> /// Sets a node status value /// </summary> private static void SetNodeStatus( IRenderNode node, NodeStatus status, ref NodeStatus[] nodeStatuses ) { GrowNodeStatusArrayToIncludeNode( node, ref nodeStatuses ); nodeStatuses[ node.Id ] = status; }
/// <summary> /// Grows a array of node status values to ensure that it includes an entry for the specified node /// </summary> private static void GrowNodeStatusArrayToIncludeNode( IRenderNode node, ref NodeStatus[] nodeStatuses ) { if ( node.Id >= nodeStatuses.Length ) { Array.Resize( ref nodeStatuses, ( node.Id + 1 ) * 2 ); } }
/// <summary> /// Enqueues a single node onto the render queue. Updates the node's status to NodeStatus.Pending /// </summary> private static void Enqueue( Queue< IRenderNode > nodeQueue, IRenderNode node, ref NodeStatus[] nodeStatuses ) { nodeQueue.Enqueue( node ); SetNodeStatus( node, NodeStatus.Pending, ref nodeStatuses ); }
public IAdornerRenderNode CreateAdorner(IRenderNode renderNode) { Guard.NotNull(renderNode, nameof(renderNode)); return(adorners.AddAndReturn(((Win2DRenderNode)renderNode).CreateAdorner())); }
public bool RemoveSpriteFromLayer(RenderLayerEnum layer, IRenderNode node) { if (node == null) { throw new ArgumentNullException(nameof(node)); } switch (layer) { case RenderLayerEnum.LAYER1: foreach (IRenderNode n in Layer1.ToArray()) { if (n == node) { _ = Layer1.Remove(node); return(true); } } break; case RenderLayerEnum.LAYER2: foreach (IRenderNode n in Layer2.ToArray()) { if (n == node) { _ = Layer2.Remove(node); return(true); } } break; case RenderLayerEnum.LAYER3: foreach (IRenderNode n in Layer3.ToArray()) { if (n == node) { _ = Layer3.Remove(node); return(true); } } break; case RenderLayerEnum.LAYER4: foreach (IRenderNode n in Layer4.ToArray()) { if (n == node) { _ = Layer4.Remove(node); return(true); } } break; case RenderLayerEnum.LAYER5: foreach (IRenderNode n in Layer5.ToArray()) { if (n == node) { _ = Layer5.Remove(node); return(true); } } break; default: break; } return(false); }
/// <summary> /// Checks that a node can be visited. Ensures all inputs to the node are in the node queue /// </summary> private static bool CheckNodeStatus( Queue<IRenderNode> nodeQueue, IRenderNode node, ref NodeStatus[] nodeStatuses ) { bool canVisit = true; foreach ( IRenderNode inputNode in node.InputNodes ) { GrowNodeStatusArrayToIncludeNode( inputNode, ref nodeStatuses ); if ( nodeStatuses[ inputNode.Id ] == NodeStatus.NotInQueue ) { // Input node is not in the queue - add it Enqueue( nodeQueue, inputNode, ref nodeStatuses ); canVisit = false; } else if ( nodeStatuses[ inputNode.Id ] == NodeStatus.Pending ) { canVisit = false; } } return canVisit; }