public GComponent()
        {
            _children = new List<GObject>();
            _controllers = new List<Controller>();
            _transitions = new List<Transition>();
            _margin = new Margin();
            _buildDelegate = BuildNativeDisplayList;

            onDrop = new EventListener(this, "onDrop");
        }
Пример #2
0
        public GComponent()
        {
            _children = new List<GObject>();
            _controllers = new List<Controller>();
            _transitions = new List<Transition>();
            _margin = new Margin();
            this.opaque = true;

            onScroll = new EventListener(this, "onScroll");
        }
Пример #3
0
        public ScrollPane(GComponent owner,
                                    ScrollType scrollType,
                                    Margin margin,
                                    Margin scrollBarMargin,
                                    ScrollBarDisplayType scrollBarDisplay,
                                    int flags)
        {
            _throwTween = new ThrowTween();

            _owner = owner;
            _container = _owner.rootContainer;

            _maskHolder = new Container();
            _container.AddChild(_maskHolder);

            _maskContentHolder = _owner.container;
            _maskContentHolder.x = 0;
            _maskContentHolder.y = 0;
            _maskHolder.AddChild(_maskContentHolder);

            if (Stage.touchScreen)
                _holdArea = 20;
            else
                _holdArea = 5;
            _holdAreaPoint = new Vector2();
            _margin = margin;
            _scrollBarMargin = scrollBarMargin;
            _bouncebackEffect = UIConfig.defaultScrollBounceEffect;
            _touchEffect = UIConfig.defaultScrollTouchEffect;
            _xPerc = 0;
            _yPerc = 0;
            _aniFlag = true;
            _scrollBarVisible = true;
            _scrollSpeed = UIConfig.defaultScrollSpeed;
            _mouseWheelSpeed = _scrollSpeed * 2;
            _displayOnLeft = (flags & 1) != 0;
            _snapToItem = (flags & 2) != 0;
            _displayInDemand = (flags & 4) != 0;
            _scrollType = scrollType;
            _mouseWheelEnabled = true;

            if (scrollBarDisplay == ScrollBarDisplayType.Default)
                scrollBarDisplay = UIConfig.defaultScrollBarDisplay;

            if (scrollBarDisplay != ScrollBarDisplayType.Hidden)
            {
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
                {
                    if (UIConfig.verticalScrollBar != null)
                    {
                        _vtScrollBar = UIPackage.CreateObjectFromURL(UIConfig.verticalScrollBar) as GScrollBar;
                        if (_vtScrollBar == null)
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.verticalScrollBar);
                        else
                        {
                            _vtScrollBar.SetScrollPane(this, true);
                            _container.AddChild(_vtScrollBar.displayObject);
                        }
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    if (UIConfig.horizontalScrollBar != null)
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(UIConfig.horizontalScrollBar) as GScrollBar;
                        if (_hzScrollBar == null)
                            Debug.LogError("FairyGUI: cannot create scrollbar from " + UIConfig.horizontalScrollBar);
                        else
                        {
                            _hzScrollBar.SetScrollPane(this, false);
                            _container.AddChild(_hzScrollBar.displayObject);
                        }
                    }
                }

                _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto;
                if (_scrollBarDisplayAuto)
                {
                    if (_vtScrollBar != null)
                        _vtScrollBar.displayObject.visible = false;
                    if (_hzScrollBar != null)
                        _hzScrollBar.displayObject.visible = false;
                    _scrollBarVisible = false;

                    _container.onRollOver.Add(__rollOver);
                    _container.onRollOut.Add(__rollOut);
                }
            }
            else
                _mouseWheelEnabled = false;

            if (_displayOnLeft && _vtScrollBar != null)
                _maskHolder.x = Mathf.FloorToInt((_margin.left + _vtScrollBar.width) * GRoot.contentScaleFactor);
            else
                _maskHolder.x = Mathf.FloorToInt(_margin.left * GRoot.contentScaleFactor);
            _maskHolder.y = Mathf.FloorToInt(_margin.top * GRoot.contentScaleFactor);

            SetSize(owner.width, owner.height);
            SetContentSize(owner.Bounds.width, owner.Bounds.height);

            _container.onMouseWheel.Add(__mouseWheel);
            _container.onMouseDown.Add(__mouseDown);
        }
