Example #1
0
        public ScrollViewLabelTest()
        {
            string       Font       = "fonts/futura-48.fnt";
            float        w          = CCDirector.SharedDirector.WinSize.Width;
            float        h          = CCDirector.SharedDirector.WinSize.Height / 2f;
            CCScrollView scrollView = new CCScrollView(new CCSize(w, h));

            scrollView.Direction = CCScrollViewDirection.Vertical;
            CCLabelBMFont testLabel = new CCLabelBMFont("Remeber we are the original XNA port of Cocos2d-X", Font);
            float         scale     = w / testLabel.ContentSize.Width;
            //Note, the scrollview requires the exact location. That's why first I need to set the scale, then SetString, so the label takes the correct size immediately.
            string text = "Thank you for visiting the cocos2d-xna tests\nPlease help us by donating to our project\nYou can find us at www.cocos2dxna.com\nRemeber we are the original XNA port of Cocos2d-X\n\n\nYou can also email us at [email protected]\n\nThank you!\n\nDon't forget to contribute to cocos2d-x\nWithout them this project would not exist.";
            //
            // The following hack is required to make the label properly show in the view.
            //
            // text = text.Replace(Environment.NewLine, "\n").Replace("\r\n", "\n").Replace("\n", " \n "); // @@ hack
            CCLabelBMFont descLabel = new CCLabelBMFont(text, Font, w);

            descLabel.LineBreakWithoutSpace = true;
            descLabel.Scale = scale;
            descLabel.SetString(text, true);
            descLabel.AnchorPoint       = new CCPoint(0, 0);
            descLabel.Color             = new CCColor3B(255, 255, 210);
            scrollView.Bounceable       = false;
            scrollView.ClippingToBounds = true;
            scrollView.MinScale         = scrollView.MaxScale = scrollView.ZoomScale = 1;
            scrollView.AddChild(descLabel, 0, 0);

            scrollView.AnchorPoint = new CCPoint(0, 0);
            scrollView.Position    = new CCPoint(0f, 45f);
            scrollView.ContentSize = new CCSize(w, Math.Max(h, descLabel.ContentSize.Height));
            scrollView.SetContentOffset(new CCPoint(0, Math.Min(0, scrollView.BoundingBox.Size.Height - scrollView.Container.ContentSize.Height)), false);
            AddChild(scrollView);
        }
Example #2
0
 public virtual void ScrollViewDidZoom(CCScrollView view)
 {
 }
Example #3
0
        public virtual void ScrollViewDidScroll(CCScrollView view)
        {
            var uCountOfItems = m_pDataSource.NumberOfCellsInTableView(this);

            if (uCountOfItems == 0)
            {
                return;
            }

            if (m_pTableViewDelegate != null)
            {
                m_pTableViewDelegate.ScrollViewDidScroll(this);
            }

            int     startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0;
            CCPoint offset = GetContentOffset() * -1;

            maxIdx = Math.Max(uCountOfItems - 1, 0);

            if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown)
            {
                offset.Y = offset.Y + m_tViewSize.Height / Container.ScaleY;
            }
            startIdx = _indexFromOffset(offset);
            if (startIdx == CCArrayForObjectSorting.CC_INVALID_INDEX)
            {
                startIdx = uCountOfItems - 1;
            }

            if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown)
            {
                offset.Y -= m_tViewSize.Height / Container.ScaleY;
            }
            else
            {
                offset.Y += m_tViewSize.Height / Container.ScaleY;
            }
            offset.X += m_tViewSize.Width / Container.ScaleX;

            endIdx = _indexFromOffset(offset);
            if (endIdx == CCArrayForObjectSorting.CC_INVALID_INDEX)
            {
                endIdx = uCountOfItems - 1;
            }

#if DEBUG_ // For Testing.
            int i = 0;
            foreach (object pObj in m_pCellsUsed)
            {
                var pCell = (CCTableViewCell)pObj;
                CCLog.Log("cells Used index {0}, value = {1}", i, pCell.getIdx());
                i++;
            }
            CCLog.Log("---------------------------------------");
            i = 0;
            foreach (object pObj in m_pCellsFreed)
            {
                var pCell = (CCTableViewCell)pObj;
                CCLog.Log("cells freed index {0}, value = {1}", i, pCell.getIdx());
                i++;
            }
            CCLog.Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
