private Frame.Region ParseRegion(JToken token) { var region = new Frame.Region(); var hAlignment = token.Value <string>("hplacement"); var vAlignment = token.Value <string>("vplacement"); var x = token.Value <int>("x"); var y = token.Value <int>("y"); var w = token.Value <int>("w"); var h = token.Value <int>("h"); // Assign trivialities region.Source = token.Value <string>("source"); region.Id = token.Value <string>("id"); region.SourceRegion.X = x; region.SourceRegion.Y = y; region.SourceRegion.Width = w; region.SourceRegion.Height = h; // Process each region's placement and set up the unified coordinates CalculateRegionPlacement(GetHorizontalPlacementIndex(hAlignment), w, _leftBorderWidth, _rightBorderWidth, ref region.DestinationRegion.Location.X, ref region.DestinationRegion.Size.X); CalculateRegionPlacement(GetVerticalPlacementIndex(vAlignment), h, _topBorderWidth, _bottomBorderWidth, ref region.DestinationRegion.Location.Y, ref region.DestinationRegion.Size.Y); return(region); }
private Frame.Region[] ParseRegions(JArray jArray) { var regions = new Frame.Region[jArray.Count]; _leftBorderWidth = 0; _rightBorderWidth = 0; _topBorderWidth = 0; _bottomBorderWidth = 0; // Detect borders foreach (var token in jArray) { var hPlacement = token.Value <string>("hplacement"); var vPlacement = token.Value <string>("vplacement"); if (hPlacement == "left") { _leftBorderWidth = Math.Max(_leftBorderWidth, token.Value <int>("w")); } else { if (hPlacement == "right") { _rightBorderWidth = Math.Max(_rightBorderWidth, token.Value <int>("w")); } } if (vPlacement == "top") { _topBorderWidth = Math.Max(_topBorderWidth, token.Value <int>("h")); } else { if (vPlacement == "bottom") { _bottomBorderWidth = Math.Max(_bottomBorderWidth, token.Value <int>("h")); } } } // Parse each region for (var i = 0; i < regions.Length; i++) { regions[i] = ParseRegion(jArray[i]); } return(regions); }