Пример #4
0
        protected void SetupOverflowAndScroll(OverflowType overflow, Margin scrollBarMargin,
			ScrollType scroll, ScrollBarDisplayType scrollBarDisplay, int flags)
        {
            if (overflow == OverflowType.Hidden)
            {
                container = new Container();
                rootContainer.AddChild(container);
                UpdateMask();
                container.SetXY(_margin.left * GRoot.contentScaleFactor, _margin.top * GRoot.contentScaleFactor);
            }
            else if (overflow == OverflowType.Scroll)
            {
                container = new Container();
                rootContainer.AddChild(container);

                scrollPane = new ScrollPane(this, scroll, _margin, scrollBarMargin, scrollBarDisplay, flags);
            }
            else if (_margin.left != 0 || _margin.top != 0)
            {
                container = new Container();
                rootContainer.AddChild(container);

                container.SetXY(_margin.left * GRoot.contentScaleFactor, _margin.top * GRoot.contentScaleFactor);
            }

            SetBoundsChangedFlag();
        }
Пример #5
0
        public virtual void ConstructFromXML(XML xml)
        {
            string str;
            string[] arr;

            underConstruct = true;

            arr = xml.GetAttributeArray("size");
            sourceWidth = int.Parse(arr[0]);
            sourceHeight = int.Parse(arr[1]);
            initWidth = sourceWidth;
            initHeight = sourceHeight;

            OverflowType overflow;
            str = xml.GetAttribute("overflow");
            if (str != null)
                overflow = FieldTypes.ParseOverflowType(str);
            else
                overflow = OverflowType.Visible;

            ScrollType scroll;
            str = xml.GetAttribute("scroll");
            if (str != null)
                scroll = FieldTypes.ParseScrollType(str);
            else
                scroll = ScrollType.Vertical;

            ScrollBarDisplayType scrollBarDisplay;
            str = xml.GetAttribute("scrollBar");
            if (str != null)
                scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
            else
                scrollBarDisplay = ScrollBarDisplayType.Default;

            int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

            Margin scrollBarMargin = new Margin();
            str = xml.GetAttribute("scrollBarMargin");
            if (str != null)
                scrollBarMargin.Parse(str);

            str = xml.GetAttribute("margin");
            if (str != null)
                _margin.Parse(str);

            SetSize(sourceWidth, sourceHeight);

            SetupOverflowAndScroll(overflow, scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags);

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));

            _buildingDisplayList = true;

            XMLList col = xml.Elements("controller");
            Controller controller;
            foreach (XML cxml in col)
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(cxml);
            }

            XML listNode = xml.GetNode("displayList");
            if (listNode != null)
            {
                col = listNode.Elements();
                GObject u;
                foreach (XML cxml in col)
                {
                    u = ConstructChild(cxml);
                    if (u == null)
                        continue;

                    u.underConstruct = true;
                    u.constructingData = cxml;
                    u.Setup_BeforeAdd(cxml);
                    AddChild(u);
                }
            }
            this.relations.Setup(xml);

            int cnt = _children.Count;
            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.relations.Setup(u.constructingData);
            }

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.Setup_AfterAdd(u.constructingData);
                u.underConstruct = false;
                u.constructingData = null;
            }

            XMLList transCol = xml.Elements("transition");
            foreach (XML cxml in transCol)
            {
                Transition trans = new Transition(this);
                trans.Setup(cxml);
                _transitions.Add(trans);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct = false;

            //build real display list
            foreach (GObject child in _children)
            {
                if (child.displayObject != null && child.finalVisible)
                    container.AddChild(child.displayObject);
            }
        }
