/// <summary> /// Opaq query on element instances /// </summary> /// <param name="element">Root element</param> /// <param name="path"></param> /// <param name="separator"></param> /// <param name="useName">Use children name instead of ID</param> /// <returns>List of elements fitting the Opaq conditions</returns> public static List <NotuiElement> Opaq(this NotuiElement element, string path, string separator = "/", bool useName = true) { IEnumerable <NotuiElement> GetChildren(NotuiElement el, string k) { if (el.Children.Count == 0) { return(Enumerable.Empty <NotuiElement>()); } if (useName) { return(el.Children.Values.Where(c => c.Name == k)); } if (el.Children.ContainsKey(k)) { return new[] { el.Children[k] } } ; return(Enumerable.Empty <NotuiElement>()); } return(element.Opaq(path, separator, el => useName ? el.Children.Values.Select(c => c.Name) : el.Children.Keys, el => useName ? el.Children.Values.Select(c => c.Name) : el.Children.Keys, GetChildren, GetChildren )); }
/// <summary> /// Determine if a state of this behavior is attached to an element /// </summary> /// <param name="element"></param> /// <returns>True if there's a state for this behavior</returns> public bool IsStateAvailable(NotuiElement element) { if (element.Value == null) { element.Value = new AttachedValues(); } return(element.Value.Auxiliary.ContainsKey(BehaviorStatePrefix + Id)); }
private void ProcessElements(NotuiElement el) { foreach (var touch in Context.Touches.Values) { el.ProcessTouch(touch); } el.Mainloop(Context.DeltaTime); }
/// <summary></summary> /// <param name="wpos">Intersection point in absolute world space</param> /// <param name="epos">Intersection point in element/object space</param> /// <param name="spos">Intersection point in the element's surface or UV space</param> /// <param name="str">Absolute world space transformation representing the element's surface tangents</param> /// <param name="element">The element in question</param> /// <param name="touch">The touch in question</param> public IntersectionPoint(Vector3 wpos, Vector3 epos, Vector3 spos, Matrix4x4 str, NotuiElement element, Touch touch) { WorldSpace = wpos; ElementSpace = epos; SurfaceSpace = spos; WorldSurfaceTangentTransform = str; Element = element; Touch = touch; }
/// <summary></summary> /// <param name="element">The hosting element</param> /// <param name="options">The creation option</param> public SubContext(NotuiElement element, SubContextOptions options) { AttachedElement = element; Options = options.Copy(); element.OnMainLoopEnd += AttachedElementMainloopListener; Context = new NotuiContext { UpdateOnlyChangeFlagged = Options.UpdateOnlyChangeFlagged }; }
/// <summary> /// Convinience function to set a state for an element corresponding to this behavior /// </summary> /// <param name="element"></param> /// <param name="value">The state to be assigned</param> /// <returns></returns> public void SetState(NotuiElement element, IAuxiliaryObject value) { if (element.Value == null) { element.Value = new AttachedValues(); } if (IsStateAvailable(element)) { element.Value.Auxiliary[BehaviorStatePrefix + Id] = value; } else { element.Value.Auxiliary.Add(BehaviorStatePrefix + Id, value); } }
/// <summary> /// Convinience function to get a state from an element's attached aux objects corresponding to this behavior /// </summary> /// <typeparam name="T">The type of the behavior state</typeparam> /// <param name="element"></param> /// <returns></returns> public T GetState <T>(NotuiElement element) where T : IAuxiliaryObject { if (element.Value == null) { element.Value = new AttachedValues(); } try { return((T)element.Value.Auxiliary[BehaviorStatePrefix + Id]); } catch (Exception e) { var we = new Exception("Getting behavior state object failed.", e); throw we; } }
/// <summary> /// Create a new prototype from an existing element instance /// </summary> /// <param name="fromInstance">The instance which should be copied</param> /// <param name="newId">If the new prototype should have a new Id generated</param> /// <remarks> /// It is strongly recommended to generate a new Id instead of copying it over from the other instance. This constructor should be only used if you are desperate. /// </remarks> protected ElementPrototype(NotuiElement fromInstance, bool newId = true) { InstanceType = fromInstance.GetType(); this.UpdateCommon(fromInstance, ApplyTransformMode.All); //Value = fromInstance.Value?.Copy(); EnvironmentObject = fromInstance.EnvironmentObject.Copy(); Parent = fromInstance.Parent.Prototype; if (newId) { Id = Guid.NewGuid().ToString(); } foreach (var child in fromInstance.Children.Values) { Children.Add(child.Id, child.Prototype.Copy()); } }
/// <summary> /// Create a new prototype from an instance /// </summary> /// <param name="element">The element instance</param> /// <param name="newId">Generate a new ID?</param> /// <returns></returns> public static ElementPrototype CreateFromInstance(NotuiElement element, bool newId = true) { var prottype = element.Prototype.GetType(); var res = (ElementPrototype)prottype.GetConstructor( new[] { typeof(NotuiElement), typeof(bool) })? .Invoke(new object[] { element, newId }); if (res == null) { throw new NoSuchPrototypeConstructorFoundException(prottype); } else { res.UpdateFrom(element); res.SubContextOptions = element.SubContext?.Options; return(res); } }
/// <inheritdoc /> /// <summary></summary> /// <param name="wpos">Intersection point in absolute world space</param> /// <param name="epos">Intersection point in element/object space</param> /// <param name="element">The element in question</param> /// <param name="touch">The touch in question</param> public IntersectionPoint(Vector3 wpos, Vector3 epos, NotuiElement element, Touch touch) : this(wpos, epos, epos, Matrix4x4.CreateTranslation(epos) * element.DisplayMatrix, element, touch) { }
/// <summary> /// The method which will be executed for the given element every frame. /// </summary> public abstract void Behave(NotuiElement element);
/// <summary> /// Copy this subcontext to another element /// </summary> /// <param name="destination"></param> /// <returns>The new SubContext</returns> public SubContext Copy(NotuiElement destination) { return(new SubContext(destination, Options.Copy())); }
/// <summary> /// Transfer this Subcontext to another element /// </summary> /// <param name="newelement"></param> public void SwitchElement(NotuiElement newelement) { AttachedElement.OnMainLoopEnd -= AttachedElementMainloopListener; AttachedElement = newelement; AttachedElement.OnMainLoopEnd += AttachedElementMainloopListener; }
/// <inheritdoc cref="IUpdateable{T}"/> public virtual void UpdateFrom(NotuiElement other) { this.UpdateCommon(other, ApplyTransformMode.All); }
/// <summary> /// Create a NotuiElement instance out of this prototype /// </summary> /// <param name="context">The context to instantiate into</param> /// <param name="parent">An optional parent</param> /// <returns></returns> public NotuiElement Instantiate(NotuiContext context, NotuiElement parent = null) { var res = (NotuiElement)GetElementConstructor().Invoke(new object[] { this, context, parent }); return(res); }