#endif

            if (m_pCellsUsed.Count > 0)
            {
                var cell = (CCTableViewCell)m_pCellsUsed[0];

                idx = cell.Index;
                while (idx < startIdx)
                {
                    _moveCellOutOfSight(cell);
                    if (m_pCellsUsed.Count > 0)
                    {
                        cell = (CCTableViewCell)m_pCellsUsed[0];
                        idx  = cell.Index;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (m_pCellsUsed.Count > 0)
            {
                var cell = (CCTableViewCell)m_pCellsUsed[m_pCellsUsed.Count - 1];
                idx = cell.Index;

                while (idx <= maxIdx && idx > endIdx)
                {
                    _moveCellOutOfSight(cell);
                    if (m_pCellsUsed.Count > 0)
                    {
                        cell = (CCTableViewCell)m_pCellsUsed[m_pCellsUsed.Count - 1];
                        idx  = cell.Index;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            for (int i = startIdx; i <= endIdx; i++)
            {
                if (m_pIndices.Contains(i))
                {
                    continue;
                }
                UpdateCellAtIndex(i);
            }
        }
		public virtual void ScrollViewDidZoom(CCScrollView view)
		{
		}
Example #5
0
        public virtual void ScrollViewDidScroll(CCScrollView view)
        {
            var uCountOfItems = m_pDataSource.NumberOfCellsInTableView(this);
            if (uCountOfItems == 0)
            {
                return;
            }

            if (m_pTableViewDelegate != null)
            {
                m_pTableViewDelegate.ScrollViewDidScroll(this);
            }

            int startIdx = 0, endIdx = 0, idx = 0, maxIdx = 0;
            CCPoint offset = GetContentOffset() * -1;
            maxIdx = Math.Max(uCountOfItems - 1, 0);

            if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown)
            {
                offset.Y = offset.Y + m_tViewSize.Height / Container.ScaleY;
            }
            startIdx = _indexFromOffset(offset);
            if (startIdx == CCArrayForObjectSorting.CC_INVALID_INDEX)
            {
                startIdx = uCountOfItems - 1;
            }

            if (m_eVordering == CCTableViewVerticalFillOrder.FillTopDown)
            {
                offset.Y -= m_tViewSize.Height / Container.ScaleY;
            }
            else
            {
                offset.Y += m_tViewSize.Height / Container.ScaleY;
            }
            offset.X += m_tViewSize.Width / Container.ScaleX;

            endIdx = _indexFromOffset(offset);
            if (endIdx == CCArrayForObjectSorting.CC_INVALID_INDEX)
            {
                endIdx = uCountOfItems - 1;
            }

#if DEBUG_ // For Testing.
			int i = 0;
			foreach (object pObj in m_pCellsUsed)
			{
				var pCell = (CCTableViewCell)pObj;
				CCLog.Log("cells Used index {0}, value = {1}", i, pCell.getIdx());
				i++;
			}
			CCLog.Log("---------------------------------------");
			i = 0;
			foreach(object pObj in m_pCellsFreed)
			{
				var pCell = (CCTableViewCell)pObj;
				CCLog.Log("cells freed index {0}, value = {1}", i, pCell.getIdx());
				i++;
			}
			CCLog.Log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
#endif

            if (m_pCellsUsed.Count > 0)
            {
                var cell = (CCTableViewCell) m_pCellsUsed[0];

                idx = cell.Index;
                while (idx < startIdx)
                {
                    _moveCellOutOfSight(cell);
                    if (m_pCellsUsed.Count > 0)
                    {
                        cell = (CCTableViewCell) m_pCellsUsed[0];
                        idx = cell.Index;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (m_pCellsUsed.Count > 0)
            {
                var cell = (CCTableViewCell) m_pCellsUsed[m_pCellsUsed.Count - 1];
                idx = cell.Index;

                while (idx <= maxIdx && idx > endIdx)
                {
                    _moveCellOutOfSight(cell);
                    if (m_pCellsUsed.Count > 0)
                    {
                        cell = (CCTableViewCell) m_pCellsUsed[m_pCellsUsed.Count - 1];
                        idx = cell.Index;
                    }
                    else
                    {
                        break;
                    }
                }
            }

            for (int i = startIdx; i <= endIdx; i++)
            {
                if (m_pIndices.Contains(i))
                {
                    continue;
                }
                UpdateCellAtIndex(i);
            }
        }
Example #6
0
        public ScrollViewLabelTest()
        {
            string Font = "fonts/futura-48.fnt";
            float w = CCDirector.SharedDirector.WinSize.Width;
            float h = CCDirector.SharedDirector.WinSize.Height / 2f;
            CCScrollView scrollView = new CCScrollView(new CCSize(w, h));
            scrollView.Direction = CCScrollViewDirection.Vertical;
            CCLabelBMFont testLabel = new CCLabelBMFont("Remeber we are the original XNA port of Cocos2d-X", Font);
            float scale = w / testLabel.ContentSize.Width;
            //Note, the scrollview requires the exact location. That's why first I need to set the scale, then SetString, so the label takes the correct size immediately.
            string text = "Thank you for visiting the cocos2d-xna tests\nPlease help us by donating to our project\nYou can find us at www.cocos2dxna.com\nRemeber we are the original XNA port of Cocos2d-X\n\n\nYou can also email us at [email protected]\n\nThank you!\n\nDon't forget to contribute to cocos2d-x\nWithout them this project would not exist.";
            //
            // The following hack is required to make the label properly show in the view.
            //
            // text = text.Replace(Environment.NewLine, "\n").Replace("\r\n", "\n").Replace("\n", " \n "); // @@ hack
            CCLabelBMFont descLabel = new CCLabelBMFont(text, Font, w);
            descLabel.LineBreakWithoutSpace = true;
            descLabel.Scale = scale;
            descLabel.SetString(text, true);
            descLabel.AnchorPoint = new CCPoint(0, 0);
            descLabel.Color = new CCColor3B(255, 255, 210);
            scrollView.Bounceable = false;
            scrollView.ClippingToBounds = true;
            scrollView.MinScale = scrollView.MaxScale = scrollView.ZoomScale = 1;
            scrollView.AddChild(descLabel, 0, 0);

            scrollView.AnchorPoint = new CCPoint(0, 0);
            scrollView.Position = new CCPoint(0f, 45f);
            scrollView.ContentSize = new CCSize(w, Math.Max(h, descLabel.ContentSize.Height));
            scrollView.SetContentOffset(new CCPoint(0, Math.Min(0, scrollView.BoundingBox.Size.Height - scrollView.Container.ContentSize.Height)), false);
            AddChild(scrollView);
        }