Пример #6
0
        public ScrollPane(GComponent owner,
            ScrollType scrollType,
            Margin scrollBarMargin,
            ScrollBarDisplayType scrollBarDisplay,
            int flags,
            string vtScrollBarRes,
            string hzScrollBarRes)
        {
            onScroll = new EventListener(this, "onScroll");
            _refreshDelegate = Refresh;

            _throwTween = new ThrowTween();
            _owner = owner;
            _container = _owner.rootContainer;

            _maskHolder = new Container();
            _container.AddChild(_maskHolder);

            _maskContentHolder = _owner.container;
            _maskContentHolder.x = 0;
            _maskContentHolder.y = 0;
            _maskHolder.AddChild(_maskContentHolder);

            _scrollBarMargin = scrollBarMargin;
            _scrollType = scrollType;
            _scrollSpeed = UIConfig.defaultScrollSpeed;
            _mouseWheelSpeed = _scrollSpeed * 2;
            _softnessOnTopOrLeftSide = UIConfig.allowSoftnessOnTopOrLeftSide;

            _displayOnLeft = (flags & 1) != 0;
            _snapToItem = (flags & 2) != 0;
            _displayInDemand = (flags & 4) != 0;
            _pageMode = (flags & 8) != 0;
            if ((flags & 16) != 0)
                _touchEffect = true;
            else if ((flags & 32) != 0)
                _touchEffect = false;
            else
                _touchEffect = UIConfig.defaultScrollTouchEffect;
            if ((flags & 64) != 0)
                _bouncebackEffect = true;
            else if ((flags & 128) != 0)
                _bouncebackEffect = false;
            else
                _bouncebackEffect = UIConfig.defaultScrollBounceEffect;

            _xPerc = 0;
            _yPerc = 0;
            _aniFlag = true;
            _scrollBarVisible = true;
            _mouseWheelEnabled = true;
            _holdAreaPoint = new Vector2();
            _pageSize = Vector2.one;

            if (scrollBarDisplay == ScrollBarDisplayType.Default)
            {
                if (Application.isMobilePlatform)
                    scrollBarDisplay = ScrollBarDisplayType.Auto;
                else
                    scrollBarDisplay = UIConfig.defaultScrollBarDisplay;
            }

            if (scrollBarDisplay != ScrollBarDisplayType.Hidden)
            {
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Vertical)
                {
                    string res = string.IsNullOrEmpty(vtScrollBarRes) ? UIConfig.verticalScrollBar : vtScrollBarRes;
                    if (!string.IsNullOrEmpty(res))
                    {
                        _vtScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar;
                        if (_vtScrollBar == null)
                            Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res);
                        else
                        {
                            _vtScrollBar.SetScrollPane(this, true);
                            _container.AddChild(_vtScrollBar.displayObject);
                        }
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    string res = string.IsNullOrEmpty(hzScrollBarRes) ? UIConfig.horizontalScrollBar : hzScrollBarRes;
                    if (!string.IsNullOrEmpty(res))
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(res) as GScrollBar;
                        if (_hzScrollBar == null)
                            Debug.LogWarning("FairyGUI: cannot create scrollbar from " + res);
                        else
                        {
                            _hzScrollBar.SetScrollPane(this, false);
                            _container.AddChild(_hzScrollBar.displayObject);
                        }
                    }
                }

                _scrollBarDisplayAuto = scrollBarDisplay == ScrollBarDisplayType.Auto;
                if (_scrollBarDisplayAuto)
                {
                    if (_vtScrollBar != null)
                        _vtScrollBar.displayObject.visible = false;
                    if (_hzScrollBar != null)
                        _hzScrollBar.displayObject.visible = false;
                    _scrollBarVisible = false;

                    _container.onRollOver.Add(__rollOver);
                    _container.onRollOut.Add(__rollOut);
                }
            }
            else
                _mouseWheelEnabled = false;

            SetSize(owner.width, owner.height);

            _container.onMouseWheel.Add(__mouseWheel);
            _container.onTouchBegin.Add(__touchBegin);
        }
