示例#1
0
        public bool InitWithMinusSpriteAndPlusSprite(CCSprite minusSprite, CCSprite plusSprite)
        {
            if (base.Init())
            {
                Debug.Assert(minusSprite != null, "Minus sprite must be not nil");
                Debug.Assert(plusSprite != null, "Plus sprite must be not nil");

                TouchEnabled = true;

                // Set the default values
                _autorepeat   = true;
                _continuous   = true;
                _minimumValue = 0;
                _maximumValue = 100;
                _value        = 0;
                _stepValue    = 1;
                _wraps        = false;
                IgnoreAnchorPointForPosition = false;

                // Add the minus components
                MinusSprite           = minusSprite;
                _minusSprite.Position = new CCPoint(minusSprite.ContentSize.Width / 2,
                                                    minusSprite.ContentSize.Height / 2);
                AddChild(_minusSprite);

                MinusLabel           = new CCLabelTTF("-", ControlStepperLabelFont, 38);
                _minusLabel.Color    = ControlStepperLabelColorDisabled;
                _minusLabel.Position = new CCPoint(_minusSprite.ContentSize.Width / 2,
                                                   _minusSprite.ContentSize.Height / 2);
                _minusSprite.AddChild(_minusLabel);

                // Add the plus components
                PlusSprite           = plusSprite;
                _plusSprite.Position =
                    new CCPoint(minusSprite.ContentSize.Width + plusSprite.ContentSize.Width / 2,
                                minusSprite.ContentSize.Height / 2);
                AddChild(_plusSprite);

                PlusLabel           = new CCLabelTTF("+", ControlStepperLabelFont, 38);
                _plusLabel.Color    = ControlStepperLabelColorEnabled;
                _plusLabel.Position = _plusSprite.ContentSize.Center;
                _plusSprite.AddChild(_plusLabel);

                // Defines the content size
                CCRect maxRect = CCControlUtils.CCRectUnion(_minusSprite.BoundingBox, _plusSprite.BoundingBox);
                ContentSize = new CCSize(_minusSprite.ContentSize.Width + _plusSprite.ContentSize.Height,
                                         maxRect.Size.Height);
                return(true);
            }
            return(false);
        }
示例#2
0
        /**
         * Initializes a slider with a background sprite, a progress bar and a thumb
         * item.
         *
         * @param backgroundSprite  CCSprite, that is used as a background.
         * @param progressSprite    CCSprite, that is used as a progress bar.
         * @param thumbItem         CCMenuItem, that is used as a thumb.
         */

        public virtual bool InitWithSprites(CCSprite backgroundSprite, CCSprite progressSprite, CCSprite thumbSprite)
        {
            if (base.Init())
            {
                Debug.Assert(backgroundSprite != null, "Background sprite must be not nil");
                Debug.Assert(progressSprite != null, "Progress sprite must be not nil");
                Debug.Assert(thumbSprite != null, "Thumb sprite must be not nil");

                IgnoreAnchorPointForPosition = false;
                TouchEnabled = true;

                BackgroundSprite = backgroundSprite;
                ProgressSprite   = progressSprite;
                ThumbSprite      = thumbSprite;

                // Defines the content size
                CCRect maxRect = CCControlUtils.CCRectUnion(backgroundSprite.BoundingBox, thumbSprite.BoundingBox);
                ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height);

                //setContentSize(CCSizeMake(backgroundSprite->getContentSize().width, thumbItem->getContentSize().height));
                // Add the slider background
                _backgroundSprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                _backgroundSprite.Position    = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
                AddChild(_backgroundSprite);

                // Add the progress bar
                _progressSprite.AnchorPoint = new CCPoint(0.0f, 0.5f);
                _progressSprite.Position    = new CCPoint(0.0f, ContentSize.Height / 2);
                AddChild(_progressSprite);

                // Add the slider thumb
                _thumbSprite.Position = new CCPoint(0, ContentSize.Height / 2);
                AddChild(_thumbSprite);

                // Init default values
                _minimumValue = 0.0f;
                _maximumValue = 1.0f;

                Value = _minimumValue;
                return(true);
            }
            return(false);
        }
示例#3
0
        public override void NeedsLayout()
        {
            if (!m_bParentInited)
            {
                return;
            }
            // Hide the background and the label
            if (m_titleLabel != null)
            {
                m_titleLabel.Visible = false;
            }
            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Visible = false;
            }
            // Update anchor of all labels
            LabelAnchorPoint = m_labelAnchorPoint;

            // Update the label to match with the current state

            m_currentTitle      = GetTitleForState(m_eState);
            m_currentTitleColor = GetTitleColorForState(m_eState);

            TitleLabel = GetTitleLabelForState(m_eState);

            var label = (ICCLabelProtocol)m_titleLabel;

            if (label != null && !String.IsNullOrEmpty(m_currentTitle))
            {
                label.Label = (m_currentTitle);
            }

            var rgbaLabel = (ICCRGBAProtocol)m_titleLabel;

            if (rgbaLabel != null)
            {
                rgbaLabel.Color = m_currentTitleColor;
            }
            if (m_titleLabel != null)
            {
                m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
            }

            // Update the background sprite
            BackgroundSprite = GetBackgroundSpriteForState(m_eState);
            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
            }

            // Get the title label size
            CCSize titleLabelSize = CCSize.Zero;

            if (m_titleLabel != null)
            {
                titleLabelSize = m_titleLabel.BoundingBox.Size;
            }

            // Adjust the background image if necessary
            if (m_doesAdjustBackgroundImage)
            {
                // Add the margins
                if (m_backgroundSprite != null)
                {
                    m_backgroundSprite.ContentSize = new CCSize(titleLabelSize.Width + m_marginH * 2, titleLabelSize.Height + m_marginV * 2);
                }
            }
            else
            {
                //TODO: should this also have margins if one of the preferred sizes is relaxed?
                if (m_backgroundSprite != null)
                {
                    CCSize preferredSize = m_backgroundSprite.PreferredSize;
                    if (preferredSize.Width <= 0)
                    {
                        preferredSize.Width = titleLabelSize.Width;
                    }
                    if (preferredSize.Height <= 0)
                    {
                        preferredSize.Height = titleLabelSize.Height;
                    }

                    m_backgroundSprite.ContentSize = preferredSize;
                }
            }

            // Set the content size
            CCRect rectTitle = CCRect.Zero;

            if (m_titleLabel != null)
            {
                rectTitle = m_titleLabel.BoundingBox;
            }
            CCRect rectBackground = CCRect.Zero;

            if (m_backgroundSprite != null)
            {
                rectBackground = m_backgroundSprite.BoundingBox;
            }

            CCRect maxRect = CCControlUtils.CCRectUnion(rectTitle, rectBackground);

            ContentSize = new CCSize(maxRect.Size.Width, maxRect.Size.Height);

            if (m_titleLabel != null)
            {
                m_titleLabel.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
                // Make visible label
                m_titleLabel.Visible = true;
            }

            if (m_backgroundSprite != null)
            {
                m_backgroundSprite.Position = new CCPoint(ContentSize.Width / 2, ContentSize.Height / 2);
                // Make visible the background
                m_backgroundSprite.Visible = true;
            }
        }