示例#1
0
        public static CCSize CCSizeFromString(string pszContent)
        {
            CCSize ret = new CCSize();

            do
            {
                List <string> strs = new List <string>();
                if (!CCUtils.SplitWithForm(pszContent, strs))
                {
                    break;
                }

                float width  = CCUtils.CCParseFloat(strs[0]);
                float height = CCUtils.CCParseFloat(strs[1]);

                ret = new CCSize(width, height);
            } while (false);

            return(ret);
        }
示例#2
0
        public static CCPoint CCPointFromString(string pszContent)
        {
            CCPoint ret = CCPoint.Zero;

            do
            {
                List <string> strs = new List <string>();
                if (!CCUtils.SplitWithForm(pszContent, strs))
                {
                    break;
                }

                float x = CCUtils.CCParseFloat(strs[0]);
                float y = CCUtils.CCParseFloat(strs[1]);

                ret.X = x;
                ret.Y = y;
            } while (false);

            return(ret);
        }
示例#3
0
        public static CCRect CCRectFromString(string pszContent)
        {
            CCRect result = CCRect.Zero;

            do
            {
                if (pszContent == null)
                {
                    break;
                }

                string content = pszContent;

                // find the first '{' and the third '}'
                int nPosLeft  = content.IndexOf('{');
                int nPosRight = content.IndexOf('}');
                for (int i = 1; i < 3; ++i)
                {
                    if (nPosRight == -1)
                    {
                        break;
                    }
                    nPosRight = content.IndexOf('}', nPosRight + 1);
                }
                if (nPosLeft == -1 || nPosRight == -1)
                {
                    break;
                }
                content = content.Substring(nPosLeft + 1, nPosRight - nPosLeft - 1);
                int nPointEnd = content.IndexOf('}');
                if (nPointEnd == -1)
                {
                    break;
                }
                nPointEnd = content.IndexOf(',', nPointEnd);
                if (nPointEnd == -1)
                {
                    break;
                }

                // get the point string and size string
                string pointStr = content.Substring(0, nPointEnd);
                string sizeStr  = content.Substring(nPointEnd + 1);
                //, content.Length - nPointEnd
                // split the string with ','
                List <string> pointInfo = new List <string>();

                if (!CCUtils.SplitWithForm(pointStr, pointInfo))
                {
                    break;
                }
                List <string> sizeInfo = new List <string>();
                if (!CCUtils.SplitWithForm(sizeStr, sizeInfo))
                {
                    break;
                }

                float x      = CCUtils.CCParseFloat(pointInfo[0]);
                float y      = CCUtils.CCParseFloat(pointInfo[1]);
                float width  = CCUtils.CCParseFloat(sizeInfo[0]);
                float height = CCUtils.CCParseFloat(sizeInfo[1]);

                result = new CCRect(x, y, width, height);
            } while (false);

            return(result);
        }