Esempio n. 1
0
        public static GObject NewObject(string type, AppContext context)
        {
            GObject cls = null;

            switch (type)
            {
            case "image":
                cls = new GImage();
                break;

            case "movieclip":
                cls = new GMovieClip();
                break;

            case "swf":
                cls = new GSwfObject();
                break;

            case "jta":
                cls = new GJtaObject();
                break;

            case "component":
                cls = new GComponent();
                break;

            case "text":
                cls = new GTextField();
                break;

            case "group":
                cls = new GGroup();
                break;

            case "list":
                cls = new GList();
                break;

            case "graph":
                cls = new GGraph();
                break;

            case "loader":
                cls = new GLoader();
                break;

            //component derived
            case "Button":
                cls = new GButton();
                break;

            case "Label":
                cls = new GLabel();
                break;

            case "ProgressBar":
                cls = new GProgressBar();
                break;

            case "Slider":
                cls = new GSlider();
                break;

            case "ScrollBar":
                cls = new GScrollBar();
                break;

            case "ComboBox":
                cls = new GComboBox();
                break;
            }
            cls.OnCreate(context);
            return(cls);
        }
Esempio n. 2
0
        public ScrollPane(GComponent owner,
                          ScrollType scrollType,
                          Margin margin,
                          int scrollSpeed,
                          ScrollBarDisplayType scrollBarDisplay)
        {
            if (_easeTypeFunc == null)
            {
                _easeTypeFunc = Ease.CubeOut;
            }

            _owner         = owner;
            _container     = _owner.rootContainer;
            _maskContent   = _owner.container;
            _maskContent.x = 0;
            _maskContent.y = 0;

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

            _maskContentHolder = new Sprite();
            _maskContentHolder.AddChild(_maskContent);
            _maskHolder.AddChild(_maskContentHolder);

            if (GRoot.touchScreen)
            {
                _holdArea = 20;
            }
            else
            {
                _holdArea = 10;
            }
            _holdAreaPoint    = Vector2.zero;
            _margin           = new Margin();
            _bouncebackEffect = UIConfig.defaultScrollBounceEffect;
            _touchEffect      = UIConfig.defaultScrollTouchEffect;
            _xPerc            = 0;
            _yPerc            = 0;
            _aniFlag          = true;

            _scrollType  = scrollType;
            _scrollSpeed = scrollSpeed;
            if (_scrollSpeed == 0)
            {
                _scrollSpeed = UIConfig.defaultScrollSpeed;
            }
            _mouseWheelSpeed = _scrollSpeed * 2;

            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)
                        {
                            throw new Exception("cannot create scrollbar from " + UIConfig.verticalScrollBar);
                        }
                        _vtScrollBar.SetScrollPane(this, true);
                        owner.rootContainer.AddChild(_vtScrollBar.displayObject);
                    }
                }
                if (_scrollType == ScrollType.Both || _scrollType == ScrollType.Horizontal)
                {
                    if (UIConfig.horizontalScrollBar != null)
                    {
                        _hzScrollBar = UIPackage.CreateObjectFromURL(UIConfig.horizontalScrollBar) as GScrollBar;
                        if (_hzScrollBar == null)
                        {
                            throw new Exception("cannot create scrollbar from " + UIConfig.horizontalScrollBar);
                        }
                        _hzScrollBar.SetScrollPane(this, false);
                        owner.rootContainer.AddChild(_hzScrollBar.displayObject);
                    }
                }

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

                    owner.rootContainer.AddEventListenerObsolete(MouseEvent.ROLL_OVER, __rollOver);
                    owner.rootContainer.AddEventListenerObsolete(MouseEvent.ROLL_OUT, __rollOut);
                }
            }

            _margin.left   = margin.left;
            _margin.top    = margin.top;
            _margin.right  = margin.right;
            _margin.bottom = margin.bottom;

            _maskHolder.x = _margin.left;
            _maskHolder.y = _margin.top;

            SetSize(owner.width, owner.height);
            SetContentSize((int)owner.bounds.width, (int)owner.bounds.height);

            _container.AddEventListenerObsolete(MouseEvent.MOUSE_WHEEL, __mouseWheel);
            _container.AddEventListenerObsolete(MouseEvent.MOUSE_DOWN, __mouseDown);
            //
            onScroll = new EventListener(this, "onScroll");
        }