Пример #7
0
        /// <summary>
        /// 进入绘画模式,整个对象将画到一张RenderTexture上,然后这种贴图将代替原有的显示内容。
        /// 可以在onPaint回调里对这张纹理进行进一步操作,实现特殊效果。
        /// 可能有多个地方要求进入绘画模式,这里用requestorId加以区别,取值是1、2、4、8、16以此类推。1024内内部保留。用户自定义的id从1024开始。
        /// </summary>
        /// <param name="requestId">请求者id</param>
        /// <param name="margin">纹理四周的留空。如果特殊处理后的内容大于原内容,那么这里的设置可以使纹理扩大。</param>
        public void EnterPaintingMode(int requestorId, Margin? margin)
        {
            bool first = _paintingMode == 0;
            _paintingMode |= requestorId;
            if (first)
            {
                if (paintingGraphics == null)
                {
                    if (graphics == null)
                        paintingGraphics = new NGraphics(this.gameObject);
                    else
                    {
                        GameObject go = new GameObject(this.gameObject.name + " (Painter)");
                        go.layer = this.gameObject.layer;
                        ToolSet.SetParent(go.transform, cachedTransform);
                        go.hideFlags = DisplayOptions.hideFlags;
                        paintingGraphics = new NGraphics(go);
                    }
                }
                else
                    paintingGraphics.enabled = true;
                paintingGraphics.vertexMatrix = null;

                if (this is Container)
                {
                    ((Container)this).SetChildrenLayer(CaptureCamera.hiddenLayer);
                    ((Container)this).UpdateBatchingFlags();
                }
                else
                    this.InvalidateBatchingState();

                if (graphics != null)
                    this.gameObject.layer = CaptureCamera.hiddenLayer;

                _paintingMargin = new Margin();
            }
            if (margin != null)
                _paintingMargin = (Margin)margin;
            _paintingFlag = 1;
        }
Пример #8
0
        public override void Setup_BeforeAdd(XML xml)
        {
            base.Setup_BeforeAdd(xml);

            string str;
            string[] arr;

            str = xml.GetAttribute("layout");
            if (str != null)
                _layout = FieldTypes.ParseListLayoutType(str);
            else
                _layout = ListLayoutType.SingleColumn;

            str = xml.GetAttribute("selectionMode");
            if (str != null)
                selectionMode = FieldTypes.ParseListSelectionMode(str);
            else
                selectionMode = ListSelectionMode.Single;

            OverflowType overflow;
            str = xml.GetAttribute("overflow");
            if (str != null)
                overflow = FieldTypes.ParseOverflowType(str);
            else
                overflow = OverflowType.Visible;

            str = xml.GetAttribute("margin");
            if (str != null)
                _margin.Parse(str);

            str = xml.GetAttribute("align");
            if (str != null)
                _align = FieldTypes.ParseAlign(str);

            str = xml.GetAttribute("vAlign");
            if (str != null)
                _verticalAlign = FieldTypes.ParseVerticalAlign(str);

            if (overflow == OverflowType.Scroll)
            {
                ScrollType scroll;
                str = xml.GetAttribute("scroll");
                if (str != null)
                    scroll = FieldTypes.ParseScrollType(str);
                else
                    scroll = ScrollType.Vertical;

                ScrollBarDisplayType scrollBarDisplay;
                str = xml.GetAttribute("scrollBar");
                if (str != null)
                    scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
                else
                    scrollBarDisplay = ScrollBarDisplayType.Default;

                int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

                Margin scrollBarMargin = new Margin();
                str = xml.GetAttribute("scrollBarMargin");
                if (str != null)
                    scrollBarMargin.Parse(str);

                string vtScrollBarRes = null;
                string hzScrollBarRes = null;
                arr = xml.GetAttributeArray("scrollBarRes");
                if (arr != null)
                {
                    vtScrollBarRes = arr[0];
                    hzScrollBarRes = arr[1];
                }

                SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes);
            }
            else
            {
                SetupOverflow(overflow);
            }

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));

            _lineGap = xml.GetAttributeInt("lineGap");
            _columnGap = xml.GetAttributeInt("colGap");
            _lineItemCount = xml.GetAttributeInt("lineItemCount");
            defaultItem = xml.GetAttribute("defaultItem");

            autoResizeItem = xml.GetAttributeBool("autoItemSize", true);

            XMLList.Enumerator et = xml.GetEnumerator("item");
            while (et.MoveNext())
            {
                XML ix = et.Current;
                string url = ix.GetAttribute("url");
                if (string.IsNullOrEmpty(url))
                {
                    url = defaultItem;
                    if (string.IsNullOrEmpty(url))
                        continue;
                }

                GObject obj = GetFromPool(url);
                if (obj != null)
                {
                    AddChild(obj);
                    str = ix.GetAttribute("title");
                    if (str != null)
                        obj.text = str;
                    str = ix.GetAttribute("icon");
                    if (str != null)
                        obj.icon = str;
                    str = ix.GetAttribute("name");
                    if (str != null)
                        obj.name = str;
                }
            }
        }
