示例#1
0
        private bool TestPackingImages(int testWidth, int testHeight, Dictionary <string, Rect> testImagePlacement)
        {
//            System.Diagnostics.Stopwatch st = new System.Diagnostics.Stopwatch();
//            st.Start();

            // create the Rect packer
            ArevaloRectanglePacker RectPacker = new ArevaloRectanglePacker(testWidth, testHeight);

            foreach (var image in filesBMP)
            {
                // get the MCBitmap for this file
                MCSize size = imageSizes[image.Name.ToString()];

                // pack the image
                Vector2 origin;
                if (!RectPacker.TryPack(size.Width + padding, size.Height + padding, out origin))
                {
//                    MechCommanderUnity.MechCommanderUnity.LogMessage("FAlsePAck");
                    return(false);
                }

                if (!testImagePlacement.ContainsKey(image.Name.ToString()))
                {
                    // add the destination Rect to our dictionary
                    testImagePlacement.Add(image.Name.ToString(), new Rect(origin.x, origin.y, size.Width + padding, size.Height + padding));
                }
                else
                {
                    // add the destination Rect to our dictionary
                    testImagePlacement.Add(image.Name.ToString() + "_", new Rect(origin.x, origin.y, size.Width + padding, size.Height + padding));
                }
            }

//            st.Stop();

//            MechCommanderUnity.MechCommanderUnity.LogMessage("TestPacking elapsed: ("+filesBMP.Count+") ->" +(st.ElapsedMilliseconds/1000) +"s");
            return(true);
        }
示例#2
0
        private bool TestPackingImages(int testWidth, int testHeight, Dictionary <string, Rectangle> testImagePlacement)
        {
            // create the rectangle packer
            ArevaloRectanglePacker rectanglePacker = new ArevaloRectanglePacker(testWidth, testHeight);

            foreach (var image in files)
            {
                // get the bitmap for this file
                Size size = bitmaps[image].Size();

                // pack the image
                Point origin;
                if (!rectanglePacker.TryPack(size.Width + padding, size.Height + padding, out origin))
                {
                    return(false);
                }

                // add the destination rectangle to our dictionary
                testImagePlacement.Add(image, new Rectangle(origin.X, origin.Y, size.Width + padding, size.Height + padding));
            }

            return(true);
        }