/// <summary> /// Adds a component to the screen /// </summary> /// <param name="newComponent">The component to add</param> public void AddComponent(AComponent newComponent) { newComponent.ParentScreen = this; if (newComponent.Initialized == false) { newComponent.Initialize(); newComponent.Initialized = true; } if (Components.Count == 0) Components.Add(newComponent); else { /* for (int i = 0; i < Components.Count; ++i) { if (i == Components.Count - 1) { Components.Add(newComponent); break; } else if (Components[i].ZIndex < newComponent.ZIndex) continue; else { Components.Insert(i, newComponent); break; } }*/ this.Components.Add(newComponent); this.Components = Components.OrderBy(x => x.ZIndex).ToList(); } }
/// <summary> /// Called when the zindex of a child component is modified /// </summary> public void OnZIndexChange(AComponent child) { //@TODO optimize this.Components = Components.OrderBy(x => x.ZIndex).ToList(); /*if (this.Components.Remove(child)) for (int i = 0; i < this.Components.Count; ++i) { if (this.Components[i].ZIndex >= child.ZIndex) this.Components.Insert(i, child); }*/ //this.Components = Components.OrderBy(x => x.ZIndex).ToList(); }