Пример #9
0
        public override void Setup_BeforeAdd(XML xml)
        {
            base.Setup_BeforeAdd(xml);

            string str;
            str = xml.GetAttribute("layout");
            if (str != null)
                _layout = FieldTypes.ParseListLayoutType(str);
            else
                _layout = ListLayoutType.SingleColumn;

            str = xml.GetAttribute("selectionMode");
            if (str != null)
                selectionMode = FieldTypes.ParseListSelectionMode(str);
            else
                selectionMode = ListSelectionMode.Single;

            OverflowType overflow;
            str = xml.GetAttribute("overflow");
            if (str != null)
                overflow = FieldTypes.ParseOverflowType(str);
            else
                overflow = OverflowType.Visible;

            ScrollType scroll;
            str = xml.GetAttribute("scroll");
            if (str != null)
                scroll = FieldTypes.ParseScrollType(str);
            else
                scroll = ScrollType.Vertical;

            ScrollBarDisplayType scrollBarDisplay;
            str = xml.GetAttribute("scrollBar");
            if (str != null)
                scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
            else
                scrollBarDisplay = ScrollBarDisplayType.Default;

            int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

            Margin scrollBarMargin = new Margin();
            str = xml.GetAttribute("scrollBarMargin");
            if (str != null)
                scrollBarMargin.Parse(str);

            str = xml.GetAttribute("margin");
            if (str != null)
                _margin.Parse(str);

            SetupOverflowAndScroll(overflow, scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags);

            string[] arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));

            _lineGap = xml.GetAttributeInt("lineGap");
            _columnGap = xml.GetAttributeInt("colGap");
            defaultItem = xml.GetAttribute("defaultItem");

            autoResizeItem = xml.GetAttributeBool("autoItemSize", true);

            XMLList col = xml.Elements("item");
            foreach (XML ix in col)
            {
                string url = ix.GetAttribute("url");
                if (string.IsNullOrEmpty(url))
                    url = defaultItem;
                if (string.IsNullOrEmpty(url))
                    continue;

                GObject obj = AddItemFromPool(url);
                if (obj is GButton)
                {
                    ((GButton)obj).title = ix.GetAttribute("title");
                    ((GButton)obj).icon = ix.GetAttribute("icon");
                }
                else if (obj is GLabel)
                {
                    ((GLabel)obj).title = ix.GetAttribute("title");
                    ((GLabel)obj).icon = ix.GetAttribute("icon");
                }
            }
        }
