Exemplo n.º 1
0
        private static void AdjustImage(ElementConfig config, Image image, double xRatio, double yRatio)
        {
            uint newX = config.X = (uint)Math.Round(config.OriginalX * xRatio);
            uint newY = config.Y = (uint)Math.Round(config.OriginalY * yRatio);

            int newWidth  = (int)Math.Round(config.Width * xRatio);
            int newHeight = (int)Math.Round(config.Height * yRatio);

            image.Margin = new Thickness(newX, newY, 0, 0);
            image.Width  = newWidth;
            image.Height = newHeight;
        }
Exemplo n.º 2
0
        private static ElementConfig ParseStandardConfig(string skinPath, XElement elem)
        {
            IEnumerable <XAttribute> imageAttr = elem.Attributes("image");

            if (!imageAttr.Any())
            {
                throw new ConfigParseException("Attribute 'image' missing for element '" + elem.Name + "'.");
            }

            BitmapImage image = LoadImage(skinPath, imageAttr.First().Value);

            uint width = (uint)image.PixelWidth;
            IEnumerable <XAttribute> widthAttr = elem.Attributes("width");

            if (widthAttr.Any())
            {
                width = uint.Parse(widthAttr.First().Value, CultureInfo.CurrentCulture);
            }

            uint height = (uint)image.PixelHeight;
            IEnumerable <XAttribute> heightAttr = elem.Attributes("height");

            if (heightAttr.Any())
            {
                height = uint.Parse(heightAttr.First().Value, CultureInfo.CurrentCulture);
            }

            uint x = ReadUintAttr(elem, "x");
            uint y = ReadUintAttr(elem, "y");

            Collection <string> targetBgs = GetArrayAttr(elem, "target", false);
            Collection <string> ignoreBgs = GetArrayAttr(elem, "ignore", false);

            var ec = new ElementConfig
            {
                X              = x,
                Y              = y,
                OriginalX      = x,
                OriginalY      = y,
                Image          = image,
                Width          = width,
                OriginalWidth  = width,
                Height         = height,
                OriginalHeight = height,
            };

            ec.SetTargetBackgrounds(targetBgs);
            ec.SetIgnoreBackgrounds(ignoreBgs);

            return(ec);
        }
Exemplo n.º 3
0
        private static void AdjustGrid(ElementConfig config, Grid grid, double xRatio, double yRatio)
        {
            uint newX = config.X = (uint)Math.Round(config.OriginalX * xRatio);
            uint newY = config.Y = (uint)Math.Round(config.OriginalY * yRatio);

            uint newWidth  = config.Width = (uint)Math.Round(config.OriginalWidth * xRatio);
            uint newHeight = config.Height = (uint)Math.Round(config.OriginalHeight * yRatio);

            ((Image)grid.Children[0]).Width  = newWidth;
            ((Image)grid.Children[0]).Height = newHeight;

            grid.Margin = new Thickness(newX, newY, 0, 0);
            grid.Width  = newWidth;
            grid.Height = newHeight;
        }