Exemplo n.º 1
0
 public void AddVariant(DeviceRequirement requirement, string path, ImageAlignment alignment, ImageResizing resizing)
 {
     ImageSetVariant newItem = new ImageSetVariant(requirement, path) {
         alignment = alignment,
         resizing = resizing
     };
     base.AddVariant(newItem);
 }
Exemplo n.º 2
0
        public void ImageSetCreationWorks()
        {
            var testFiles = new TestFileCache(Path.Combine(GetTestOutputPath(), "Imageset1Files"));

            string catalogPath = Path.Combine(GetTestOutputPath(), "Imageset1.xcassets");
            var    catalog     = new AssetCatalog(catalogPath, "test.test");
            var    imageset    = catalog.OpenImageSet("img1");

            imageset.AddVariant(new DeviceRequirement().AddWidthClass(SizeClassRequirement.Regular),
                                testFiles.CreateFile("data1.png", "img1"));

            imageset.AddVariant(new DeviceRequirement().AddHeightClass(SizeClassRequirement.Compact),
                                testFiles.CreateFile("data2.png", "img2"));

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X1),
                                testFiles.CreateFile("data3.png", "img3"));

            var alignment = new ImageAlignment();

            alignment.top    = 1;
            alignment.bottom = 2;
            alignment.left   = 3;
            alignment.right  = 4;

            var resizing = new ImageResizing();

            resizing.type             = ImageResizing.SlicingType.HorizontalAndVertical;
            resizing.top              = 1;
            resizing.bottom           = 2;
            resizing.left             = 3;
            resizing.right            = 4;
            resizing.centerResizeMode = ImageResizing.ResizeMode.Stretch;
            resizing.centerWidth      = 2;
            resizing.centerHeight     = 4;

            imageset.AddVariant(new DeviceRequirement().AddScale(ScaleRequirement.X3),
                                testFiles.CreateFile("data4.png", "img4"), alignment, resizing);
            catalog.Write();

            string imagesetPath = Path.Combine(catalogPath, "img1.imageset");

            Assert.IsTrue(Directory.Exists(catalogPath));
            Assert.IsTrue(Directory.Exists(imagesetPath));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "Contents.json"),
                                           File.ReadAllText(Path.Combine(GetTestSourcePath(), "Imageset1.Contents.json")));
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data1.png"), "img1");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data2.png"), "img2");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data3.png"), "img3");
            AssertFileExistsAndHasContents(Path.Combine(imagesetPath, "data4.png"), "img4");

            if (!DebugEnabled())
            {
                testFiles.CleanUp();
                Directory.Delete(catalogPath, true);
            }
        }
Exemplo n.º 3
0
 private static string GetCenterResizeMode(ImageResizing.ResizeMode mode)
 {
     if (mode != ImageResizing.ResizeMode.Stretch)
     {
         if (mode == ImageResizing.ResizeMode.Tile)
         {
             return "tile";
         }
     }
     else
     {
         return "stretch";
     }
     return "";
 }
Exemplo n.º 4
0
        private void WriteResizingToJson(JsonElementDict item, ImageResizing resizing)
        {
            JsonElementDict dict1 = item.CreateDict("resizing");

            dict1.SetString("mode", AssetImageSet.GetSlicingMode(resizing.type));
            JsonElementDict dict2 = dict1.CreateDict("center");

            dict2.SetString("mode", AssetImageSet.GetCenterResizeMode(resizing.centerResizeMode));
            dict2.SetInteger("width", resizing.centerWidth);
            dict2.SetInteger("height", resizing.centerHeight);
            JsonElementDict dict3 = dict1.CreateDict("cap-insets");

            dict3.SetInteger("top", resizing.top);
            dict3.SetInteger("bottom", resizing.bottom);
            dict3.SetInteger("left", resizing.left);
            dict3.SetInteger("right", resizing.right);
        }
Exemplo n.º 5
0
 private static string GetSlicingMode(ImageResizing.SlicingType mode)
 {
     if (mode != ImageResizing.SlicingType.Horizontal)
     {
         if (mode == ImageResizing.SlicingType.Vertical)
         {
             return "3-part-vertical";
         }
         if (mode == ImageResizing.SlicingType.HorizontalAndVertical)
         {
             return "9-part";
         }
     }
     else
     {
         return "3-part-horizontal";
     }
     return "";
 }
Exemplo n.º 6
0
        void WriteResizingToJson(JsonElementDict item, ImageResizing resizing)
        {
            var docResizing = item.CreateDict("resizing");

            docResizing.SetString("mode", GetSlicingMode(resizing.type));

            var docCenter = docResizing.CreateDict("center");

            docCenter.SetString("mode", GetCenterResizeMode(resizing.centerResizeMode));
            docCenter.SetInteger("width", resizing.centerWidth);
            docCenter.SetInteger("height", resizing.centerHeight);

            var docInsets = docResizing.CreateDict("cap-insets");

            docInsets.SetInteger("top", resizing.top);
            docInsets.SetInteger("bottom", resizing.bottom);
            docInsets.SetInteger("left", resizing.left);
            docInsets.SetInteger("right", resizing.right);
        }
Exemplo n.º 7
0
 public void AddVariant(DeviceRequirement requirement, string path, ImageAlignment alignment, ImageResizing resizing)
 {
     this.AddVariant((AssetCatalogItemWithVariants.VariantData) new AssetImageSet.ImageSetVariant(requirement, path)
     {
         alignment = alignment,
         resizing  = resizing
     });
 }
Exemplo n.º 8
0
 public ImageSetVariant(DeviceRequirement requirement, string path) : base(requirement, path)
 {
     this.alignment = null;
     this.resizing = null;
 }
Exemplo n.º 9
0
 private void WriteResizingToJson(JsonElementDict item, ImageResizing resizing)
 {
     JsonElementDict dict = item.CreateDict("resizing");
     dict.SetString("mode", GetSlicingMode(resizing.type));
     JsonElementDict dict2 = dict.CreateDict("center");
     dict2.SetString("mode", GetCenterResizeMode(resizing.centerResizeMode));
     dict2.SetInteger("width", resizing.centerWidth);
     dict2.SetInteger("height", resizing.centerHeight);
     JsonElementDict dict3 = dict.CreateDict("cap-insets");
     dict3.SetInteger("top", resizing.top);
     dict3.SetInteger("bottom", resizing.bottom);
     dict3.SetInteger("left", resizing.left);
     dict3.SetInteger("right", resizing.right);
 }
Exemplo n.º 10
0
        public void AddVariant(DeviceRequirement requirement, string path, ImageAlignment alignment, ImageResizing resizing)
        {
            var imageset = new ImageSetVariant(requirement, path);

            imageset.alignment = alignment;
            imageset.resizing  = resizing;
            AddVariant(imageset);
        }
Exemplo n.º 11
0
        public void AddVariant(DeviceRequirement requirement, string path, ImageAlignment alignment, ImageResizing resizing)
        {
            ImageSetVariant newItem = new ImageSetVariant(requirement, path)
            {
                alignment = alignment,
                resizing  = resizing
            };

            base.AddVariant(newItem);
        }
Exemplo n.º 12
0
 public ImageSetVariant(DeviceRequirement requirement, string path) : base(requirement, path)
 {
     this.alignment = null;
     this.resizing  = null;
 }