Пример #10
0
        public virtual void ConstructFromXML(XML xml)
        {
            string str;
            string[] arr;

            underConstruct = true;

            arr = xml.GetAttributeArray("size");
            sourceWidth = int.Parse(arr[0]);
            sourceHeight = int.Parse(arr[1]);
            initWidth = sourceWidth;
            initHeight = sourceHeight;

            SetSize(sourceWidth, sourceHeight);

            arr = xml.GetAttributeArray("pivot");
            if (arr != null)
            {
                float f1 = float.Parse(arr[0]);
                float f2 = float.Parse(arr[1]);
                this.SetPivot(f1, f2, xml.GetAttributeBool("anchor"));
            }

            this.opaque = xml.GetAttributeBool("opaque", true);
            arr = xml.GetAttributeArray("hitTest");
            if (arr != null)
            {
                PixelHitTestData hitTestData = _packageItem.owner.GetPixelHitTestData(arr[0]);
                if (hitTestData != null)
                    this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2]));
            }

            OverflowType overflow;
            str = xml.GetAttribute("overflow");
            if (str != null)
                overflow = FieldTypes.ParseOverflowType(str);
            else
                overflow = OverflowType.Visible;

            str = xml.GetAttribute("margin");
            if (str != null)
                _margin.Parse(str);

            if (overflow == OverflowType.Scroll)
            {
                ScrollType scroll;
                str = xml.GetAttribute("scroll");
                if (str != null)
                    scroll = FieldTypes.ParseScrollType(str);
                else
                    scroll = ScrollType.Vertical;

                ScrollBarDisplayType scrollBarDisplay;
                str = xml.GetAttribute("scrollBar");
                if (str != null)
                    scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
                else
                    scrollBarDisplay = ScrollBarDisplayType.Default;

                int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

                Margin scrollBarMargin = new Margin();
                str = xml.GetAttribute("scrollBarMargin");
                if (str != null)
                    scrollBarMargin.Parse(str);

                string vtScrollBarRes = null;
                string hzScrollBarRes = null;
                arr = xml.GetAttributeArray("scrollBarRes");
                if (arr != null)
                {
                    vtScrollBarRes = arr[0];
                    hzScrollBarRes = arr[1];
                }

                SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes);
            }
            else
                SetupOverflow(overflow);

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));

            _buildingDisplayList = true;

            XMLList col = xml.Elements("controller");
            Controller controller;
            foreach (XML cxml in col)
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(cxml);
            }

            XML listNode = xml.GetNode("displayList");
            if (listNode != null)
            {
                col = listNode.Elements();
                GObject u;
                foreach (XML cxml in col)
                {
                    u = ConstructChild(cxml);
                    if (u == null)
                        continue;

                    u.underConstruct = true;
                    u.constructingData = cxml;
                    u.Setup_BeforeAdd(cxml);
                    AddChild(u);
                }
            }
            this.relations.Setup(xml);

            int cnt = _children.Count;
            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.relations.Setup(u.constructingData);
            }

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.Setup_AfterAdd(u.constructingData);
                u.underConstruct = false;
                u.constructingData = null;
            }

            str = xml.GetAttribute("mask");
            if (str != null)
                this.mask = GetChildById(str).displayObject;

            XMLList transCol = xml.Elements("transition");
            foreach (XML cxml in transCol)
            {
                Transition trans = new Transition(this);
                trans.Setup(cxml);
                _transitions.Add(trans);
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct = false;

            BuildNativeDisplayList();
        }
Пример #11
0
        protected void SetupScroll(Margin scrollBarMargin,
            ScrollType scroll, ScrollBarDisplayType scrollBarDisplay, int flags,
            String vtScrollBarRes, String hzScrollBarRes)
        {
            container = new Container();
            rootContainer.AddChild(container);

            scrollPane = new ScrollPane(this, scroll, scrollBarMargin, scrollBarDisplay, flags, vtScrollBarRes, hzScrollBarRes);
            UpdateClipRect();
            SetBoundsChangedFlag();
        }
