예제 #1
0
        protected override List <ImageInfo> OnToImageList(PListDict plistDict)
        {
            List <ImageInfo> imageInfoList = new List <ImageInfo>();

            foreach (KeyValuePair <string, IPListElement> keyValuePair in (Dictionary <string, IPListElement>)(plistDict["frames"] as PListDict))
            {
                string    key        = keyValuePair.Key;
                PListDict plistDict1 = keyValuePair.Value as PListDict;
                Rectangle rect       = PlistFormatHelp.ConvertToRect(((PListElement <string>)plistDict1["frame"]).Value);
                Point     point      = PlistFormatHelp.ConvertToPoint(((PListElement <string>)plistDict1["offset"]).Value);
                Size      size       = PlistFormatHelp.ConvertToSize(((PListElement <string>)plistDict1["sourceSize"]).Value);
                int       x          = (size.Width - rect.Width) / 2 + point.X;
                int       y          = (size.Height - rect.Height) / 2 - point.Y;
                ImageInfo imageInfo  = new ImageInfo(key, rect, size, new Point(x, y));
                imageInfoList.Add(imageInfo);
            }
            return(imageInfoList);
        }
예제 #2
0
        public static Rectangle ConvertToRect(string plistString)
        {
            int num1 = plistString.IndexOf('{');
            int num2 = 0;
            int index;

            for (index = 0; index < plistString.Length; ++index)
            {
                if ((int)plistString[index] == 125)
                {
                    ++num2;
                }
                if (num2 == 3)
                {
                    break;
                }
            }
            int num3 = index;

            if (num1 < 0 || num2 != 3)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            plistString = plistString.Substring(num1 + 1, num3 - num1 - 1);
            int startIndex = plistString.IndexOf('}');

            if (startIndex < 0)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            int length = plistString.IndexOf(',', startIndex);

            if (length < 0)
            {
                throw new FormatException("大括号不匹配," + plistString);
            }
            return(new Rectangle(PlistFormatHelp.ConvertToPoint(plistString.Substring(0, length)), PlistFormatHelp.ConvertToSize(plistString.Substring(length + 1, plistString.Length - length - 1))));
        }