コード例 #1
0
ファイル: Container.cs プロジェクト: qutin/github-kgui-qutin
        public DisplayObject AddChildAt(DisplayObject child, int index)
        {
            int numChildren = _children.Count;

            if (index >= 0 && index <= numChildren)
            {
                if (child.parent == this)
                {
                    SetChildIndex(child, index);
                }
                else
                {
                    child.RemoveFromParent();
                    if (index == numChildren)
                    {
                        if (_isRendering)
                        {
                            CacheAddList(_children.Count, child);
                        }
                        else
                        {
                            _children.Add(child);
                        }
                    }
                    else
                    {
                        if (_isRendering)
                        {
                            CacheAddList(index, child);
                        }
                        else
                        {
                            _children.Insert(index, child);
                        }
                    }
                    child.SetParent(this);

                    if (stage != null)
                    {
                        Container container = child as Container;
                        if (container != null)
                        {
                            container.BroadcastEvent(sHelperEvent1);
                            container.onAddedToStage.BroadcastCall();
                        }
                        else
                        {
                            child.DispatchEventObsolete(sHelperEvent1);
                            child.onAddedToStage.Call();
                        }
                    }
                }
                return(child);
            }
            else
            {
                throw new Exception("Invalid child index");
            }
        }
コード例 #2
0
ファイル: Container.cs プロジェクト: qutin/github-kgui-qutin
        public DisplayObject RemoveChildAt(int index)
        {
            if (index >= 0 && index < _children.Count)
            {
                DisplayObject child = _children[index];

                if (stage != null)
                {
                    Container container = child as Container;
                    if (container != null)
                    {
                        container.BroadcastEvent(sHelperEvent2);
                        container.onRemovedFromStage.BroadcastCall();
                    }
                    else
                    {
                        child.DispatchEventObsolete(sHelperEvent2);
                        child.onRemovedFromStage.Call();
                    }
                }


                if (_isRendering)
                {
                    _cahcheRemoveList.Add(child);
                }
                else
                {
                    _children.Remove(child);
                }

                child.SetParent(null);

                return(child);
            }
            else
            {
                throw new Exception("Invalid child index");
            }
        }