Пример #12
0
        virtual public void ConstructFromXML(XML xml)
        {
            string str;

            string[] arr;

            underConstruct = true;

            arr          = xml.GetAttributeArray("size");
            sourceWidth  = int.Parse(arr[0]);
            sourceHeight = int.Parse(arr[1]);
            initWidth    = sourceWidth;
            initHeight   = sourceHeight;

            SetSize(sourceWidth, sourceHeight);

            this.opaque = xml.GetAttributeBool("opaque", true);
            arr         = xml.GetAttributeArray("hitTest");
            if (arr != null)
            {
                PixelHitTestData hitTestData = _packageItem.owner.GetPixelHitTestData(arr[0]);
                if (hitTestData != null)
                {
                    this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2]));
                }
            }

            OverflowType overflow;

            str = xml.GetAttribute("overflow");
            if (str != null)
            {
                overflow = FieldTypes.ParseOverflowType(str);
            }
            else
            {
                overflow = OverflowType.Visible;
            }

            str = xml.GetAttribute("margin");
            if (str != null)
            {
                _margin.Parse(str);
            }

            if (overflow == OverflowType.Scroll)
            {
                ScrollType scroll;
                str = xml.GetAttribute("scroll");
                if (str != null)
                {
                    scroll = FieldTypes.ParseScrollType(str);
                }
                else
                {
                    scroll = ScrollType.Vertical;
                }

                ScrollBarDisplayType scrollBarDisplay;
                str = xml.GetAttribute("scrollBar");
                if (str != null)
                {
                    scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
                }
                else
                {
                    scrollBarDisplay = ScrollBarDisplayType.Default;
                }

                int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

                Margin scrollBarMargin = new Margin();
                str = xml.GetAttribute("scrollBarMargin");
                if (str != null)
                {
                    scrollBarMargin.Parse(str);
                }

                string vtScrollBarRes = null;
                string hzScrollBarRes = null;
                arr = xml.GetAttributeArray("scrollBarRes");
                if (arr != null)
                {
                    vtScrollBarRes = arr[0];
                    hzScrollBarRes = arr[1];
                }

                SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes);
            }
            else
            {
                SetupOverflow(overflow);
            }

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
            {
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));
            }

            _buildingDisplayList = true;

            XMLList    col = xml.Elements("controller");
            Controller controller;

            foreach (XML cxml in col)
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(cxml);
            }

            XML listNode = xml.GetNode("displayList");

            if (listNode != null)
            {
                col = listNode.Elements();
                GObject u;
                foreach (XML cxml in col)
                {
                    u = ConstructChild(cxml);
                    if (u == null)
                    {
                        continue;
                    }

                    u.underConstruct   = true;
                    u.constructingData = cxml;
                    u.Setup_BeforeAdd(cxml);
                    AddChild(u);
                }
            }
            this.relations.Setup(xml);

            int cnt = _children.Count;

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.relations.Setup(u.constructingData);
            }

            for (int i = 0; i < cnt; i++)
            {
                GObject u = _children[i];
                u.Setup_AfterAdd(u.constructingData);
                u.underConstruct   = false;
                u.constructingData = null;
            }

            str = xml.GetAttribute("mask");
            if (str != null)
            {
                this.mask = GetChildById(str).displayObject;
            }

            XMLList transCol = xml.Elements("transition");

            foreach (XML cxml in transCol)
            {
                Transition trans = new Transition(this);
                trans.Setup(cxml);
                _transitions.Add(trans);
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct       = false;

            BuildNativeDisplayList();
        }
