/// <summary> /// Initializes a new instance of the <see cref="VisjectContextNavigationButton"/> class. /// </summary> /// <param name="surface">The parent surface.</param> /// <param name="context">The target context.</param> /// <param name="x">The x position.</param> /// <param name="y">The y position.</param> /// <param name="height">The height.</param> public VisjectContextNavigationButton(VisjectSurface surface, ISurfaceContext context, float x, float y, float height) : base(x, y, height) { Surface = surface; Context = context; Text = context.SurfaceName + "/"; }
/// <summary> /// Changes the current opened context to the given one. Used as a navigation method. /// </summary> /// <param name="context">The target context.</param> public void ChangeContext(ISurfaceContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (_context == null) { OpenContext(context); return; } if (_context.Context == context) { return; } // Check if already in a path if (_contextCache.TryGetValue(context, out VisjectSurfaceContext surfaceContext) && ContextStack.Contains(surfaceContext)) { // Change stack do { ContextStack.Pop(); } while (ContextStack.Peek() != surfaceContext); } else { // TODO: implement this case (need to find first parent of the context that is in path) throw new NotSupportedException("TODO: support changing context to one not in the active path"); } // Update OnContextChanged(); }
/// <summary> /// Initializes a new instance of the <see cref="VisjectSurfaceContext"/> class. /// </summary> /// <param name="surface">The Visject surface using this context.</param> /// <param name="parent">The parent context. Defines the higher key surface graph context. May be null for the top-level context.</param> /// <param name="context">The context.</param> /// <param name="rootControl">The surface root control.</param> public VisjectSurfaceContext(VisjectSurface surface, VisjectSurfaceContext parent, ISurfaceContext context, SurfaceRootControl rootControl) { _surface = surface; Parent = parent; Context = context ?? throw new ArgumentNullException(nameof(context)); RootControl = rootControl ?? throw new ArgumentNullException(nameof(rootControl)); // Set initial scale to provide nice zoom in effect on startup RootControl.Scale = new Vector2(0.5f); }
/// <summary> /// Opens the child context of the current context. /// </summary> /// <param name="context">The context.</param> public void OpenContext(ISurfaceContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (_context != null && _context.Context == context) { return; } // Get or create context VisjectSurfaceContext surfaceContext; if (!_contextCache.TryGetValue(context, out surfaceContext)) { surfaceContext = CreateContext(_context, context); _context?.Children.Add(surfaceContext); _contextCache.Add(context, surfaceContext); context.OnContextCreated(surfaceContext); // Load context if (_root != null) { if (surfaceContext.Load()) { throw new Exception("Failed to load graph."); } } } if (_root == null) { _root = surfaceContext; } else if (ContextStack.Contains(surfaceContext)) { throw new ArgumentException("Context has been already added to the stack."); } // Change stack ContextStack.Push(surfaceContext); // Update OnContextChanged(); }
/// <summary> /// Removes the context from the surface and any related cached data. /// </summary> /// <param name="context">The context.</param> public void RemoveContext(ISurfaceContext context) { // Skip if surface is already disposing if (IsDisposing || _isReleasing) { return; } // Validate input if (context == null) { throw new ArgumentNullException(nameof(context)); } // Removing root requires to close every context if (RootContext != null && context == RootContext.Context) { while (ContextStack.Count > 0) { CloseContext(); } } // Check if has context in cache VisjectSurfaceContext surfaceContext; if (_contextCache.TryGetValue(context, out surfaceContext)) { // Remove from navigation path while (ContextStack.Contains(surfaceContext)) { CloseContext(); } // Dispose surfaceContext.Clear(); _contextCache.Remove(context); } }
/// <summary> /// Creates the Visject surface context for the given surface data source context. /// </summary> /// <param name="parent">The parent context.</param> /// <param name="context">The context.</param> /// <returns></returns> protected virtual VisjectSurfaceContext CreateContext(VisjectSurfaceContext parent, ISurfaceContext context) { return(new VisjectSurfaceContext(this, parent, context)); }
/// <summary> /// Initializes a new instance of the <see cref="VisjectSurfaceContext"/> class. /// </summary> /// <param name="surface">The Visject surface using this context.</param> /// <param name="parent">The parent context. Defines the higher key surface graph context. May be null for the top-level context.</param> /// <param name="context">The context.</param> public VisjectSurfaceContext(VisjectSurface surface, VisjectSurfaceContext parent, ISurfaceContext context) : this(surface, parent, context, new SurfaceRootControl()) { }