Example #1
0
        public void AddComponent(Component Component)
        {
            if (!components.Contains(Component))
            {
                components.Add(Component);
                Component.Parent = this;
                Component.LoadComponent();
                PutComponentInOrder(Component);

                // Store timers so we can delete them when needed
                if (Component.GetType() == typeof(Timer) && !timers.Contains((Timer)Component))
                {
                    timers.Add((Timer)Component);
                }
            }
        }
Example #2
0
 public void RemoveComponent(Component Component)
 {
     if (Component != null && components.Contains(Component))
     {
         components.Remove(Component);
         Component.Parent = null;
     }
 }
Example #3
0
        // The components are stored in their draw order, so it is easy to loop
        // through them and draw them in the correct order without having to sort
        // them every time they are drawn
        public void PutComponentInOrder(Component component)
        {
            if (components.Contains(component))
            {
                components.Remove(component);

                int i = 0;

                // Iterate through the components in order until we find one with
                // a higher or equal draw order, and insert the component at that
                // position.
                for (i = 0; i < components.Count; i++)
                    if (components[i].DrawOrder >= component.DrawOrder)
                        break;

                components.Insert(i, component);
            }
        }