Пример #13
0
        internal void ConstructFromResource(List<GObject> objectPool, int poolIndex)
        {
            this.gameObjectName = packageItem.name;

            XML xml = packageItem.componentData;

            string str;
            string[] arr;

            underConstruct = true;

            arr = xml.GetAttributeArray("size");
            sourceWidth = int.Parse(arr[0]);
            sourceHeight = int.Parse(arr[1]);
            initWidth = sourceWidth;
            initHeight = sourceHeight;

            SetSize(sourceWidth, sourceHeight);

            arr = xml.GetAttributeArray("pivot");
            if (arr != null)
            {
                float f1 = float.Parse(arr[0]);
                float f2 = float.Parse(arr[1]);
                this.SetPivot(f1, f2, xml.GetAttributeBool("anchor"));
            }

            this.opaque = xml.GetAttributeBool("opaque", true);
            arr = xml.GetAttributeArray("hitTest");
            if (arr != null)
            {
                PixelHitTestData hitTestData = packageItem.owner.GetPixelHitTestData(arr[0]);
                if (hitTestData != null)
                    this.rootContainer.hitArea = new PixelHitTest(hitTestData, int.Parse(arr[1]), int.Parse(arr[2]));
            }

            OverflowType overflow;
            str = xml.GetAttribute("overflow");
            if (str != null)
                overflow = FieldTypes.ParseOverflowType(str);
            else
                overflow = OverflowType.Visible;

            str = xml.GetAttribute("margin");
            if (str != null)
                _margin.Parse(str);

            if (overflow == OverflowType.Scroll)
            {
                ScrollType scroll;
                str = xml.GetAttribute("scroll");
                if (str != null)
                    scroll = FieldTypes.ParseScrollType(str);
                else
                    scroll = ScrollType.Vertical;

                ScrollBarDisplayType scrollBarDisplay;
                str = xml.GetAttribute("scrollBar");
                if (str != null)
                    scrollBarDisplay = FieldTypes.ParseScrollBarDisplayType(str);
                else
                    scrollBarDisplay = ScrollBarDisplayType.Default;

                int scrollBarFlags = xml.GetAttributeInt("scrollBarFlags");

                Margin scrollBarMargin = new Margin();
                str = xml.GetAttribute("scrollBarMargin");
                if (str != null)
                    scrollBarMargin.Parse(str);

                string vtScrollBarRes = null;
                string hzScrollBarRes = null;
                arr = xml.GetAttributeArray("scrollBarRes");
                if (arr != null)
                {
                    vtScrollBarRes = arr[0];
                    hzScrollBarRes = arr[1];
                }

                SetupScroll(scrollBarMargin, scroll, scrollBarDisplay, scrollBarFlags, vtScrollBarRes, hzScrollBarRes);
            }
            else
                SetupOverflow(overflow);

            arr = xml.GetAttributeArray("clipSoftness");
            if (arr != null)
                this.clipSoftness = new Vector2(int.Parse(arr[0]), int.Parse(arr[1]));

            _buildingDisplayList = true;

            XMLList.Enumerator et = xml.GetEnumerator("controller");
            Controller controller;
            while (et.MoveNext())
            {
                controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(et.Current);
            }

            GObject child;

            DisplayListItem[] displayList = packageItem.displayList;
            int childCount = displayList.Length;
            for (int i = 0; i < childCount; i++)
            {
                DisplayListItem di = displayList[i];
                if (objectPool != null)
                    child = objectPool[poolIndex + i];
                else if (di.packageItem != null)
                {
                    di.packageItem.Load();
                    child = UIObjectFactory.NewObject(di.packageItem);
                    child.packageItem = di.packageItem;
                    child.ConstructFromResource();
                }
                else
                    child = UIObjectFactory.NewObject(di.type);

                child.underConstruct = true;
                child.Setup_BeforeAdd(di.desc);
                child.InternalSetParent(this);
                _children.Add(child);
            }

            this.relations.Setup(xml);

            for (int i = 0; i < childCount; i++)
                _children[i].relations.Setup(displayList[i].desc);

            for (int i = 0; i < childCount; i++)
            {
                child = _children[i];
                child.Setup_AfterAdd(displayList[i].desc);
                child.underConstruct = false;
                if (child.displayObject != null)
                    ToolSet.SetParent(child.displayObject.cachedTransform, this.displayObject.cachedTransform);
            }

            str = xml.GetAttribute("mask");
            if (str != null)
                this.mask = GetChildById(str).displayObject;

            et = xml.GetEnumerator("transition");
            while (et.MoveNext())
            {
                Transition trans = new Transition(this);
                trans.Setup(et.Current);
                _transitions.Add(trans);
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct = false;

            BuildNativeDisplayList();
            SetBoundsChangedFlag();

            ConstructFromXML(xml);
        }
Пример #14
0
        protected void SetupScroll(Margin scrollBarMargin,
            ScrollType scroll, ScrollBarDisplayType scrollBarDisplay, int flags,
            String vtScrollBarRes, String hzScrollBarRes)
        {
            if (rootContainer == container)
            {
                container = new Container();
                rootContainer.AddChild(container);
            }

            scrollPane = new ScrollPane(this, scroll, scrollBarMargin, scrollBarDisplay, flags, vtScrollBarRes, hzScrollBarRes);
        }