示例#1
0
            /// <summary>
            ///   Creates and places the regions needed to be drawn to render the frame
            /// </summary>
            /// <param name="frameElement">
            ///   XML node for the frame containing the region
            /// </param>
            /// <param name="bitmaps">
            ///   Bitmap lookup table to associate a region's bitmap id to the real bitmap
            /// </param>
            /// <returns>The regions created for the frame</returns>
            private Frame.Region[] createAndPlaceRegions(
                XElement frameElement, IDictionary <string, Texture2D> bitmaps
                )
            {
                var regions = new List <Frame.Region>();

                // Fill all regions making up the current frame
                foreach (XElement element in frameElement.Descendants("region"))
                {
                    XAttribute idAttribute = element.Attribute("id");
                    string     id          = (idAttribute == null) ? null : idAttribute.Value;
                    string     source      = element.Attribute("source").Value;
                    string     hplacement  = element.Attribute("hplacement").Value;
                    string     vplacement  = element.Attribute("vplacement").Value;
                    string     x           = element.Attribute("x").Value;
                    string     y           = element.Attribute("y").Value;
                    string     w           = element.Attribute("w").Value;
                    string     h           = element.Attribute("h").Value;

                    // Assign the trivial attributes
                    var region = new Frame.Region()
                    {
                        Id      = id,
                        Texture = bitmaps[source]
                    };
                    region.SourceRegion.X      = int.Parse(x);
                    region.SourceRegion.Y      = int.Parse(y);
                    region.SourceRegion.Width  = int.Parse(w);
                    region.SourceRegion.Height = int.Parse(h);

                    // Process each region's placement and set up the unified coordinates
                    calculateRegionPlacement(
                        getHorizontalPlacementIndex(hplacement),
                        int.Parse(w),
                        this.leftBorderWidth,
                        this.rightBorderWidth,
                        ref region.DestinationRegion.Location.X,
                        ref region.DestinationRegion.Size.X
                        );
                    calculateRegionPlacement(
                        getVerticalPlacementIndex(vplacement),
                        int.Parse(h),
                        this.topBorderWidth,
                        this.bottomBorderWidth,
                        ref region.DestinationRegion.Location.Y,
                        ref region.DestinationRegion.Size.Y
                        );

                    regions.Add(region);
                }

                return(regions.ToArray());
            }
            /// <summary>
            ///   Creates and places the regions needed to be drawn to render the frame
            /// </summary>
            /// <param name="bitmaps">
            ///   Bitmap lookup table to associate a region's bitmap id to the real bitmap
            /// </param>
            /// <returns>The regions created for the frame</returns>
            private Frame.Region[] createAndPlaceRegions(IDictionary <string, Texture2D> bitmaps)
            {
                Frame.Region[] regions = new Frame.Region[this.regionNodes.Count];

                // Fill all regions making up the current frame
                for (int regionIndex = 0; regionIndex < this.regionNodes.Count; ++regionIndex)
                {
                    // Obtain all attributes of the region node
                    XmlAttribute idAttribute = this.regionNodes[regionIndex].Attributes["id"];
                    string       id          = (idAttribute == null) ? null : idAttribute.Value;
                    string       source      = this.regionNodes[regionIndex].Attributes["source"].Value;
                    string       hplacement  = this.regionNodes[regionIndex].Attributes["hplacement"].Value;
                    string       vplacement  = this.regionNodes[regionIndex].Attributes["vplacement"].Value;
                    string       x           = this.regionNodes[regionIndex].Attributes["x"].Value;
                    string       y           = this.regionNodes[regionIndex].Attributes["y"].Value;
                    string       w           = this.regionNodes[regionIndex].Attributes["w"].Value;
                    string       h           = this.regionNodes[regionIndex].Attributes["h"].Value;

                    // Assign the trivial attributes
                    regions[regionIndex].Id                  = id;
                    regions[regionIndex].Texture             = bitmaps[source];
                    regions[regionIndex].SourceRegion.X      = int.Parse(x);
                    regions[regionIndex].SourceRegion.Y      = int.Parse(y);
                    regions[regionIndex].SourceRegion.Width  = int.Parse(w);
                    regions[regionIndex].SourceRegion.Height = int.Parse(h);

                    // Process each region's placement and set up the unified coordinates
                    calculateRegionPlacement(
                        getHorizontalPlacementIndex(hplacement),
                        int.Parse(w),
                        this.leftBorderWidth,
                        this.rightBorderWidth,
                        ref regions[regionIndex].DestinationRegion.Location.X,
                        ref regions[regionIndex].DestinationRegion.Size.X
                        );
                    calculateRegionPlacement(
                        getVerticalPlacementIndex(vplacement),
                        int.Parse(h),
                        this.topBorderWidth,
                        this.bottomBorderWidth,
                        ref regions[regionIndex].DestinationRegion.Location.Y,
                        ref regions[regionIndex].DestinationRegion.Size.Y
                        );
                }

                return(regions);
            }
      /// <summary>
      ///   Creates and places the regions needed to be drawn to render the frame
      /// </summary>
      /// <param name="frameElement">
      ///   XML node for the frame containing the region
      /// </param>
      /// <param name="bitmaps">
      ///   Bitmap lookup table to associate a region's bitmap id to the real bitmap
      /// </param>
      /// <returns>The regions created for the frame</returns>
      private Frame.Region[] createAndPlaceRegions(
        XElement frameElement, IDictionary<string, Texture2D> bitmaps
      ) {
        var regions = new List<Frame.Region>();

        // Fill all regions making up the current frame
        foreach (XElement element in frameElement.Descendants("region")) {
          XAttribute idAttribute = element.Attribute("id");
          string id = (idAttribute == null) ? null : idAttribute.Value;
          string source = element.Attribute("source").Value;
          string hplacement = element.Attribute("hplacement").Value;
          string vplacement = element.Attribute("vplacement").Value;
          string x = element.Attribute("x").Value;
          string y = element.Attribute("y").Value;
          string w = element.Attribute("w").Value;
          string h = element.Attribute("h").Value;

          // Assign the trivial attributes
          var region = new Frame.Region() {
            Id = id,
            Texture = bitmaps[source]
          };
          region.SourceRegion.X = int.Parse(x);
          region.SourceRegion.Y = int.Parse(y);
          region.SourceRegion.Width = int.Parse(w);
          region.SourceRegion.Height = int.Parse(h);

          // Process each region's placement and set up the unified coordinates
          calculateRegionPlacement(
            getHorizontalPlacementIndex(hplacement),
            int.Parse(w),
            this.leftBorderWidth,
            this.rightBorderWidth,
            ref region.DestinationRegion.Location.X,
            ref region.DestinationRegion.Size.X
          );
          calculateRegionPlacement(
            getVerticalPlacementIndex(vplacement),
            int.Parse(h),
            this.topBorderWidth,
            this.bottomBorderWidth,
            ref region.DestinationRegion.Location.Y,
            ref region.DestinationRegion.Size.Y
          );

          regions.Add(region);
        }

        return regions.ToArray();
      }
      /// <summary>
      ///   Creates and places the regions needed to be drawn to render the frame
      /// </summary>
      /// <param name="bitmaps">
      ///   Bitmap lookup table to associate a region's bitmap id to the real bitmap
      /// </param>
      /// <returns>The regions created for the frame</returns>
      private Frame.Region[] createAndPlaceRegions(IDictionary<string, Texture2D> bitmaps) {
        Frame.Region[] regions = new Frame.Region[this.regionNodes.Count];

        // Fill all regions making up the current frame
        for (int regionIndex = 0; regionIndex < this.regionNodes.Count; ++regionIndex) {

          // Obtain all attributes of the region node
          XmlAttribute idAttribute = this.regionNodes[regionIndex].Attributes["id"];
          string id = (idAttribute == null) ? null : idAttribute.Value;
          string source = this.regionNodes[regionIndex].Attributes["source"].Value;
          string hplacement = this.regionNodes[regionIndex].Attributes["hplacement"].Value;
          string vplacement = this.regionNodes[regionIndex].Attributes["vplacement"].Value;
          string x = this.regionNodes[regionIndex].Attributes["x"].Value;
          string y = this.regionNodes[regionIndex].Attributes["y"].Value;
          string w = this.regionNodes[regionIndex].Attributes["w"].Value;
          string h = this.regionNodes[regionIndex].Attributes["h"].Value;

          // Assign the trivial attributes
          regions[regionIndex].Id = id;
          regions[regionIndex].Texture = bitmaps[source];
          regions[regionIndex].SourceRegion.X = int.Parse(x);
          regions[regionIndex].SourceRegion.Y = int.Parse(y);
          regions[regionIndex].SourceRegion.Width = int.Parse(w);
          regions[regionIndex].SourceRegion.Height = int.Parse(h);

          // Process each region's placement and set up the unified coordinates
          calculateRegionPlacement(
            getHorizontalPlacementIndex(hplacement),
            int.Parse(w),
            this.leftBorderWidth,
            this.rightBorderWidth,
            ref regions[regionIndex].DestinationRegion.Location.X,
            ref regions[regionIndex].DestinationRegion.Size.X
          );
          calculateRegionPlacement(
            getVerticalPlacementIndex(vplacement),
            int.Parse(h),
            this.topBorderWidth,
            this.bottomBorderWidth,
            ref regions[regionIndex].DestinationRegion.Location.Y,
            ref regions[regionIndex].DestinationRegion.Size.Y
          );

        }

        return regions;
      }